Files
rune/scripts/check_grading_gap_parity.py
Nick a367ebd605 feat(grading): literal-100% residue — dichotomy wave
Audit-missing fn _gr_core ported name-preserving (gap.rs): the
delegation-probe verdict as data (salience_gate _sg_core / spine
_rust_core pattern — the loader module is unrepresentable over FFI).
Shared-harness frozen truth (frozen_gr_gap_truth.json, byte-verified
via freeze_truth.py --verify) + gap battery + live gap parity (pinned
2/2, live matrix 2/2 — 100%) + pytest both pins green. Audit: grading
3/4 -> 4/4 FULL.

Lane factory-literal-l0 (issue #2479).
2026-10-15 05:47:47 +01:00

85 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""Live parity for the grading literal-100% residue fn (dichotomy wave
#2479, lane factory-literal-l0): `_gr_core`.
Legs (the kernel side replays the SAME frozen rows in
src/rust/grading/src/gap_battery.rs — cargo test):
1. pinned row re-captured LIVE: RUNE_GR_CORE=python → the oracle probe
observes None (byte-equal to frozen_gr_gap_truth.json).
2. live delegation matrix: auto + built .so → the probe answers the
loader (NOT None — requires `cargo build --release` in
src/rust/grading); auto + bogus GR_RUST_LIB → None.
Exit 0 only on 100%.
"""
from __future__ import annotations
import importlib
import json
import os
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
from rune import grading # noqa: E402
TRUTH = REPO / "src" / "rust" / "grading" / "frozen_gr_gap_truth.json"
def live_pinned_rows() -> int:
rows = json.loads(TRUTH.read_text())
assert rows, "no rows in frozen gap truth"
os.environ["RUNE_GR_CORE"] = "python"
for row in rows:
assert row["fn"] == "_gr_core"
got = grading._gr_core()
assert got is None, f"pinned probe must observe None, got {got!r}"
assert row["expected"] is None, "frozen row must be the None verdict"
return len(rows)
def live_delegation_matrix() -> int:
from rune import gr_loader
os.environ["RUNE_GR_CORE"] = "auto"
try:
if gr_loader.core() is None:
print("Rust core not built — run cargo build --release in src/rust/grading")
raise SystemExit(2)
got = grading._gr_core()
assert got is not None, "auto + built core must answer the loader"
assert got is gr_loader, "the probe's answer IS gr_loader"
ok = 1
finally:
os.environ["RUNE_GR_CORE"] = "python"
# bogus .so path: gr_loader resolves it at import — reload = fresh load
env_lib = os.environ.get("GRADING_RUST_LIB")
os.environ["GRADING_RUST_LIB"] = "/nonexistent/libgrading.so"
try:
importlib.reload(gr_loader)
os.environ["RUNE_GR_CORE"] = "auto"
got = grading._gr_core()
assert got is None, "absent core must observe None"
ok += 1
finally:
os.environ.pop("GRADING_RUST_LIB", None)
if env_lib is not None:
os.environ["GRADING_RUST_LIB"] = env_lib
importlib.reload(gr_loader)
os.environ["RUNE_GR_CORE"] = "python"
return ok
def main() -> int:
pinned = live_pinned_rows()
matrix = live_delegation_matrix()
print(f"grading gap parity: _gr_core pinned {pinned}/{pinned}, live matrix {matrix}/{matrix} — 100%")
return 0
if __name__ == "__main__":
raise SystemExit(main())