headroom/tests/test_cache
Tejas Chopra 908a9a1bb1
fix(cache): stop DynamicContentDetector false positives corrupting cached prompts (#2110) (#2119)
## Description
`DynamicContentDetector` / `RegexDetector` in
`headroom/cache/dynamic_detector.py` (used by the `cache_aligner`
transform) misclassified ordinary English words and code identifiers
(e.g. `in_pr`) as "dynamic content," extracting them from the system
prompt and re-appending a `[Dynamic Context]` tail that grows
unboundedly and corrupts the cached prompt over a session.

Fix tightens detection to require genuinely-dynamic shapes (timestamps,
UUIDs, hashes, numbers-with-units, ISO dates) rather than bare tokens —
no hardcoded wordlist — and bounds the tail. `cache_aligner` is off by
default, so blast radius is limited, but the detector logic is now
correct.

Closes #2110

## Type of Change
- [x] Bug fix (non-breaking change that fixes an issue)

## Changes Made
- `headroom/cache/dynamic_detector.py`: raise the evidence bar so
ordinary words/identifiers aren't extracted; bound the dynamic tail.
- `tests/test_cache/test_dynamic_detector.py`: assert false positives
(ordinary words/identifiers) are NOT extracted while real dynamic values
still are.

## Testing
- [x] Unit tests pass (`pytest
tests/test_cache/test_dynamic_detector.py`)
- [x] Linting passes (`ruff check`)
### Test Output
```text
55 passed, 2 skipped
ruff: All checks passed!
```

## Real Behavior Proof
- Before: identifiers like `in_pr` extracted into a growing `[Dynamic
Context]` tail, corrupting cached prompts.
- After: ordinary tokens stay in place; only genuinely-dynamic values
are detected.
2026-07-13 17:39:01 -04:00
..
__init__.py Add cache optimization module with scalable dynamic content detection 2026-01-07 14:07:49 -08:00
test_anthropic.py Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00
test_backends.py Add pluggable storage backend abstraction for CompressionStore 2026-01-20 23:25:28 -08:00
test_base.py Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00
test_client_integration.py Fix ruff formatting 2026-01-17 17:14:12 -08:00
test_dynamic_detector.py fix(cache): stop DynamicContentDetector false positives corrupting cached prompts (#2110) (#2119) 2026-07-13 17:39:01 -04:00
test_google.py Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00
test_openai.py Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00
test_prefix_tracker.py fix(proxy/anthropic): scope session id by top-level system prompt (#2070) 2026-07-12 19:40:58 -04:00
test_registry.py Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00
test_semantic.py fix(cache/semantic): don't evict an unrelated entry on an update at capacity (#2094) 2026-07-13 10:50:23 -04:00