Files
rune/scripts/check_dependency_tracker_parity.py
Nick 795e429159 feat(dependency_tracker): close PARTIAL gaps — dichotomy wave
audit 2/5 PARTIAL -> 6/6 FULL (RUST side; the 5 oracle fns + the main_cli
mirror). Name-preserving port into src/rust/dependency_tracker: the W6-era
stub was semantically INVERTED (map KEYS collected for value-list hits, a
transitive BFS where the oracle classifies direct dependents) — replaced
wholesale (audit_ledger precedent, one chain one implementation). Kernels:
get_dependents (posix basename + map lookup), check_propagation,
propagate (the full classification matrix against SCRIPTS_DIR —
propagated-with-reference / not-found / no-direct-reference /
IsADirectoryError crash-parity '[Errno 21] Is a directory: <path>' with
errno mapping + Display-suffix stripping, dry_run would-update
short-circuit), get_full_map (dict INSERTION order — the warm_router
dict-literal overwrite quirk: first position, last value), main (CLI
mirror, pure fn over argv incl. the frozen argparse help text).

Kernel/facade split: the facade's 4 compute fns delegate via dt_loader
(DT_RUST_LIB override; RUNE_DEPENDENCY_TRACKER_CORE=python pins the
load-bearing Python bodies; kernel failure falls back); SCRIPTS_DIR stays
import-time on the Python side and rides the propagate payload; main()
stays Python argparse (process boundary, never delegates); main_cli is
the JSON-native stdout+rc capture mirror. Spine scope test constraints
preserved (harness SCRIPTS_DIR, inline os.path.join body, no spine
imports).

Frozen truth: 24-row corpus via the shared freeze_truth harness under
scripts/dt_freeze_seams (HOME='.' + cwd-is-the-rig + deterministic
fixture tree incl. the directory-named-as-file error fixture; COLUMNS=80
for the argparse help width). --verify byte-identical twice. Battery
gap_battery.rs replays the truth VERBATIM in order (serde to_string
equality pins insertion order, not just structure). Live parity
scripts/check_dependency_tracker_parity.py 72/72 (pinned facade / live
facade / kernel direct). clippy -D warnings + fmt clean. Python suite
both pins: failure set byte-identical across pins AND the stashed base
(244 pre-existing, none touching this module); ruff clean.

New quirk (docs/dichotomy-oracle-quirks.json): Python 3.14
OSError.__str__ QUOTES the filename — proved by frozen battery row 20.

Evidence: verification/dt-*.exit + dt-summary.md (logs gitignored).
2026-10-14 21:10:31 +01:00

138 lines
5.0 KiB
Python

#!/usr/bin/env python3
"""check_dependency_tracker_parity — live-parity replay for the
dependency_tracker dichotomy gap-close (worktree rune-wave-dl).
Three passes over the frozen truth (frozen_dt_truth.json, generated
from the pinned-pristine Python oracle under scripts/dt_freeze_seams —
HOME=".", cwd-is-the-rig, deterministic fixture tree):
PASS 1 (pinned facade): RUNE_DEPENDENCY_TRACKER_CORE=python — the
module runs its pure-Python fallback bodies (the pristine oracle
behaviour); every row replays through the public fns.
PASS 2 (live facade): pin unset, .so present — the module DELEGATES
to the Rust core through dt_loader (the production strangler
path; SCRIPTS_DIR rides the propagate payload).
PASS 3 (kernel direct): dt_loader FFI calls per row — the doc
envelope surface itself.
The rig environment is reproduced here (fresh throwaway cwd with the
fixture tree, HOME=".", COLUMNS=80) BEFORE the module imports, so
main_cli's argparse help and every propagate path match the frozen
shape byte-for-byte. Dict/list rows compare structurally AND in key
order (json.dumps without sort_keys); main_cli rows compare stdout+rc
exactly. Exit 0 iff every compared row matches the frozen expected.
"""
from __future__ import annotations
import json
import os
import sys
import tempfile
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
def build_fixtures() -> None:
scripts = Path.cwd() / ".config" / "opencode" / "scripts"
scripts.mkdir(parents=True, exist_ok=True)
(scripts / "memory_consolidation.py").write_text(
"# harness stub\nimport memory_store # references memory_store\n"
"print('memory_store ready')\n",
encoding="utf-8",
)
(scripts / "curator.py").write_text(
"# harness stub - unrelated content\n",
encoding="utf-8",
)
(scripts / "shard_manager.py").mkdir(exist_ok=True)
# ── the rig environment, before any rune import ────────────────────────
os.environ["HOME"] = "."
os.environ["COLUMNS"] = "80"
os.chdir(tempfile.mkdtemp(prefix="dt-parity-"))
build_fixtures()
os.environ["RUNE_DEPENDENCY_TRACKER_CORE"] = "python" # PASS 1 starts pinned
sys.path.insert(0, str(REPO / "src"))
from rune import dependency_tracker as dt # noqa: E402
from rune import dt_loader # noqa: E402
TRUTH = REPO / "src" / "rust" / "dependency_tracker" / "src" / "frozen_dt_truth.json"
SCRIPTS_DIR = "./.config/opencode/scripts"
def same(a, b) -> bool:
return json.dumps(a, ensure_ascii=False) == json.dumps(b, ensure_ascii=False)
def replay_module(row) -> object:
fn, args, kwargs = row["fn"], row["args"], row["kwargs"]
return getattr(dt, fn)(*args, **kwargs)
def replay_kernel(row) -> object:
fn, args, kwargs = row["fn"], row["args"], row["kwargs"]
if fn == "get_dependents":
return dt_loader.get_dependents(args[0])
if fn == "check_propagation":
return dt_loader.check_propagation(args[0])
if fn == "propagate":
return dt_loader.propagate(
args[0], dry_run=kwargs.get("dry_run", False), scripts_dir=SCRIPTS_DIR
)
if fn == "get_full_map":
return dt_loader.get_full_map()
if fn == "main_cli":
return dt_loader.main(args[0], scripts_dir=SCRIPTS_DIR)
raise AssertionError(f"unknown fn {fn}")
def run_pass(rows, replay, label, failures):
for i, row in enumerate(rows):
fn = row["fn"]
try:
got = replay(row)
except Exception as e: # noqa: BLE001 — a parity crash IS a failure row
failures.append(f"{label} row {i} {fn}: raised {type(e).__name__}: {e}")
continue
if not same(got, row["expected"]):
failures.append(
f"{label} row {i} {fn}: {json.dumps(got, ensure_ascii=False)[:220]} != "
f"{json.dumps(row['expected'], ensure_ascii=False)[:220]}"
)
def main() -> int:
assert dt_loader.available(), "Rust core .so not built (cargo build --release)"
rows = json.loads(TRUTH.read_text())
failures: list[str] = []
# ── PASS 1: pinned facade (pure-Python fallback = pristine oracle) ──
os.environ["RUNE_DEPENDENCY_TRACKER_CORE"] = "python"
run_pass(rows, replay_module, "pinned", failures)
# ── PASS 2: live facade (delegation through dt_loader) ──────────────
os.environ.pop("RUNE_DEPENDENCY_TRACKER_CORE", None)
run_pass(rows, replay_module, "live", failures)
# ── PASS 3: kernel direct (the FFI doc-envelope surface) ────────────
run_pass(rows, replay_kernel, "kernel", failures)
total = 3 * len(rows)
if failures:
print(f"PARITY FAILED: {len(failures)}/{total} row-passes failed")
for f in failures[:20]:
print(" -", f)
return 1
print(f"PARITY OK: {total}/{total} row-passes "
f"({len(rows)} rows x pinned-facade / live-facade / kernel-direct)")
return 0
if __name__ == "__main__":
raise SystemExit(main())