Skip to content

The agent that grows with you

test(agent): fold the new marker and restart tests into existing harnesses

kshitijk4poor91ff5e422de5
diff --git a/tests/agent/test_tool_call_guardrail_runtime.py b/tests/agent/test_tool_call_guardrail_runtime.py
index e1c7addcc12..6260441b957 100644
--- a/tests/agent/test_tool_call_guardrail_runtime.py
+++ b/tests/agent/test_tool_call_guardrail_runtime.py
@@ -412,30 +412,11 @@ def test_context_pruned_effectful_call_blocks_before_dispatch():
"write_file",
{"content": f"template {_COMPRESSION_MARKER_PREFIX} {{omitted:,}} of {{total:,}}"},
) == []
-
-
[email protected]("suffix", [" 1,800", " 1,800 of", " 1,800 of 2,000 chars omitted"])
-def test_partial_counted_context_marker_blocks_before_dispatch(suffix):
- from agent.compression_marker import _COMPRESSION_MARKER_PREFIX
-
- agent = _make_agent("test_effectful_write")
- pruned = {"body": f"prefix {_COMPRESSION_MARKER_PREFIX}{suffix}"}
- tc = _mock_tool_call(
- "test_effectful_write", json.dumps(pruned, ensure_ascii=False), "c-pruned-partial"
- )
- msg = SimpleNamespace(content="", tool_calls=[tc])
- messages = []
-
- with (
- patch("hermes_cli.plugins._dispatch_pre_tool_call_hooks", return_value=(None, pruned)),
- patch("model_tools.handle_function_call", return_value="SHOULD_NOT_RUN") as dispatch,
- ):
- agent._execute_tool_calls_sequential(msg, messages, "task-1")
-
- dispatch.assert_not_called()
- payload = json.loads(messages[0]["content"])
- assert payload["error"] == "suspected_pruned_tool_arguments"
- assert payload["argument_paths"] == ["$.body"]
+ # A marker cut before its fixed sentence is still an artifact once a count is rendered.
+ for suffix in (" 1,800", " 1,800 of", " 1,800 of 2,000 chars omitted"):
+ assert _context_pruned_argument_paths(
+ "write_file", {"body": f"prefix {_COMPRESSION_MARKER_PREFIX}{suffix}"}
+ ) == ["$.body"]
def test_read_only_tool_may_quote_current_context_prune_marker():
diff --git a/tests/agent/test_turn_iteration_prep.py b/tests/agent/test_turn_iteration_prep.py
index 456bbb96055..ba7933d0150 100644
--- a/tests/agent/test_turn_iteration_prep.py
+++ b/tests/agent/test_turn_iteration_prep.py
@@ -18,11 +18,13 @@ RESTART_FLAGS = ["restart_with_redirected_messages", "restart_with_rebuilt_messa
MAX_RETRIES = 3
-def _apply(agent, flag: str, restart_count: int):
+def _apply(agent, flag: str | None, restart_count: int, response=None):
+ """Run one iteration's restart handling; ``flag=None`` with a response means the model answered."""
_retry = TurnRetryState()
- setattr(_retry, flag, True)
+ if flag:
+ setattr(_retry, flag, True)
return apply_retry_restarts(
- agent, _retry=_retry, response=None, interrupted=False, messages=[],
+ agent, _retry=_retry, response=response, interrupted=False, messages=[],
conversation_history=[], user_message="hi", api_kwargs={}, current_turn_user_idx=0,
final_response=None, retry_count=0, max_retries=MAX_RETRIES, api_call_count=1,
restart_count=restart_count, length_continue_retries=0,
@@ -92,17 +94,6 @@ def test_interrupt_exit_reason_names_the_system_issuer(tool_interrupt_reason, ex
assert (verdict.action, verdict.interrupted, verdict._turn_exit_reason) == ("break", True, expected)
-def _respond(agent, restart_count: int):
- """No restart flag and a response in hand: the iteration proceeds to process it."""
- return apply_retry_restarts(
- agent, _retry=TurnRetryState(), response=SimpleNamespace(), interrupted=False, messages=[],
- conversation_history=[], user_message="hi", api_kwargs={}, current_turn_user_idx=0,
- final_response=None, retry_count=0, max_retries=MAX_RETRIES, api_call_count=1,
- restart_count=restart_count, length_continue_retries=0,
- _preflight_compression_blocked=True, _turn_exit_reason="unknown",
- )
-
-
@pytest.mark.parametrize("flag", RESTART_FLAGS)
def test_response_between_restarts_resets_the_bound(flag):
"""#128000: the user answering clarify cards / sending follow-ups while the model works
@@ -116,7 +107,7 @@ def test_response_between_restarts_resets_the_bound(flag):
verdict = _apply(agent, flag, restart_count)
actions.append(verdict.action)
restart_count = verdict.restart_count
- verdict = _respond(agent, restart_count)
+ verdict = _apply(agent, None, restart_count, response=SimpleNamespace())
assert (verdict.action, verdict.restart_count) == ("fallthrough", 0)
restart_count = verdict.restart_count
assert actions == ["continue"] * (3 * MAX_RETRIES)