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:
Paula Rossi
2026-08-26 19:03:36 -04:00
committed by brooklyn!
parent 5fce460df8
commit 934b2b94cc
2 changed files with 14 additions and 0 deletions

View File

@@ -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": ""})]

View File

@@ -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