Files
rune/scripts/close_contract_event_bus.py
T

106 lines
4.1 KiB
Python

#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave event_bus gap contract (GO port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions take ~60s each — do NOT split across processes). Designed
close() entry (quality-gate law: raw transition->closed is refused).
Carries the already-pushed SHAs as evidence:
feat 3fc5b7cd close PARTIAL gaps — dichotomy wave (parity)
refactor 5795322a Phase B language-advantage pass
Usage: close_contract_event_bus.py
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "3fc5b7cd"
PHASE_B_SHA = "5795322a"
EVIDENCE = f"parity {PARITY_SHA}"
iface = ConstructionInterface(builder="factory-gap-eb")
r = iface.submit_need(
"event_bus dichotomy gap-close (GO): name-preserving port of the "
"2 audit-missing functions (_store_path, handle_hook) into "
"src/go/event-bus (storePathNormalized env-derivation chain with "
"set-but-empty env + ~ / $VAR expansion; HandleHook prefix + payload "
"shaping raw[:200]/str(v)[:200]), plus the full-store seams: Emit "
"durable append (ValueError loud source contract), LogRows "
"filter + [-limit:] truncation incl. limit 0 -> ALL and -N front-drop, "
"Stats first-occurrence by_type, typed CorruptEventStoreError, "
"captured-CLI main. Freeze rig scripts/eb_freeze_seams (frozen clock "
"on both seams, deterministic uuid counter, hermetic RUNE_MEMORY_DIR "
"sandbox), 61-case frozen corpus truth_bus.json via the shared "
"harness verified byte-identical, battery replay verbatim + -race, "
"live parity 73/73 + negative control "
"(scripts/check_event_bus_parity.py), gofmt/vet/go build clean, "
"Python tests 4/4 both pins (live and RUNE_EVENT_BUS_CORE=python). "
"Phase B language-advantage pass: typed errors.As discrimination, "
"journalMu serialized concurrent appends, atomic mint counter, "
"8x4 concurrent-emit race battery with id-uniqueness law. Dichotomy "
"audit 5/7 PARTIAL -> 7/7 FULL (GO). Delivered on gitea/master: "
"feat " + PARITY_SHA + " + refactor " + PHASE_B_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)
observed_evidence = [
{
"entity": "module:rune.event_bus",
"source": "git",
"detail": "feat " + PARITY_SHA + " close PARTIAL gaps — dichotomy wave; audit 7/7 GO",
"authority": "dichotomy-audit",
},
{
"entity": "src/go/event-bus",
"source": "git",
"detail": "refactor " + PHASE_B_SHA + " Phase B language-advantage pass (typed CorruptEventStoreError, journalMu, atomic mint, race battery)",
"authority": "builder",
},
{
"entity": "verification/eb-summary.md",
"source": "tests",
"detail": "freeze 61/61 byte-identical; parity 73/73 + negative control; go build/vet/gofmt/race green; pytest 4/4 both pins (eb2-*.exit)",
"authority": "verification-ladder",
},
]
res = iface.close(c, observed_evidence=observed_evidence)
print("close:", json.dumps(res)[:400])
if not res.get("success"):
sys.exit(1)
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
if not e or e.get("phase") != "closed":
sys.exit(1)
q = e.get("ext", {}).get("contract_quality")
if q:
print("quality buckets:", json.dumps({k: q[k] for k in (
"correctly_predicted", "genuinely_unexpected_new",
"expected_new_observed", "expected_new_missing",
"predicted_but_unaffected") if k in q})[:300])
print("CLOSED", c)