mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-08-27 14:17:10 -04:00
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.
This commit is contained in:
parent
5b38cbf8a7
commit
be5d9f7baa
1 changed files with 26 additions and 3 deletions
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue