#!/usr/bin/env python3 import hashlib import json import os import pathlib import sys import tempfile import bpy TEXT_NAME = "WBV2-P1-001-RuntimeReceipt" def read_receipt(): text = bpy.data.texts.get(TEXT_NAME) if text is None: raise RuntimeError("RUNTIME_RECEIPT_INVALID: receipt text is missing") source = text.as_string() return source, json.loads(source) def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 2: raise SystemExit("usage: blender -b --python check-wbv2-p1-001-desktop.py -- FIXTURE REPORT") fixture, output = (pathlib.Path(value).resolve() for value in arguments) bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=False) source, before = read_receipt() descriptor, temporary = tempfile.mkstemp(prefix="wbv2-p1-001-reopen-", suffix=".blend", dir=fixture.parent) os.close(descriptor) try: bpy.ops.wm.save_as_mainfile(filepath=temporary, check_existing=False, compress=True) bpy.ops.wm.open_mainfile(filepath=temporary, load_ui=False) after_source, after = read_receipt() finally: pathlib.Path(temporary).unlink(missing_ok=True) if before != after or source != after_source: raise RuntimeError("RUNTIME_RECEIPT_INVALID: desktop save/reopen drift") value = { "schemaVersion": 1, "task": "WBV2-P1-001", "operation": "RUNTIME_VARIANTS_SOURCE_RECEIPT_DESKTOP", "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "receipt": after, "sourceSha256": hashlib.sha256(after_source.encode("utf-8")).hexdigest(), "saveReopen": "EXACT", "blenderVersion": bpy.app.version_string, } output.parent.mkdir(parents=True, exist_ok=True) output.write_text(json.dumps(value, indent=2, sort_keys=True) + "\n", encoding="utf-8") print(f"wbv2-p1-001-desktop-ok receipt={after['receiptId']} variants={len(after['variants'])} saveReopen=exact") if __name__ == "__main__": main()