#!/usr/bin/env python3 """Run the L152 passage and envelope gates across the 16 owner seeds.""" from __future__ import annotations import argparse import json import re import subprocess import time from pathlib import Path from PassageEnvelopeAudit import audit_layout ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l152/seeds" BIN = ROOT / "Standalone/bin/linux/VoxelForgeCoreHeadless-l152-clang" DATA = ROOT / "Standalone/data/owner_world.json" STAMP = "b299076d814ff7cc098aa373cdc3a26533ed8bfe1ef6df1ea9de4d400d231b25" STAMP_RE = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=([0-9a-f]+)$", re.M) DISPATCH = { "tunnel-network": re.compile( r"^\[DensityDispatch\] strate=2 generator=TunnelNetwork " r"recipe=Core\.Caves\.PrimitiveField version=1 " r"bound_path=Caves-native adapter=FCavesFieldAdapter$", re.M), "vertical-shafts": re.compile( r"^\[DensityDispatch\] strate=3 generator=VerticalShafts " r"recipe=Core\.Caves\.PrimitiveField version=1 " r"bound_path=Caves-native adapter=FCavesFieldAdapter$", re.M), } ROUTES = { "tunnel-network": re.compile( r"^\[ResolvedStrateRouteAudit\] strate=2 .*unsupported=0 " r"grade_failures=0 .*status=PASS$", re.M), "vertical-shafts": re.compile( r"^\[ResolvedStrateRouteAudit\] strate=3 .*unsupported=0 " r"grade_failures=0 .*status=PASS$", re.M), } CONTROLS = { "tunnel-network": re.compile( r"^\[TunnelNetworkBlockedRouteControl\].*expected=FAIL status=PASS$", re.M), "vertical-shafts": re.compile( r"^\[VerticalShaftsBlockedRouteControl\].*expected=FAIL status=PASS$", re.M), } REQUIRED = { "passage_summary": re.compile(r"^\[ResolvedPassageAuditSummary\].*status=PASS$", re.M), "seams": re.compile(r"^\[PassageTileSeamAudit\].*status=PASS$", re.M), "shell": re.compile(r"^\[PassageShellAuditSummary\].*status=PASS$", re.M), "naturalness": re.compile(r"^\[PassageNaturalnessSummary\].*status=PASS$", re.M), "mouth_profile": re.compile(r"^\[PassageMouthProfileSummary\].*status=PASS$", re.M), "ripple": re.compile(r"^\[PassageRippleAuditSummary\].*status=PASS$", re.M), "interior_capsules": re.compile( r"^\[PassageInteriorCapsuleAuditSummary\].*status=PASS$", re.M), "layout_controls": re.compile( r"^\[ResolvedLayoutValidatorControls\] rejected=10/10 status=PASS$", re.M), "floor_profile_controls": re.compile( r"^\[FloorProfileBlendNegativeControls\].*detected=true/true status=PASS$", re.M), "naturalness_control": re.compile( r"^\[PassageNaturalnessNegativeControl\].*detected=true$", re.M), "mouth_control": re.compile( r"^\[PassageMouthProfileNegativeControl\].*detected=true$", re.M), } def passage_rows(content: str) -> list[str]: return re.findall(r"^\[ResolvedPassageAudit\].*$", content, re.M) def grade_audit(content: str) -> tuple[bool, list[str]]: rows = re.findall(r"^\[PassagePlanGradeAudit\].*$", content, re.M) ids = set() passed = bool(rows) for row in rows: identifier = re.search(r"\bid=([^ ]+)", row) maximum = re.search(r"\bmax_grade_deg=([0-9.]+)", row) limit = re.search(r"\blimit_deg=([0-9.]+)", row) violations = re.search(r"\bviolations=(\d+)", row) status = "status=PASS" in row if identifier: ids.add(identifier.group(1)) passed &= bool(identifier and maximum and limit and violations and status and float(maximum.group(1)) <= float(limit.group(1)) and float(limit.group(1)) == 15.0 and int(violations.group(1)) == 0) return passed and len(ids) >= 3, rows def main() -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--kind", choices=tuple(DISPATCH), required=True) args = parser.parse_args() if not BIN.is_file() or not DATA.is_file(): raise SystemExit("missing L152 Clang binary or composed owner fixture") mode_out = OUT / args.kind mode_out.mkdir(parents=True, exist_ok=True) results = [] partial = mode_out / "runs-partial.json" for seed in range(16): log = mode_out / f"seed{seed}.log" layout = mode_out / f"seed{seed}.json" command = ["taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(BIN), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--workers=8", "--clip-radius=3", "--max-clip-level=8", "--max-level=0", "--force-generate", f"--seed={seed}", "--recipe=surface-world", "--density-dispatch-report", "--audit-resolved-layout-passages", "--audit-passage-tile-seams", f"--resolved-layout-output={layout}"] started = time.monotonic() with log.open("w", encoding="utf-8") as output: proc = subprocess.run(command, cwd=ROOT, stdout=output, stderr=subprocess.STDOUT, check=False, timeout=1740) content = log.read_text(encoding="utf-8", errors="replace") stamp = STAMP_RE.search(content) checks = {name: bool(pattern.search(content)) for name, pattern in REQUIRED.items()} checks["process_exit_zero"] = proc.returncode == 0 checks["source_stamp"] = stamp is not None and stamp.group(1) == STAMP checks["dispatch"] = bool(DISPATCH[args.kind].search(content)) checks["route"] = bool(ROUTES[args.kind].search(content)) checks["blocked_route_control"] = bool(CONTROLS[args.kind].search(content)) passages = passage_rows(content) checks["three_passages_walkable_and_open"] = ( len(passages) == 3 and all("walkability=PASS" in row and "interior_air=PASS" in row and re.search(r"\bblocked=0\b", row) and re.search(r"\bunsupported=0\b", row) and re.search(r"\bgrade_failures=0\b", row) for row in passages)) checks["three_interior_negative_controls"] = len(re.findall( r"^\[ResolvedPassageInteriorNegativeControl\].*detected=true status=PASS$", content, re.M)) == 3 checks["three_ripple_gap_controls"] = len(re.findall( r"^\[PassageRippleSamplingControl\].*status=PASS$", content, re.M)) == 3 checks["three_blocked_passage_controls"] = len(re.findall( r"^\[ResolvedPassageBlockedControl\].*detected=true$", content, re.M)) == 3 chamber_rows = re.findall(r"^\[PassageLandingChamberAudit\].*$", content, re.M) checks["six_chamber_floors"] = (len(chamber_rows) == 6 and all( "status=PASS" in row and re.search(r"\bsolid_samples=0\b", row) and re.search(r"\bgrade_failures=0\b", row) for row in chamber_rows)) checks["plan_grade"] = grade_audit(content)[0] chamber_controls = re.search( r"^\[PassageLandingChamberNegativeControlSummary\] " r"detected=(\d+)/6 .*status=OBSERVED$", content, re.M) checks["chamber_negative_control"] = bool( chamber_controls and int(chamber_controls.group(1)) > 0) checks["three_ripple_profiles"] = len(re.findall( r"^\[PassageRippleAudit\].*status=PASS$", content, re.M)) >= 3 checks["passage_count"] = len(re.findall( r"^\[ResolvedPassageAudit\].*walkability=PASS", content, re.M)) == 3 checks["layout_output"] = layout.is_file() envelope = audit_layout(json.loads(layout.read_text(encoding="utf-8"))) \ if layout.is_file() else None checks["envelope"] = bool(envelope and envelope["passed"] and envelope["outside_chamber_conflicts"] == 0) checks["envelope_negative_control"] = bool(envelope and envelope["negative_controls"] == envelope["negative_controls_expected"] == 1) passed = all(checks.values()) failed = [name for name, ok in checks.items() if not ok] row = {"kind": args.kind, "seed": seed, "verdict": "PASS" if passed else "FAIL", "reason": ", ".join(failed) if failed else "all requested gates pass", "exit": proc.returncode, "checks": checks, "plan_grade_rows": grade_audit(content)[1], "envelope_audit": envelope, "elapsed_s": round(time.monotonic() - started, 3), "log": str(log.relative_to(ROOT)), "layout": str(layout.relative_to(ROOT))} results.append(row) print("[L152SeedSweep] " + json.dumps(row, sort_keys=True), flush=True) partial.write_text(json.dumps(results, indent=2) + "\n", encoding="utf-8") passed_count = sum(row["verdict"] == "PASS" for row in results) summary = {"kind": args.kind, "source_stamp": STAMP, "seeds": list(range(16)), "passed": passed_count, "failed": 16 - passed_count, "results": results} (mode_out / "summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8") print(f"[L152SeedSweepSummary] kind={args.kind} passed={passed_count}/16 " f"failed={16-passed_count} status={'PASS' if passed_count == 16 else 'FAIL'}", flush=True) return 0 if passed_count == 16 else 1 if __name__ == "__main__": raise SystemExit(main())