#!/usr/bin/env python3 """Run L33 route/proof and transition invariants with recipe-stamped logs.""" import re import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l36" BINARIES = { "clang": OUT / "bin/VoxelForgeCoreHeadless-l36-final-clang", "gcc": OUT / "bin/VoxelForgeCoreHeadless-l36-final-gcc", } rows = [] failed = False def run(name, binary, data, recipe, extra, checks): global failed logfile = OUT / f"{name}.log" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "900s", str(binary), str(data), "--workers=12", "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--force-generate", "--clip-radius=3", "--max-clip-level=8", "--max-level=-1", f"--recipe={recipe}", *extra, ] started = time.monotonic() try: with logfile.open("w", encoding="utf-8") as stream: result = subprocess.run(command, stdout=stream, stderr=subprocess.STDOUT, timeout=900, check=False) except subprocess.TimeoutExpired: result = None elapsed = time.monotonic() - started text = logfile.read_text(encoding="utf-8", errors="replace") stamps = re.findall( r"^\[WorldAssemblerRecipeAudit\] requested=([^ ]+) actual=([^ ]+).*status=([^ ]+)$", text, re.M) stamp_ok = stamps == [(recipe, recipe, "PASS")] checks_ok = all(check(text) for check in checks) ok = result is not None and result.returncode == 0 and stamp_ok and checks_ok rows.append((name, recipe, elapsed, result.returncode if result else "TIMEOUT", ok)) print(f"{name} elapsed={elapsed:.1f}s recipe={stamps[0][1] if stamps else 'MISSING'} " f"stamp={'PASS' if stamp_ok else 'FAIL'} checks={'PASS' if checks_ok else 'FAIL'} " f"{'PASS' if ok else 'FAIL'}", flush=True) failed |= not ok owner = ROOT / "Standalone/data/owner_world.json" for recipe in ("surface-world", "floating-islands"): for compiler, binary in BINARIES.items(): name = f"invariant-route-proof-{recipe}-{compiler}" run(name, binary, owner, recipe, ["--stream-hash", "--audit-uniform-block-proofs", "--audit-route-parity"], [lambda text: bool(re.search( r"^\[RouteParityAudit\].*status=PASS$", text, re.M)), lambda text: bool(re.search( r"^\[UniformBlockProofAudit\].*violations=0(?:\s|$)", text, re.M))]) for recipe in ("surface-world", "floating-islands"): for compiler, binary in BINARIES.items(): for mode in ("hard", "gradient", "interleaved"): name = f"invariant-transition-{recipe}-{mode}-{compiler}" run(name, binary, owner, recipe, [f"--transition-mode={mode}", "--audit-strate-transitions"], [lambda text: bool(re.search( r"^\[StrateTransitionAuditSummary\].*hole_columns=0 air_samples=0 .*status=PASS$", text, re.M)), lambda text: bool(re.search( r"^\[StrateTransitionNegativeControls\].*status=PASS$", text, re.M))]) summary = OUT / "invariant-audits.csv" summary.write_text( "run,recipe,elapsed_seconds,exit_code,status\n" + "".join(f"{name},{recipe},{elapsed:.3f},{code},{'PASS' if ok else 'FAIL'}\n" for name, recipe, elapsed, code, ok in rows), encoding="utf-8") print(f"[L33InvariantAudits] runs={len(rows)} pass={sum(row[-1] for row in rows)} " f"fail={sum(not row[-1] for row in rows)} summary={summary}", flush=True) raise SystemExit(1 if failed or len(rows) != 16 else 0)