fix(tests): stop fixture helpers leaking temp dirs into /tmp

Why: new_repo/make_fixture/make_repo created a mktemp dir and appended
it to the cleanup array, but every caller runs them as R="$(helper)".
The append happens in that command-substitution subshell and is lost,
so the EXIT trap removed nothing. Each run leaked one dir per call:
31, 54, 22 and 9 for the four suites, about 1,700 dirs on one day.

Implementation Notes:
- Each suite creates one RUN_TMP root up front with a single
  `trap 'rm -rf "$RUN_TMP"' EXIT`; every fixture is `mktemp -d` under
  it, so cleanup no longer depends on where the helper runs.
- The CLEANUP_DIRS / FIXTURES arrays are gone from these four suites.
- test-check-scope-walkup-sync.sh and test-check-apm-agents-valid.sh
  already register fixtures in the caller and are unchanged.

Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-11-28 14:40:47 +00:00
1 parent 8ffff54fbc
commit da88cd8d32
4 files changed
+29 -30

No files matched your search

+8 -7
View File
@@ -20,8 +20,10 @@ fi
# Output assertions use here-strings, never `echo | grep -q` (pipefail race;
# see docs/spec/gates.md, Tests).
CLEANUP_DIRS=()
trap 'rm -rf ${CLEANUP_DIRS[@]+"${CLEANUP_DIRS[@]}"}' EXIT
# One root per run: fixture helpers run inside $(...) subshells, where an
# array append never reaches the parent's trap, so register the root instead.
RUN_TMP="$(mktemp -d)"
trap 'rm -rf "$RUN_TMP"' EXIT
# write_skill <repo> <plugin> <skill> <version-line|""> [body]
# An empty version line writes a SKILL.md with no metadata block at all.
@@ -48,8 +50,7 @@ commit() { (cd "$1" && git add -A && git commit -q -m "${2:-change}"); }
# onto a feature branch.
make_fixture() {
local dir
dir="$(mktemp -d)"
CLEANUP_DIRS+=("$dir")
dir="$(mktemp -d "$RUN_TMP/fx.XXXXXX")"
(cd "$dir" && git init -q -b main && git config user.email [email protected] && git config user.name t)
write_skill "$dir" demo alpha 'version: "1.0.0"'
write_skill "$dir" demo beta "version: 1.0.9"
@@ -255,7 +256,7 @@ expect_fail "the report names alpha and the versions read from origin/main's mer
echo ""
echo "--- 19. no main ref fails closed ---"
F="$(mktemp -d)"; CLEANUP_DIRS+=("$F")
F="$(mktemp -d "$RUN_TMP/fx.XXXXXX")"
(cd "$F" && git init -q -b trunk && git config user.email [email protected] && git config user.name t)
write_skill "$F" demo alpha 'version: "1.0.0"'; commit "$F"
expect_fail "missing main fails with a clear message" "neither origin/main nor main resolves" "$F"
@@ -323,7 +324,7 @@ expect_pass "a zero inside a part (1.0.10) is not a leading zero" "$F"
echo ""
echo "--- 24. python3 / PyYAML failures are never reported as a missing version ---"
REAL_PYTHON="$(command -v python3)"
SHIM_ROOT="$(mktemp -d)"; CLEANUP_DIRS+=("$SHIM_ROOT")
SHIM_ROOT="$(mktemp -d "$RUN_TMP/fx.XXXXXX")"
mkdir -p "$SHIM_ROOT/shadow" "$SHIM_ROOT/noyaml" "$SHIM_ROOT/crash"
printf 'raise ImportError("PyYAML deliberately unavailable in this fixture")\n' \
> "$SHIM_ROOT/shadow/yaml.py"
@@ -602,7 +603,7 @@ echo "--- 40. a criss-cross history is judged against EVERY merge-base ---"
# +-- feature: F1 bumps alpha to 1.0.1
# +-- main: M1 unrelated, then M2 merges F1
# feature: F2 merges M1 -> merge bases {M1, F1}
F="$(mktemp -d)"; CLEANUP_DIRS+=("$F")
F="$(mktemp -d "$RUN_TMP/fx.XXXXXX")"
(cd "$F" && git init -q -b main && git config user.email [email protected] && git config user.name t)
write_skill "$F" demo alpha 'version: "1.0.0"'; commit "$F" C0
(cd "$F" && git checkout -q -b feature)