#!/usr/bin/env python3 """Check deterministic matrices and protected SurfaceWorld identities against L14.""" import re from pathlib import Path ROOT = Path(__file__).resolve().parents[4] MATRIX = ROOT / "Saved/Linux/l19-matrix" CROSSING = ROOT / "Saved/Linux/l19-crossing" ROW = re.compile(r"^\[Pipeline(?:FullDetailHash|WholeViewHash|LODHash|ExactQueryHash)\].*$", re.M) LOD = re.compile(r"^\[PipelineLODHash\] lod=(\d+) .*$", re.M) failed = [] def stable_rows(path): rows = ROW.findall(path.read_text(encoding="utf-8", errors="replace")) full = next((row for row in rows if row.startswith("[PipelineFullDetailHash]")), None) exact = next((row for row in rows if row.startswith("[PipelineExactQueryHash]")), None) lods = {int(match.group(1)): match.group(0) for match in LOD.finditer( path.read_text(encoding="utf-8", errors="replace"))} return rows, full, exact, {level: lods.get(level) for level in range(3)} for compiler in ("clang-off", "gcc-default"): baseline_name = "clang-off" if compiler == "clang-off" else "gcc-default" baseline = ROOT / f"Saved/Linux/l14-final-hash-sw-{baseline_name}-w12-r5.log" expected = stable_rows(baseline) logs = sorted(MATRIX.glob(f"surface-world-{compiler}-w*-r*.log")) if len(logs) != 7: failed.append(f"matrix {compiler}: expected 7 rows, found {len(logs)}") for path in logs: actual = stable_rows(path) if len(actual[0]) != 12 or actual[1:] != expected[1:]: failed.append(f"protected SurfaceWorld mismatch: {path.name}") crossing_baseline_name = "clang" if compiler == "clang-off" else "gcc" crossing_baseline = ROOT / f"Saved/Linux/l14-final-crossing-24m-{crossing_baseline_name}-w12.log" expected_crossing = stable_rows(crossing_baseline) crossing_logs = sorted(CROSSING.glob(f"{compiler}-w*-r*.log")) if len(crossing_logs) != 7: failed.append(f"crossing {compiler}: expected 7 rows, found {len(crossing_logs)}") for path in crossing_logs: actual = stable_rows(path) if len(actual[0]) != 12 or actual[1:] != expected_crossing[1:]: failed.append(f"protected crossing identity mismatch: {path.name}") print(f"[L19ProtectedHashGate] SurfaceWorld LOD0-2, full-detail, and exact query hashes " f"result={'FAIL' if failed else 'PASS'}") for failure in failed: print(f"[L19HashMismatch] {failure}") raise SystemExit(1 if failed else 0)