From ead9d7b256390876a2170e2751365fdf2fb6cc5f Mon Sep 17 00:00:00 2001 From: aui Date: Thu, 16 Jul 2026 08:14:13 +0800 Subject: [PATCH] test: cover gemini-native max_tokens forwarding in _build_call_kwargs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Requested in review: builder-level assertions that the gemini-native branch forwards max_tokens (provider names and the native generativelanguage.googleapis.com base_url, max_tokens=600), plus a control showing gemini models on OpenAI-compatible endpoints — including Gemini's own /openai compatibility endpoint — keep the existing omission behavior (#34530). Co-Authored-By: Claude Fable 5 --- tests/agent/test_auxiliary_client.py | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/agent/test_auxiliary_client.py b/tests/agent/test_auxiliary_client.py index 44ae12026517..86b5ae4adc50 100644 --- a/tests/agent/test_auxiliary_client.py +++ b/tests/agent/test_auxiliary_client.py @@ -775,6 +775,55 @@ class TestBuildCallKwargsMaxTokens: ) assert "max_tokens" not in kw3 + @pytest.mark.parametrize( + "provider,model,base_url", + [ + ("gemini", "gemini-2.5-pro", None), + ("google", "gemini-2.5-flash", None), + ( + "custom", + "gemini-2.5-pro", + "https://generativelanguage.googleapis.com/v1beta", + ), + ], + ) + def test_keeps_max_tokens_for_gemini_native(self, provider, model, base_url): + # Native generateContent maps max_tokens → maxOutputTokens; when it is + # omitted Gemini applies a fixed 65,535-token ceiling, which silently + # turned MoA's reference_max_tokens into a no-op for gemini advisors. + from agent.auxiliary_client import _build_call_kwargs + + kwargs = _build_call_kwargs( + provider=provider, + model=model, + messages=[{"role": "user", "content": "hi"}], + max_tokens=600, + base_url=base_url, + ) + assert kwargs["max_tokens"] == 600 + assert "max_completion_tokens" not in kwargs + + def test_omits_max_tokens_for_gemini_model_on_openai_compatible_endpoint(self): + # Control: the gemini branch keys on provider/base_url, never the model + # name. A gemini model served through an OpenAI-compatible endpoint + # keeps the default omission behavior (#34530), including Gemini's own + # /openai compatibility endpoint. + from agent.auxiliary_client import _build_call_kwargs + + for provider, base_url in [ + ("openrouter", "https://openrouter.ai/api/v1"), + ("custom", "https://generativelanguage.googleapis.com/v1beta/openai"), + ]: + kwargs = _build_call_kwargs( + provider=provider, + model="google/gemini-2.5-pro", + messages=[{"role": "user", "content": "hi"}], + max_tokens=600, + base_url=base_url, + ) + assert "max_tokens" not in kwargs + assert "max_completion_tokens" not in kwargs + class TestNousTagsScoping: def test_tags_injected_when_provider_is_nous(self, monkeypatch):