Files
workinf_Blender_Wasm/tools/web/check-wbv2-p1-003-desktop.py
mes123456 c2c65d3a09
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
Rebuild local Blender WASM environment and recovery evidence
2026-08-27 20:22:15 +08:00

61 lines
2.2 KiB
Python

#!/usr/bin/env python3
import hashlib
import json
import os
import pathlib
import sys
import tempfile
import bpy
TEXT_NAME = "WBV2-P1-003-TransactionContract"
def read_contract():
text = bpy.data.texts.get(TEXT_NAME)
if text is None:
raise RuntimeError("TRANSACTION_CONTRACT_INVALID: contract 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-003-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_contract()
obj = bpy.data.objects.get("WBV2P1003CubeObject")
if obj is None or obj.hide_viewport is not False:
raise RuntimeError("TRANSACTION_CONTRACT_INVALID: initial visibility drift")
descriptor, temporary = tempfile.mkstemp(prefix="wbv2-p1-003-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_contract()
after_obj = bpy.data.objects.get("WBV2P1003CubeObject")
finally:
pathlib.Path(temporary).unlink(missing_ok=True)
if before != after or source != after_source or after_obj is None or after_obj.hide_viewport is not False:
raise RuntimeError("TRANSACTION_CONTRACT_INVALID: desktop save/reopen drift")
value = {
"schemaVersion": 1,
"task": "WBV2-P1-003",
"operation": "MAIN_TRANSACTION_HISTORY_SAVE_DESKTOP",
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
"contract": after,
"objectId": "object:" + after_obj.name,
"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-003-desktop-ok object={value['objectId']} saveReopen=exact")
if __name__ == "__main__":
main()