From be5d9f7baaf11d706afecf7c0ca0b9da984f38a2 Mon Sep 17 00:00:00 2001 From: chopratejas Date: Wed, 6 May 2026 14:39:39 -0700 Subject: [PATCH] fix(tests): update CacheAligner detector-only tests for F2.2 5-field CompressionPolicy The two F2.1 fixtures constructed CompressionPolicy with only 2 fields; F2.2 added three required tuning fields (volatile_token_threshold, max_lossy_ratio, toin_read_only). Updated subscription-disabled fixture to use Subscription defaults (32 / 0.25 / True) and the PAYG-enabled fixture to use PAYG defaults (128 / 0.45 / False), mirroring policy_for_mode(). Prefer the fixture update over default-valued fields in the dataclass so the F2.2 parity-test invariant (every CompressionPolicy is fully specified per-mode) stays load-bearing. --- tests/test_cache_aligner_detector_only.py | 29 ++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/tests/test_cache_aligner_detector_only.py b/tests/test_cache_aligner_detector_only.py index 8579797fd..5d8a25c6c 100644 --- a/tests/test_cache_aligner_detector_only.py +++ b/tests/test_cache_aligner_detector_only.py @@ -205,6 +205,12 @@ def test_should_apply_false_when_policy_disables_aligner(tokenizer: Tokenizer) - ``self._previous_prefix_hash`` and emitting volatility warnings, which are the exact log lines #327/#388 reporters complained about. + + F2.2 added three per-mode tuning fields to CompressionPolicy + (``volatile_token_threshold``, ``max_lossy_ratio``, + ``toin_read_only``); the policy here uses the Subscription + defaults from ``policy_for_mode(AuthMode.SUBSCRIPTION)`` so the + fixture mirrors a real subscription request. """ from headroom.transforms.compression_policy import CompressionPolicy @@ -213,18 +219,35 @@ def test_should_apply_false_when_policy_disables_aligner(tokenizer: Tokenizer) - # Sanity: without a policy, the detector opts in. assert aligner.should_apply(messages, tokenizer) # F2.1 gate: with the subscription policy, the detector opts out. - sub_policy = CompressionPolicy(live_zone_only=True, cache_aligner_enabled=False) + sub_policy = CompressionPolicy( + live_zone_only=True, + cache_aligner_enabled=False, + volatile_token_threshold=32, + max_lossy_ratio=0.25, + toin_read_only=True, + ) assert not aligner.should_apply(messages, tokenizer, compression_policy=sub_policy) def test_should_apply_true_when_policy_enables_aligner(tokenizer: Tokenizer) -> None: """F2.1 c4/5: ``compression_policy.cache_aligner_enabled=True`` - must NOT short-circuit. PAYG/OAuth keep current behaviour.""" + must NOT short-circuit. PAYG/OAuth keep current behaviour. + + F2.2 added three per-mode tuning fields; the policy here uses the + PAYG defaults from ``policy_for_mode(AuthMode.PAYG)`` so the + fixture mirrors a real PAYG request. + """ from headroom.transforms.compression_policy import CompressionPolicy messages = _system_user_messages("Session: 550e8400-e29b-41d4-a716-446655440000") aligner = CacheAligner(CacheAlignerConfig(enabled=True)) - payg_policy = CompressionPolicy(live_zone_only=False, cache_aligner_enabled=True) + payg_policy = CompressionPolicy( + live_zone_only=False, + cache_aligner_enabled=True, + volatile_token_threshold=128, + max_lossy_ratio=0.45, + toin_read_only=False, + ) assert aligner.should_apply(messages, tokenizer, compression_policy=payg_policy)