Skip to content

test(#110): stop bun test from leaving scratch dirs under tests/ - #125

Merged
bigknoxy merged 1 commit into
mainfrom
fix/110-test-scratch-cleanup
Aug 19, 2026
Merged

test(#110): stop bun test from leaving scratch dirs under tests/#125
bigknoxy merged 1 commit into
mainfrom
fix/110-test-scratch-cleanup

Conversation

@bigknoxy

Copy link
Copy Markdown
Owner

Closes #110.

Problem

bun test left scratch state in the working copy:

  • tests/__tmp_intent_tests__/ — populated with a.ts, b.ts, app.ts, utils.ts, package.json, tsconfig.json. Four describe blocks in tests/intent.test.ts register afterEach(cleanup), but parseIntent, generatePlan, and executePlan verification / rollback correctness call setup() with no matching cleanup.
  • tests/tmp/cas-locking/ and tests/tmp/locking-mp/ — each describe removed its own fixture directory, but nothing removed the shared parents, so the empty trees survived every run.

Consequence: git status was never clean after a test run, and the next run started from stale fixtures instead of a fresh tree.

Fix

  • tests/intent.test.ts — file-level afterAll removing both TMP_DIR and the B15 fixture, so the sweep happens regardless of which block created the tree or whether a test threw partway through. B15's declaration is hoisted above the hook; its paths and the literal path assertions are unchanged.
  • tests/cas-locking.test.ts, tests/locking-multiprocess.test.ts — file-level afterAll that removes the file's subtree and rmdirs tests/tmp when it is empty (ignored when another file still owns it).
  • .gitignoretests/tmp/ added next to the existing tests/__tmp_*/, as a backstop for a run killed before afterAll fires.

Verification

tests/scratch-hygiene.test.ts (3 tests) is functional rather than static: it runs tests/intent.test.ts and tests/cas-locking.test.ts in child processes and asserts the scratch trees are absent when the child exits, plus asserts the gitignore backstop.

Falsification — with the three test files and .gitignore stashed, all 3 fail; with the fixes, all 3 pass.

Full suite: 856 pass / 0 fail, and git status --porcelain is empty afterward (previously it was not). bun run lint:docs passes.

Eval suite

No bench case. The bench harness models edit correctness (correct / silent-corruption / false-refusal); this defect is test-harness hygiene with no HashPilot edit path involved, so there is nothing for a case to assert. The regression is pinned by the functional guard above instead.

No src/ change, so no README/ARCHITECTURE update is required by the Docs Verify gate.

🤖 Generated with Claude Code

`bun test` left `tests/__tmp_intent_tests__/` populated and the empty
`tests/tmp/{cas-locking,locking-mp}/` parents behind, dirtying `git status`
after every run and letting the next run start from stale fixtures.

- tests/intent.test.ts: several describe blocks call setup() with no matching
  afterEach, so add a file-level afterAll that removes both TMP_DIR and the
  B15 fixture regardless of which block created them or whether a test threw.
- tests/cas-locking.test.ts, tests/locking-multiprocess.test.ts: each describe
  already removed its own fixture, but nothing swept the shared parent. Add a
  file-level afterAll that removes the subtree and rmdirs tests/tmp when empty.
- .gitignore: cover tests/tmp/ alongside tests/__tmp_*/ as a backstop for a run
  that dies before afterAll fires.
- tests/scratch-hygiene.test.ts: functional guard — run the owning test files in
  a child process and assert the scratch trees are gone on exit, plus assert the
  gitignore backstop. All 3 fail without the fixes above.

Suite: 856 pass / 0 fail, clean `git status` after.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@bigknoxy
bigknoxy merged commit a10576f into main Aug 19, 2026
4 checks passed
@bigknoxy
bigknoxy deleted the fix/110-test-scratch-cleanup branch August 19, 2026 19:19
@bigknoxy

Copy link
Copy Markdown
Owner Author

🎉 This PR is included in version 4.4.15 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P3] bun test leaves scratch directories behind in tests/

1 participant