fix(tools): search_files treats a JSON-null path like a blank one
The model can send `"path": null` as easily as `"path": ""`; on base a None path reached search_tool and surfaced as an os.PathLike TypeError instead of the documented current-directory default. Widen the blank-path normalisation in _handle_search_files to any non-string and pin it in the existing parametrized test. Co-authored-by: joaomarcos <joaomarcosdias444@gmail.com>
This commit is contained in:
@@ -288,8 +288,9 @@ def test_handler_forwards_modified_order(monkeypatch):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("target", ["content", "files"])
|
||||
@pytest.mark.parametrize("blank_path", ["", " \t "])
|
||||
@pytest.mark.parametrize("blank_path", ["", " \t ", None])
|
||||
def test_handler_normalizes_blank_path_to_current_directory(monkeypatch, target, blank_path):
|
||||
"""#112424: a present-but-blank (or null) path must fall back to the documented '.' default."""
|
||||
captured = {}
|
||||
|
||||
def fake_search_tool(**kwargs):
|
||||
|
||||
@@ -1291,8 +1291,10 @@ def _handle_search_files(args, **kw):
|
||||
target_map = {"grep": "content", "find": "files"}
|
||||
raw_target = args.get("target", "content")
|
||||
target = target_map.get(raw_target, raw_target)
|
||||
# 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 isinstance(path, str) and not path.strip():
|
||||
if not isinstance(path, str) or not path.strip():
|
||||
path = "."
|
||||
return search_tool(
|
||||
pattern=args.get("pattern", ""), target=target, path=path,
|
||||
|
||||
Reference in New Issue
Block a user