Skip to content

Keep the classifier cache in the test tmpdir so the suite is hermetic#37

Merged
cgraf78 merged 1 commit into
mainfrom
fix-test-cache-hermetic
Jul 2, 2026
Merged

Keep the classifier cache in the test tmpdir so the suite is hermetic#37
cgraf78 merged 1 commit into
mainfrom
fix-test-cache-hermetic

Conversation

@cgraf78

@cgraf78 cgraf78 commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

Scrub and re-point XDG_CACHE_HOME in the hook test harness so the
protected-bare classifier cache no longer writes into the developer's
real ~/.cache during a test run.

The harness already redirects hook state (XDG_RUNTIME_DIR/
XDG_STATE_HOME) at the test tmpdir, but _protected_bare_nested_cache_file
resolves its cache from XDG_CACHE_HOME (falling back to ~/.cache),
which the harness left untouched. So running the suite rewrote a real
~/.cache/agentguard/protected-bare-nested-roots-* file — a pre-existing
hermeticity leak surfaced during review of the hook-state change.

  • add XDG_CACHE_HOME to the ambient XDG scrub and export it at
    $TEST_TMPDIR alongside XDG_RUNTIME_DIR, matching the same pattern
    and rationale

Testing

  • before/after check: the real ~/.cache/agentguard mtime is unchanged
    across a full suite run (was rewritten at test time before this change)
  • full suite green (./test/agentguard-test: ok, all suites 0 failed);
    checkrun lint and shellcheck -x clean
  • no test asserts the classifier cache path, so redirecting it is safe

Summary

Scrub and re-point `XDG_CACHE_HOME` in the hook test harness so the
protected-bare classifier cache no longer writes into the developer's
real `~/.cache` during a test run.

The harness already redirects hook state (`XDG_RUNTIME_DIR`/
`XDG_STATE_HOME`) at the test tmpdir, but `_protected_bare_nested_cache_file`
resolves its cache from `XDG_CACHE_HOME` (falling back to `~/.cache`),
which the harness left untouched. So running the suite rewrote a real
`~/.cache/agentguard/protected-bare-nested-roots-*` file — a pre-existing
hermeticity leak surfaced during review of the hook-state change.

- add `XDG_CACHE_HOME` to the ambient XDG scrub and export it at
  `$TEST_TMPDIR` alongside `XDG_RUNTIME_DIR`, matching the same pattern
  and rationale

Testing

- before/after check: the real `~/.cache/agentguard` mtime is unchanged
  across a full suite run (was rewritten at test time before this change)
- full suite green (`./test/agentguard-test`: ok, all suites 0 failed);
  `checkrun lint` and `shellcheck -x` clean
- no test asserts the classifier cache path, so redirecting it is safe
@cgraf78 cgraf78 merged commit e9b95cc into main Jul 2, 2026
6 checks passed
@cgraf78 cgraf78 deleted the fix-test-cache-hermetic branch July 2, 2026 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant