Skip to content

Commit 98d26c5

Browse files
committed
fix(agent): exclude images/ and .git dirs from grep search; tighten cmd test
1 parent 098c7b4 commit 98d26c5

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

openkb/agent/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def grep_wiki_files(
115115
if not grep:
116116
return "grep unavailable on this system."
117117

118-
cmd = [grep, "-rn", "--include=*.md"]
118+
cmd = [grep, "-rn", "--include=*.md", "--exclude-dir=images", "--exclude-dir=.git"]
119119
for name in sorted(EXCLUDED_WIKI_FILES):
120120
cmd.append(f"--exclude={name}")
121121
if ignore_case:

tests/test_grep.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ def test_excludes_schema_md(tmp_path):
110110
assert "SCHEMA.md" not in out
111111

112112

113+
@requires_grep
114+
def test_excludes_images_dir(tmp_path):
115+
wiki = _wiki(tmp_path)
116+
(tmp_path / "wiki" / "sources" / "images" / "caption.md").write_text(
117+
"transformer figure caption\n", encoding="utf-8",
118+
)
119+
out = grep_wiki_files("transformer", wiki)
120+
assert "images/" not in out
121+
122+
113123
# --- regex dialect ------------------------------------------------------------
114124

115125
@requires_grep
@@ -249,7 +259,10 @@ def _fake_run(cmd, *args, **kwargs):
249259
assert f"--exclude={name}" in cmd
250260
assert cmd[-3] == "-e"
251261
assert cmd[-2] == "needle"
252-
assert cmd[-1].endswith("wiki")
262+
from pathlib import Path as _P
263+
assert cmd[-1] == str(_P(wiki).resolve())
264+
assert "--exclude-dir=images" in cmd
265+
assert "--exclude-dir=.git" in cmd
253266

254267

255268
def test_grep_command_uses_F_when_fixed_and_omits_i(tmp_path, monkeypatch):

0 commit comments

Comments
 (0)