Files
rune/scripts/close_contract_microkernel.py
T

121 lines
5.3 KiB
Python

#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave microkernel gap contract (GO port).
Full lifecycle walk in ONE process (shared-store clobber hazard — do NOT
split across processes; re-walk on a fresh post-rebase store per the
segment-architecture conflict pattern). The QUALITY-GATE LAW (scaffold.py
2026-10-13) requires the designed close() entry (predicted-vs-observed
quality + material-change) rather than a raw transition to 'closed'.
Carries the already-pushed SHAs:
feat 3a1b9e54 close PARTIAL gaps — dichotomy wave
chore da9e15e9 regenerate audit — microkernel FULL
Usage: close_contract_microkernel.py
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/research_budget/target/release/deps/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "3a1b9e54"
AUDIT_SHA = "da9e15e9"
EVIDENCE = f"parity {PARITY_SHA}; audit {AUDIT_SHA}"
DETAIL = (
f"microkernel GO dichotomy gap-close — parity commit {PARITY_SHA}, "
f"audit commit {AUDIT_SHA}; dichotomy audit fn coverage 6/12 "
"PARTIAL -> 12/12 FULL. Ported name-preserving into "
"src/go/microkernel: NowIso (+nowFunc clock seam, Python "
"isoformat timespec=seconds +00:00 shape), ExtractManifest "
"(brace-counted PLUGIN block + ast.literal_eval-subset parser: "
"dicts/lists/tuples/strings-with-escapes/ints/floats/True/False/"
"None, comments, trailing commas, unicode, rune-safe truncation), "
"Discover (self-registration sweep, sorted listing), RunHook "
"(subprocess hook runner: skipped / file-not-found / ok-JSON / "
"raw-stdout-[:500] / rc-error stderr-[:200] / timeout, banker's-"
"rounded durations), Fire (8-way parallel dispatch + bounded "
"fire-log, CLI fire case rewired off the old fake), "
"LoadRegistry/SaveRegistry (renamed from lowercase; corrupt-file "
"full-default parity, log normalized to []). Register fixes proven "
"vs oracle: Python truthiness for hook values (string targets "
"index — real PLUGIN dicts use them) and auto_activate, _file "
"plumbed into entries. Frozen truth via the shared "
"scripts/freeze_truth.py harness (generator "
"scripts/gen_microkernel_gap_truth.py, aware-clock pin — fire() "
"mixes naive/aware datetime.now()): 25-case envelope regen-stable, "
"--verify byte-identical x2; Go battery 25/25 subtests "
"(truth_microkernel_gap_test.go), -race clean; live oracle-vs-Go "
"parity 24/24 (scripts/check_microkernel_parity.py, parity op mode "
"in parity.go); gofmt/vet/go build ./... clean; Python both-pins "
"green for the module (18 test_p1_01 failures proven pre-existing "
"on stashed base). Six representation-level divergences documented "
"(listing order, non-dict PLUGIN crash class, --data separators, "
"partial-registry crash class, integral-float rendering, typed-"
"struct persistence). Evidence read back: verification/"
"summary-microkernel.md + verification/microkernel-"
"{truth,goladder,live-parity,pytest-*,audit}.exit"
)
iface = ConstructionInterface(builder="factory-gap-mk")
r = iface.submit_need(
"microkernel dichotomy gap-close (GO): name-preserving port of the 6 "
"unmatched fns (now_iso, discover, _extract_manifest, _load_registry, "
"_save_registry, _run_hook) into src/go/microkernel, plus Fire wiring "
"the CLI fire case to real 8-way parallel subprocess dispatch with the "
"bounded fire-log, and Register fixes (Python truthiness for hook "
"values, _file plumbing). Frozen-truth battery 25/25, live parity "
"24/24, gofmt/vet/build clean, Python both-pins green (18 test_p1_01 "
"failures proven pre-existing). Audit: microkernel 6/12 PARTIAL -> "
"12/12 FULL. Delivered on gitea/master: feat " + PARITY_SHA + ", "
"audit " + AUDIT_SHA + ".",
origin="builder",
)
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
c = r["ids"]["contract_id"]
print("contract_id:", c)
for phase in ("approved", "building", "verifying"):
t = iface.transition(c, phase, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{phase}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
closed = iface.close(
c,
observed_evidence=[{"kind": "port_evidence", "detail": DETAIL}],
scope_files=[
"src/go/microkernel/main.go",
"src/go/microkernel/microkernel.go",
"src/go/microkernel/parity.go",
"src/go/microkernel/truth_microkernel.json",
"src/go/microkernel/truth_microkernel_test.go",
"src/go/microkernel/truth_microkernel_gap.json",
"src/go/microkernel/truth_microkernel_gap_test.go",
"scripts/gen_microkernel_gap_truth.py",
"scripts/check_microkernel_parity.py",
"scripts/close_contract_microkernel.py",
"verification/summary-microkernel.md",
],
)
print("close:", json.dumps(closed)[:400])
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
if not closed.get("success") or not e or e.get("phase") != "closed":
sys.exit(1)
print("CLOSED", c)