Isolate HOME for the unit suite (hermetic audit/queue/state) #307

Merged
didericis-claude merged 1 commits from hermetic-audit-tests into main 2026-06-26 21:19:17 -04:00
Collaborator

Closes #302.

Summary

The unit suite could write to and flock the real ~/.bot-bottle — state, queue, and audit dirs all derive from supervise.bot_bottle_root()Path.home(). A test taking a flock on the real audit log blocks indefinitely when a live bottle's supervise sidecar holds that lock (observed this session: a coverage run hung at 0% CPU); unisolated tests otherwise pollute the developer's home dir.

Rather than patch each call site, tests/unit/__init__.py now points HOME at a throwaway temp dir for the whole unit package (restored + rmtree'd at exit). This is the robust fix:

  • bot_bottle_root() resolves under the temp dir during the suite (verified).
  • Tests that set their own HOME (the manifest tests) now restore to the isolated dir, never the real one.
  • Tests that patch supervise.bot_bottle_root directly are unaffected.

Note: TestAuditLog / test_supervise_edge were already hermetic; the leak was a test touching the real root for queue/state paths without isolation — the package-level fix closes the whole class. Full unit suite (1476) passes; pyright clean; pylint 10.00.

Closes #302. ## Summary The unit suite could write to and `flock` the real `~/.bot-bottle` — state, queue, and audit dirs all derive from `supervise.bot_bottle_root()` → `Path.home()`. A test taking a `flock` on the real audit log **blocks indefinitely** when a live bottle's supervise sidecar holds that lock (observed this session: a `coverage run` hung at 0% CPU); unisolated tests otherwise pollute the developer's home dir. Rather than patch each call site, `tests/unit/__init__.py` now points `HOME` at a throwaway temp dir for the **whole unit package** (restored + `rmtree`'d at exit). This is the robust fix: - `bot_bottle_root()` resolves under the temp dir during the suite (verified). - Tests that set their own `HOME` (the manifest tests) now restore to the isolated dir, never the real one. - Tests that patch `supervise.bot_bottle_root` directly are unaffected. Note: `TestAuditLog` / `test_supervise_edge` were already hermetic; the leak was a test touching the real root for queue/state paths without isolation — the package-level fix closes the whole class. Full unit suite (1476) passes; pyright clean; pylint 10.00.
didericis-claude added 1 commit 2026-06-26 20:36:10 -04:00
test: isolate HOME for the unit suite (hermetic audit/queue/state)
test / unit (pull_request) Successful in 58s
test / integration (pull_request) Successful in 26s
test / coverage (pull_request) Successful in 1m13s
lint / lint (push) Successful in 2m22s
test / unit (push) Successful in 58s
test / integration (push) Successful in 26s
test / coverage (push) Successful in 1m17s
Update Quality Badges / update-badges (push) Successful in 2m24s
8006702ee7
The unit suite could write to and flock the real ~/.bot-bottle: state,
queue, and audit dirs all derive from supervise.bot_bottle_root() ->
Path.home(). A test taking a flock on the real audit log blocks
indefinitely when a live bottle's supervise sidecar holds that lock
(observed: a `coverage run` hung at 0% CPU), and unisolated tests
otherwise pollute the developer's home dir.

Point HOME at a throwaway temp dir for the whole tests/unit package
(restored + cleaned at exit). Tests that set their own HOME now restore
to the isolated dir, not the real one; tests that patch bot_bottle_root
directly are unaffected.

Closes #302

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NkwFXLFff9PYPy4wgVBJp9
didericis-claude merged commit 8006702ee7 into main 2026-06-26 21:19:17 -04:00
didericis-claude deleted branch hermetic-audit-tests 2026-06-26 21:19:21 -04:00
Sign in to join this conversation.