From 04783d11d870759e3f0374859f5513743a38cfa5 Mon Sep 17 00:00:00 2001 From: mol <1477787+Gerkinfeltser@users.noreply.github.com> Date: Fri, 17 Jul 2026 16:33:52 +0000 Subject: [PATCH] fix: normalize Codex handoff base URL --- api/routes.py | 2 +- tests/test_issue1013_handoff_dock.py | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/api/routes.py b/api/routes.py index 94280869..0d9c37bd 100644 --- a/api/routes.py +++ b/api/routes.py @@ -24808,7 +24808,7 @@ def _handle_handoff_summary(handler, body): codex_kwargs = agent._build_api_kwargs(api_messages) codex_kwargs.pop("tools", None) codex_provider = str(getattr(agent, "provider", "") or "").strip().lower() - codex_base_url = str(getattr(agent, "base_url", "") or "").lower() + codex_base_url = str(getattr(agent, "base_url", "") or "").strip().lower() is_chatgpt_codex = ( codex_provider == "openai-codex" or ( diff --git a/tests/test_issue1013_handoff_dock.py b/tests/test_issue1013_handoff_dock.py index 42eac320..87e4e5d0 100644 --- a/tests/test_issue1013_handoff_dock.py +++ b/tests/test_issue1013_handoff_dock.py @@ -504,21 +504,31 @@ def test_handoff_summary_retries_once_when_length_limit_reached(monkeypatch): @pytest.mark.parametrize( - ("provider", "base_url", "expects_output_cap"), + ("provider", "base_url", "expects_output_cap", "expects_normalized_base_url"), [ - ("openai-codex", "https://chatgpt.com/backend-api/codex", False), - ("custom:chatgpt-codex", "https://chatgpt.com/backend-api/codex", False), - ("custom:responses-proxy", "https://responses.example/v1", True), + ("openai-codex", "https://chatgpt.com/backend-api/codex", False, False), + ("custom:chatgpt-codex", "https://chatgpt.com/backend-api/codex", False, False), + ("custom:chatgpt-codex", " https://chatgpt.com/backend-api/codex ", False, True), + ("custom:responses-proxy", "https://responses.example/v1", True, False), ], ) def test_handoff_summary_codex_output_cap_matches_provider_compatibility( - monkeypatch, provider, base_url, expects_output_cap, + monkeypatch, provider, base_url, expects_output_cap, expects_normalized_base_url, ): """ChatGPT Codex rejects the cap, while other Responses transports retain it.""" import api.config as cfg import api.models as models import api.routes as routes + if expects_normalized_base_url: + real_urlsplit = routes.urlsplit + + def _strict_urlsplit(value): + assert value == value.strip() + return real_urlsplit(value) + + monkeypatch.setattr(routes, "urlsplit", _strict_urlsplit) + monkeypatch.setattr(routes, "require", lambda body, *keys: None) monkeypatch.setattr(routes, "bad", lambda _handler, msg, status=400: {"ok": False, "error": msg, "status": status}) monkeypatch.setattr(routes, "j", lambda _handler, payload, status=200, extra_headers=None: payload)