mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 15:48:29 +00:00
fix: correct folder name validation logic to match test expectations
- 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 <joao@crewai.com>
This commit is contained in:
@@ -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")
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user