From 6f4684b34bb1a040462cdea1b4a90df67cae3292 Mon Sep 17 00:00:00 2001 From: Joao Moura Date: Mon, 15 Jun 2026 14:17:38 -0700 Subject: [PATCH] fix(cli): align json zip wrapper detection --- lib/cli/src/crewai_cli/deploy/archive.py | 12 +++----- lib/cli/tests/deploy/test_archive.py | 35 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/lib/cli/src/crewai_cli/deploy/archive.py b/lib/cli/src/crewai_cli/deploy/archive.py index 3013b6c9b..6005e76e8 100644 --- a/lib/cli/src/crewai_cli/deploy/archive.py +++ b/lib/cli/src/crewai_cli/deploy/archive.py @@ -157,14 +157,10 @@ def _is_json_crew_project(root: Path) -> bool: project = _read_pyproject(root) tool_config = project.get("tool") or {} - if not isinstance(tool_config, dict): - return False - - crewai_config = tool_config.get("crewai") or {} - if not isinstance(crewai_config, dict): - return False - - declared_type = crewai_config.get("type") + crewai_config = tool_config.get("crewai") if isinstance(tool_config, dict) else None + declared_type = ( + crewai_config.get("type") if isinstance(crewai_config, dict) else None + ) if declared_type == "flow": return False diff --git a/lib/cli/tests/deploy/test_archive.py b/lib/cli/tests/deploy/test_archive.py index afa312e24..256e3716e 100644 --- a/lib/cli/tests/deploy/test_archive.py +++ b/lib/cli/tests/deploy/test_archive.py @@ -177,6 +177,41 @@ type = "crew" assert "run_crew = \"json_crew.main:run\"" in pyproject +@pytest.mark.parametrize( + "tool_config", + [ + 'tool = "invalid"\n', + '[tool]\ncrewai = "invalid"\n', + ], +) +def test_create_project_zip_adds_json_wrapper_for_malformed_tool_config( + tmp_path: Path, tool_config: str +): + (tmp_path / "pyproject.toml").write_text( + f""" +[project] +name = "json_crew" +version = "0.1.0" + +{tool_config} +""".strip() + + "\n" + ) + (tmp_path / "crew.jsonc").write_text("{}\n") + + archive_path = create_project_zip("json_crew", project_dir=tmp_path) + try: + with zipfile.ZipFile(archive_path) as archive: + names = set(archive.namelist()) + pyproject = archive.read("pyproject.toml").decode() + finally: + archive_path.unlink(missing_ok=True) + + assert "src/json_crew/crew.py" in names + assert "src/json_crew/main.py" in names + assert "run_crew = \"json_crew.main:run\"" in pyproject + + def test_create_project_zip_rejects_empty_normalized_package_name(tmp_path: Path): (tmp_path / "pyproject.toml").write_text( """