From d41c678172a5fc45ffce72fc9993c041bda78df0 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Sat, 5 Dec 2026 20:17:38 +0700 Subject: [PATCH] fix(session): use guarded mktemp template and cleanup in smoke test Replace bare mktemp -d at lib/session/observe/tests/smoke.sh:132 with an explicit TMPDIR template and failure guard (rules R1 and R3 of test-mktemp-template-guard), and remove the temporary stub directory on exit and test completion. --- .../smoke-mktemp-template-guard.md | 48 +++++++++++++++++++ lib/session/observe/tests/smoke.sh | 4 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 docs/verification/smoke-mktemp-template-guard.md diff --git a/docs/verification/smoke-mktemp-template-guard.md b/docs/verification/smoke-mktemp-template-guard.md new file mode 100644 index 00000000..66a0ea85 --- /dev/null +++ b/docs/verification/smoke-mktemp-template-guard.md @@ -0,0 +1,48 @@ +# Verification: smoke-mktemp-template-guard + +`lib/session/observe/tests/smoke.sh` created a temporary stub directory with a bare `stub="$(mktemp -d)"` and never removed it, failing `tests/test-mktemp-template-guard.sh` rules R1 and R3 on `ubuntu-latest` and `macos-latest`. Line 132 now uses an explicit `${TMPDIR:-/tmp}` template with `|| exit 1`, registers an `EXIT` trap (`trap 'rm -rf "${stub:-}"' EXIT`), and removes `$stub` once case `[30b]` completes. + +## Green run + +``` +Command: bash tests/test-mktemp-template-guard.sh +Exit: 0 +Output: +=== G1: the live tree has no bare mktemp and no unguarded test use === + PASS scanned 877 files + PASS no violations +=== 11 passed, 0 failed === +Verdict: PASS +``` + +``` +Command: bash lib/session/observe/tests/smoke.sh +Exit: 0 +Output: +[30b] session-semantic: the default command asks for Haiku (stub claude on PATH) + ok: default command pins --model haiku +smoke: all 120 passed +Verdict: PASS +``` + +Running `smoke.sh` with an isolated `TMPDIR` leaves zero `session-observe-smoke.*` directories behind after exit. + +## Negative control + +Before the fix (at `origin/master` `b6c9545b`, with bare `stub="$(mktemp -d)"` at `lib/session/observe/tests/smoke.sh:132`): + +``` +Command: bash tests/test-mktemp-template-guard.sh +Exit: 1 +Output: +=== G1: the live tree has no bare mktemp and no unguarded test use === + PASS scanned 877 files + FAIL violations: +R1 lib/session/observe/tests/smoke.sh:132: stub="$(mktemp -d)" +=== 10 passed, 1 failed === +Verdict: RED, as expected +``` + +## Rollback + +Revert the commit. The change is limited to a test script and holds no persistent state. diff --git a/lib/session/observe/tests/smoke.sh b/lib/session/observe/tests/smoke.sh index 12d5c9d3..60f278a8 100755 --- a/lib/session/observe/tests/smoke.sh +++ b/lib/session/observe/tests/smoke.sh @@ -129,10 +129,12 @@ echo "[30] session-semantic --json: valid JSON with status ok" if SESSION_SEMANTIC_CMD="cat $SEMOUT" "$CS" --root "$DIR/tests/fixtures" --days 0 --json | python3 -m json.tool >/dev/null 2>&1; then ok "valid json"; else no "json invalid"; fi echo "[30b] session-semantic: the default command asks for Haiku (stub claude on PATH)" -stub="$(mktemp -d)" +stub="$(mktemp -d "${TMPDIR:-/tmp}/session-observe-smoke.XXXXXX")" || exit 1 +trap 'rm -rf "${stub:-}"' EXIT printf '#!/bin/sh\nprintf "%%s\\n" "$*" > "%s/args"\ncat "%s"\n' "$stub" "$SEMOUT" > "$stub/claude"; chmod +x "$stub/claude" (unset SESSION_SEMANTIC_CMD; PATH="$stub:$PATH" "$CS" --root "$DIR/tests/fixtures" --days 0 >/dev/null 2>&1) if grep -q -- '--model haiku' "$stub/args" 2>/dev/null; then ok "default command pins --model haiku"; else no "default command has no model pin: $(cat "$stub/args" 2>/dev/null)"; fi +rm -rf "$stub" echo "[31] skills --latency: tiny-frequent total 150ms over 3 fires (max 50)" out="$("$CC" skills --latency --file "$LFIX")"