Four shell test suites leaked one temp directory into /tmp per fixture. On the dev host that came to about 1,700 leftover git repos in a single day.
The fixture helpers did dir="$(mktemp -d)"; CLEANUP_DIRS+=("$dir"), and callers ran them as R="$(new_repo)". Because $(...) runs the helper in a subshell, the array append was lost when that subshell exited. The parent's EXIT trap then ran rm -rf over an empty array.
Fix
Each script now creates one RUN_TMP root up front with trap 'rm -rf "$RUN_TMP"' EXIT. Every fixture is created under it with mktemp -d "$RUN_TMP/fx.XXXXXX", so cleanup works no matter which shell made the fixture. The CLEANUP_DIRS/FIXTURES arrays are removed.
Files:
tests/test-tag-plugin-releases.sh
tests/test-skill-version-bump.sh
tests/test-check-executables-allow-sync.sh
tests/test-check-provenance-corpus.sh
test-check-scope-walkup-sync.sh was checked and is not affected, because its caller registers fixtures outside the subshell.
Verification
Each suite was run with TMPDIR set to an empty scratch dir. The numbers are dirs left behind per run:
Suite
main
this branch
Tests
tag-plugin-releases
31
0
194 pass / 0 fail
skill-version-bump
54
0
89 / 0
executables-allow-sync
22
0
38 / 0
provenance-corpus
9
0
13 / 0
A separate clean-context review found no blocking issues: one trap per script, no leftover array references under set -u, quoting correct, and no assertions changed. The full pre-push suite passes.
Follow-up (not in this PR)
Other test scripts still use plain mktemp -d inside $(...), the same pattern that leaked here. Examples: test-check-scope-walkup-sync.sh:37, test-check-apm-agents-valid.sh:76, test-apm-hooks-git-env.sh:68. They have not been checked for actual leaks.
## Problem
Four shell test suites leaked one temp directory into `/tmp` per fixture. On the dev host that came to about 1,700 leftover git repos in a single day.
The fixture helpers did `dir="$(mktemp -d)"; CLEANUP_DIRS+=("$dir")`, and callers ran them as `R="$(new_repo)"`. Because `$(...)` runs the helper in a subshell, the array append was lost when that subshell exited. The parent's EXIT trap then ran `rm -rf` over an empty array.
## Fix
Each script now creates one `RUN_TMP` root up front with `trap 'rm -rf "$RUN_TMP"' EXIT`. Every fixture is created under it with `mktemp -d "$RUN_TMP/fx.XXXXXX"`, so cleanup works no matter which shell made the fixture. The `CLEANUP_DIRS`/`FIXTURES` arrays are removed.
Files:
- `tests/test-tag-plugin-releases.sh`
- `tests/test-skill-version-bump.sh`
- `tests/test-check-executables-allow-sync.sh`
- `tests/test-check-provenance-corpus.sh`
`test-check-scope-walkup-sync.sh` was checked and is not affected, because its caller registers fixtures outside the subshell.
## Verification
Each suite was run with `TMPDIR` set to an empty scratch dir. The numbers are dirs left behind per run:
| Suite | main | this branch | Tests |
|---|---|---|---|
| tag-plugin-releases | 31 | 0 | 194 pass / 0 fail |
| skill-version-bump | 54 | 0 | 89 / 0 |
| executables-allow-sync | 22 | 0 | 38 / 0 |
| provenance-corpus | 9 | 0 | 13 / 0 |
A separate clean-context review found no blocking issues: one trap per script, no leftover array references under `set -u`, quoting correct, and no assertions changed. The full pre-push suite passes.
## Follow-up (not in this PR)
Other test scripts still use plain `mktemp -d` inside `$(...)`, the same pattern that leaked here. Examples: `test-check-scope-walkup-sync.sh:37`, `test-check-apm-agents-valid.sh:76`, `test-apm-hooks-git-env.sh:68`. They have not been checked for actual leaks.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_014uGZTPYvyvTNkv7Z9wAcEc
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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Problem
Four shell test suites leaked one temp directory into
/tmpper fixture. On the dev host that came to about 1,700 leftover git repos in a single day.The fixture helpers did
dir="$(mktemp -d)"; CLEANUP_DIRS+=("$dir"), and callers ran them asR="$(new_repo)". Because$(...)runs the helper in a subshell, the array append was lost when that subshell exited. The parent's EXIT trap then ranrm -rfover an empty array.Fix
Each script now creates one
RUN_TMProot up front withtrap 'rm -rf "$RUN_TMP"' EXIT. Every fixture is created under it withmktemp -d "$RUN_TMP/fx.XXXXXX", so cleanup works no matter which shell made the fixture. TheCLEANUP_DIRS/FIXTURESarrays are removed.Files:
tests/test-tag-plugin-releases.shtests/test-skill-version-bump.shtests/test-check-executables-allow-sync.shtests/test-check-provenance-corpus.shtest-check-scope-walkup-sync.shwas checked and is not affected, because its caller registers fixtures outside the subshell.Verification
Each suite was run with
TMPDIRset to an empty scratch dir. The numbers are dirs left behind per run:A separate clean-context review found no blocking issues: one trap per script, no leftover array references under
set -u, quoting correct, and no assertions changed. The full pre-push suite passes.Follow-up (not in this PR)
Other test scripts still use plain
mktemp -dinside$(...), the same pattern that leaked here. Examples:test-check-scope-walkup-sync.sh:37,test-check-apm-agents-valid.sh:76,test-apm-hooks-git-env.sh:68. They have not been checked for actual leaks.🤖 Generated with Claude Code
https://claude.ai/code/session_014uGZTPYvyvTNkv7Z9wAcEc