fix(tools): scope recursive directory ignores to listed root
This commit is contained in:
1 parent
b0d2382856
commit
8052c3a460
2 files changed
+20
-2
No files matched your search
@@ -1174,11 +1174,11 @@ class ListDirTool(_FsTool):
|
|||||||
|
|
||||||
if recursive:
|
if recursive:
|
||||||
for item in sorted(dp.rglob("*")):
|
for item in sorted(dp.rglob("*")):
|
||||||
if any(p in self._IGNORE_DIRS for p in item.parts):
|
rel = item.relative_to(dp)
|
||||||
|
if any(p in self._IGNORE_DIRS for p in rel.parts):
|
||||||
continue
|
continue
|
||||||
total += 1
|
total += 1
|
||||||
if len(items) < cap:
|
if len(items) < cap:
|
||||||
rel = item.relative_to(dp)
|
|
||||||
items.append(f"{rel}/" if item.is_dir() else str(rel))
|
items.append(f"{rel}/" if item.is_dir() else str(rel))
|
||||||
else:
|
else:
|
||||||
for item in sorted(dp.iterdir()):
|
for item in sorted(dp.iterdir()):
|
||||||
|
|||||||
@@ -327,6 +327,24 @@ class TestListDirTool:
|
|||||||
assert ".git" not in result
|
assert ".git" not in result
|
||||||
assert "node_modules" not in result
|
assert "node_modules" not in result
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.parametrize("relative_root", ["build", "build/project"])
|
||||||
|
async def test_recursive_ignores_only_descendants(self, tool, tmp_path, relative_root):
|
||||||
|
root = tmp_path / relative_root
|
||||||
|
(root / "src").mkdir(parents=True)
|
||||||
|
(root / "src" / "main.py").write_text("pass")
|
||||||
|
(root / "README.md").write_text("hi")
|
||||||
|
(root / ".git").mkdir()
|
||||||
|
(root / ".git" / "config").write_text("ignored")
|
||||||
|
(root / "src" / "node_modules").mkdir()
|
||||||
|
(root / "src" / "node_modules" / "package.json").write_text("{}")
|
||||||
|
|
||||||
|
result = await tool.execute(path=str(root), recursive=True)
|
||||||
|
|
||||||
|
assert set(result.replace("\\", "/").splitlines()) == {
|
||||||
|
"README.md", "src/", "src/main.py",
|
||||||
|
}
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_max_entries_truncation(self, tool, tmp_path):
|
async def test_max_entries_truncation(self, tool, tmp_path):
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
|
|||||||
Reference in new issue
Block a user