@@ -660,3 +660,42 @@ def test_run_web_command_mcp_success(tmp_path: Path, mocker: MockerFixture, capf
660660 mock_uvicorn_run .assert_called_once ()
661661 output = capfd .readouterr ().out
662662 assert 'Loaded 1 MCP server(s)' in output
663+
664+
665+ def test_run_web_command_agent_model_merged_with_cli_models (
666+ mocker : MockerFixture , create_test_module : Callable [..., None ]
667+ ):
668+ """Test that agent's model is included first, followed by CLI models."""
669+ mock_uvicorn_run = mocker .patch ('uvicorn.run' )
670+ mock_create_app = mocker .patch ('pydantic_ai._cli._web.create_web_app' )
671+
672+ test_agent = Agent (TestModel (custom_output_text = 'test' ))
673+ create_test_module (custom_agent = test_agent )
674+
675+ result = _run_web_command (
676+ agent_path = 'test_module:custom_agent' , models = ['openai:gpt-5' , 'anthropic:claude-sonnet-4-5' ]
677+ )
678+
679+ assert result == 0
680+ mock_uvicorn_run .assert_called_once ()
681+
682+ call_kwargs = mock_create_app .call_args .kwargs
683+ assert call_kwargs .get ('models' ) == snapshot (['test:test' , 'openai:gpt-5' , 'anthropic:claude-sonnet-4-5' ])
684+
685+
686+ def test_run_web_command_agent_model_deduplicated (mocker : MockerFixture , create_test_module : Callable [..., None ]):
687+ """Test that duplicate models are removed when CLI passes the same model as agent."""
688+ mock_uvicorn_run = mocker .patch ('uvicorn.run' )
689+ mock_create_app = mocker .patch ('pydantic_ai._cli._web.create_web_app' )
690+
691+ test_agent = Agent (TestModel (custom_output_text = 'test' ))
692+ create_test_module (custom_agent = test_agent )
693+
694+ # Pass the same model that the agent has, plus another
695+ result = _run_web_command (agent_path = 'test_module:custom_agent' , models = ['test:test' , 'openai:gpt-5' ])
696+
697+ assert result == 0
698+ mock_uvicorn_run .assert_called_once ()
699+
700+ call_kwargs = mock_create_app .call_args .kwargs
701+ assert call_kwargs .get ('models' ) == snapshot (['test:test' , 'openai:gpt-5' ])
0 commit comments