Skip to content

The agent that grows with you

fix(search): terminate rg root options

Royalaid3c864fe331d1
diff --git a/tests/tools/test_macos_protected_search.py b/tests/tools/test_macos_protected_search.py
index c36ff854ae0..cde5d6fc7bd 100644
--- a/tests/tools/test_macos_protected_search.py
+++ b/tests/tools/test_macos_protected_search.py
@@ -333,6 +333,32 @@ def test_rg_scoped_multi_root_handles_dot_spaces_and_overlapping_roots(monkeypat
assert result.files == ["/Users/alice/work space/local.txt"]
+def test_rg_scoped_multi_root_terminates_options_before_dash_prefixed_root(monkeypatch):
+ env = RecordingEnvironment("/Users/alice")
+ ops = ShellFileOperations(env)
+ monkeypatch.setattr(file_operations, "_HOME", "/Users/alice")
+ monkeypatch.setattr(file_operations.sys, "platform", "darwin")
+
+ def execute(command, cwd=None, **kwargs):
+ env.commands.append(command)
+ if command.startswith("test -e"):
+ output = "not_found\n" if "'., --version'" in command else "exists\n"
+ return {"output": output, "returncode": 0}
+ if command.startswith("command -v rg"):
+ return {"output": "/usr/bin/rg\n", "returncode": 0}
+ if "--files" in command:
+ return {"output": "", "returncode": 0}
+ raise AssertionError(command)
+
+ env.execute = execute
+ result = ops.search("*.txt", path="., --version", target="files")
+
+ command = _rg_files_commands(env.commands)[0]
+ assert "cd '/Users/alice' &&" in command
+ assert " -- '.' '--version' 2>/dev/null" in command
+ assert result.error is None
+
+
def test_real_ripgrep_does_not_descend_into_protected_folder(tmp_path, monkeypatch):
home = tmp_path / "Users" / "alice"
safe = home / "safe"
diff --git a/tools/file_operations.py b/tools/file_operations.py
index 1d9f8bea188..b9b8a01b571 100644
--- a/tools/file_operations.py
+++ b/tools/file_operations.py
@@ -3871,7 +3871,7 @@ class ShellFileOperations(FileOperations):
)
cmd = (
f"set -o pipefail; {cd_prefix}{rg} --files{sort_arg} -g {self._escape_shell_arg(glob_pattern)}"
- f"{exclusion_args} {root_args} 2>/dev/null | head -n {fetch_limit}"
+ f"{exclusion_args} -- {root_args} 2>/dev/null | head -n {fetch_limit}"
)
result = self._exec(cmd, timeout=60)
stdout, limit_reason = _search_stdout_and_limit(result)