The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: pin the residency header on both models-catalog probes' wire requests
teknium159e858c20cd5
diff --git a/tests/agent/test_codex_cloudflare_headers.py b/tests/agent/test_codex_cloudflare_headers.pyindex 592abb6f616..c49309d4db9 100644--- a/tests/agent/test_codex_cloudflare_headers.py+++ b/tests/agent/test_codex_cloudflare_headers.py@@ -97,17 +97,46 @@ class TestCodexCloudflareHeaders:assert headers["originator"] == "hermes-agent"assert "ChatGPT-Account-ID" not in headers- def test_residency_header_from_jwt_claims(self):+ def test_residency_header_from_jwt_claims(self, monkeypatch):"""#23896: residency-enforced workspaces 401 without x-openai-internal-codex-residency.- chatgpt_data_residency wins; chatgpt_compute_residency is the fallback; every Codex- header builder derives it from the same JWT."""- from agent.account_usage import _codex_headers+ chatgpt_data_residency wins; chatgpt_compute_residency is the fallback; and the two+ models-catalog probes (picker via httpx, context-length via requests) send it on the+ wire — not just the shared helper."""+ import sys++ from agent import model_metadatafrom agent.auxiliary_client import _codex_cloudflare_headers+ from hermes_cli import codex_models+both = _make_codex_jwt(data_residency="us", compute_residency="eu")assert _codex_cloudflare_headers(both)["x-openai-internal-codex-residency"] == "us"compute_only = _make_codex_jwt(compute_residency="eu")- assert _codex_cloudflare_headers(compute_only)["x-openai-internal-codex-residency"] == "eu"- assert _codex_headers(compute_only, None)["x-openai-internal-codex-residency"] == "eu"++ sent: list[dict] = []++ class _FakeResp:+ status_code = 200++ def json(self):+ return {"models": []}++ class _FakeHttp:+ @staticmethod+ def get(url, headers=None, timeout=None, verify=None):+ sent.append(dict(headers or {}))+ return _FakeResp()++ monkeypatch.setitem(sys.modules, "httpx", _FakeHttp)+ codex_models._fetch_models_from_api(access_token=compute_only)+ monkeypatch.setattr(model_metadata, "requests", _FakeHttp)+ monkeypatch.setattr(model_metadata, "_ensure_requests", lambda: None)+ monkeypatch.setattr(model_metadata, "_codex_oauth_context_cache", {})+ model_metadata._fetch_codex_oauth_context_lengths_with_source(compute_only)++ assert len(sent) == 2+ for headers in sent:+ assert headers["x-openai-internal-codex-residency"] == "eu"+ assert headers["ChatGPT-Account-ID"] == "acct-test-123"def test_no_residency_claim_omits_header(self):"""Control: tokens without the claim, and malformed tokens, never carry the header."""