Skip to content

The agent that grows with you

test(auxiliary): trim Codex completion-status tests to two invariants

kshitijk4poor20ca2bf1bbcf
diff --git a/tests/agent/test_auxiliary_codex_completion_status.py b/tests/agent/test_auxiliary_codex_completion_status.py
index b68f8a7c573..fdb545ea626 100644
--- a/tests/agent/test_auxiliary_codex_completion_status.py
+++ b/tests/agent/test_auxiliary_codex_completion_status.py
@@ -15,13 +15,6 @@ def _message(text, *, phase: str | None = "final_answer", status="completed"):
)
-def _reasoning(text):
- return SimpleNamespace(
- type="reasoning", id="rs_test", encrypted_content=None,
- summary=[SimpleNamespace(text=text)],
- )
-
-
def _adapter_response(final, *, streamed, base_url=""):
class FakeStream:
def __iter__(self):
@@ -46,28 +39,22 @@ def _adapter_response(final, *, streamed, base_url=""):
).create(messages=[{"role": "user", "content": "Summarize the task."}])
[email protected]("fallback", [False, True], ids=["abort", "main-fallback"])
-def test_compressor_rejects_actual_adapter_partial_summary(monkeypatch, fallback):
+def test_compressor_rejects_actual_adapter_partial_summary(monkeypatch):
partial = SimpleNamespace(
status="incomplete", output=[_message("PARTIAL_CHECKPOINT")],
incomplete_details={"reason": "max_output_tokens"}, error=None,
usage=SimpleNamespace(input_tokens=11, output_tokens=3, total_tokens=14),
)
- complete = SimpleNamespace(
- status="completed", output=[_message("COMPLETE_CHECKPOINT")],
- incomplete_details=None, error=None, usage=None,
- )
calls = []
def fake_call_llm(**kwargs):
calls.append(kwargs.get("model"))
- return _adapter_response(partial if len(calls) == 1 else complete, streamed=True)
+ return _adapter_response(partial, streamed=True)
monkeypatch.setattr("agent.context_compressor.call_llm", fake_call_llm)
monkeypatch.setattr("agent.context_compressor.get_model_context_length", lambda *a, **k: 100000)
compressor = ContextCompressor(
- model="main-model", summary_model_override="aux-model" if fallback else "",
- quiet_mode=True, tail_mode="legacy", protect_first_n=2, protect_last_n=2,
+ model="main-model", quiet_mode=True, tail_mode="legacy", protect_first_n=2, protect_last_n=2,
abort_on_summary_failure=False,
)
messages = [
@@ -77,105 +64,46 @@ def test_compressor_rejects_actual_adapter_partial_summary(monkeypatch, fallback
original = [dict(message) for message in messages]
result = compressor.compress(messages, current_tokens=999999, force=True)
- assert "PARTIAL_CHECKPOINT" not in (compressor._previous_summary or "")
- assert messages == original
- if fallback:
- assert calls == ["aux-model", None]
- assert "COMPLETE_CHECKPOINT" in (compressor._previous_summary or "")
- assert result != original
- assert compressor._last_compress_aborted is False
- else:
- assert calls == [None]
- assert result == original
- assert compressor._previous_summary is None
- assert compressor._last_summary_truncated_failure is True
- assert compressor._last_compress_aborted is True
+ assert calls == [None]
+ assert result == original and messages == original
+ assert compressor._previous_summary is None
+ assert compressor._last_summary_truncated_failure is True
+ assert compressor._last_compress_aborted is True
[email protected]("streamed", [False, True], ids=["response-object", "sse"])
- "base_url, reasoning_text, expected_content, expected_finish",
- [
- pytest.param(
- "https://chatgpt.com/backend-api/codex",
- "still thinking",
- None,
- "length",
- id="codex-reasoning-only",
- ),
- pytest.param(
- "https://api.x.ai/v1",
- "scratch\n<response>FINAL ANSWER</response>",
- "FINAL ANSWER",
- "stop",
- id="xai-reasoning-answer",
- ),
- ],
+_TOOL_CALL = SimpleNamespace(
+ type="function_call", status="completed", call_id="call_1", name="inspect", arguments='{"path":"x"}',
+)
+_CODEX_REASONING_ONLY = SimpleNamespace(
+ type="reasoning", id="rs_test", encrypted_content=None, summary=[SimpleNamespace(text="still thinking")],
)
-def test_actual_adapter_preserves_route_sensitive_reasoning(
- streamed, base_url, reasoning_text, expected_content, expected_finish,
-):
- final = SimpleNamespace(
- status="completed", output=[_reasoning(reasoning_text)], output_text="",
- incomplete_details=None, error=None,
- usage=SimpleNamespace(input_tokens=11, output_tokens=3, total_tokens=14),
- )
-
- response = _adapter_response(final, streamed=streamed, base_url=base_url)
-
- choice = response.choices[0]
- assert choice.message.content == expected_content
- assert choice.finish_reason == expected_finish
- assert getattr(response, "status", None) == "completed"
- assert (response.usage.prompt_tokens, response.usage.completion_tokens, response.usage.total_tokens) == (11, 3, 14)
@pytest.mark.parametrize("streamed", [False, True], ids=["response-object", "sse"])
@pytest.mark.parametrize(
- "status, output, reason, output_text, expected_content, expected_finish, error",
+ "base_url, status, output, reason, expected_content, expected_finish",
[
- pytest.param("completed", [_message("FINAL")], None, "", "FINAL", "stop", None, id="final-answer"),
- pytest.param("completed", [_message("LEGACY", phase=None)], None, "", "LEGACY", "stop", None, id="unphased"),
- pytest.param("completed", [_message("COMMENTARY", phase="commentary")], None, "COMMENTARY", None, "length", None, id="commentary-only"),
- pytest.param("completed", [_message("ANALYSIS", phase="analysis")], None, "ANALYSIS", None, "length", None, id="analysis-only"),
- pytest.param("completed", [_message("COMMENTARY", phase="commentary"), _message("FINAL", phase="final")], None, "COMMENTARYFINAL", "FINAL", "stop", None, id="commentary-then-final"),
- pytest.param("completed", [SimpleNamespace(type="message", status="completed", content=[{"type": "refusal", "refusal": "DECLINED"}])], None, "", "DECLINED", "stop", None, id="refusal"),
- pytest.param("completed", [SimpleNamespace(type="function_call", status="completed", call_id="call_1", name="inspect", arguments='{"path":"x"}')], None, "", None, "tool_calls", None, id="tool-call"),
- pytest.param("incomplete", [_message("PARTIAL")], "max_output_tokens", "", "PARTIAL", "length", None, id="token-cap-final-phase"),
- pytest.param("incomplete", [_message("PARTIAL", phase=None)], "other", "", "PARTIAL", "length", None, id="other-incomplete"),
- pytest.param("completed", [_message("PARTIAL", status="incomplete")], None, "", "PARTIAL", "length", None, id="incomplete-item"),
- pytest.param("completed", [SimpleNamespace(type="function_call", status="in_progress", call_id="call_1", name="inspect", arguments='{"path":')], None, "", None, "length", None, id="partial-tool-call"),
- pytest.param("incomplete", None, "content_filter", "", None, "content_filter", None, id="content-filter"),
- pytest.param("failed", [_message("NOT_A_FINAL")], None, "", None, None, {"code": "provider_error", "message": "backend failed"}, id="failed"),
- pytest.param("cancelled", [_message("NOT_A_FINAL")], None, "", None, None, {"message": "request cancelled"}, id="cancelled"),
- pytest.param("completed", None, None, "DELTA_FINAL", "DELTA_FINAL", "stop", None, id="output-text-fallback"),
- pytest.param("completed", None, None, "", None, "stop", None, id="legacy-empty"),
+ pytest.param("", "completed", [_message("FINAL")], None, "FINAL", "stop", id="final-answer"),
+ pytest.param("", "completed", [_message("COMMENTARY", phase="commentary")], None, None, "length", id="commentary-only"),
+ pytest.param("", "completed", [_TOOL_CALL], None, None, "tool_calls", id="tool-call"),
+ pytest.param("", "incomplete", [_message("PARTIAL")], "max_output_tokens", "PARTIAL", "length", id="token-cap"),
+ # Route-sensitive normalization: the issuer comes from the request's route classification.
+ pytest.param("https://chatgpt.com/backend-api/codex", "completed", [_CODEX_REASONING_ONLY], None, None, "length",
+ id="codex-reasoning-only"),
],
)
def test_actual_adapter_preserves_completion_contract(
- streamed, status, output, reason, output_text, expected_content, expected_finish, error,
+ streamed, base_url, status, output, reason, expected_content, expected_finish,
):
- details = {"reason": reason} if reason else None
final = SimpleNamespace(
- status=status, output=output, output_text=output_text,
- incomplete_details=details, error=error,
+ status=status, output=output, output_text="",
+ incomplete_details={"reason": reason} if reason else None, error=None,
usage={"input_tokens": 11, "output_tokens": 3, "total_tokens": 14},
)
- if error:
- with pytest.raises(RuntimeError, match=error["message"]):
- _adapter_response(final, streamed=streamed)
- return
-
- response = _adapter_response(final, streamed=streamed)
- choice = response.choices[0]
- assert choice.message.content == expected_content
- assert choice.finish_reason == expected_finish
- assert getattr(response, "status", None) == status
- assert getattr(response, "incomplete_details", None) == details
- assert getattr(response, "error", None) is None
- assert (response.usage.prompt_tokens, response.usage.completion_tokens, response.usage.total_tokens) == (11, 3, 14)
+
+ choice = _adapter_response(final, streamed=streamed, base_url=base_url).choices[0]
+
+ assert (choice.message.content, choice.finish_reason) == (expected_content, expected_finish)
if expected_finish == "tool_calls":
call, = choice.message.tool_calls
assert (call.id, call.function.name, call.function.arguments) == ("call_1", "inspect", '{"path":"x"}')
- else:
- assert choice.message.tool_calls is None