@@ -26,6 +26,16 @@ def test_litellm_env_mapping(monkeypatch):
2626 assert cfg ["litellm" ]["base_url" ] == "https://litellm.example/v1"
2727
2828
29+ def test_uniform_llm_max_tokens_env_mapping (monkeypatch ):
30+ monkeypatch .setenv ("LLM_MAX_TOKENS" , "16384" )
31+ _reset_config_cache ()
32+
33+ cfg = load_addon_config ()
34+
35+ assert cfg ["llm" ]["max_tokens" ] == 16384
36+ assert LLMService ().get_max_tokens () == 16384
37+
38+
2939def test_atlascloud_env_mapping (monkeypatch ):
3040 monkeypatch .setenv ("ATLASCLOUD_API_KEY" , "atlas-key" )
3141 monkeypatch .setenv ("ATLASCLOUD_MODEL" , "openai/gpt-5.4" )
@@ -90,9 +100,82 @@ def fake_post(url, headers, json, timeout):
90100 assert captured ["url" ] == "https://api.atlascloud.ai/v1/chat/completions"
91101 assert captured ["headers" ]["Authorization" ] == "Bearer atlas-key"
92102 assert captured ["json" ]["model" ] == "deepseek-v3"
103+ assert captured ["json" ]["max_tokens" ] == 16384
93104 assert "response_format" not in captured ["json" ]
94105
95106
107+ def test_google_gemini_uses_uniform_max_tokens (monkeypatch ):
108+ captured = {}
109+
110+ class FakeResponse :
111+ def raise_for_status (self ):
112+ return None
113+
114+ def json (self ):
115+ return {
116+ "candidates" : [
117+ {"content" : {"parts" : [{"text" : "{\" ok\" : true}" }]}}
118+ ]
119+ }
120+
121+ service = LLMService (provider = "google" )
122+ monkeypatch .setattr (service , "get_max_tokens" , lambda : 16384 )
123+
124+ def fake_post (url , ** kwargs ):
125+ captured .update ({"url" : url , ** kwargs })
126+ return FakeResponse ()
127+
128+ monkeypatch .setattr (service , "_llm_post" , fake_post )
129+
130+ out = service ._call_google_gemini (
131+ [{"role" : "user" , "content" : "hello" }],
132+ "gemini-1.5-flash" ,
133+ 0.7 ,
134+ "google-key" ,
135+ "https://generativelanguage.googleapis.com/v1beta" ,
136+ 30 ,
137+ )
138+
139+ assert out == "{\" ok\" : true}"
140+ assert captured ["json_payload" ]["generationConfig" ]["maxOutputTokens" ] == 16384
141+
142+
143+ def test_openai_compatible_stream_uses_uniform_max_tokens (monkeypatch ):
144+ captured = {}
145+
146+ class FakeResponse :
147+ status_code = 200
148+
149+ def iter_lines (self , decode_unicode = False ):
150+ return [b"data: [DONE]" ]
151+
152+ def close (self ):
153+ return None
154+
155+ service = LLMService (provider = "openrouter" )
156+ monkeypatch .setattr (service , "get_max_tokens" , lambda : 16384 )
157+
158+ def fake_post (url , ** kwargs ):
159+ captured .update ({"url" : url , ** kwargs })
160+ return FakeResponse ()
161+
162+ monkeypatch .setattr (service , "_llm_post" , fake_post )
163+
164+ chunks = list (
165+ service ._stream_openai_compatible (
166+ [{"role" : "user" , "content" : "hello" }],
167+ "openai/gpt-5.4" ,
168+ 0.7 ,
169+ "openrouter-key" ,
170+ "https://openrouter.ai/api/v1" ,
171+ 30 ,
172+ )
173+ )
174+
175+ assert chunks == []
176+ assert captured ["json_payload" ]["max_tokens" ] == 16384
177+
178+
96179@pytest .mark .parametrize (
97180 ("payload" , "expected" ),
98181 [
@@ -400,9 +483,12 @@ def completion(**kwargs):
400483
401484
402485def test_litellm_response_content (monkeypatch ):
486+ captured = {}
487+
403488 class FakeLiteLLM :
404489 @staticmethod
405490 def completion (** kwargs ):
491+ captured .update (kwargs )
406492 return SimpleNamespace (
407493 choices = [SimpleNamespace (message = SimpleNamespace (content = "hello" ))]
408494 )
@@ -421,3 +507,4 @@ def completion(**kwargs):
421507 )
422508
423509 assert out == "hello"
510+ assert captured ["max_tokens" ] == 16384
0 commit comments