From dc9e03357175b202b86648250e187dc00fcea08a Mon Sep 17 00:00:00 2001 From: Greyson Lalonde Date: Tue, 5 May 2026 05:10:00 +0800 Subject: [PATCH] refactor(deploy): drop redundant _validate_project_structure --- lib/cli/src/crewai_cli/deploy/main.py | 39 ------------------------ lib/cli/tests/deploy/test_deploy_main.py | 13 ++------ lib/cli/tests/deploy/test_validate.py | 1 - 3 files changed, 3 insertions(+), 50 deletions(-) diff --git a/lib/cli/src/crewai_cli/deploy/main.py b/lib/cli/src/crewai_cli/deploy/main.py index cd8fc3282..606bf1c16 100644 --- a/lib/cli/src/crewai_cli/deploy/main.py +++ b/lib/cli/src/crewai_cli/deploy/main.py @@ -1,4 +1,3 @@ -from pathlib import Path from typing import Any from rich.console import Console @@ -48,40 +47,6 @@ class DeployCommand(BaseCommand, PlusAPIMixin): PlusAPIMixin.__init__(self, telemetry=self._telemetry) self.project_name = get_project_name(require=True) - def _validate_project_structure(self) -> None: - """Validate that the local project has the files required for deployment.""" - errors: list[str] = [] - - if not Path("pyproject.toml").exists(): - errors.append("Cannot find pyproject.toml in the current directory.") - - has_lockfile = Path("uv.lock").exists() or Path("poetry.lock").exists() - if not has_lockfile: - errors.append( - "No uv.lock or poetry.lock found. " - "Run 'uv lock' or 'poetry lock' to generate one." - ) - - src_dir = Path("src") / (self.project_name or "") - crew_py = src_dir / "crew.py" - config_dir = src_dir / "config" - if not crew_py.exists() and not config_dir.exists(): - errors.append( - f"Cannot find src/{self.project_name}/crew.py or " - f"src/{self.project_name}/config. " - "Ensure you are running this command from the project root." - ) - - if errors: - console.print( - "\n[bold red]Pre-flight check failed:[/bold red] " - "Your project is missing required files for deployment.\n" - ) - for error in errors: - console.print(f" • {error}", style="red") - console.print() - raise SystemExit(1) - def _standard_no_param_error_message(self) -> None: """ Display a standard error message when no UUID or project name is available. @@ -126,8 +91,6 @@ class DeployCommand(BaseCommand, PlusAPIMixin): uuid (Optional[str]): The UUID of the crew to deploy. skip_validate (bool): Skip pre-deploy validation checks. """ - if not skip_validate: - self._validate_project_structure() if not _run_predeploy_validation(skip_validate): return self._telemetry.start_deployment_span(uuid) @@ -151,8 +114,6 @@ class DeployCommand(BaseCommand, PlusAPIMixin): confirm (bool): Whether to skip the interactive confirmation prompt. skip_validate (bool): Skip pre-deploy validation checks. """ - if not skip_validate: - 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 5dc781471..4f9fbbc4f 100644 --- a/lib/cli/tests/deploy/test_deploy_main.py +++ b/lib/cli/tests/deploy/test_deploy_main.py @@ -15,10 +15,8 @@ class TestDeployCommand(unittest.TestCase): @patch("crewai_cli.command.get_auth_token") @patch("crewai_cli.deploy.main.get_project_name") @patch("crewai_cli.command.PlusAPI") - @patch.object(DeployCommand, "_validate_project_structure") def setUp( self, - mock_validate_structure, mock_plus_api, mock_get_project_name, mock_get_auth_token, @@ -125,9 +123,8 @@ 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, mock_validate_structure): + def test_deploy_with_uuid(self, mock_display): mock_response = MagicMock() mock_response.status_code = 200 mock_response.json.return_value = {"uuid": "test-uuid"} @@ -138,9 +135,8 @@ 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, mock_validate_structure): + def test_deploy_with_project_name(self, mock_display): mock_response = MagicMock() mock_response.status_code = 200 mock_response.json.return_value = {"uuid": "test-uuid"} @@ -151,13 +147,10 @@ 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, mock_validate_structure - ): + def test_create_crew(self, mock_input, mock_git_origin_url, mock_fetch_env): mock_fetch_env.return_value = {"ENV_VAR": "value"} mock_git_origin_url.return_value = "https://github.com/test/repo.git" mock_input.return_value = "" diff --git a/lib/cli/tests/deploy/test_validate.py b/lib/cli/tests/deploy/test_validate.py index 14356e9a6..17ff0fda9 100644 --- a/lib/cli/tests/deploy/test_validate.py +++ b/lib/cli/tests/deploy/test_validate.py @@ -419,7 +419,6 @@ def test_create_crew_aborts_on_validation_error(tmp_path: Path) -> None: mock_patch("crewai_cli.command.get_auth_token", return_value="tok"), mock_patch("crewai_cli.deploy.main.get_project_name", return_value="p"), mock_patch("crewai_cli.command.PlusAPI") as mock_api, - mock_patch.object(DeployCommand, "_validate_project_structure"), mock_patch( "crewai_cli.deploy.main.validate_project" ) as mock_validate,