Files
rune/scripts/check_self_modify_gap_parity.py
T
Nick 3a09a2c015 feat(self_modify): literal-100% residue — dichotomy wave
Audit-missing fn _smod_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;
RUNE_SM_CORE belongs to shard_manager, smod keeps its own pin).
Shared-harness frozen truth (frozen_smod_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:
self_modify 7/8 -> 8/8 FULL.

Lane factory-literal-l0 (issue #2479).
2026-10-15 06:19:08 +01:00

85 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""Live parity for the self_modify literal-100% residue fn (dichotomy
wave #2479, lane factory-literal-l0): `_smod_core`.
Legs (the kernel side replays the SAME frozen rows in
src/rust/self_modify/src/gap_battery.rs — cargo test):
1. pinned row re-captured LIVE: RUNE_SMOD_CORE=python → the oracle
probe observes None (byte-equal to frozen_smod_gap_truth.json).
2. live delegation matrix: auto + built .so → the probe answers the
loader (NOT None — requires `cargo build --release` in
src/rust/self_modify); auto + bogus SMOD_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 self_modify # noqa: E402
TRUTH = REPO / "src" / "rust" / "self_modify" / "src" / "frozen_smod_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_SMOD_CORE"] = "python"
for row in rows:
assert row["fn"] == "_smod_core"
got = self_modify._smod_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 smod_loader
os.environ["RUNE_SMOD_CORE"] = "auto"
try:
if not smod_loader.available():
print("Rust core not built — run cargo build --release in src/rust/self_modify")
raise SystemExit(2)
got = self_modify._smod_core()
assert got is not None, "auto + built core must answer the loader"
assert got is smod_loader, "the probe's answer IS smod_loader"
ok = 1
finally:
os.environ["RUNE_SMOD_CORE"] = "python"
# bogus .so path: smod_loader resolves it at import — reload = fresh load
env_lib = os.environ.get("SMOD_RUST_LIB")
os.environ["SMOD_RUST_LIB"] = "/nonexistent/libself_modify.so"
try:
importlib.reload(smod_loader)
os.environ["RUNE_SMOD_CORE"] = "auto"
got = self_modify._smod_core()
assert got is None, "absent core must observe None"
ok += 1
finally:
os.environ.pop("SMOD_RUST_LIB", None)
if env_lib is not None:
os.environ["SMOD_RUST_LIB"] = env_lib
importlib.reload(smod_loader)
os.environ["RUNE_SMOD_CORE"] = "python"
return ok
def main() -> int:
pinned = live_pinned_rows()
matrix = live_delegation_matrix()
print(f"self_modify gap parity: _smod_core pinned {pinned}/{pinned}, live matrix {matrix}/{matrix} — 100%")
return 0
if __name__ == "__main__":
raise SystemExit(main())