Skip to content

Commit 92e5983

Browse files
committed
test(hook): wait for the daemon cohort before asserting the conflict notice
The daemon's cohort join completes asynchronously after 'daemon start' returns; on slower CI hosts the single probe landed pre-cohort, never observed the conflict, and the seam guard failed the leg. Poll for the asserted state (a probe observing the build conflict) with a bounded backstop, clearing the throttled notice marker before each probe so the stdout assertion holds on whichever probe first sees the conflict. Daemon-start failures and backstop exhaustion now dump diagnostics. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 716f1d6 commit 92e5983

1 file changed

Lines changed: 35 additions & 13 deletions

File tree

‎tests/test_hook_conflict_notice.sh‎

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,46 @@ cleanup() {
2323
}
2424
trap cleanup EXIT
2525

26-
CBM_CACHE_DIR="${tmpdir}/cache" "${BINARY}" daemon start >/dev/null 2>&1
26+
if ! CBM_CACHE_DIR="${tmpdir}/cache" "${BINARY}" daemon start >"${tmpdir}/daemon-start.log" 2>&1; then
27+
echo "daemon start failed on this host - cannot exercise the conflict path" >&2
28+
cat "${tmpdir}/daemon-start.log" >&2
29+
exit 2
30+
fi
2731
payload='{"session_id":"probe","hook_event_name":"PreToolUse","tool_name":"Grep","tool_input":{"pattern":"x","path":"/tmp"},"cwd":"/tmp"}'
2832
forced_build="$(printf 'f%.0s' $(seq 1 64))"
2933

30-
set +e
31-
out="$(printf '%s' "${payload}" | CBM_CACHE_DIR="${tmpdir}/cache" \
32-
CBM_TEST_HOOK_CLIENT_BUILD="${forced_build}" \
33-
"${BINARY}" hook-augment 2>"${tmpdir}/probe.err")"
34-
rc=$?
35-
set -e
34+
# The daemon's cohort join completes asynchronously after `daemon start`
35+
# returns. Wait for the STATE the assertion needs - a probe that observes the
36+
# build conflict - with a bounded liveness backstop; never a bare sleep. The
37+
# throttled notice marker is cleared before each probe so the stdout
38+
# assertion stays valid on whichever probe first observes the conflict.
39+
rc=0
40+
out=""
41+
for _attempt in $(seq 1 40); do
42+
rm -f "${tmpdir}/cache/.hook-daemon-absent-notice"
43+
set +e
44+
out="$(printf '%s' "${payload}" | CBM_CACHE_DIR="${tmpdir}/cache" \
45+
CBM_TEST_HOOK_CLIENT_BUILD="${forced_build}" \
46+
"${BINARY}" hook-augment 2>"${tmpdir}/probe.err")"
47+
rc=$?
48+
set -e
49+
if [[ ${rc} -ne 0 ]]; then
50+
echo "hook-augment must fail open (exit 0); got ${rc}" >&2
51+
cat "${tmpdir}/probe.err" >&2
52+
exit 1
53+
fi
54+
if grep -q "conflicting CBM process" "${tmpdir}/probe.err"; then
55+
break
56+
fi
57+
sleep 0.5
58+
done
3659

37-
if [[ ${rc} -ne 0 ]]; then
38-
echo "hook-augment must fail open (exit 0); got ${rc}" >&2
39-
cat "${tmpdir}/probe.err" >&2
40-
exit 1
41-
fi
4260
if ! grep -q "conflicting CBM process" "${tmpdir}/probe.err"; then
43-
echo "seam did not produce a build conflict - is this a TEST_SEAMS=1 binary?" >&2
61+
echo "no probe observed the build conflict within the backstop - daemon cohort" >&2
62+
echo "never became active, or this is not a TEST_SEAMS=1 binary" >&2
63+
echo "--- daemon-start.log ---" >&2
64+
cat "${tmpdir}/daemon-start.log" >&2
65+
echo "--- last probe stderr ---" >&2
4466
cat "${tmpdir}/probe.err" >&2
4567
exit 2
4668
fi

0 commit comments

Comments
 (0)