test(hook): assert the seam precondition and self-diagnose CI failures

The conflict regression went red on six CI legs with an unhelpful
message: every probe produced empty stderr, which reads as "the notice
is missing" when it actually means no conflict was ever raised. Three
changes, all diagnosis rather than tolerance:

- Assert the binary carries the hook-client seam up front, failing with
  the rebuild hint, exactly as tests/test_worker_watchdog.sh does for
  the crash-orphan probe. A seam-less binary can never raise the
  conflict, and that must be said plainly rather than inferred from a
  silent backstop expiry.
- Drop the `seq`-derived fingerprint for a literal 64-char constant
  (length-checked), removing a dependency on a tool whose presence
  varies across the MSYS2/macOS/Linux legs.
- On backstop expiry, dump stdout, the forced fingerprint and its
  length, and daemon status, so the next run names the cause instead of
  requiring another round trip.

Still green locally (seam-bearing binary): the conflict is observed and
the systemMessage asserted.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
This commit is contained in:
Martin Vogel
2026-08-05 13:14:14 +02:00
parent 92e5983e50
commit e0d229fc65
+23 -2
View File
@@ -16,6 +16,17 @@ if [[ ! -x "${BINARY}" ]]; then
exit 2
fi
# PRECONDITION, not a skip (same doctrine as tests/test_worker_watchdog.sh): this
# test drives the hook-client build seam, which is compiled out of ordinary
# builds. Against a seam-less binary no conflict can ever occur and the failure
# would read as "the notice is missing" instead of "the capability is absent".
if ! LC_ALL=C grep -a -q -F 'CBM_TEST_HOOK_CLIENT_BUILD' "${BINARY}"; then
echo "binary lacks the hook-client build seam: ${BINARY}" >&2
echo " rebuild it with: make -f Makefile.cbm cbm TEST_SEAMS=1" >&2
echo " or run this test through scripts/test.sh, which does that for you." >&2
exit 2
fi
tmpdir="$(mktemp -d)"
cleanup() {
CBM_CACHE_DIR="${tmpdir}/cache" "${BINARY}" daemon stop >/dev/null 2>&1 || true
@@ -29,7 +40,11 @@ if ! CBM_CACHE_DIR="${tmpdir}/cache" "${BINARY}" daemon start >"${tmpdir}/daemon
exit 2
fi
payload='{"session_id":"probe","hook_event_name":"PreToolUse","tool_name":"Grep","tool_input":{"pattern":"x","path":"/tmp"},"cwd":"/tmp"}'
forced_build="$(printf 'f%.0s' $(seq 1 64))"
forced_build="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
if [[ ${#forced_build} -ne 64 ]]; then
echo "internal: forced fingerprint must be 64 hex chars, got ${#forced_build}" >&2
exit 2
fi
# The daemon's cohort join completes asynchronously after `daemon start`
# returns. Wait for the STATE the assertion needs - a probe that observes the
@@ -62,8 +77,14 @@ if ! grep -q "conflicting CBM process" "${tmpdir}/probe.err"; then
echo "never became active, or this is not a TEST_SEAMS=1 binary" >&2
echo "--- daemon-start.log ---" >&2
cat "${tmpdir}/daemon-start.log" >&2
echo "--- last probe stderr ---" >&2
echo "--- last probe stderr (empty means no conflict was raised) ---" >&2
cat "${tmpdir}/probe.err" >&2
echo "--- last probe stdout ---" >&2
printf '%s\n' "${out}" >&2
echo "--- diagnosis ---" >&2
echo "forced_build=${forced_build} (len ${#forced_build})" >&2
echo "seam present in binary: yes (asserted above)" >&2
CBM_CACHE_DIR="${tmpdir}/cache" "${BINARY}" daemon status >&2 2>&1 || true
exit 2
fi
if ! printf '%s' "${out}" | grep -q "systemMessage"; then