- read .gitmodules, AGENTS.md and JSON fixtures as UTF-8 instead of the locale codec - materialize the credential pattern file before git grep so Windows file locking cannot skip the scan - clear read-only Git object bits when fixture trees are removed - probe symlink support and skip only the symlink-only negative fixtures, keeping the NFC checks - add a small platform helper for the integration tests
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""Portable helpers shared by the root integration tests.
|
|
|
|
The governance gates are also run on developer workstations, so the fixtures
|
|
must not depend on Unix-only filesystem semantics:
|
|
|
|
- Git marks object files read-only; Windows therefore refuses a plain
|
|
``shutil.rmtree`` over a checked-out submodule.
|
|
- Unprivileged Windows accounts cannot create symbolic links unless Developer
|
|
Mode or the SeCreateSymbolicLinkPrivilege is enabled. Tests that need a
|
|
symlink skip with an explicit reason instead of failing the whole gate; the
|
|
Linux CI keeps exercising that path.
|
|
|
|
The helpers never change what a test asserts on a platform that provides the
|
|
behaviour.
|
|
"""
|
|
|
|
import os
|
|
import shutil
|
|
import stat
|
|
import sys
|
|
import tempfile
|
|
|
|
|
|
def rmtree(path):
|
|
"""Remove *path*, clearing the read-only bits Windows Git leaves behind."""
|
|
if sys.version_info >= (3, 12):
|
|
shutil.rmtree(path, onexc=_clear_read_only)
|
|
else: # pragma: no cover - Python 3.11 compatibility
|
|
shutil.rmtree(path, onerror=_clear_read_only)
|
|
|
|
|
|
def _clear_read_only(function, target, _exception):
|
|
os.chmod(target, stat.S_IWRITE)
|
|
function(target)
|
|
|
|
|
|
def symlinks_supported():
|
|
"""Return True when this account can create symbolic links."""
|
|
if not hasattr(os, "symlink"):
|
|
return False
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
try:
|
|
os.symlink(
|
|
os.path.join(directory, "target"),
|
|
os.path.join(directory, "link"),
|
|
)
|
|
except OSError:
|
|
return False
|
|
return True
|