"""The sim hooks are wired (phase 04, task 06) — grep-style guard. A half-wired hook hides in a `TODO(phase NN)` marker left in `src/undercooked/sim/` (the placeholder for a subsystem a later phase was going to fill in). This test greps the kernel's sources for those markers and fails on any whose phase is ≤ 04: by the end of this phase every stage the kernel runs (movement, carry, interact, stations, freshness, orders, hazards, round state) is real, so a phase ≤ 04 marker names work that should already exist. Markers for later phases (≥ 05, e.g. a hazard detail phase 10 fills in) stay legal until that phase lands — the gate is on the number, not on the word. The scan reads the same files a reader of the module would see (the directory on disk, `*.py`), so a marker hidden in a new file cannot slip past, and the sanity assertion below fails if the scan ever points at an empty directory (a guard that passes by scanning nothing). """ from __future__ import annotations import re from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[2] SIM_DIR = REPO_ROOT / "src" / "undercooked" / "sim" #: A placeholder marker: `TODO(phase NN)` with an optional note, in any #: comment style the kernel uses (`#`, `"""` docstring text). TODO_MARKER = re.compile(r"TODO\(\s*phase\s+(\d{2})\b", re.IGNORECASE) #: Phases ≤ 04 are done by the end of this phase: their hooks are wired. DONE_PHASE = 4 def _sim_sources() -> list[tuple[str, str]]: """`(name, text)` for every `*.py` in the kernel (sorted, stable).""" return [ (path.name, path.read_text(encoding="utf-8")) for path in sorted(SIM_DIR.glob("*.py")) ] def test_the_scan_covers_the_kernel() -> None: """Sanity: the directory is the kernel's and the scan reads real code (a guard that passes by scanning nothing is worthless).""" sources = _sim_sources() assert SIM_DIR.is_dir(), "src/undercooked/sim/ is missing" assert len(sources) >= 5, f"only {len(sources)} kernel files found" names = {name for name, _ in sources} for expected in ("step.py", "stations.py", "orders.py", "scoring.py", "round_state.py"): assert expected in names, f"the scan lost {expected}" def test_no_stale_hooks_for_phases_at_or_below_04() -> None: """No `TODO(phase NN)` with `NN ≤ 04` remains in the kernel: a placeholder for a stage this phase wired is a half-wired hook.""" stale: list[str] = [] for name, text in _sim_sources(): for match in TODO_MARKER.finditer(text): phase = int(match.group(1)) if phase <= DONE_PHASE: line = text[: match.start()].count("\n") + 1 stale.append(f"{name}:{line}: {match.group(0)}") assert not stale, "stale phase ≤ 04 hooks in the kernel:\n" + "\n".join(stale) def test_a_stale_marker_is_found_when_one_exists() -> None: """The regex actually catches the marker shape (the guard's own evidence test: a `TODO(phase 04)` in a sample is reported, a `TODO(phase 10)` is not — the gate is on the number).""" sample = ( "def step(state):\n" " # TODO(phase 04) wire the stations stage\n" " # TODO(phase 10) hazard details\n" " return state\n" ) found = {int(match.group(1)) for match in TODO_MARKER.finditer(sample)} assert 4 in found, "the 04 marker shape is not caught" assert all(phase <= DONE_PHASE for phase in found & {4}) assert 10 in found, "the 10 marker shape is not seen (so it could hide)"