"""Public-boundary discipline check. No file under `e2e/` may import `gps_denied_onboard.*` — the runner image must NEVER reach into SUT source. This unit test grep-walks the tree and fails fast if anyone smuggles an import in. """ from __future__ import annotations import re from pathlib import Path E2E_ROOT = Path(__file__).resolve().parents[1] _FORBIDDEN_IMPORT = re.compile(r"^\s*(?:from|import)\s+gps_denied_onboard\b") def test_no_sut_imports_in_e2e_tree() -> None: """Walk every *.py under e2e/ and ensure none import gps_denied_onboard.*.""" violations: list[tuple[Path, int, str]] = [] for py in E2E_ROOT.rglob("*.py"): # Skip __pycache__ and this unit test file itself (it intentionally # mentions the SUT package name in the regex). if "__pycache__" in py.parts or py.name == "test_no_sut_imports.py": continue try: text = py.read_text(encoding="utf-8") except UnicodeDecodeError: continue for lineno, line in enumerate(text.splitlines(), start=1): if _FORBIDDEN_IMPORT.match(line): violations.append((py.relative_to(E2E_ROOT), lineno, line.strip())) assert not violations, ( "Public-boundary discipline violated — e2e/ files import the SUT:\n " + "\n ".join(f"{p}:{ln}: {src}" for p, ln, src in violations) )