@@ -315,6 +315,109 @@ async def test_modify_llm_settings_basic_invalid_input(
315315 assert settings .llm_api_key .get_secret_value () == 'new-api-key'
316316 assert settings .llm_base_url is None
317317
318+ def test_default_provider_preference (self ):
319+ """Test that the default provider prefers 'anthropic' if available."""
320+ # This is a simple test to verify that the default provider prefers 'anthropic'
321+ # We're directly checking the code in settings.py where the default provider is set
322+
323+ # Import the settings module to check the default provider
324+ # Find the line where the default provider is set
325+ import inspect
326+
327+ import openhands .cli .settings as settings_module
328+
329+ source_lines = inspect .getsource (
330+ settings_module .modify_llm_settings_basic
331+ ).splitlines ()
332+
333+ # Look for the line that sets the default provider
334+ default_provider_found = False
335+ for i , line in enumerate (source_lines ):
336+ if "# Set default provider - prefer 'anthropic' if available" in line :
337+ default_provider_found = True
338+ break
339+
340+ # Assert that the default provider comment exists
341+ assert default_provider_found , 'Could not find the default provider comment'
342+
343+ # Now look for the actual implementation
344+ provider_impl_found = False
345+ for i , line in enumerate (source_lines ):
346+ if "'anthropic'" in line and "if 'anthropic' in provider_list" in line :
347+ provider_impl_found = True
348+ break
349+
350+ assert provider_impl_found , (
351+ "Could not find the implementation that prefers 'anthropic'"
352+ )
353+
354+ # Also check the fallback provider when provider not in organized_models
355+ fallback_comment_found = False
356+ for i , line in enumerate (source_lines ):
357+ if (
358+ "# If the provider doesn't exist, prefer 'anthropic' if available"
359+ in line
360+ ):
361+ fallback_comment_found = True
362+ break
363+
364+ assert fallback_comment_found , 'Could not find the fallback provider comment'
365+
366+ # Now look for the actual implementation
367+ fallback_impl_found = False
368+ for i , line in enumerate (source_lines ):
369+ if "'anthropic'" in line and "if 'anthropic' in organized_models" in line :
370+ fallback_impl_found = True
371+ break
372+
373+ assert fallback_impl_found , (
374+ "Could not find the fallback implementation that prefers 'anthropic'"
375+ )
376+
377+ def test_default_model_selection (self ):
378+ """Test that the default model selection uses the first model in the list."""
379+ # This is a simple test to verify that the default model selection uses the first model in the list
380+ # We're directly checking the code in settings.py where the default model is set
381+
382+ import inspect
383+
384+ import openhands .cli .settings as settings_module
385+
386+ source_lines = inspect .getsource (
387+ settings_module .modify_llm_settings_basic
388+ ).splitlines ()
389+
390+ # Look for the block that sets the default model
391+ default_model_block = []
392+ in_default_model_block = False
393+ for line in source_lines :
394+ if '# Set default model to the first model in the list' in line :
395+ in_default_model_block = True
396+ default_model_block .append (line )
397+ elif in_default_model_block :
398+ default_model_block .append (line )
399+ if '# Show the default model' in line :
400+ break
401+
402+ # Assert that we found the default model selection logic
403+ assert default_model_block , (
404+ 'Could not find the block that sets the default model'
405+ )
406+
407+ # Print the actual lines for debugging
408+ print ('Default model block found:' )
409+ for line in default_model_block :
410+ print (f' { line .strip ()} ' )
411+
412+ # Check that the logic uses the first model in the list
413+ first_model_check = any (
414+ 'provider_models[0]' in line for line in default_model_block
415+ )
416+
417+ assert first_model_check , (
418+ 'Default model selection should use the first model in the list'
419+ )
420+
318421
319422class TestModifyLLMSettingsAdvanced :
320423 @pytest .fixture
0 commit comments