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

Merged
Defame1297 merged 1 commits from fix/test-fixture-tmp-leak into main 2026-11-28 17:37:13 +00:00
Owner

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.ai/code/session_014uGZTPYvyvTNkv7Z9wAcEc

## 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
Claude added 1 commit 2026-11-28 17:04:10 +00:00
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
Defame1297 approved these changes 2026-11-28 17:37:03 +00:00
Defame1297 merged commit 4380dd03ce into main 2026-11-28 17:37:13 +00:00
Defame1297 deleted branch fix/test-fixture-tmp-leak 2026-11-28 17:37:15 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Holocron#242