Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions corecoder/tools/glob_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class GlobTool(Tool):
def execute(self, pattern: str, path: str = ".") -> str:
try:
base = Path(path).expanduser().resolve()
if not base.exists():
return f"Error: {path} not found"
if not base.is_dir():
return f"Error: {path} is not a directory"

Expand Down
12 changes: 12 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,18 @@ def test_glob_no_match():
assert "No files" in r


def test_glob_nonexistent_path():
glob_t = get_tool("glob")
r = glob_t.execute(pattern="*.py", path="/nonexistent_dir_abc")
assert "not found" in r.lower() or "Error" in r


def test_glob_path_is_file():
glob_t = get_tool("glob")
r = glob_t.execute(pattern="*.py", path=__file__)
assert "not a directory" in r.lower()


# --- grep ---

def test_grep_finds_pattern():
Expand Down