#!/usr/bin/env python3 """Compare owner and resolved-planner hashes against the exact L147 parent build.""" from __future__ import annotations import hashlib import json import re import subprocess from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l147/identity" DATA = ROOT / "Standalone/data/owner_world.json" HEAD_BIN = ROOT / "Saved/Linux/l140/bin/VoxelForgeCoreHeadless-l140-clang" L147_BIN = ROOT / "Standalone/bin/linux/VoxelForgeCoreHeadless-l147-clang" HEAD_STAMP = "6205e6c180ef32c41792dc3e0d8bf443a96df41974f40334af4bf3a157ab88da" L147_STAMP = "c6b8a100355e271ddc40eb5973569d2ff4e2ba8d9c628c72f8e0af2493f0609f" STAMP_RE = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=([0-9a-f]+)$", re.M) PIPELINE_HASH_RE = re.compile( r"^\[Pipeline(?:FullDetailHash|WholeViewHash|LODHash|ExactQueryHash)\].*$", re.M) PLAN_RE = re.compile(r"^\[WorldAssemblerPlanSerialization\].*plan_hash=([0-9a-f]+).*$", re.M) def run(label: str, binary: Path, expected_stamp: str) -> dict[str, object]: if not binary.is_file(): raise SystemExit(f"missing {label} binary: {binary}") log = OUT / f"{label}.log" layout = OUT / f"{label}-layout.json" command = ["taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(binary), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--workers=8", "--clip-radius=3", "--max-clip-level=8", "--max-level=0", "--force-generate", "--seed=0", "--recipe=surface-world", "--stream-hash", f"--resolved-layout-output={layout}"] 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) pipeline_hashes = PIPELINE_HASH_RE.findall(content) plan = PLAN_RE.search(content) layout_bytes = layout.read_bytes() if layout.is_file() else b"" result = { "label": label, "exit": proc.returncode, "stamp": stamp.group(1) if stamp else None, "stamp_matches_expected": stamp is not None and stamp.group(1) == expected_stamp, "pipeline_hashes": pipeline_hashes, "plan_hash": plan.group(1) if plan else None, "resolved_layout_sha256": hashlib.sha256(layout_bytes).hexdigest() if layout_bytes else None, "resolved_layout_identity": None, "log": str(log.relative_to(ROOT)), "layout": str(layout.relative_to(ROOT)), } if layout_bytes: result["resolved_layout_identity"] = json.loads(layout_bytes).get("stable_identity") return result def main() -> int: OUT.mkdir(parents=True, exist_ok=True) head = run("head", HEAD_BIN, HEAD_STAMP) l147 = run("l147", L147_BIN, L147_STAMP) passed = (head["exit"] == 0 and l147["exit"] == 0 and head["stamp_matches_expected"] and l147["stamp_matches_expected"] and bool(head["pipeline_hashes"]) and head["pipeline_hashes"] == l147["pipeline_hashes"] and head["plan_hash"] is not None and head["plan_hash"] == l147["plan_hash"] and head["resolved_layout_sha256"] is not None and head["resolved_layout_sha256"] == l147["resolved_layout_sha256"] and head["resolved_layout_identity"] == l147["resolved_layout_identity"]) summary = {"status": "PASS" if passed else "FAIL", "head": head, "l147": l147, "owner_pipeline_hashes_identical": head["pipeline_hashes"] == l147["pipeline_hashes"], "plan_hash_identical": head["plan_hash"] == l147["plan_hash"], "resolved_layout_identical": head["resolved_layout_sha256"] == l147["resolved_layout_sha256"]} path = OUT / "summary.json" path.write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8") print(f"[L147OwnerIdentity] status={summary['status']} " f"owner_hashes={summary['owner_pipeline_hashes_identical']} " f"planner_hash={summary['plan_hash_identical']} " f"resolved_layout={summary['resolved_layout_identical']} " f"head_stamp={head['stamp']} l147_stamp={l147['stamp']} " f"summary={path.relative_to(ROOT)}") return 0 if passed else 1 if __name__ == "__main__": raise SystemExit(main())