From d77cf5ae5190d5dc321a036f6b48bdc2fdf22edf Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Wed, 16 Sep 2026 12:42:43 -0700 Subject: [PATCH] fix(tools): search_files only defaults None/blank paths, not wrong-typed ones MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The #112424 normalisation used `not isinstance(path, str) or not path.strip()`, which also silently mapped a non-null wrong-typed path (e.g. 5 or a list) to "." and searched the whole cwd instead of reporting the bad argument — wider than the issue (blank/null) asked for. Restrict the predicate to `path is None or (isinstance(path, str) and not path.strip())` so any other type falls through to search_tool's existing error path, exactly as on main. Test: test_handler_preserves_nonblank_path now also covers 5 and ["src"]; those two cases fail on the previous commit (path became ".") and pass here. --- tests/tools/test_search_files_engine_selection.py | 8 +++++--- tools/file_tools.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/tools/test_search_files_engine_selection.py b/tests/tools/test_search_files_engine_selection.py index 6cdb5e3616..7bda6892b6 100644 --- a/tests/tools/test_search_files_engine_selection.py +++ b/tests/tools/test_search_files_engine_selection.py @@ -305,7 +305,9 @@ def test_handler_normalizes_blank_path_to_current_directory(monkeypatch, target, assert captured["path"] == "." -def test_handler_preserves_nonblank_path(monkeypatch): +@pytest.mark.parametrize("raw_path", ["src", 5, ["src"]]) +def test_handler_preserves_nonblank_path(monkeypatch, raw_path): + """Only None/blank normalise to '.'; a wrong-typed path reaches search_tool's own error path.""" captured = {} def fake_search_tool(**kwargs): @@ -314,9 +316,9 @@ def test_handler_preserves_nonblank_path(monkeypatch): monkeypatch.setattr("tools.file_tools.search_tool", fake_search_tool) - registry.dispatch("search_files", {"pattern": "needle", "path": "src"}) + registry.dispatch("search_files", {"pattern": "needle", "path": raw_path}) - assert captured["path"] == "src" + assert captured["path"] == raw_path def test_repeated_search_key_distinguishes_order(monkeypatch): diff --git a/tools/file_tools.py b/tools/file_tools.py index 4b312b63e7..a9f264978c 100644 --- a/tools/file_tools.py +++ b/tools/file_tools.py @@ -1294,7 +1294,7 @@ def _handle_search_files(args, **kw): # The schema documents path='.'; a present-but-blank (or JSON null) value # is not a missing key for dict.get, so apply the default here (#112424). path = args.get("path", ".") - if not isinstance(path, str) or not path.strip(): + if path is None or (isinstance(path, str) and not path.strip()): path = "." return search_tool( pattern=args.get("pattern", ""), target=target, path=path,