diff --git a/corecoder/tools/glob_tool.py b/corecoder/tools/glob_tool.py index 4f4713aa..4ec1e32a 100644 --- a/corecoder/tools/glob_tool.py +++ b/corecoder/tools/glob_tool.py @@ -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" diff --git a/tests/test_tools.py b/tests/test_tools.py index 2fc44548..4c74cabe 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -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():