From 6493998b27db541de98a66843b7fbfad5e4e73a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=81=AA=E3=81=9F=E3=81=AE=E5=90=8D=E5=89=8D?= Date: Thu, 29 Oct 2026 12:30:25 +0900 Subject: [PATCH] fix(api-runner): pass glob filter on grep fallback and fix glob truncation count - In `_execute_grep`, pass `--include={glob_filter}` when falling back to `grep` if `rg` is unavailable. Previously, `glob` was dropped, causing grep to match files of all extensions. - In `_execute_glob`, capture the pre-truncation total count before slicing `matches = matches[:500]` so the truncation message reflects actual total matches. - Add `test_glob_truncation` and verify `test_grep_with_glob_filter` passes on systems without `rg`. --- scripts/orchestrator/api_runner.py | 5 ++++- tests/test_api_runner.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/orchestrator/api_runner.py b/scripts/orchestrator/api_runner.py index b7d5d388..7b68370e 100644 --- a/scripts/orchestrator/api_runner.py +++ b/scripts/orchestrator/api_runner.py @@ -219,6 +219,8 @@ def _execute_grep(params: dict[str, Any]) -> str: except FileNotFoundError: # Fallback to grep if rg not available cmd_fallback = ["grep", "-rn"] + if glob_filter: + cmd_fallback.extend([f"--include={glob_filter}"]) if context: cmd_fallback.extend([f"-C{context}"]) cmd_fallback.extend([pattern, path]) @@ -259,8 +261,9 @@ def _execute_glob(params: dict[str, Any]) -> str: # Limit output if len(matches) > 500: + total = len(matches) matches = matches[:500] - matches.append(f"... ({len(matches)} total, truncated)") + matches.append(f"... ({total} total, truncated)") return "\n".join(matches) diff --git a/tests/test_api_runner.py b/tests/test_api_runner.py index eca3bd71..015a2af5 100644 --- a/tests/test_api_runner.py +++ b/tests/test_api_runner.py @@ -137,6 +137,12 @@ def test_glob_recursive(self, tmp_path): result = _execute_glob({"pattern": "**/*.go", "path": str(tmp_path)}) assert "deep.go" in result + def test_glob_truncation(self, tmp_path): + for i in range(505): + (tmp_path / f"file_{i:03d}.dat").touch() + result = _execute_glob({"pattern": "*.dat", "path": str(tmp_path)}) + assert "... (505 total, truncated)" in result + class TestWriteTool: """Tests for the Write tool executor."""