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:
1 parent
8ffff54fbc
commit
da88cd8d32
4 files changed
+29
-30
No files matched your search
@@ -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"
|
||||
|
||||
|
||||
Reference in new issue
Block a user