diff --git a/lib/cli/src/crewai_cli/create_flow.py b/lib/cli/src/crewai_cli/create_flow.py index 1352cb5ee..a026cea44 100644 --- a/lib/cli/src/crewai_cli/create_flow.py +++ b/lib/cli/src/crewai_cli/create_flow.py @@ -12,14 +12,14 @@ def create_flow(name: str) -> None: click.secho(f"Creating flow {folder_name}...", fg="green", bold=True) - telemetry = Telemetry() - telemetry.flow_creation_span(class_name) - project_root = Path(folder_name) if project_root.exists(): click.secho(f"Error: Folder {folder_name} already exists.", fg="red") return + telemetry = Telemetry() + telemetry.flow_creation_span(class_name) + # Create directory structure (project_root / "src" / folder_name).mkdir(parents=True) (project_root / "src" / folder_name / "crews").mkdir(parents=True) diff --git a/lib/cli/src/crewai_cli/deploy/main.py b/lib/cli/src/crewai_cli/deploy/main.py index 7a61e42dc..f72658115 100644 --- a/lib/cli/src/crewai_cli/deploy/main.py +++ b/lib/cli/src/crewai_cli/deploy/main.py @@ -47,7 +47,6 @@ class DeployCommand(BaseCommand, PlusAPIMixin): BaseCommand.__init__(self) PlusAPIMixin.__init__(self, telemetry=self._telemetry) self.project_name = get_project_name(require=True) - self._validate_project_structure() def _validate_project_structure(self) -> None: """Validate that the local project has the files required for deployment.""" @@ -127,6 +126,7 @@ class DeployCommand(BaseCommand, PlusAPIMixin): uuid (Optional[str]): The UUID of the crew to deploy. skip_validate (bool): Skip pre-deploy validation checks. """ + self._validate_project_structure() if not _run_predeploy_validation(skip_validate): return self._telemetry.start_deployment_span(uuid) @@ -150,6 +150,7 @@ class DeployCommand(BaseCommand, PlusAPIMixin): confirm (bool): Whether to skip the interactive confirmation prompt. skip_validate (bool): Skip pre-deploy validation checks. """ + self._validate_project_structure() if not _run_predeploy_validation(skip_validate): return self._telemetry.create_crew_deployment_span() diff --git a/lib/cli/tests/deploy/test_deploy_main.py b/lib/cli/tests/deploy/test_deploy_main.py index f947d51e1..5dc781471 100644 --- a/lib/cli/tests/deploy/test_deploy_main.py +++ b/lib/cli/tests/deploy/test_deploy_main.py @@ -125,8 +125,9 @@ class TestDeployCommand(unittest.TestCase): ) self.assertIn("2023-01-01 - INFO: Test log", fake_out.getvalue()) + @patch.object(DeployCommand, "_validate_project_structure") @patch("crewai_cli.deploy.main.DeployCommand._display_deployment_info") - def test_deploy_with_uuid(self, mock_display): + def test_deploy_with_uuid(self, mock_display, mock_validate_structure): mock_response = MagicMock() mock_response.status_code = 200 mock_response.json.return_value = {"uuid": "test-uuid"} @@ -137,8 +138,9 @@ class TestDeployCommand(unittest.TestCase): self.mock_client.deploy_by_uuid.assert_called_once_with("test-uuid") mock_display.assert_called_once_with({"uuid": "test-uuid"}) + @patch.object(DeployCommand, "_validate_project_structure") @patch("crewai_cli.deploy.main.DeployCommand._display_deployment_info") - def test_deploy_with_project_name(self, mock_display): + def test_deploy_with_project_name(self, mock_display, mock_validate_structure): mock_response = MagicMock() mock_response.status_code = 200 mock_response.json.return_value = {"uuid": "test-uuid"} @@ -149,10 +151,13 @@ class TestDeployCommand(unittest.TestCase): self.mock_client.deploy_by_name.assert_called_once_with("test_project") mock_display.assert_called_once_with({"uuid": "test-uuid"}) + @patch.object(DeployCommand, "_validate_project_structure") @patch("crewai_cli.deploy.main.fetch_and_json_env_file") @patch("crewai_cli.deploy.main.git.Repository.origin_url") @patch("builtins.input") - def test_create_crew(self, mock_input, mock_git_origin_url, mock_fetch_env): + def test_create_crew( + self, mock_input, mock_git_origin_url, mock_fetch_env, mock_validate_structure + ): mock_fetch_env.return_value = {"ENV_VAR": "value"} mock_git_origin_url.return_value = "https://github.com/test/repo.git" mock_input.return_value = ""