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,