mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 23:47:54 +08:00
core/tools: rename grep_files to regex_files (regex pattern)
This commit is contained in:
@@ -79,7 +79,7 @@ def test_parallel_tool_outputs_interleaved_after_calls() -> None:
|
||||
),
|
||||
AssistantFunctionToolCall(
|
||||
id="call_02_ABCD",
|
||||
function=AssistantFunctionTool(name="grep_files", arguments='{"pattern":"todo"}'),
|
||||
function=AssistantFunctionTool(name="regex_files", arguments='{"pattern":"todo"}'),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -352,13 +352,13 @@ async def test_pretty_glob_truncated(capsys: pytest.CaptureFixture[str]) -> None
|
||||
|
||||
async def test_pretty_grep(capsys: pytest.CaptureFixture[str]) -> None:
|
||||
result = "src/a.py:3: x = 1\nsrc/a.py:9: x = 2\nsrc/b.py:1: y = 3\n"
|
||||
await render_events(_aiter([_pretty_call("grep_files", '{"pattern": "x"}'), _result(result)]))
|
||||
await render_events(_aiter([_pretty_call("regex_files", '{"pattern": "x"}'), _result(result)]))
|
||||
out = capsys.readouterr().out
|
||||
assert "* Grep 'x' in '.' (3 matches in 2 files)" in out
|
||||
|
||||
|
||||
async def test_pretty_grep_no_matches(capsys: pytest.CaptureFixture[str]) -> None:
|
||||
await render_events(_aiter([_pretty_call("grep_files", '{"pattern": "zzz"}'), _result("(no matches)")]))
|
||||
await render_events(_aiter([_pretty_call("regex_files", '{"pattern": "zzz"}'), _result("(no matches)")]))
|
||||
out = capsys.readouterr().out
|
||||
assert "* Grep 'zzz' in '.' (no matches)" in out
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ def test_yaml_subset_types_lists_and_booleans() -> None:
|
||||
"read_only: true",
|
||||
"confirm: no",
|
||||
"retries: 3",
|
||||
"allowed-tools: [read_file, grep_files]",
|
||||
"allowed-tools: [read_file, regex_files]",
|
||||
"tags:",
|
||||
" - alpha",
|
||||
" - beta",
|
||||
@@ -72,7 +72,7 @@ def test_yaml_subset_types_lists_and_booleans() -> None:
|
||||
"read_only": True,
|
||||
"confirm": False,
|
||||
"retries": 3,
|
||||
"allowed-tools": ["read_file", "grep_files"],
|
||||
"allowed-tools": ["read_file", "regex_files"],
|
||||
"tags": ["alpha", "beta"],
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ def test_read_only_classification() -> None:
|
||||
"read_file",
|
||||
"get_truncated",
|
||||
"glob_paths",
|
||||
"grep_files",
|
||||
"regex_files",
|
||||
"listdir",
|
||||
"tree",
|
||||
"todo_list",
|
||||
|
||||
@@ -2,46 +2,46 @@ from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from plyngent.tools.file.grep_files import grep_files
|
||||
from plyngent.tools.file.regex_files import regex_files
|
||||
from tests.test_tools.helpers import call_sync
|
||||
|
||||
|
||||
def test_grep_files_basic(workspace: object) -> None:
|
||||
def test_regex_files_basic(workspace: object) -> None:
|
||||
assert isinstance(workspace, Path)
|
||||
_ = (workspace / "a.py").write_text("hello world\nfoo\n", encoding="utf-8")
|
||||
_ = (workspace / "b.py").write_text("nope\n", encoding="utf-8")
|
||||
out = call_sync(grep_files, "hello")
|
||||
out = call_sync(regex_files, "hello")
|
||||
assert "a.py:1:" in out
|
||||
assert "hello world" in out
|
||||
assert "b.py" not in out
|
||||
|
||||
|
||||
def test_grep_files_case_insensitive(workspace: object) -> None:
|
||||
def test_regex_files_case_insensitive(workspace: object) -> None:
|
||||
assert isinstance(workspace, Path)
|
||||
_ = (workspace / "t.txt").write_text("Hello\n", encoding="utf-8")
|
||||
assert "no matches" in call_sync(grep_files, "hello")
|
||||
out = call_sync(grep_files, "hello", case_insensitive=True)
|
||||
assert "no matches" in call_sync(regex_files, "hello")
|
||||
out = call_sync(regex_files, "hello", case_insensitive=True)
|
||||
assert "t.txt:1:" in out
|
||||
|
||||
|
||||
def test_grep_files_invalid_regex(workspace: object) -> None:
|
||||
def test_regex_files_invalid_regex(workspace: object) -> None:
|
||||
del workspace
|
||||
assert "invalid regex" in call_sync(grep_files, "[")
|
||||
assert "invalid regex" in call_sync(regex_files, "[")
|
||||
|
||||
|
||||
def test_grep_files_skip_git(workspace: object) -> None:
|
||||
def test_regex_files_skip_git(workspace: object) -> None:
|
||||
assert isinstance(workspace, Path)
|
||||
(workspace / ".git").mkdir()
|
||||
_ = (workspace / ".git" / "x").write_text("secret\n", encoding="utf-8")
|
||||
_ = (workspace / "ok.txt").write_text("secret\n", encoding="utf-8")
|
||||
out = call_sync(grep_files, "secret")
|
||||
out = call_sync(regex_files, "secret")
|
||||
assert "ok.txt" in out
|
||||
assert ".git" not in out
|
||||
|
||||
|
||||
def test_grep_files_max_matches(workspace: object) -> None:
|
||||
def test_regex_files_max_matches(workspace: object) -> None:
|
||||
assert isinstance(workspace, Path)
|
||||
lines = "\n".join(f"match {i}" for i in range(10))
|
||||
_ = (workspace / "m.txt").write_text(lines + "\n", encoding="utf-8")
|
||||
out = call_sync(grep_files, "match", max_matches=3)
|
||||
out = call_sync(regex_files, "match", max_matches=3)
|
||||
assert "truncated" in out
|
||||
@@ -198,7 +198,7 @@ async def test_skill_search_single_skill_and_errors(tmp_path: Path) -> None:
|
||||
async def test_skill_search_inside_the_workspace_rebases_the_hit(tmp_path: Path) -> None:
|
||||
"""A project-scope skill root lives inside the workspace: one path, once.
|
||||
|
||||
Grep reports in-workspace files relative to the workspace root and outside
|
||||
The search reports in-workspace files relative to the workspace root and outside
|
||||
ones absolutely, so the skill name must never be glued onto a path that
|
||||
already carries the root.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user