Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/nodes/test_build_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,13 @@ def test_build_context_reports_read_error_without_fake_empty_content(
def deny_open(*args: object, **kwargs: object) -> int:
raise PermissionError("sensitive operating-system detail")

# The secure open dispatches on the platform: POSIX goes through os.open,
# Windows through the handle-based helper. Deny both so the failure is
# injected wherever the test happens to run.
monkeypatch.setattr("skillspector.input_handler.os.open", deny_open)
monkeypatch.setattr(
"skillspector.input_handler._open_regular_file_from_windows_handle", deny_open
)
result = build_context({"skill_path": str(tmp_path)})

assert "broken.py" in result["components"]
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/test_input_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from skillspector.input_handler import (
ALLOWED_GIT_HOSTS,
InputHandler,
_FileOpenError,
_open_regular_file_from_windows_handle,
_open_regular_file_no_follow,
)
Expand Down Expand Up @@ -225,8 +226,18 @@ def test_resolve_file_open_failure_does_not_create_temp_dir(tmp_path: Path) -> N
source = tmp_path / "SKILL.md"
source.write_text("# Skill", encoding="utf-8")
handler = InputHandler()
denied = OSError("denied")
try:
with patch("skillspector.input_handler.os.open", side_effect=OSError("denied")):
# The secure open dispatches on the platform: POSIX goes through os.open,
# Windows through the handle-based helper. Deny both so the failure is
# injected wherever the test happens to run.
with (
patch("skillspector.input_handler.os.open", side_effect=denied),
patch(
"skillspector.input_handler._open_regular_file_from_windows_handle",
side_effect=_FileOpenError(source, denied),
),
):
with pytest.raises(ValueError, match="Could not safely open"):
handler.resolve(str(source))
assert handler.temp_dir_for_cleanup() is None
Expand Down
Loading