Files
aetherbound-guild/tools/verify_p9_0r2_animation_assets.py
T

73 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""Verify P9.0R2 animation provenance, frame integrity and state diversity."""
from __future__ import annotations
import hashlib
import json
from collections import defaultdict
from pathlib import Path
from PIL import Image, ImageChops
ROOT = Path(__file__).resolve().parents[1]
MANIFEST = ROOT / "runtime/assets/animations/asset-manifest.json"
def sha256(path: Path) -> str:
return hashlib.sha256(path.read_bytes()).hexdigest()
def main() -> int:
payload = json.loads(MANIFEST.read_text(encoding="utf-8"))
records = payload["records"]
if len(records) != 92:
raise SystemExit(f"expected 92 records, found {len(records)}")
states: dict[str, list[Path]] = defaultdict(list)
for record in records:
source = ROOT / record["source"]
runtime = ROOT / record["runtime"]
if not source.is_file() or not runtime.is_file():
raise SystemExit(f"missing source/runtime pair: {record}")
if sha256(source) != record["sha256"] or sha256(runtime) != record["sha256"]:
raise SystemExit(f"hash mismatch: {record['runtime']}")
with Image.open(runtime) as image:
if image.mode != "RGBA" or image.getbbox() is None:
raise SystemExit(f"invalid transparent animation frame: {record['runtime']}")
if image.width != record["width"] or image.height != record["height"]:
raise SystemExit(f"dimension mismatch: {record['runtime']}")
relative = Path(record["runtime"])
states[(relative.parts[-3] + "/" + relative.parts[-2])].append(runtime)
for state, frames in states.items():
if len(frames) < 2:
raise SystemExit(f"state has fewer than two frames: {state}")
with Image.open(frames[0]) as first:
first_rgba = first.convert("RGBA")
distinct = False
for path in frames[1:]:
with Image.open(path) as image:
candidate = image.convert("RGBA")
if candidate.size != first_rgba.size or ImageChops.difference(first_rgba, candidate).getbbox() is not None:
distinct = True
break
if not distinct:
raise SystemExit(f"state frames are visually identical: {state}")
if payload["generated_calls"] != 4 or abs(payload["generated_cost_usd"] - 0.056) > 0.000001:
raise SystemExit("generation cost/call provenance mismatch")
if payload["rejected"] != [
{
"run": "wayrunner",
"reason": "detached duplicate blade fragment and missing held dagger at counter impact",
}
]:
raise SystemExit("rejected generation history mismatch")
print(f"ABG_P9_0R2_ANIMATION_ASSETS_OK files={len(records)} states={len(states)} calls=4 cost_usd=0.056")
return 0
if __name__ == "__main__":
raise SystemExit(main())