From 911e02da8e476e9e79568a3c07a73de0ff6436a7 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 26 Jun 2025 13:18:41 +0000 Subject: [PATCH] fix: correct folder name validation logic to match test expectations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix validation regex to catch names starting with invalid characters like '@#/' - Ensure validation properly raises ValueError for cases expected by tests - Maintain support for valid cases like 'my.project/' -> 'myproject' - Address lucasgomide's comment about valid Python module names Co-Authored-By: João --- src/crewai/cli/create_crew.py | 4 ++++ tests/cli/test_create_crew.py | 16 +++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/crewai/cli/create_crew.py b/src/crewai/cli/create_crew.py index 79722e959..1d3e3ddce 100644 --- a/src/crewai/cli/create_crew.py +++ b/src/crewai/cli/create_crew.py @@ -25,6 +25,10 @@ def create_folder_structure(name, parent_folder=None): folder_name = name.replace(" ", "_").replace("-", "_").lower() folder_name = re.sub(r'[^a-zA-Z0-9_]', '', folder_name) + # Check if the name starts with invalid characters or is primarily invalid + if re.match(r'^[^a-zA-Z0-9_-]+', name): + raise ValueError(f"Project name '{name}' contains no valid characters for a Python module name") + if not folder_name: raise ValueError(f"Project name '{name}' contains no valid characters for a Python module name") diff --git a/tests/cli/test_create_crew.py b/tests/cli/test_create_crew.py index 42d7bdac5..b645d8522 100644 --- a/tests/cli/test_create_crew.py +++ b/tests/cli/test_create_crew.py @@ -1,3 +1,4 @@ +import keyword import shutil import tempfile from pathlib import Path @@ -169,8 +170,6 @@ def test_create_folder_structure_raises_error_for_invalid_names(): def test_create_folder_structure_validates_names(): - import keyword - with tempfile.TemporaryDirectory() as temp_dir: valid_cases = [ ("hello/", "hello", "Hello"), @@ -207,6 +206,12 @@ def test_create_crew_with_parent_folder_and_trailing_slash(mock_load_env, mock_w with tempfile.TemporaryDirectory() as work_dir: parent_path = Path(work_dir) / "parent" parent_path.mkdir() + + create_crew("child-crew/", skip_provider=True, parent_folder=parent_path) + + crew_path = parent_path / "child_crew" + assert crew_path.exists() + assert not (crew_path / "src").exists() def test_create_folder_structure_folder_name_validation(): @@ -239,10 +244,3 @@ def test_create_folder_structure_folder_name_validation(): if folder_path.exists(): shutil.rmtree(folder_path) - - - create_crew("child-crew/", skip_provider=True, parent_folder=parent_path) - - crew_path = parent_path / "child_crew" - assert crew_path.exists() - assert not (crew_path / "src").exists()