The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(context): cover preflight timeout provider boundary
anhtahaylove4d95d8eca8ca
diff --git a/tests/agent/test_turn_context.py b/tests/agent/test_turn_context.pyindex 9c087111ed0..74e5957bf57 100644--- a/tests/agent/test_turn_context.py+++ b/tests/agent/test_turn_context.py@@ -15,7 +15,11 @@ from unittest.mock import MagicMock, patchimport pytestfrom agent.context_compressor import ContextCompressor-from agent.turn_context import TurnContext, build_turn_context+from agent.turn_context import (+ PreflightCompressionTimedOut,+ TurnContext,+ build_turn_context,+)from hermes_state import SessionDB@@ -210,6 +214,44 @@ def test_returns_turn_context_with_user_message_appended():assert ctx.active_system_prompt == "SYSTEM"+def test_preflight_timeout_stops_turn_before_provider_boundary():+ """An unchanged oversized payload must not escape turn construction."""+ agent = _FakeAgent()+ agent.compression_enabled = True+ agent.max_compression_attempts = 3+ agent.context_compressor = types.SimpleNamespace(+ protect_first_n=2,+ protect_last_n=2,+ threshold_tokens=1_000,+ context_length=4_000,+ summary_target_ratio=0.3,+ last_prompt_tokens=0,+ should_compress=lambda tokens=None: True,+ should_compress_info=lambda tokens=None: (True, None),+ get_active_compression_failure_cooldown=lambda: None,+ )++ def stalled_compression(messages, *_args, **_kwargs):+ agent._last_compression_timed_out = True+ return messages, "SYSTEM"++ agent._compress_context = MagicMock(side_effect=stalled_compression)+ oversized_history = [+ {"role": "assistant", "content": "x" * 8_000},+ ]+ provider_call = MagicMock()++ def run_turn():+ context = _build(agent, conversation_history=oversized_history)+ provider_call(context.messages)++ with pytest.raises(PreflightCompressionTimedOut, match="provider call was not sent"):+ run_turn()++ agent._compress_context.assert_called_once()+ provider_call.assert_not_called()++def test_user_message_preserves_platform_event_timestamp():agent = _FakeAgent()