test(tools): pin open_preview missing-path emit (#95853)
Independent review: document OSError fail-open on is_dir, and lock that only existing directories are rejected.
This commit is contained in:
@@ -80,3 +80,14 @@ def test_file_uri_directory_is_an_error(tmp_path):
|
||||
assert "error" in result
|
||||
assert "director" in result["error"].lower()
|
||||
assert emitted == []
|
||||
|
||||
|
||||
def test_missing_path_still_emits(tmp_path):
|
||||
"""Reject only existing directories — a missing path is the renderer's call."""
|
||||
emitted = _capture_emits()
|
||||
missing = tmp_path / "no-such-folder"
|
||||
|
||||
result = json.loads(op.open_preview_tool(str(missing)))
|
||||
|
||||
assert result["success"] is True
|
||||
assert emitted == [("preview.open", {"url": str(missing), "label": ""})]
|
||||
|
||||
@@ -61,6 +61,9 @@ def _is_existing_directory(target: str) -> bool:
|
||||
try:
|
||||
return path.is_dir()
|
||||
except OSError:
|
||||
# Stat failed (permissions, broken reparse, etc.). Do not treat that
|
||||
# as "this is a directory" — reject only when we positively observe
|
||||
# an existing directory. The renderer still sees the original target.
|
||||
return False
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user