test(codex): cover nested retention entry paths

This commit is contained in:
Falko
2026-08-20 07:08:17 +10:00
committed by kshitij
parent f6d1d774a1
commit 8430c1b4da
2 changed files with 74 additions and 0 deletions

View File

@@ -234,6 +234,31 @@ def test_provider_request_overlays_interceptor_added_codex_field():
assert provider_request["prompt_cache_retention"] == "24h"
def test_provider_request_overlays_interceptor_added_extra_body():
"""Relay rewrites may also carry provider fields through extra_body."""
original = {"model": "gpt-5.6-sol", "input": "hello"}
relay_request_body = relay_llm._relay_request_body(
original,
{"api_mode": "codex_responses"},
)
provider_request = relay_llm._provider_request(
original,
SimpleNamespace(
content={
**relay_request_body,
"extra_body": {"prompt_cache_retention": "24h"},
},
headers={},
),
relay_request_body=relay_request_body,
codec_baseline_body=dict(relay_request_body),
metadata={"api_mode": "codex_responses"},
)
assert "extra_body" not in original
assert provider_request["extra_body"] == {"prompt_cache_retention": "24h"}
def test_stream_uses_rewritten_request_and_post_intercept_chunks(relay_turn):
relay, turn = relay_turn
captured_requests = []

View File

@@ -590,6 +590,55 @@ def test_run_codex_stream_strips_relay_added_retention_at_consumer_wire(
)
def test_run_codex_stream_strips_nested_request_override_retention(
monkeypatch,
caplog,
):
"""Configured extra_body retention cannot cross the final wire boundary."""
from agent.transports.codex import ResponsesApiTransport
agent = _build_agent(monkeypatch)
captured = {}
def _fake_create(**kwargs):
captured.update(kwargs)
return _FakeCreateStream([
SimpleNamespace(
type="response.completed",
response=SimpleNamespace(status="completed"),
)
])
agent.client = SimpleNamespace(
responses=SimpleNamespace(create=_fake_create),
)
request = ResponsesApiTransport().build_kwargs(
model="gpt-5.6-sol",
messages=[
{"role": "system", "content": "You are Hermes."},
{"role": "user", "content": "Ping"},
],
tools=[],
is_codex_backend=True,
base_url="https://chatgpt.com/backend-api/codex",
request_overrides={
"extra_body": {"prompt_cache_retention": "24h"},
},
)
assert request["extra_body"] == {"prompt_cache_retention": "24h"}
with caplog.at_level("WARNING", logger="agent.codex_runtime"):
agent._run_codex_stream(request)
assert "extra_body" not in captured
assert request["extra_body"] == {"prompt_cache_retention": "24h"}
assert any(
"Dropped unsupported prompt_cache_retention at consumer Codex wire boundary"
in record.message
for record in caplog.records
)
def test_consumer_codex_wire_guard_strips_nested_extra_body_retention(caplog):
"""The SDK merges ``extra_body`` into the JSON body, so a nested
``extra_body.prompt_cache_retention`` reaches the endpoint exactly like the