fix new project detection
This commit is contained in:
parent
9f6089d0d7
commit
c83815c836
|
|
@ -28,7 +28,7 @@ def is_new_project(directory: str) -> bool:
|
||||||
|
|
||||||
A project is considered new if it either:
|
A project is considered new if it either:
|
||||||
- Is an empty directory
|
- Is an empty directory
|
||||||
- Contains only .git directory and/or .gitignore file
|
- Contains only .git directory, .gitignore file, and/or .ra-aid directory
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
directory: String path to the directory to check
|
directory: String path to the directory to check
|
||||||
|
|
@ -49,8 +49,8 @@ def is_new_project(directory: str) -> bool:
|
||||||
if not path.is_dir():
|
if not path.is_dir():
|
||||||
raise DirectoryNotFoundError(f"Path is not a directory: {directory}")
|
raise DirectoryNotFoundError(f"Path is not a directory: {directory}")
|
||||||
|
|
||||||
# Get all files/dirs in the directory, excluding contents of .git
|
# Get all files/dirs in the directory, excluding allowed items
|
||||||
_allowed_items: Set[str] = {".git", ".gitignore"}
|
_allowed_items: Set[str] = {".git", ".gitignore", ".ra-aid"}
|
||||||
try:
|
try:
|
||||||
contents = set()
|
contents = set()
|
||||||
for item in path.iterdir():
|
for item in path.iterdir():
|
||||||
|
|
@ -60,8 +60,8 @@ def is_new_project(directory: str) -> bool:
|
||||||
except PermissionError as e:
|
except PermissionError as e:
|
||||||
raise DirectoryAccessError(f"Cannot access directory {directory}: {e}")
|
raise DirectoryAccessError(f"Cannot access directory {directory}: {e}")
|
||||||
|
|
||||||
# Directory is new if empty or only contains .gitignore
|
# Directory is new if empty or only contains allowed items
|
||||||
return len(contents) == 0 or contents.issubset({".gitignore"})
|
return len(contents) == 0 or contents.issubset(_allowed_items)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, ProjectStateError):
|
if isinstance(e, ProjectStateError):
|
||||||
|
|
|
||||||
|
|
@ -439,9 +439,6 @@ Guidelines:
|
||||||
|
|
||||||
Are you writing a program that needs to be compiled? Make sure it compiles, if relevant.
|
Are you writing a program that needs to be compiled? Make sure it compiles, if relevant.
|
||||||
|
|
||||||
After finalizing the overall approach:
|
|
||||||
Use emit_plan to store the high-level implementation plan.
|
|
||||||
|
|
||||||
Once you are absolutely sure you are completed planning, you may begin to call request_task_implementation one-by-one for each task to implement the plan.
|
Once you are absolutely sure you are completed planning, you may begin to call request_task_implementation one-by-one for each task to implement the plan.
|
||||||
If you have any doubt about the correctness or thoroughness of the plan, consult the expert (if expert is available) for verification.
|
If you have any doubt about the correctness or thoroughness of the plan, consult the expert (if expert is available) for verification.
|
||||||
|
|
||||||
|
|
@ -455,6 +452,8 @@ You have often been criticized for:
|
||||||
- Asking the user if they want to implement the plan (you are an *autonomous* agent, with no user interaction unless you use the ask_human tool explicitly).
|
- Asking the user if they want to implement the plan (you are an *autonomous* agent, with no user interaction unless you use the ask_human tool explicitly).
|
||||||
- Not calling tools/functions properly, e.g. leaving off required arguments, calling a tool in a loop, calling tools inappropriately.
|
- Not calling tools/functions properly, e.g. leaving off required arguments, calling a tool in a loop, calling tools inappropriately.
|
||||||
|
|
||||||
|
DO NOT WRITE ANY FILES YET. CODE WILL BE WRITTEN AS YOU CALL request_task_implementation.
|
||||||
|
|
||||||
NEVER ANNOUNCE WHAT YOU ARE DOING, JUST DO IT!
|
NEVER ANNOUNCE WHAT YOU ARE DOING, JUST DO IT!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,26 @@ def git_only_dir(tmp_path):
|
||||||
return tmp_path
|
return tmp_path
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def ra_aid_only_dir(tmp_path):
|
||||||
|
"""Create a directory with only a .ra-aid directory."""
|
||||||
|
ra_aid_dir = tmp_path / ".ra-aid"
|
||||||
|
ra_aid_dir.mkdir()
|
||||||
|
return tmp_path
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mixed_allowed_dir(tmp_path):
|
||||||
|
"""Create a directory with all allowed items (.git, .gitignore, and .ra-aid)."""
|
||||||
|
git_dir = tmp_path / ".git"
|
||||||
|
git_dir.mkdir()
|
||||||
|
gitignore = tmp_path / ".gitignore"
|
||||||
|
gitignore.write_text("*.pyc\n")
|
||||||
|
ra_aid_dir = tmp_path / ".ra-aid"
|
||||||
|
ra_aid_dir.mkdir()
|
||||||
|
return tmp_path
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def project_dir(tmp_path):
|
def project_dir(tmp_path):
|
||||||
"""Create a directory with some project files."""
|
"""Create a directory with some project files."""
|
||||||
|
|
@ -46,6 +66,16 @@ def test_git_only_directory(git_only_dir):
|
||||||
assert is_new_project(str(git_only_dir)) is True
|
assert is_new_project(str(git_only_dir)) is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_ra_aid_only_directory(ra_aid_only_dir):
|
||||||
|
"""Test that a directory with only a .ra-aid directory is considered a new project."""
|
||||||
|
assert is_new_project(str(ra_aid_only_dir)) is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_mixed_allowed_directory(mixed_allowed_dir):
|
||||||
|
"""Test that a directory with all allowed items is considered a new project."""
|
||||||
|
assert is_new_project(str(mixed_allowed_dir)) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def git_dir_with_contents(tmp_path):
|
def git_dir_with_contents(tmp_path):
|
||||||
"""Create a directory with .git containing files and .gitignore."""
|
"""Create a directory with .git containing files and .gitignore."""
|
||||||
|
|
@ -98,3 +128,23 @@ def test_permission_error(tmp_path):
|
||||||
finally:
|
finally:
|
||||||
# Restore permissions to allow cleanup
|
# Restore permissions to allow cleanup
|
||||||
os.chmod(tmp_path, 0o755)
|
os.chmod(tmp_path, 0o755)
|
||||||
|
|
||||||
|
|
||||||
|
def test_verify_fix(tmp_path):
|
||||||
|
"""
|
||||||
|
Verify fix: a project with only .ra-aid directory is considered new,
|
||||||
|
but adding other files makes it recognized as an existing project.
|
||||||
|
"""
|
||||||
|
# Create a .ra-aid directory inside the temporary directory
|
||||||
|
ra_aid_dir = tmp_path / ".ra-aid"
|
||||||
|
ra_aid_dir.mkdir()
|
||||||
|
|
||||||
|
# Check that is_new_project() returns True (only .ra-aid directory)
|
||||||
|
assert is_new_project(str(tmp_path)) is True
|
||||||
|
|
||||||
|
# Add a README.md file to the directory
|
||||||
|
readme_file = tmp_path / "README.md"
|
||||||
|
readme_file.write_text("# Test Project")
|
||||||
|
|
||||||
|
# Check that is_new_project() now returns False (has actual content)
|
||||||
|
assert is_new_project(str(tmp_path)) is False
|
||||||
Loading…
Reference in New Issue