The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(compression): resolve context_length inside mocks across suites hit by lazy-init deferral
kshitijk4poor5ce8e347672c
diff --git a/tests/agent/test_cjk_token_estimation.py b/tests/agent/test_cjk_token_estimation.pyindex 71299a7ce11..aee03029848 100644--- a/tests/agent/test_cjk_token_estimation.py+++ b/tests/agent/test_cjk_token_estimation.py@@ -35,6 +35,8 @@ def test_cjk_tail_does_not_expand_to_english_char_budget():summary_target_ratio=0.2,quiet_mode=True,)+ # Resolve while the mock is active (lazy init, #32221).+ _ = compressor.context_lengthmessages = [{"role": "user", "content": "head 1"},diff --git a/tests/agent/test_compression_small_ctx_threshold_floor.py b/tests/agent/test_compression_small_ctx_threshold_floor.pyindex 03c64a00cbd..5b8c0a5010c 100644--- a/tests/agent/test_compression_small_ctx_threshold_floor.py+++ b/tests/agent/test_compression_small_ctx_threshold_floor.py@@ -20,9 +20,13 @@ from agent.context_compressor import ContextCompressordef _make(ctx: int, pct: float = 0.50) -> ContextCompressor:with patch.object(cc, "get_model_context_length", return_value=ctx):- return ContextCompressor(+ comp = ContextCompressor(model="test/model", threshold_percent=pct, quiet_mode=True,)+ # Resolve while the mock is active — lazy init (#32221) defers the+ # window probe (and the floor application) past __init__.+ _ = comp.context_length+ return compclass TestSmallContextThresholdFloor:diff --git a/tests/agent/test_pre_compress_memory_context.py b/tests/agent/test_pre_compress_memory_context.pyindex 14f8addb42a..d33bc7fa4ad 100644--- a/tests/agent/test_pre_compress_memory_context.py+++ b/tests/agent/test_pre_compress_memory_context.py@@ -13,10 +13,14 @@ def _make_compressor():compressor = ContextCompressor.__new__(ContextCompressor)compressor.protect_first_n = 2compressor.protect_last_n = 5- compressor.tail_token_budget = 20_000+ # Set context_length BEFORE the derived budgets: its setter resets the+ # lazily-cached threshold/tail/summary budgets (#32221 lazy init), so+ # assigning it later would clear the explicit values below.compressor.context_length = 200_000compressor.threshold_percent = 0.80compressor.threshold_tokens = 160_000+ compressor.summary_target_ratio = 0.20+ compressor.tail_token_budget = 20_000compressor.max_summary_tokens = 10_000compressor.quiet_mode = Truecompressor.compression_count = 0diff --git a/tests/run_agent/test_per_model_compression_threshold.py b/tests/run_agent/test_per_model_compression_threshold.pyindex 575cd6b165e..1259b040317 100644--- a/tests/run_agent/test_per_model_compression_threshold.py+++ b/tests/run_agent/test_per_model_compression_threshold.py@@ -89,6 +89,8 @@ class TestContextCompressorModelThresholds:model_thresholds={"glm-5.2": 0.40},quiet_mode=True,)+ # Resolve while mock is active (lazy init defers floor past __init__).+ _ = cc.context_length# 256K < 512K → floor at 0.75; override 0.40 < 0.75, so floor winsassert cc.threshold_percent == 0.75assert cc.threshold_tokens == int(256_000 * 0.75)@@ -113,6 +115,8 @@ class TestContextCompressorModelThresholds:threshold_percent=0.50,quiet_mode=True,)+ # Resolve while mock is active (lazy init defers floor past __init__).+ _ = cc.context_length# 256K < 512K → floored at 0.75assert cc.threshold_percent == 0.75assert cc.model_thresholds == {}