diff --git a/lib/cli/src/crewai_cli/deploy/main.py b/lib/cli/src/crewai_cli/deploy/main.py index a114a23dd..0a397cf1d 100644 --- a/lib/cli/src/crewai_cli/deploy/main.py +++ b/lib/cli/src/crewai_cli/deploy/main.py @@ -222,8 +222,11 @@ class DeployCommand(BaseCommand, PlusAPIMixin): console.print(f"\nOpening deployment page: [blue]{deployment_url}[/blue]") try: - webbrowser.open(deployment_url) - except Exception: # pragma: no cover + opened = webbrowser.open(deployment_url) + except Exception: + opened = False + + if not opened: console.print( "Could not open the deployment page automatically.", style="yellow", diff --git a/lib/cli/tests/deploy/test_deploy_main.py b/lib/cli/tests/deploy/test_deploy_main.py index 03ef36839..1b2fab0a8 100644 --- a/lib/cli/tests/deploy/test_deploy_main.py +++ b/lib/cli/tests/deploy/test_deploy_main.py @@ -311,6 +311,38 @@ class TestDeployCommand(unittest.TestCase): "https://app.crewai.com/crewai_plus/deployments/128687" ) + def test_display_deployment_info_warns_when_browser_open_returns_false(self): + self.mock_browser_open.return_value = False + + with patch("sys.stdout", new=StringIO()) as fake_out: + self.deploy_command._display_deployment_info( + {"uuid": "test-uuid", "id": 128687, "status": "deployed"} + ) + self.assertIn( + "Could not open the deployment page automatically.", + fake_out.getvalue(), + ) + + self.mock_browser_open.assert_called_once_with( + "https://app.crewai.com/crewai_plus/deployments/128687" + ) + + def test_display_deployment_info_warns_when_browser_open_raises(self): + self.mock_browser_open.side_effect = RuntimeError("no browser") + + with patch("sys.stdout", new=StringIO()) as fake_out: + self.deploy_command._display_deployment_info( + {"uuid": "test-uuid", "id": 128687, "status": "deployed"} + ) + self.assertIn( + "Could not open the deployment page automatically.", + fake_out.getvalue(), + ) + + self.mock_browser_open.assert_called_once_with( + "https://app.crewai.com/crewai_plus/deployments/128687" + ) + def test_display_logs(self): with patch("sys.stdout", new=StringIO()) as fake_out: self.deploy_command._display_logs(