fix(tools): scope recursive directory ignores to listed root

This commit is contained in:
RaycarlLei authored and Xubin Ren committed 2026-10-03 20:40:37 +08:00
1 parent b0d2382856
commit 8052c3a460
2 files changed
+20 -2

No files matched your search

+2 -2
View File
@@ -1174,11 +1174,11 @@ class ListDirTool(_FsTool):
if recursive:
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
total += 1
if len(items) < cap:
rel = item.relative_to(dp)
items.append(f"{rel}/" if item.is_dir() else str(rel))
else:
for item in sorted(dp.iterdir()):
+18
View File
@@ -327,6 +327,24 @@ class TestListDirTool:
assert ".git" 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
async def test_max_entries_truncation(self, tool, tmp_path):
for i in range(10):