@@ -30,7 +30,8 @@ def test_plugin_module_imports():
3030 'optillm.plugins.deep_research_plugin' ,
3131 'optillm.plugins.deepthink_plugin' ,
3232 'optillm.plugins.longcepo_plugin' ,
33- 'optillm.plugins.spl_plugin'
33+ 'optillm.plugins.spl_plugin' ,
34+ 'optillm.plugins.proxy_plugin'
3435 ]
3536
3637 for module_name in plugin_modules :
@@ -51,7 +52,7 @@ def test_plugin_approach_detection():
5152 load_plugins ()
5253
5354 # Check if known plugins are loaded
54- expected_plugins = ["memory" , "readurls" , "privacy" , "web_search" , "deep_research" , "deepthink" , "longcepo" , "spl" ]
55+ expected_plugins = ["memory" , "readurls" , "privacy" , "web_search" , "deep_research" , "deepthink" , "longcepo" , "spl" , "proxy" ]
5556 for plugin_name in expected_plugins :
5657 assert plugin_name in plugin_approaches , f"Plugin { plugin_name } not loaded"
5758
@@ -141,6 +142,63 @@ def test_spl_plugin():
141142 assert run_spl is not None
142143
143144
145+ def test_proxy_plugin ():
146+ """Test proxy plugin module"""
147+ import optillm .plugins .proxy_plugin as plugin
148+ assert hasattr (plugin , 'run' )
149+ assert hasattr (plugin , 'SLUG' )
150+ assert plugin .SLUG == "proxy"
151+
152+ # Test proxy submodules can be imported
153+ from optillm .plugins .proxy import client , config , approach_handler
154+ assert client is not None
155+ assert config is not None
156+ assert approach_handler is not None
157+
158+
159+ def test_proxy_plugin_token_counts ():
160+ """Test that proxy plugin returns complete token usage information"""
161+ import optillm .plugins .proxy_plugin as plugin
162+ from unittest .mock import Mock , MagicMock
163+
164+ # Create a mock client with a mock response that has all token counts
165+ mock_client = Mock ()
166+ mock_response = MagicMock ()
167+ mock_response .choices = [Mock (message = Mock (content = "Test response" ))]
168+ mock_response .usage = Mock (
169+ prompt_tokens = 10 ,
170+ completion_tokens = 5 ,
171+ total_tokens = 15
172+ )
173+ mock_response .model_dump .return_value = {
174+ 'choices' : [{'message' : {'content' : 'Test response' }}],
175+ 'usage' : {
176+ 'prompt_tokens' : 10 ,
177+ 'completion_tokens' : 5 ,
178+ 'total_tokens' : 15
179+ }
180+ }
181+ mock_client .chat .completions .create .return_value = mock_response
182+
183+ # Run the proxy plugin
184+ result , _ = plugin .run (
185+ system_prompt = "Test system" ,
186+ initial_query = "Test query" ,
187+ client = mock_client ,
188+ model = "test-model"
189+ )
190+
191+ # Verify the result contains all token counts
192+ assert isinstance (result , dict ), "Result should be a dictionary"
193+ assert 'usage' in result , "Result should contain usage information"
194+ assert 'prompt_tokens' in result ['usage' ], "Usage should contain prompt_tokens"
195+ assert 'completion_tokens' in result ['usage' ], "Usage should contain completion_tokens"
196+ assert 'total_tokens' in result ['usage' ], "Usage should contain total_tokens"
197+ assert result ['usage' ]['prompt_tokens' ] == 10
198+ assert result ['usage' ]['completion_tokens' ] == 5
199+ assert result ['usage' ]['total_tokens' ] == 15
200+
201+
144202def test_plugin_subdirectory_imports ():
145203 """Test all plugins with subdirectories can import their submodules"""
146204 # Test deep_research
@@ -159,6 +217,12 @@ def test_plugin_subdirectory_imports():
159217 # Test spl
160218 from optillm .plugins .spl import run_spl
161219 assert run_spl is not None
220+
221+ # Test proxy
222+ from optillm .plugins .proxy import client , config , approach_handler
223+ assert client is not None
224+ assert config is not None
225+ assert approach_handler is not None
162226
163227
164228def test_no_relative_import_errors ():
@@ -170,7 +234,8 @@ def test_no_relative_import_errors():
170234 'optillm.plugins.deepthink_plugin' ,
171235 'optillm.plugins.deep_research_plugin' ,
172236 'optillm.plugins.longcepo_plugin' ,
173- 'optillm.plugins.spl_plugin'
237+ 'optillm.plugins.spl_plugin' ,
238+ 'optillm.plugins.proxy_plugin'
174239 ]
175240
176241 for plugin_name in plugins_with_subdirs :
@@ -256,6 +321,18 @@ def test_no_relative_import_errors():
256321 except Exception as e :
257322 print (f"❌ SPL plugin test failed: { e } " )
258323
324+ try :
325+ test_proxy_plugin ()
326+ print ("✅ Proxy plugin test passed" )
327+ except Exception as e :
328+ print (f"❌ Proxy plugin test failed: { e } " )
329+
330+ try :
331+ test_proxy_plugin_token_counts ()
332+ print ("✅ Proxy plugin token counts test passed" )
333+ except Exception as e :
334+ print (f"❌ Proxy plugin token counts test failed: { e } " )
335+
259336 try :
260337 test_plugin_subdirectory_imports ()
261338 print ("✅ Plugin subdirectory imports test passed" )
0 commit comments