From 9be2b180641d29f59130c972efe28364e4d4ce66 Mon Sep 17 00:00:00 2001 From: Lume Date: Sun, 5 Apr 2026 07:33:10 +0100 Subject: [PATCH] test: add test for _should_sanitize_tool_calls() Adds test verifying that: - Codex mode returns False (no sanitization needed) - Chat completions mode returns True (sanitization needed) - Anthropic mode returns True (sanitization needed) This ensures strict APIs like Fireworks receive properly sanitized tool_calls. --- tests/test_provider_parity.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_provider_parity.py b/tests/test_provider_parity.py index 0d36a89ba..0029376ab 100644 --- a/tests/test_provider_parity.py +++ b/tests/test_provider_parity.py @@ -137,6 +137,23 @@ class TestBuildApiKwargsOpenRouter: assert messages[1]["tool_calls"][0]["response_item_id"] == "fc_123" assert "codex_reasoning_items" in messages[1] + def test_should_sanitize_tool_calls_codex_vs_chat(self, monkeypatch): + """Codex API should NOT sanitize, all other APIs should sanitize.""" + # Codex mode should NOT need sanitization + codex_agent = _make_agent(monkeypatch, "openrouter") + codex_agent.api_mode = "codex_responses" + assert codex_agent._should_sanitize_tool_calls() is False + + # Chat completions mode should need sanitization + chat_agent = _make_agent(monkeypatch, "openrouter") + chat_agent.api_mode = "chat_completions" + assert chat_agent._should_sanitize_tool_calls() is True + + # Anthropic mode should need sanitization + anthropic_agent = _make_agent(monkeypatch, "openrouter") + anthropic_agent.api_mode = "anthropic_messages" + assert anthropic_agent._should_sanitize_tool_calls() is True + class TestDeveloperRoleSwap: """GPT-5 and Codex models should get 'developer' instead of 'system' role."""