Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(test): arm smoke runtime cleanup at init, retire the daemon first

Anton Standrikfa138acf4452
diff --git a/scripts/smoke-test.sh b/scripts/smoke-test.sh
index e996da847..d1c64c6b7 100755
--- a/scripts/smoke-test.sh
+++ b/scripts/smoke-test.sh
@@ -51,6 +51,11 @@ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")/.." && pwd)"
# shellcheck source=test-runtime.sh
source "$REPO_ROOT/scripts/test-runtime.sh"
cbm_test_runtime_init
+# Armed here rather than only with the fixture trap below: the fixture mktemp
+# and its cygpath conversion sit between the two, and under `set -e` a failure
+# there would otherwise leave the private root behind. The fixture trap
+# replaces this one and keeps the same cleanup as its first step.
+trap 'cbm_test_runtime_cleanup "$BINARY"' EXIT
smoke_mktemp_file() {
if [ -n "${SMOKE_TEMP_ROOT:-}" ]; then
@@ -160,7 +165,11 @@ CODEX_LIFECYCLE_HOME=""
if command -v cygpath &>/dev/null; then
TMPDIR=$(cygpath -m "$TMPDIR")
fi
-trap 'smoke_rmtree "$TMPDIR" "${DRYRUN_HOME:-}" "${CODEX_LIFECYCLE_HOME:-}"; cbm_test_runtime_cleanup "$BINARY"' EXIT
+# Runtime cleanup first, so no earlier cleanup step stands between the exit
+# and the private daemon's retirement; on Windows that retirement is also what
+# unblocks the fixture rm (mapped binary, open logs). smoke_rmtree never fails,
+# so the fixture removal still runs after it.
+trap 'cbm_test_runtime_cleanup "$BINARY"; smoke_rmtree "$TMPDIR" "${DRYRUN_HOME:-}" "${CODEX_LIFECYCLE_HOME:-}"' EXIT
CLI_STDERR=$(smoke_mktemp_file)
# 10 of the cli call sites assign directly (VAR=$(cli ...)). Under
diff --git a/tests/test_smoke_runtime_isolation_contract.sh b/tests/test_smoke_runtime_isolation_contract.sh
index e91e1d38d..31ba7a7b6 100755
--- a/tests/test_smoke_runtime_isolation_contract.sh
+++ b/tests/test_smoke_runtime_isolation_contract.sh
@@ -79,4 +79,25 @@ done < "$ENV_LOG"
[[ ! -e "$private_root" ]] || fail "smoke-test left its private root behind: $private_root"
+# The run above exits through the fixture trap, so it cannot show what happens
+# to the private root when the harness dies before that trap exists — the
+# fixture mktemp and its cygpath conversion are in that window, and under
+# `set -e` either can end the run. Reproducing that failure would mean scanning
+# the shared /tmp parent for orphaned roots, which races every other harness
+# test in the same suite, so pin the ordering instead: the cleanup trap is
+# armed between the init call and the first fixture work.
+smoke="$ROOT/scripts/smoke-test.sh"
+smoke_line_of() {
+ # A missing pattern is the failure this check reports, not a reason to end
+ # the test silently under `set -e`.
+ grep -n "$1" "$smoke" | head -1 | cut -d: -f1 || true
+}
+init_line=$(smoke_line_of '^cbm_test_runtime_init$')
+early_trap_line=$(smoke_line_of "^trap 'cbm_test_runtime_cleanup \"\$BINARY\"' EXIT\$")
+fixture_line=$(smoke_line_of '^TMPDIR=\$(smoke_mktemp_dir)$')
+if [[ -z "$init_line" || -z "$early_trap_line" || -z "$fixture_line" ]] ||
+ ((early_trap_line < init_line || early_trap_line > fixture_line)); then
+ fail "smoke-test must arm the runtime cleanup trap between cbm_test_runtime_init and its first fixture"
+fi
+
echo "PASS: smoke harness isolates its daemon runtime and cache from the caller"