#!/usr/bin/env python3 """Run the reusable VoxelForge verification tiers: fast, medium, or full.""" from __future__ import annotations import argparse import hashlib import json import math import os from pathlib import Path import re import shutil import signal import statistics import struct import subprocess import sys import time import zlib ROOT = Path(__file__).resolve().parents[3] VERIFY_DIR = ROOT / "Standalone/Tools/verify" LINUX37 = ROOT / "Standalone/Research/WorldAssemblerM3/Linux37" OWNER = ROOT / "Standalone/data/owner_world.json" OUT_DEFAULT = ROOT / "Saved/Linux/l42" PARSER = argparse.ArgumentParser(description=__doc__) PARSER.add_argument("tier", choices=("fast", "medium", "full")) PARSER.add_argument("--out", type=Path, default=OUT_DEFAULT, help="artifact directory (default: Saved/Linux/l41)") PARSER.add_argument("--baseline", default="HEAD", help="commit used for the full-tier cost baseline (default: HEAD)") PARSER.add_argument("--overall-timeout", type=int, default=7200, help="maximum tier wall time in seconds (default: 7200; each child is capped at 1800)") ARGS = PARSER.parse_args() OUT = ARGS.out.resolve() ROUND_NAME = OUT.name os.environ["VOXELFORGE_VERIFY_OUT"] = str(OUT) os.environ["PYTHONDONTWRITEBYTECODE"] = "1" sys.dont_write_bytecode = True sys.path.insert(0, str(VERIFY_DIR)) from owner_step import measure as measure_owner_step from runner import VerificationFailure, VerificationRunner, bounded_run from source_stamp import source_stamp CLANG = OUT / "bin" / f"VoxelForgeCoreHeadless-{ROUND_NAME}-clang" GCC = OUT / "bin" / f"VoxelForgeCoreHeadless-{ROUND_NAME}-gcc" RENDERER = OUT / "bin" / f"VoxelForgeOffscreenCapture-{ROUND_NAME}-clang" HASH_RE = re.compile(r"^\[Pipeline(?:FullDetailHash|WholeViewHash|LODHash|ExactQueryHash)\].*$", re.M) TILE_HASH_RE = re.compile( r"^\[PipelineTileHash\] lod=(-?\d+) x=(-?\d+) y=(-?\d+) z=(-?\d+) " r"density=(0x[0-9a-f]+) mesh=(0x[0-9a-f]+) " r"payload=(0x[0-9a-f]+) topology=(0x[0-9a-f]+)$", re.M) CAMERA_SWEEP_SEED = 0x4C3434 RECIPE_RE = re.compile( r"^\[WorldAssemblerRecipeAudit\] requested=([^ ]+) actual=([^ ]+).*status=([^ ]+)$", re.M) def compiler_name(binary: Path) -> str: return "gcc" if "gcc" in binary.name else "clang" def env_for(*, capture: bool = False) -> dict[str, str]: result = os.environ.copy() result["VOXELFORGE_VERIFY_OUT"] = str(OUT) result["VOXELFORGE_L37_OUT"] = str(OUT) result["VOXELFORGE_L37_CAPTURE_DIR"] = str(OUT / "captures") result["VOXELFORGE_L37_HEADLESS"] = str(CLANG) result["VOXELFORGE_L37_RENDERER"] = str(RENDERER) result["VOXELFORGE_VERIFY_HEADLESS"] = str(CLANG) if capture: result["LP_NUM_THREADS"] = "12" result["XDG_CACHE_HOME"] = str(OUT / "xdg-cache") return result def all_match(text: str, pattern: str) -> bool: return re.search(pattern, text, re.M) is not None def parse_ratio(text: str, name: str) -> float | None: match = re.search(rf"(?:^| ){re.escape(name)}=(\d+)/(\d+)", text) return int(match.group(1)) / max(1, int(match.group(2))) if match else None def validate_passage(runner: VerificationRunner, name: str, output: str) -> None: required = ( ("strict-layout", r"^\[ResolvedLayoutStrict\] accepted=true issues=0 error=$"), ("layout-controls", r"^\[ResolvedLayoutValidatorControls\].*status=PASS$"), ("walkability", r"^\[Walkability\] PASS"), ("floor-profile", r"^\[FloorProfileBlend\].*negative_controls=step_detected/slope_detected status=PASS$"), ("mouth-profile", r"^\[PassageMouthProfileAudit\].*status=PASS$"), ("route-binding", r"^\[ResolvedStrateRouteAudit\].*mouth_binding=PASS status=PASS$"), ("naturalness", r"^\[PassageNaturalnessSummary\].*status=PASS$"), ("open-air", r"^\[PassageOpenAirAuditSummary\].*status=PASS$"), ("no-long-bridge", r"^\[PassageNoLongBridgeAudit\].*status=PASS$"), ("rock-columns", r"^\[PassageRockColumnAuditSummary\].*status=PASS$"), ("ripple-controls", r"^\[PassageRippleAuditSummary\].*status=PASS$"), ("passage-summary", r"^\[ResolvedPassageAuditSummary\].*route_binding_failures=0 .*status=PASS$"), ) for gate, pattern in required: runner.require(f"{name}:{gate}", all_match(output, pattern), "required resolved-passage gate") rows = re.findall(r"^\[PassageRippleAudit\].*$", output, re.M) ripple_ok = bool(rows) for line in rows: wall = re.search(r"local_peak_amplitude_m=([-0-9.]+)", line) if wall is None: wall = re.search(r"amplitude_m=([-0-9.]+)", line) wall_threshold = re.search(r"threshold_m=([-0-9.]+)", line) floor = re.search(r"floor_amplitude_m=([-0-9.]+)", line) floor_threshold = re.search(r"floor_threshold_m=([-0-9.]+)", line) wall_coverage = parse_ratio(line, "coverage") floor_coverage = parse_ratio(line, "floor_coverage") ripple_ok &= bool( "status=PASS" in line and wall and wall_threshold and floor and floor_threshold and wall_coverage is not None and floor_coverage is not None and float(wall.group(1)) <= float(wall_threshold.group(1)) and float(floor.group(1)) <= float(floor_threshold.group(1)) and wall_coverage >= 0.75 and floor_coverage >= 0.75) runner.require(f"{name}:wall-floor-ripple-and-coverage", ripple_ok, f"profiles={len(rows)} wall/floor amplitudes under their thresholds; coverage>=0.75") def run_passage(runner: VerificationRunner, binary: Path, name: str, data: Path, recipe: str, style: int, *, workers: int = 12, flags: list[str] | None = None, max_level: int = -1, layout_path: Path | None = None, passage_style: int | None = None, expected_strate_styles: dict[str, int] | None = None) -> tuple[dict, str]: layout_path = layout_path or OUT / "layouts" / f"{name}.json" row, output = runner.run_cpp(name, binary, data, recipe, ["--audit-resolved-layout-passages", *(flags or [])], expected_style=style if passage_style is None else passage_style, expected_strate_styles=expected_strate_styles, workers=workers, max_level=max_level, layout_path=layout_path) row["requested_style"] = style row["expected_passage_style"] = style if passage_style is None else passage_style row["requested_strate_styles"] = expected_strate_styles validate_passage(runner, name, output) return row, output def run_owner_passages(runner: VerificationRunner, binaries: tuple[Path, ...]) -> dict[str, tuple[dict, str]]: result: dict[str, tuple[dict, str]] = {} expected_strate_styles = {"0": 2, "1": 1} for binary in binaries: compiler = compiler_name(binary) for recipe, style in (("floating-islands", 2), ("surface-world", 1)): name = f"owner-{recipe}-style{style}-{compiler}" row, output = run_passage(runner, binary, name, OWNER, recipe, style, passage_style=2, expected_strate_styles=expected_strate_styles) result[f"{compiler}:{recipe}"] = (row, output) actual_styles = row.get("resolved_strate_styles", {}) runner.require(f"{name}:owner-style-map", actual_styles == expected_strate_styles, f"resolved_strate_styles={actual_styles} expected={expected_strate_styles}") if compiler == "clang": measured = measure_owner_step(output) worst = measured.get("worst") runner.require(f"{name}:adjacent-owner-step", bool(measured["passed"]), f"max_step_m={measured['maximum_adjacent_step_m']:.6f} " f"limit_m=0.100 pairs={measured['adjacent_pairs']} " f"fitted_periods_m={measured['fitted_periods_m']} " f"period_role=diagnostic worst={worst}") return result def expected_control_row(runner: VerificationRunner, name: str) -> None: if runner.runs: row = runner.runs[-1] row["observed_status"] = row["status"] row["status"] = "EXPECTED_FAIL" row["negative_control"] = name def run_stamp_and_input_controls(runner: VerificationRunner) -> None: # Mutate one compiled Core input only while checking that the runner refuses it. core_file = ROOT / "Standalone/Core/src/VoxelForgeCore.cpp" original = core_file.read_bytes() rejected = False try: core_file.write_bytes(original + b"\n// temporary L39 stale-build negative control\n") try: runner.probe_binary(CLANG) except RuntimeError as error: rejected = "source changed" in str(error) finally: core_file.write_bytes(original) runner.assert_current_tree("after restoring stale-build control") runner.require("stale-build-source-edit-control", rejected, "runner refused the binary after a Core source edit; original bytes restored") fixture = ROOT / "Saved/Linux/l33/fixtures/sw-upper-tunnel-network-style0.json" mislabelled = OUT / "controls/mislabelled-owner/owner_world.json" mislabelled.parent.mkdir(parents=True, exist_ok=True) shutil.copyfile(fixture, mislabelled) try: runner.run_cpp("control-mislabelled-owner-style0", CLANG, mislabelled, "floating-islands", ["--resolved-layout-only"], expected_style=2, layout_path=OUT / "controls/mislabelled-owner/layout-owner.json") detected = False except VerificationFailure: detected = bool(runner.runs and 0 in runner.runs[-1]["resolved_style"] and runner.runs[-1]["status"] == "FAIL") if detected: expected_control_row(runner, "mislabelled-style0-input") runner.require("mislabelled-owner-style-control", detected, "style-0 fixture named owner_world.json rejected for expected FI Style 2") black = OUT / "controls/all-black.png" black.parent.mkdir(parents=True, exist_ok=True) write_black_png(black) script = VERIFY_DIR / "capture_quality.py" try: runner.run_stage("control-all-black-capture", script, [str(black)], binary=CLANG, data=None, recipe=None, style=None, env=env_for(), script_inputs=[black]) black_rejected = False except VerificationFailure: black_rejected = "status=FAIL" in (OUT / "control-all-black-capture.log").read_text( encoding="utf-8", errors="replace") if black_rejected: expected_control_row(runner, "all-black-capture") runner.require("all-black-capture-control", black_rejected, "pixel variance and coverage floor reject a valid all-black PNG") def write_black_png(path: Path) -> None: def chunk(tag: bytes, payload: bytes) -> bytes: return (struct.pack(">I", len(payload)) + tag + payload + struct.pack(">I", zlib.crc32(tag + payload) & 0xffffffff)) pixels = b"".join(b"\0" + b"\0\0\0" * 2 for _ in range(2)) body = (b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", 2, 2, 8, 2, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(pixels)) + chunk(b"IEND", b"")) path.write_bytes(body) def run_regression_controls(runner: VerificationRunner) -> None: run_stamp_and_input_controls(runner) controls = ( ("l35-wall-ribs", "wall-ribs", ROOT / "Saved/Linux/l35/failed/passage-audit-cascade-cosine-owner-fi-style3-clang.log"), ("l36-floor-washboard", "floor-washboard", ROOT / "Saved/Linux/l36/audit-nearest-fi-style0.log"), ) script = VERIFY_DIR / "historical_controls.py" for name, kind, log in controls: runner.run_stage(f"control-{name}", script, [kind, str(log)], binary=CLANG, data=None, recipe=None, style=None, env=env_for(), script_inputs=[log]) l38 = ROOT / "Saved/Linux/l38/owner-fi-real-final.log" step_script = VERIFY_DIR / "owner_step.py" runner.run_stage("control-l38-owner-step", step_script, [str(l38), "--expect-fail"], binary=CLANG, data=None, recipe=None, style=None, env=env_for(), script_inputs=[l38]) def run_hash_pairs(runner: VerificationRunner, owner_results: dict[str, tuple[dict, str]]) -> None: for recipe, style in (("floating-islands", 2), ("surface-world", 1)): hashes: dict[int, tuple[str, ...]] = {} for workers in (1, 12): name = f"owner-hash-{recipe}-style{style}-w{workers}" row, output = runner.run_cpp(name, CLANG, OWNER, recipe, ["--stream-hash"], expected_style=2, expected_strate_styles={"0": 2, "1": 1}, workers=workers, layout_path=OUT / "layouts" / f"{name}.json") row["requested_style"] = style row["expected_passage_style"] = 2 values = tuple(HASH_RE.findall(output)) hashes[workers] = values runner.require(f"{name}:hash-count", len(values) == 12, f"hashes={len(values)}/12") same = hashes[1] == hashes[12] baseline = ROOT / "Saved/Linux/l37" / f"determinism-l25-clang-{recipe}-w12.log" old_hashes = tuple(HASH_RE.findall(baseline.read_text(encoding="utf-8", errors="replace"))) same_l37 = hashes[12] == old_hashes and len(old_hashes) == 12 runner.require(f"owner-hash-{recipe}-w1-w12", same, "W1 and W12 each produced identical 12-hash signatures") runner.require(f"owner-hash-{recipe}-matches-l37", same_l37, f"current owner hashes match {baseline.name}; hashes={len(old_hashes)}") class _SplitMix64: """Small fixed-seed generator whose camera sequence is independent of Python random.""" def __init__(self, seed: int): self.state = seed & 0xffffffffffffffff def unit(self) -> float: self.state = (self.state + 0x9e3779b97f4a7c15) & 0xffffffffffffffff value = self.state value = ((value ^ (value >> 30)) * 0xbf58476d1ce4e5b9) & 0xffffffffffffffff value = ((value ^ (value >> 27)) * 0x94d049bb133111eb) & 0xffffffffffffffff value ^= value >> 31 return (value >> 11) / float(1 << 53) def between(self, low: float, high: float) -> float: return low + (high - low) * self.unit() def seeded_camera_positions(count: int) -> list[tuple[float, float, float, float, float]]: rng = _SplitMix64(CAMERA_SWEEP_SEED) positions: list[tuple[float, float, float, float, float]] = [] for index in range(count): if index == 0: # Stay in the known failing 8 m tile neighbourhood while still deriving the # camera from the fixed seed. The negative Y offset keeps it below the 32 m seam. x = -8.918 + rng.between(-0.02, 0.02) y = 31.95 - rng.between(0.005, 0.035) z = -513.083 + rng.between(-0.02, 0.02) else: x = rng.between(-900.0, 900.0) y = rng.between(-900.0, 900.0) while math.hypot(x + 46.45, y + 472.88) < 320.0: x = rng.between(-900.0, 900.0) y = rng.between(-900.0, 900.0) if index % 2: z = -256.0 + rng.between(-12.0, 12.0) # SurfaceWorld strate 0. else: z = -1536.0 + rng.between(-120.0, 120.0) # FloatingIslands strate 1. yaw = rng.between(-180.0, 180.0) pitch = rng.between(-35.0, 35.0) positions.append((x, y, z, yaw, pitch)) return positions def parse_tile_hashes(output: str) -> dict[tuple[int, int, int, int], tuple[str, ...]]: rows: dict[tuple[int, int, int, int], tuple[str, ...]] = {} for match in TILE_HASH_RE.finditer(output): key = tuple(int(match.group(i)) for i in range(1, 5)) rows[key] = tuple(match.group(i) for i in range(5, 9)) return rows def run_random_camera_sweep(runner: VerificationRunner, binaries: tuple[Path, ...], camera_count: int, configurations: tuple[tuple[int, int, int], ...]) -> None: positions = seeded_camera_positions(camera_count) for binary in binaries: compiler = compiler_name(binary) for recipe in ("surface-world", "floating-islands"): for camera_index, camera in enumerate(positions): x, y, z, yaw, pitch = camera camera_flag = f"--camera={x:.6f},{y:.6f},{z:.6f},{yaw:.3f},{pitch:.3f}" for clip_radius, max_clip_level, max_level in configurations: settings = (clip_radius, max_clip_level, max_level) label = (f"random-camera-{compiler}-{recipe}-s{CAMERA_SWEEP_SEED:06x}" f"-p{camera_index:02d}-r{clip_radius}-c{max_clip_level}-m{max_level}") signatures: dict[int, dict[tuple[int, int, int, int], tuple[str, ...]]] = {} for workers in (1, 8, 12): name = f"{label}-w{workers}" flags = ["--stream-hash-tiles", camera_flag, f"--clip-radius={clip_radius}", f"--max-clip-level={max_clip_level}", f"--max-level={max_level}", "--render-distance-chunks=0"] row, output = runner.run_cpp(name, binary, OWNER, recipe, flags, expected_style=2, expected_strate_styles={"0": 2, "1": 1}, workers=workers, layout_path=OUT / "layouts" / f"{name}.json") row["camera_sweep_seed"] = CAMERA_SWEEP_SEED row["camera_position_m"] = [round(value, 6) for value in camera[:3]] row["camera_rotation_degrees"] = [round(value, 3) for value in camera[3:]] row["sweep_settings"] = { "clip_radius": clip_radius, "max_clip_level": max_clip_level, "max_level": max_level, } current = parse_tile_hashes(output) signatures[workers] = current whole = re.search(r"^\[PipelineWholeViewHash\] tiles=(\d+)", output, re.M) expected_rows = int(whole.group(1)) if whole else -1 runner.require(f"{name}:tile-hash-rows", bool(current) and len(current) == expected_rows, f"rows={len(current)} expected={expected_rows} settings={settings}") camera_text = (f"seed=0x{CAMERA_SWEEP_SEED:06x} camera_m=" f"({x:.3f},{y:.3f},{z:.3f}) recipe={recipe} settings={settings}") for left, right in ((1, 8), (1, 12), (8, 12)): left_rows, right_rows = signatures[left], signatures[right] keys = set(left_rows) | set(right_rows) density_diff = [key for key in keys if left_rows.get(key, (None,))[0] != right_rows.get(key, (None,))[0]] mesh_diff = [key for key in keys if left_rows.get(key, (None, None))[1] != right_rows.get(key, (None, None))[1]] payload_diff = [key for key in keys if left_rows.get(key, (None, None, None))[2] != right_rows.get(key, (None, None, None))[2]] topology_diff = [key for key in keys if left_rows.get(key, (None, None, None, None))[3] != right_rows.get(key, (None, None, None, None))[3]] detail = (f"{camera_text} W{left}=W{right} " f"density_tiles={len(density_diff)} mesh_tiles={len(mesh_diff)} " f"payload_tiles={len(payload_diff)} topology_tiles={len(topology_diff)} " f"sample_coords={sorted(density_diff or mesh_diff)[:6]}") runner.require(f"{label}:W{left}-W{right}", left_rows == right_rows, detail) def run_ring(runner: VerificationRunner, *, full: bool) -> None: script = LINUX37 / "RunRingAuditsL37.py" audit_inputs = [script, ROOT / "Standalone/Research/WorldAssemblerM3/Linux32/AuditRingTerraceL32.py", ROOT / "Standalone/Research/WorldAssemblerM3/Linux32/AuditRingSetL32.py"] for label, recipe, style in (("fi-floor", "floating-islands", 2), ("sw-ceiling", "surface-world", 1)): args = ["--scene", label] layout = OUT / "layouts" / f"ring-layout-{label}-lod0.json" if not full: args.append("--lod0-only") if label == "sw-ceiling": args.append("--skip-controls") runner.run_stage(f"ring-{label}-{'lod0-8' if full else 'lod0'}", script, args, binary=CLANG, data=OWNER, recipe=recipe, style=style, layout_path=layout, env=env_for(), script_inputs=audit_inputs) def style_override_matrix(runner: VerificationRunner, binary: Path) -> None: sources: list[tuple[str, Path, str]] = [] for recipe in ("floating-islands", "surface-world"): for style in range(4): source = ROOT / f"Saved/Linux/linux25-owner-{recipe}-style{style}.json" sources.append((f"{recipe}-style{style}", source, recipe)) for style in range(4): source = ROOT / f"Saved/Linux/l33/fixtures/sw-upper-tunnel-network-style{style}.json" sources.append((f"upper-sw-fixture-style{style}", source, "floating-islands")) for fixture_name, source, recipe in sources: label = f"style-override-{fixture_name}" destination = OUT / "fixtures" / f"{label}.json" destination.parent.mkdir(parents=True, exist_ok=True) shutil.copyfile(source, destination) style = int(re.search(r"style([0-3])$", fixture_name).group(1)) name = f"{label}-{compiler_name(binary)}" if fixture_name.startswith("upper-sw-fixture-"): expected_strate_styles = {"1": style} else: expected_strate_styles = {"0": style, "1": 1} row, output = runner.run_cpp(name, binary, destination, recipe, ["--audit-resolved-layout-passages"], expected_style=None, expected_strate_styles=expected_strate_styles, layout_path=OUT / "layouts" / f"{name}.json") row["requested_style"] = style row["requested_strate_styles"] = expected_strate_styles validate_passage(runner, name, output) def run_transitions_and_invariants(runner: VerificationRunner, binaries: tuple[Path, ...]) -> None: for binary in binaries: compiler = compiler_name(binary) for recipe, style in (("floating-islands", 2), ("surface-world", 1)): for mode in ("hard", "gradient", "interleaved"): name = f"transition-{recipe}-{mode}-{compiler}" row, output = runner.run_cpp(name, binary, OWNER, recipe, [f"--transition-mode={mode}", "--audit-strate-transitions"], expected_style=2, expected_strate_styles={"0": 2, "1": 1}, layout_path=OUT / "layouts" / f"{name}.json") row["requested_style"] = style row["expected_passage_style"] = 2 gates = (r"^\[StrateTransitionAuditSummary\].*hole_columns=0 air_samples=0 .*status=PASS$", r"^\[StrateTransitionNegativeControls\].*status=PASS$") for index, pattern in enumerate(gates): runner.require(f"{name}:gate-{index + 1}", all_match(output, pattern), pattern) name = f"invariant-route-proof-{recipe}-{compiler}" row, output = runner.run_cpp(name, binary, OWNER, recipe, ["--audit-uniform-block-proofs", "--audit-route-parity"], expected_style=2, expected_strate_styles={"0": 2, "1": 1}, layout_path=OUT / "layouts" / f"{name}.json") row["requested_style"] = style row["expected_passage_style"] = 2 runner.require(f"{name}:route-parity", all_match(output, r"^\[RouteParityAudit\].*status=PASS$"), "route parity L13") runner.require(f"{name}:uniform-block-proof", all_match(output, r"^\[UniformBlockProofAudit\].*violations=0(?:\s|$)"), "uniform-block proof L9") def run_captures_and_mesh_audits(runner: VerificationRunner) -> None: capture_script = LINUX37 / "CapturePassageStandardSetL37.py" capture_inputs = [capture_script, VERIFY_DIR / "capture_quality.py", ROOT / "Standalone/Research/WorldAssemblerM3/Linux32/AuditRingTerraceL32.py"] capture_rows: dict[str, tuple[dict, str]] = {} for scene, recipe, style in (("owner-fi", "floating-islands", 2), ("owner-sw", "surface-world", 1)): layout_path = OUT / f"layout-{scene}.json" name = f"capture-standard-{scene}-style{style}" row, output = runner.run_stage(name, capture_script, ["--scene", scene], binary=CLANG, data=OWNER, recipe=recipe, style=style, layout_path=layout_path, env=env_for(capture=True), script_inputs=capture_inputs) resolved_strate_styles = row.get("resolved_strate_styles", {}) target_strate = "0" if scene == "owner-fi" else "1" style_ok = (resolved_strate_styles == {"0": 2, "1": 1} and resolved_strate_styles.get(target_strate) == style) runner.require(f"{name}:resolved-style", style_ok, f"resolved_strate_styles={resolved_strate_styles} " f"target_strate={target_strate} expected_style={style}") capture_rows[scene] = (row, output) shape_script = LINUX37 / "AuditMouthShapeL37.py" baseline = ROOT / "Saved/Linux/l37/no-tread-control" controls = [ROOT / "Saved/Linux/l36/owner-fi-ground-mouth.vfmesh"] for scene, recipe, style in (("owner-fi", "floating-islands", 2), ("owner-sw", "surface-world", 1)): name = f"mouth-shape-{scene}-style{style}" runner.run_stage(name, shape_script, [f"--out={OUT}", f"--baseline-out={baseline}", "--control-out=Saved/Linux/l36", "--scene", scene], binary=CLANG, data=OWNER, recipe=recipe, style=style, layout_path=OUT / f"layout-{scene}.json", env=env_for(), script_inputs=[shape_script, *controls]) crease_script = LINUX37 / "RunMouthCreaseAuditL37.py" sw_capture_log = OUT / "capture-standard-owner-sw-style1.log" crease_args = [ f"--candidate={OUT / 'owner-fi-ground-mouth.vfmesh'}", f"--candidate-sw={OUT / 'owner-sw-ground-mouth.vfmesh'}", f"--layout-sw={OUT / 'layout-owner-sw.json'}", f"--capture-log-sw={sw_capture_log}"] control_meshes = [ROOT / f"Saved/Linux/{round_name}/owner-fi-ground-mouth.vfmesh" for round_name in ("l35", "l36")] runner.run_stage("mouth-crease-fragments-owner-fi2-sw1", crease_script, crease_args, binary=CLANG, data=OWNER, recipe="floating-islands", style=2, layout_path=OUT / "layout-owner-fi.json", env=env_for(), script_inputs=[crease_script, LINUX37 / "RunMouthFragmentAuditL37.py", *control_meshes, OUT / "owner-fi-ground-mouth.vfmesh", OUT / "owner-sw-ground-mouth.vfmesh", OUT / "layout-owner-sw.json", sw_capture_log]) overview_script = LINUX37 / "CaptureMouthOverviewL37.py" runner.run_stage("capture-fi-overview-style2", overview_script, [], binary=CLANG, data=OWNER, recipe="floating-islands", style=2, layout_path=OUT / "layout-owner-fi.json", env=env_for(capture=True), script_inputs=[overview_script, VERIFY_DIR / "capture_quality.py", OUT / "owner-fi-ground-mouth.vfmesh"]) def verify_determinism_cell(runner: VerificationRunner, binary: Path, kind: str, recipe: str, style: int, workers: int, reference: dict[tuple[str, str], tuple[str, ...]]) -> None: name = f"determinism-{kind}-{recipe}-{compiler_name(binary)}-w{workers}" flags = ["--stream-hash"] if kind == "crossing24": flags.extend(("--camera-step=24,0,0", "--region-crossing")) row, output = runner.run_cpp(name, binary, OWNER, recipe, flags, expected_style=2, expected_strate_styles={"0": 2, "1": 1}, workers=workers, layout_path=OUT / "layouts" / f"{name}.json") row["requested_style"] = style row["expected_passage_style"] = 2 values = tuple(HASH_RE.findall(output)) key = (kind, recipe) expected = reference.get(key) stable = expected is None or values == expected if expected is None and values: reference[key] = values runner.require(f"{name}:stable-hashes", len(values) == 12 and stable, f"hashes={len(values)}/12 stable={stable}") def run_30_cell_determinism(runner: VerificationRunner) -> None: references: dict[tuple[str, str], tuple[str, ...]] = {} count = 0 for kind in ("l25", "crossing24"): for recipe, style in (("surface-world", 1), ("floating-islands", 2)): for binary in (CLANG, GCC): for workers in (1, 8, 12): verify_determinism_cell(runner, binary, kind, recipe, style, workers, references) count += 1 fixture_source = ROOT / "Saved/Linux/l33/fixtures/sw-upper-tunnel-network-style0.json" fixture = OUT / "fixtures/style-override-upper-sw-fixture-style0.json" fixture.parent.mkdir(parents=True, exist_ok=True) shutil.copyfile(fixture_source, fixture) signatures = None for binary in (CLANG, GCC): for workers in (1, 8, 12): name = f"determinism-style-override-upper-sw-fixture-style0-{compiler_name(binary)}-w{workers}" row, output = runner.run_cpp(name, binary, fixture, "floating-islands", ["--audit-resolved-layout-passages"], expected_style=None, expected_strate_styles={"1": 0}, workers=workers, layout_path=OUT / "layouts" / f"{name}.json") row["requested_style"] = 0 row["requested_strate_styles"] = {"1": 0} validate_passage(runner, name, output) current = tuple(re.findall( r"^\[ResolvedLayoutSnapshot\].*stable_identity=([^ ]+)", output, re.M) + re.findall(r"^\[WorldAssemblyPlanSerialization\].*plan_hash=([0-9a-f]+)", output, re.M) + re.findall(r"^\[WorldAssemblerRouteAccepted\].*$", output, re.M)) stable = signatures is None or current == signatures if signatures is None and current: signatures = current runner.require(f"{name}:stable-plan-route", bool(current) and stable, f"snapshot-plan-route_records={len(current)} stable={stable}") count += 1 runner.require("determinism-30-cell-count", count == 30, f"cells={count}/30") def prepare_cost_baseline(runner: VerificationRunner) -> tuple[Path, str]: resolved = bounded_run(["git", "rev-parse", "--verify", f"{ARGS.baseline}^{{commit}}"], timeout=120) if resolved is None or resolved.returncode != 0: raise VerificationFailure(f"could not resolve cost baseline commit {ARGS.baseline!r}") baseline_commit = resolved.stdout.strip() if not re.fullmatch(r"[0-9a-f]{40,64}", baseline_commit): raise VerificationFailure(f"git returned an invalid baseline commit: {baseline_commit!r}") temp = Path(f"/tmp/voxelforge-cost-baseline-{baseline_commit[:12]}") if temp.exists(): shutil.rmtree(temp) temp.mkdir(parents=True) tarball = temp / "baseline.tar" archive = bounded_run(["git", "archive", "-o", str(tarball), baseline_commit, "Standalone"], timeout=120) if archive is None or archive.returncode != 0 or not tarball.is_file(): raise VerificationFailure( f"could not export Standalone from cost baseline commit {baseline_commit}") extract = bounded_run(["tar", "-xf", str(tarball), "-C", str(temp)], timeout=120) if extract is None or extract.returncode != 0: raise VerificationFailure("cost baseline source extraction failed") tarball.unlink(missing_ok=True) base = temp / "Standalone" (base / "Tools/verify").mkdir(parents=True, exist_ok=True) shutil.copy2(ROOT / "Standalone/BuildLinux.sh", base / "BuildLinux.sh") shutil.copy2(VERIFY_DIR / "source_stamp.py", base / "Tools/verify/source_stamp.py") shutil.copy2(ROOT / "Standalone/Source/SourceStamp.h", base / "Source/SourceStamp.h") legacy_main = base / "Source/StreamBenchmarkHeadless.cpp" text = legacy_main.read_text(encoding="utf-8") if "VoxelForgePrintSourceStamp" not in text: text = text.replace("#include \"OwnerWorldLoader.h\"", "#include \"SourceStamp.h\"\n#include \n#include \"OwnerWorldLoader.h\"", 1) anchor = re.search(r"int main\(int argc,\s*char\*\*\s*argv\)\s*\{", text) if anchor is None: raise VerificationFailure("cannot instrument cost-baseline headless entry point") injected = ("\n VoxelForgePrintSourceStamp();\n" " if(argc==2&&std::strcmp(argv[1],\"--print-source-stamp\")==0)return 0;") text = text[:anchor.end()] + injected + text[anchor.end():] legacy_main.write_text(text, encoding="utf-8") baseline_stamp = source_stamp(temp) baseline_variant = f"baseline-{baseline_commit[:12]}-stamped" binary = OUT / "historical-bin" / f"VoxelForgeCoreHeadless-{baseline_variant}" env = os.environ.copy() env["VOXELFORGE_BUILD_ROOT"] = str(temp / "build") env["VOXELFORGE_BIN_DIR"] = str(binary.parent) command = ["bash", str(base / "BuildLinux.sh"), "--compiler=clang++-19", f"--variant={baseline_variant}", "--fp-contract=off", "--jobs=12"] log = OUT / "cost-baseline-build.log" log.parent.mkdir(parents=True, exist_ok=True) started = time.monotonic() with log.open("w", encoding="utf-8") as stream: proc = bounded_run(command, timeout=1800, env=env, stdout=stream) elapsed = time.monotonic() - started runner.require("cost-baseline-build", proc is not None and proc.returncode == 0 and binary.is_file(), f"baseline={baseline_commit} source_stamp={baseline_stamp} " f"elapsed_seconds={elapsed:.1f} log={log}") runner.binary_stamp_overrides[str(binary)] = baseline_stamp return binary, baseline_stamp def run_cost_pairs(runner: VerificationRunner) -> None: baseline, baseline_stamp = prepare_cost_baseline(runner) candidate = CLANG orders = (("baseline", "candidate"), ("candidate", "baseline"), ("baseline", "candidate"), ("candidate", "baseline"), ("baseline", "candidate")) by_recipe: dict[str, dict[str, list[float]]] = { "floating-islands": {"baseline": [], "candidate": []}, "surface-world": {"baseline": [], "candidate": []}} by_pair: dict[tuple[str, int], dict[str, float]] = {} for recipe, style in (("floating-islands", 2), ("surface-world", 1)): for pair, order in enumerate(orders, 1): for build in order: binary = baseline if build == "baseline" else candidate name = f"cost-{recipe}-pair{pair}-{build}" expected_stamp = baseline_stamp if build == "baseline" else None row, output = runner.run_cpp(name, binary, OWNER, recipe, [], expected_style=2 if build == "candidate" else None, expected_strate_styles={"0": 2, "1": 1} if build == "candidate" else None, layout_path=OUT / "layouts" / f"{name}.json", expected_stamp=expected_stamp) row["requested_style"] = style row["expected_passage_style"] = 2 if build == "candidate" else None ready = re.findall(r"\bwhole_view_ready=([0-9.]+)s", output) ok = (len(ready) == 1 and "hash=off" in output and "cache_hits=0" in output and RECIPE_RE.findall(output) == [(recipe, recipe, "PASS")]) runner.require(f"{name}:cost-record", ok, f"whole_view_ready={ready[0] if ready else 'MISSING'}s " f"source_stamp={row['source_stamp']}") by_recipe[recipe][build].append(float(ready[0])) by_pair.setdefault((recipe, pair), {})[build] = float(ready[0]) for recipe, values in by_recipe.items(): old = statistics.median(values["baseline"]) new = statistics.median(values["candidate"]) paired = [((by_pair[(recipe, pair)]["candidate"] - by_pair[(recipe, pair)]["baseline"]) / by_pair[(recipe, pair)]["baseline"] * 100.0) for pair in range(1, 6)] runner.require(f"cost-{recipe}-five-pairs", len(values["baseline"]) == len(values["candidate"]) == 5, f"median_baseline_s={old:.3f} median_candidate_s={new:.3f} " f"median_change_pct={(new / old - 1.0) * 100.0:+.2f} " f"paired_change_pct={','.join(f'{value:+.2f}' for value in paired)}") def run_medium_suite(runner: VerificationRunner, *, both_compilers: bool = False) -> None: binaries = (CLANG, GCC) if both_compilers else (CLANG,) run_owner_passages(runner, binaries) run_regression_controls(runner) style_override_matrix(runner, CLANG) if both_compilers: style_override_matrix(runner, GCC) run_transitions_and_invariants(runner, binaries) run_ring(runner, full=True) run_captures_and_mesh_audits(runner) run_random_camera_sweep(runner, (CLANG,), 5, ((3, 0, 0), (2, 1, 1), (3, 2, 1))) def run_gcc_supplement(runner: VerificationRunner) -> None: """Add GCC evidence to a stamped, already-passed Clang medium tier.""" run_owner_passages(runner, (GCC,)) style_override_matrix(runner, GCC) run_transitions_and_invariants(runner, (GCC,)) def _tier_deadline(_signum: int, _frame: object) -> None: raise VerificationFailure( f"{ARGS.tier} tier exceeded its {ARGS.overall_timeout}s overall timeout") def main() -> int: runner = VerificationRunner(ARGS.tier) started = time.monotonic() if ARGS.overall_timeout <= 0: raise VerificationFailure("--overall-timeout must be a positive number of seconds") signal.signal(signal.SIGALRM, _tier_deadline) signal.setitimer(signal.ITIMER_REAL, ARGS.overall_timeout) try: if not OWNER.is_file(): raise VerificationFailure(f"canonical owner input is missing: {OWNER}") for binary in (CLANG, GCC, RENDERER): if binary.is_file(): runner.probe_binary(binary) if ARGS.tier == "fast": owners = run_owner_passages(runner, (CLANG,)) run_regression_controls(runner) run_hash_pairs(runner, owners) run_random_camera_sweep(runner, (CLANG,), 3, ((3, 0, 0),)) run_ring(runner, full=False) elif ARGS.tier == "medium": run_medium_suite(runner, both_compilers=False) else: medium_summary = OUT / "medium-summary.json" if not runner.reuse_passed_tier(medium_summary, "medium"): run_medium_suite(runner, both_compilers=False) run_gcc_supplement(runner) run_random_camera_sweep(runner, (GCC,), 5, ((3, 0, 0), (2, 1, 1), (3, 2, 1))) run_30_cell_determinism(runner) run_cost_pairs(runner) # The validated medium summary carries the final canonical capture set. runner.assert_binaries_current() runner.assert_current_tree("at tier completion") elapsed = time.monotonic() - started runner.save_summary("PASS") print(f"[{ARGS.tier}] DONE PASS elapsed={elapsed:.1f}s", flush=True) return 0 except Exception as error: elapsed = time.monotonic() - started runner.save_summary("FAIL", str(error)) print(f"[{ARGS.tier}] DONE FAIL elapsed={elapsed:.1f}s error={error}", flush=True) return 1 finally: signal.setitimer(signal.ITIMER_REAL, 0) if __name__ == "__main__": raise SystemExit(main())