Compare commits

...
1 Commits
Author SHA1 Message Date
Defame1297 da88cd8d32 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
2026-11-28 14:40:47 +00:00
4 changed files with 29 additions and 30 deletions

No files matched your search

+7 -7
View File
@@ -26,17 +26,17 @@ fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); }
command -v python3 > /dev/null 2>&1 || { echo "SKIP: python3 is required to exercise the PyYAML reader"; exit 77; }
python3 -c 'import yaml' > /dev/null 2>&1 || { echo "SKIP: PyYAML is required to exercise the PyYAML reader"; exit 77; }
FIXTURES=()
cleanup() { [[ ${#FIXTURES[@]} -eq 0 ]] || rm -rf "${FIXTURES[@]}"; }
trap cleanup 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
# make_fixture <plugin-version-line> <root-executables-block>
# The executables block is passed verbatim (may be empty) so a fixture can omit
# it entirely, which is one of the failure modes under test.
make_fixture() {
local version_line="$1" executables_block="$2" dir
dir="$(mktemp -d)"
FIXTURES+=("$dir")
dir="$(mktemp -d "$RUN_TMP/fx.XXXXXX")"
# kyberforge ships both hooks and bin, which is what makes the gate check it.
mkdir -p "$dir/plugins/kyberforge/.apm/hooks" "$dir/plugins/kyberforge/bin"
@@ -196,7 +196,7 @@ run_gate "$REPO_ROOT/definitely-not-a-directory"
|| fail "a bad path must not exit 0 — that reads as 'checked, in sync'"
# No executable-shipping plugin at all is the one legitimate no-op: nothing to pin.
NO_PLUGIN="$(mktemp -d)"; FIXTURES+=("$NO_PLUGIN")
NO_PLUGIN="$(mktemp -d "$RUN_TMP/fx.XXXXXX")"
echo "name: someone-else" > "$NO_PLUGIN/apm.yml"
run_gate "$NO_PLUGIN"
[[ $GATE_RC -eq 0 ]] && pass "no-ops in a repo with no executable-shipping plugin" \
@@ -290,7 +290,7 @@ echo "--- the fallback reader agrees with the PyYAML reader ---"
# hook needs it), so the shape-scan fallback carries the same verdicts. Masking
# is done with a python3 stub whose `import yaml` fails, which is the exact
# condition on a machine that has python3 without PyYAML.
NO_YAML_BIN="$(mktemp -d)"; FIXTURES+=("$NO_YAML_BIN")
NO_YAML_BIN="$(mktemp -d "$RUN_TMP/fx.XXXXXX")"
printf '#!/usr/bin/env bash\nexit 1\n' > "$NO_YAML_BIN/python3"
chmod +x "$NO_YAML_BIN/python3"
+6 -9
View File
@@ -10,14 +10,12 @@ FAIL=0
pass() { echo " PASS: $1"; PASS=$((PASS + 1)); }
fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); }
FIXTURES=()
cleanup() { [[ ${#FIXTURES[@]} -eq 0 ]] || rm -rf "${FIXTURES[@]}"; }
trap cleanup EXIT
# Per-run scratch for captured output, for the reason check-scope-walkup-sync's
# test gives: tests/run-tests.sh fans test scripts out concurrently.
# Per-run scratch for output and fixtures, for the reason check-scope-walkup-sync's
# test gives: tests/run-tests.sh fans test scripts out concurrently. Fixtures live
# under it because make_repo runs in a $(...) subshell, where an array append never
# reaches the parent's trap.
RUN_TMP="$(mktemp -d)"
FIXTURES+=("$RUN_TMP")
trap 'rm -rf "$RUN_TMP"' EXIT
# A minimal REPO_ROOT: a .git entry (the validator's find_repo_root stops at
# it), a copy of the real validator at its real relative path, and one plugin
@@ -25,8 +23,7 @@ FIXTURES+=("$RUN_TMP")
# exercise the actual FAIL/INFO/exit contract rather than a stub of it.
make_repo() {
local dir
dir="$(mktemp -d)"
FIXTURES+=("$dir")
dir="$(mktemp -d "$RUN_TMP/fx.XXXXXX")"
mkdir -p "$dir/.git" "$dir/$VALIDATOR_DIR" "$dir/plugins/p/docs/research/docs/t"
cp -R "$REPO_ROOT/$VALIDATOR_DIR/." "$dir/$VALIDATOR_DIR/"
cat > "$dir/plugins/p/docs/research/docs/t/sources.md" <<'EOF'
+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)
+8 -7
View File
@@ -23,13 +23,14 @@ unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR
# 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
new_repo() {
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 \
&& git config tag.gpgSign false && git config commit.gpgSign false)
echo "$dir"
@@ -150,7 +151,7 @@ expect_rc "same tag on the right commit" 0
expect_row "row is OK" delta 2.0.0 "$BUMP" OK
echo "Case 6: shallow clone exits 2"
S="$(mktemp -d)"; CLEANUP_DIRS+=("$S")
S="$(mktemp -d "$RUN_TMP/fx.XXXXXX")"
git clone -q --depth 1 "file://$R" "$S/c" 2>/dev/null
run "$S/c"
expect_rc "shallow clone" 2
@@ -370,7 +371,7 @@ expect_row "ua 1.1.0 MISSING after the one-off" ua 1.1.0 "$U2" MISSING
echo "Case 12l: default ref is origin/main, not local main"
R="$(new_repo)"
write_apm "$R" va 1.0.0; commit "$R" a; V1="$(head_sha "$R")"
B="$(mktemp -d)"; CLEANUP_DIRS+=("$B")
B="$(mktemp -d "$RUN_TMP/fx.XXXXXX")"
git init -q --bare "$B/r.git"
(cd "$R" && git remote add origin "$B/r.git" && git push -q origin main 2>/dev/null)
write_apm "$R" va 2.0.0; commit "$R" local-only
@@ -544,7 +545,7 @@ expect_row "next version MISSING" om 1.3.0 "$OM4" MISSING
echo "Case 12u: a git rev-list failure or an empty history exits 2, not a crash"
R="$(new_repo)"
write_apm "$R" rl 1.0.0; commit "$R" a
W="$(mktemp -d)"; CLEANUP_DIRS+=("$W")
W="$(mktemp -d "$RUN_TMP/fx.XXXXXX")"
REAL_GIT="$(command -v git)"
cat > "$W/git" <<EOF
#!/usr/bin/env bash