#!/usr/bin/env python3 import hashlib import json import pathlib import sys import tempfile import os import bpy def report(): return [{"name": c.name, "children": sorted(ch.name for ch in c.children), "objects": sorted(o.name for o in c.objects)} for c in sorted(bpy.data.collections, key=lambda value: value.name) if c.name.startswith("WebGap")] def main(): args = sys.argv[sys.argv.index("--") + 1:] if len(args) != 2: raise SystemExit("usage: blender -b --python check-collection-desktop.py -- FIXTURE REPORT") fixture, output = (pathlib.Path(value).resolve() for value in args) bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=False); before = report(); descriptor, temporary = tempfile.mkstemp(prefix="m16-collection-reopen-", suffix=".blend"); 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 = report() finally: pathlib.Path(temporary).unlink(missing_ok=True) if before != after: raise RuntimeError(f"collection save/reopen drift: {before} != {after}") value = {"schemaVersion": 1, "task": "M16-GAP-00005", "operation": "COLLECTION_DATABLOCK_DESKTOP", "fixture": str(fixture), "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "collections": after, "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"collection-desktop-ok collections={len(after)} saveReopen=exact") if __name__ == "__main__": main()