Files
VoxelForge/Standalone/Tools/verify/verify.py
T
Fr0zkaandClaude Opus 5.5 753cc9c259 tools(verify): fast/medium/full verification tiers with a compiled-in source stamp (L39); research R6
BuildLinux.sh hashes a sorted manifest of compiled inputs into VOXELFORGE_SOURCE_STAMP, printed first by
every executable; Standalone/Tools/verify/verify.py checks it before and after each tier and records
binary/input hashes and the resolved recipe, style map and layout. Fast (163 s) runs on the canonical owner
world only and asserts FI Style 2 / SW Style 1; medium (8 min) and full (26 min) add the style matrix,
GCC, determinism and cost. Controls: stale source, mislabelled style-0 owner, all-black capture, L30/L31,
L35/L36 and the L38 step are all rejected. No geometry change; owner hashes identical to L37.
Research R6: leak table, generator contract and a 10-step metre-native migration plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016dhxM43dnWvUu2B5Ph1iG1
2026-10-23 15:27:52 +02:00

641 lines
31 KiB
Python

#!/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 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/l39"
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/l39)")
ARGS = PARSER.parse_args()
OUT = ARGS.out.resolve()
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/VoxelForgeCoreHeadless-l39-clang"
GCC = OUT / "bin/VoxelForgeCoreHeadless-l39-gcc"
RENDERER = OUT / "bin/VoxelForgeOffscreenCapture-l39-clang"
HASH_RE = re.compile(r"^\[Pipeline(?:FullDetailHash|WholeViewHash|LODHash|ExactQueryHash)\].*$", re.M)
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)}")
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_l36_cost_baseline(runner: VerificationRunner) -> tuple[Path, str]:
temp = Path("/tmp/voxelforge-l36-stamped")
if temp.exists():
shutil.rmtree(temp)
temp.mkdir(parents=True)
tarball = temp / "l36.tar"
archive = bounded_run(["git", "archive", "-o", str(tarball),
"8be1c4d", "Standalone"], timeout=120)
if archive is None or archive.returncode != 0 or not tarball.is_file():
raise VerificationFailure("could not export historical L36 source commit 8be1c4d")
extract = bounded_run(["tar", "-xf", str(tarball), "-C", str(temp)], timeout=120)
if extract is None or extract.returncode != 0:
raise VerificationFailure("historical L36 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 <cstring>\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 historical L36 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)
binary = OUT / "historical-bin/VoxelForgeCoreHeadless-l36-stamped"
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",
"--variant=l36-stamped", "--fp-contract=off", "--jobs=12"]
log = OUT / "cost-baseline-build-l36.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-l36-build",
proc is not None and proc.returncode == 0 and binary.is_file(),
f"source_stamp={baseline_stamp} 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_l36_cost_baseline(runner)
candidate = CLANG
orders = (("l36", "l39"), ("l39", "l36"), ("l36", "l39"),
("l39", "l36"), ("l36", "l39"))
by_recipe: dict[str, dict[str, list[float]]] = {
"floating-islands": {"l36": [], "l39": []},
"surface-world": {"l36": [], "l39": []}}
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 == "l36" else candidate
expected_style = None if build == "l36" else style
name = f"cost-{recipe}-pair{pair}-{build}"
expected_stamp = baseline_stamp if build == "l36" else None
row, output = runner.run_cpp(name, binary, OWNER, recipe, [],
expected_style=2 if build == "l39" else None,
expected_strate_styles={"0": 2, "1": 1} if build == "l39" else None,
layout_path=OUT / "layouts" / f"{name}.json",
expected_stamp=expected_stamp)
row["requested_style"] = style
row["expected_passage_style"] = 2 if build == "l39" 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["l36"])
new = statistics.median(values["l39"])
paired = [((by_pair[(recipe, pair)]["l39"] - by_pair[(recipe, pair)]["l36"])
/ by_pair[(recipe, pair)]["l36"] * 100.0)
for pair in range(1, 6)]
runner.require(f"cost-{recipe}-five-pairs",
len(values["l36"]) == len(values["l39"]) == 5,
f"median_l36_s={old:.3f} median_l39_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)
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 main() -> int:
runner = VerificationRunner(ARGS.tier)
started = time.monotonic()
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_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_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
if __name__ == "__main__":
raise SystemExit(main())