feat(stores): route audit-cache through AuditCacheStore protocol (feature 035) - #413
Merged
Marc-cn merged 1 commit intoSep 6, 2026
Conversation
mlieberman85
force-pushed
the
035-audit-cache-store-migration
branch
from
September 5, 2026 17:01
670dec5 to
2bc52ad
Compare
…ture 035) Close the wiring gap where tools/audit.py::run_sieve_audit called core.audit_cache.write_audit_cache directly, ignoring feature 033's execution_context.stores.cache bundle. Operators setting [stores.cache] backend/root in .baseline.toml now see the audit-cache actually redirect. Core changes: - core/audit_cache.py rewritten as thin wrapper over AuditCacheStore. Public API keeps positional signatures (backward compat) plus two new kwargs (store, cache_key) for driver-side calls. TTL / git-HEAD / working-tree-dirty staleness enforcement stays in the wrapper, not the store. - tools/audit.py picks cache_key by whether stores_config.cache is set: "audit-cache" for the default-store case (root already encodes repo identity), sha256(abspath(repo))[:16] for the configured-store case (per-repo isolation under a shared root). - stores/selection.py default cache_root moved from <repo>/.darnit/ audit-cache/ to <tempdir>/darnit/<sha256(abspath(repo))[:16]> so bundle.cache's default backend produces the same byte-for-byte on-disk path as the pre-feature audit_cache wrapper. Behavior changes documented in the spec: - write_audit_cache is best-effort per feature 033 FR-011 (log and continue; previously raised on tempfile failure). - invalidate_audit_cache writes an expired envelope (timestamp 1970-01-01T00:00:00Z) rather than deleting the file. The AuditCacheStore protocol has no delete(key) method; the surface stays unchanged. Tests: - 11 new driver-level integration tests at tests/darnit/ test_audit_cache_store_wiring.py cover configured-store routing, zero-config invariance, staleness through a configured store, shared -root non-collision, fault injection, and backward-compat call form. - Two existing tests updated for behavior change: no-raise on write failure, invalidate leaves an expired envelope. - Two zero-config path-shape tests updated to expect the new default cache_root shape (tempdir/hash instead of repo/.darnit/audit-cache). Verified end-to-end: darnit audit with [stores.cache] backend="local-fs" root="/tmp/qs-cache" writes /tmp/qs-cache/<hash>.json and does NOT create a fallback file under the system tempdir. Full framework test suite: 1900 passed, 6 skipped, 0 failed.
mlieberman85
force-pushed
the
035-audit-cache-store-migration
branch
from
September 5, 2026 17:27
2bc52ad to
33999f9
Compare
Collaborator
|
The wiring works end to end with this in the cache lands at
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Close the wiring gap where
tools/audit.py::run_sieve_auditcalledcore.audit_cache.write_audit_cachedirectly, ignoring feature 033'sexecution_context.stores.cachebundle. Operators setting[stores.cache]backend/rootin.baseline.tomlnow see the audit-cache actually redirect.Changes
core/audit_cache.pyrewritten as thin wrapper overAuditCacheStore. Public API keeps positional signatures (backward compat) plus two new kwargs (store,cache_key) for driver-side calls. TTL / git-HEAD / working-tree-dirty staleness enforcement stays in the wrapper, not the store.tools/audit.pypickscache_keyby whetherstores_config.cacheis set:"audit-cache"for default-store (root already encodes repo identity) orsha256(abspath(repo))[:16]for a configured store (per-repo isolation under a shared root).stores/selection.pydefaultcache_rootmoved from<repo>/.darnit/audit-cache/to<tempdir>/darnit/<sha256(abspath(repo))[:16]>sobundle.cache's default backend produces the same byte-for-byte on-disk path as the pre-feature wrapper.Documented behavior changes
write_audit_cacheis best-effort per feature 033 FR-011 (log and continue; previously raised on tempfile failure).invalidate_audit_cachewrites an expired envelope (timestamp1970-01-01T00:00:00Z) rather than deleting the file. TheAuditCacheStoreProtocol has nodelete(key)method; the surface stays unchanged.Test plan
tests/darnit/test_audit_cache_store_wiring.py(configured-store routing, zero-config invariance, staleness through a configured store, shared-root non-collision, fault injection, backward-compat call form).cache_root(tempdir/hash instead ofrepo/.darnit/audit-cache).darnit auditwith[stores.cache] backend = "local-fs" root = "/tmp/qs-cache"writes/tmp/qs-cache/<hash>.jsonand does NOT create a fallback under the tempdir.Follow-up (out of scope)
packages/darnit-baseline/src/darnit_baseline/remediation/orchestrator.pycallsread_audit_cache(local_path)positionally, so it always reads from the backward-compat default store. To honor configured[stores.cache]on the remediate side too, that consumer needs its own driver-style call refactor. Explicitly listed as out-of-scope inspecs/035-audit-cache-store-migration/spec.md.Spec
Full spec, plan, and tasks live at
specs/035-audit-cache-store-migration/.