Skip to content

Commit b1c6203

Browse files
authored
Merge pull request #900 from microsasa/fix/896-test-is-dir-oserror-76bfa0ffb5e93093
Test OSError in _full_scandir_discovery is_dir() (#896)
2 parents 3be35c4 + 5f456e7 commit b1c6203

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

tests/copilot_usage/test_parser.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
_extract_session_name,
5656
_first_pass,
5757
_FirstPassResult,
58+
_full_scandir_discovery,
5859
_infer_model_from_metrics,
5960
_insert_session_entry,
6061
_read_config_model,
@@ -522,6 +523,33 @@ def test_two_level_deep_events_not_discovered(self, tmp_path: Path) -> None:
522523
assert paths == [valid]
523524

524525

526+
# ---------------------------------------------------------------------------
527+
# _full_scandir_discovery — OSError on DirEntry.is_dir (issue #896)
528+
# ---------------------------------------------------------------------------
529+
530+
531+
class TestFullScanDirDiscovery:
532+
"""Cover error-handling paths in _full_scandir_discovery."""
533+
534+
def test_is_dir_oserror_entry_is_skipped(self, tmp_path: Path) -> None:
535+
"""An entry whose is_dir() raises OSError must be silently skipped."""
536+
from unittest.mock import MagicMock
537+
538+
bad_entry = MagicMock(spec=os.DirEntry)
539+
bad_entry.name = "broken-session"
540+
bad_entry.is_dir.side_effect = OSError("permission denied")
541+
542+
ctx = MagicMock()
543+
ctx.__enter__ = MagicMock(return_value=iter([bad_entry]))
544+
ctx.__exit__ = MagicMock(return_value=False)
545+
546+
with patch("os.scandir", return_value=ctx):
547+
result = _full_scandir_discovery(tmp_path, include_plan=False)
548+
549+
assert result == []
550+
bad_entry.is_dir.assert_called_once_with(follow_symlinks=False)
551+
552+
525553
# ---------------------------------------------------------------------------
526554
# _discover_with_identity — no stat for absent plan.md (issue #763)
527555
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)