diff --git a/tests/conftest.py b/tests/conftest.py index 08a0ada6..bebf3967 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,6 +2,7 @@ from __future__ import annotations +import errno import os from typing import TYPE_CHECKING @@ -85,6 +86,13 @@ def _isolate_git_config( monkeypatch.setenv("GIT_COMMITTER_EMAIL", "tests@example.com") +# Errors that mean "this name is not representable here", as opposed to a +# filesystem that is full, read-only, or otherwise broken. +_REJECTED_NAME_ERRNOS = frozenset( + {errno.EINVAL, errno.EILSEQ, errno.ENAMETOOLONG}, +) + + @pytest.fixture def write_control_character_file() -> Callable[[Path, str, str], Path]: """Create a file whose *name* carries terminal control characters, or skip. @@ -103,6 +111,11 @@ def write_control_character_file() -> Callable[[Path, str, str], Path]: try: path.write_text(content, encoding="utf-8") except OSError as exc: # pragma: no cover - platform dependent + # Only "the name itself is unacceptable" is a reason to skip. A + # full disk or an unwritable temp directory must still fail these + # security tests rather than quietly reporting them as skipped. + if exc.errno not in _REJECTED_NAME_ERRNOS: + raise pytest.skip(f"this filesystem rejects control characters in filenames: {exc}") return path diff --git a/tests/test_local_sources.py b/tests/test_local_sources.py index f03bed46..be73fa84 100644 --- a/tests/test_local_sources.py +++ b/tests/test_local_sources.py @@ -182,9 +182,14 @@ def test_infer_target_type_applies_the_mount_policy() -> None: # so pick a protected system directory this platform actually has. The # policy itself already knows about both families (`_FORBIDDEN_MOUNT_TREES` # and `_FORBIDDEN_WINDOWS_TREE_NAMES`); only the fixture was Unix-only. - candidates = ( - [Path(Path.cwd().anchor) / "Windows"] if os.name == "nt" else [Path("/etc"), Path("/usr")] - ) + if os.name == "nt": + # Ask Windows where it is installed. Deriving the drive from the + # checkout would look for D:\Windows on a repo cloned to D:, miss, and + # skip the very branch this test exists to cover. + system_root = os.environ.get("SYSTEMROOT") or os.environ.get("WINDIR") + candidates = [Path(system_root)] if system_root else [] + else: + candidates = [Path("/etc"), Path("/usr")] system_dir = next((p for p in candidates if p.is_dir()), None) if system_dir is None: pytest.skip("no protected system directory on this platform")