headroom/tests/test_transforms
chopratejas 704fb2f19d fix: A2 — system prompt immutable; memory routes to live-zone tail; cache_aligner detector-only
P0-1: Delete `_inject_system_context` from `proxy/server.py`. Memory
context now routes exclusively to the first text block of the latest
non-frozen user message via `_append_context_to_latest_non_frozen_user_turn`
(promoted to the canonical default in handlers/anthropic.py). Mirror
applied to OpenAI Responses API at handlers/openai.py: `body["instructions"]`
is no longer mutated; memory context appends to the latest user item in
`body["input"]`.

P2-23: Replace `headroom/transforms/cache_aligner.py` with a detector-only
implementation. The legacy rewrite path (~400 LOC) is removed. The volatile-
content detector uses no regex — UUIDs via `uuid.UUID`, ISO 8601 via
`datetime.fromisoformat`, JWT shape via base64url segment-count check, hex
hashes via length + `int(token, 16)` validation. Volatile findings surface
through `cache_metrics`/`warnings`/`logger.warning`; the prompt is never
mutated.

Configurability: new env var `HEADROOM_MEMORY_INJECTION_MODE` with values
`live_zone_tail` (default) and `disabled`. No `system_prompt` value — that
path is permanently retired.

Structured logs: every memory injection emits `event=memory_injection`
with `decision`, `bytes_injected`, `query_hash` (BLAKE2b, never raw query),
`session_id`, `request_id`. Auth is never logged.

Tests:
- Add `tests/test_proxy_system_prompt_immutable.py` (7 tests).
- Add `tests/test_cache_aligner_detector_only.py` (20 tests).
- Replace `tests/test_transforms/test_cache_aligner.py` (rewrite-path
  tests, 58 cases) with detector-only behavior.
- Update `tests/test_acceptance.py::TestDateTrap` to pin the new
  detector-only contract.

Acceptance:
- `git grep -n "_inject_system_context\|_inject_to_system_or_instructions" headroom/`
  returns nothing.
- `git grep -n "import re\|from re import" headroom/transforms/cache_aligner.py`
  returns nothing.
- Targeted suite (`test_proxy_system_prompt_immutable.py`,
  `test_cache_aligner_detector_only.py`, `test_proxy_anthropic_cache_stability.py`,
  `test_acceptance.py::TestDateTrap`, `test_memory*.py`, `test_cli/`) green.
2026-05-02 08:34:34 -07:00
..
__init__.py Initial commit: Headroom SDK - LLM context optimization toolkit 2026-01-06 23:16:58 -08:00
test_code_compressor.py Fix CI test, bump to 0.5.7 2026-03-26 12:04:30 -07:00
test_content_router.py Fix tests: update default assertions for disabled CodeCompressor 2026-04-11 10:40:44 -07:00
test_diff_compressor.py feat(rust): retire python diff_compressor, ship rust-only via pyo3 2026-04-26 09:15:37 -07:00
test_diff_compressor_rust_parity.py feat(rust): retire python diff_compressor, ship rust-only via pyo3 2026-04-26 09:15:37 -07:00
test_html_extractor.py fix(tests): skip HTML extractor tests when trafilatura not installed 2026-01-31 15:39:55 -08:00
test_intelligent_context.py fix: Extend Anthropic format tool protection to IntelligentContextManager 2026-02-01 12:27:17 -08:00
test_kompress_compressor.py Make KompressCompressor model-configurable: model_id, chunk_words, score_threshold 2026-04-14 13:19:35 -07:00
test_progressive_summarizer.py Add quality retention eval and fix linting for Python 3.12 2026-01-19 21:52:18 -08:00
test_read_lifecycle.py fix: dashboard metrics, TTFB tracking, eager LLMLingua loading, and multi-provider consistency 2026-03-07 23:33:45 -08:00
test_rolling_window.py fix: Extend Anthropic format tool protection to IntelligentContextManager 2026-02-01 12:27:17 -08:00
test_scoring.py Add IntelligentContextManager for semantic-aware context management 2026-01-18 22:22:48 -08:00
test_smart_crusher_bugs.py feat(rust): retire python smart_crusher, ship rust-only via pyo3 2026-04-27 00:52:21 -07:00
test_smart_crusher_ccr_roundtrip.py chore(rust): SmartCrusher CCR marker injection + walker unification 2026-04-27 20:25:22 -07:00
test_smart_crusher_lossless_default.py feat(rust): SmartCrusher PR4 — lossless-first default + CCR-Dropped restoration 2026-04-27 16:30:22 -07:00
test_smart_crusher_rust_parity.py feat(rust): SmartCrusher PR4 — lossless-first default + CCR-Dropped restoration 2026-04-27 16:30:22 -07:00
test_tag_protector.py feat(rust): port tag_protector to Rust + 5 bug fixes (Phase 3e.4) 2026-04-29 23:18:09 -07:00
test_tool_crusher.py Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00