fix(file): align grep fallback regex behavior

This commit is contained in:
Kevin Yin 2026-06-05 08:44:03 -07:00 committed by kshitij
parent 71f1b371c6
commit 7c6f9affd7
2 changed files with 27 additions and 1 deletions

View File

@ -253,6 +253,32 @@ class TestPaginationBounds:
class TestSearchContextParsing:
def test_search_with_grep_uses_extended_regex(self):
env = MagicMock()
env.cwd = "/tmp"
ops = ShellFileOperations(env)
with patch.object(ops, "_exec") as mock_exec:
mock_exec.return_value = MagicMock(
exit_code=0,
stdout="./first.txt:1:foo\n./second.txt:1:bar\n",
)
result = ops._search_with_grep(
"foo|bar",
path=".",
file_glob=None,
limit=10,
offset=0,
output_mode="content",
context=0,
)
cmd_arg = mock_exec.call_args[0][0]
assert cmd_arg.startswith("set -o pipefail; grep -rnHE ")
assert result.error is None
assert result.total_count == 2
assert [match.content for match in result.matches] == ["foo", "bar"]
def test_parse_search_context_line_prefers_rightmost_numeric_separator(self):
parsed = _parse_search_context_line("dir/file-12-name.py-8-context here")

View File

@ -2684,7 +2684,7 @@ class ShellFileOperations(FileOperations):
def _search_with_grep(self, pattern: str, path: str, file_glob: Optional[str],
limit: int, offset: int, output_mode: str, context: int) -> SearchResult:
"""Fallback search using grep."""
cmd_parts = ["grep", "-rnH"] # -H forces filename even for single-file searches
cmd_parts = ["grep", "-rnHE"] # -H forces filenames; -E matches rg regex behavior
# Exclude hidden directories (matching ripgrep's default behavior).
# This prevents searching inside .hub/index-cache/, .git/, etc.