fix(tools): search_files only defaults None/blank paths, not wrong-typed ones
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.
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user