This commit is contained in:
Michael Ingvarsson
2026-07-16 12:04:51 +02:00
parent b99730f9a4
commit e81f03c5aa
2 changed files with 22 additions and 4 deletions
+2 -2
View File
@@ -274,10 +274,10 @@ class CodingTools:
"""
resolved: str = self._resolve_path(path)
try:
command: str = f"grep -ri '{pattern}' {resolved}"
command: list[str] = ["grep", "-ri", pattern, resolved]
process: subprocess.Popen[str] = subprocess.Popen(
command,
shell=True,
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
+20 -2
View File
@@ -126,8 +126,17 @@ def test_grep_search_success(mock_popen: MagicMock) -> None:
mock_process.returncode = 0
mock_popen.return_value = mock_process
res: str = CodingTools().grep_search("pattern", "/path")
tools = CodingTools()
res: str = tools.grep_search("pattern", "/path")
assert res == "match_line"
mock_popen.assert_called_once_with(
["grep", "-ri", "pattern", tools._resolve_path("/path")],
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
cwd=tools.repo_path,
)
@patch("subprocess.Popen")
@@ -137,8 +146,17 @@ def test_grep_search_no_matches(mock_popen: MagicMock) -> None:
mock_process.returncode = 1
mock_popen.return_value = mock_process
res: str = CodingTools().grep_search("pattern", "/path")
tools = CodingTools()
res: str = tools.grep_search("pattern", "/path")
assert "No matches found" in res
mock_popen.assert_called_once_with(
["grep", "-ri", "pattern", tools._resolve_path("/path")],
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
cwd=tools.repo_path,
)
def test_grep_search_error() -> None: