72 lines
2.9 KiB
Python
72 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import pathlib
|
|
import sys
|
|
import tempfile
|
|
|
|
import bpy
|
|
|
|
|
|
TEXT_NAME = "WBV2-P1-004-WorkerLifecycleContract"
|
|
|
|
|
|
def read_contract():
|
|
text = bpy.data.texts.get(TEXT_NAME)
|
|
if text is None:
|
|
raise RuntimeError("WORKER_LIFECYCLE_CONTRACT_INVALID: contract text is missing")
|
|
source = text.as_string()
|
|
return source, json.loads(source)
|
|
|
|
|
|
def canonical_hash(value):
|
|
payload = dict(value)
|
|
payload.pop("schemaHash", None)
|
|
return hashlib.sha256(json.dumps(payload, sort_keys=True, separators=(",", ":")).encode("utf-8")).hexdigest()
|
|
|
|
|
|
def main():
|
|
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
|
if len(arguments) != 2:
|
|
raise SystemExit("usage: blender -b --python check-wbv2-p1-004-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()
|
|
if before.get("contractId") != "workflow:harden_worker_cancel_restart_and_dispose":
|
|
raise RuntimeError("WORKER_LIFECYCLE_CONTRACT_INVALID: contract id drift")
|
|
if before["cancel"]["resultPublished"] is not False or before["generation"]["staleResult"] != "REJECTED":
|
|
raise RuntimeError("WORKER_LIFECYCLE_CONTRACT_INVALID: cancellation/generation drift")
|
|
if any(before["owners"][owner]["afterDispose"] != 0 for owner in ("cpu", "wasm", "gpu")):
|
|
raise RuntimeError("WORKER_LIFECYCLE_CONTRACT_INVALID: owner budget not released")
|
|
if canonical_hash(before) != before.get("schemaHash"):
|
|
raise RuntimeError("WORKER_LIFECYCLE_CONTRACT_INVALID: schema hash drift")
|
|
|
|
descriptor, temporary = tempfile.mkstemp(prefix="wbv2-p1-004-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()
|
|
finally:
|
|
pathlib.Path(temporary).unlink(missing_ok=True)
|
|
if before != after or source != after_source:
|
|
raise RuntimeError("WORKER_LIFECYCLE_CONTRACT_INVALID: desktop save/reopen drift")
|
|
value = {
|
|
"schemaVersion": 1,
|
|
"task": "WBV2-P1-004",
|
|
"operation": "WORKER_CANCEL_RESTART_DISPOSE_DESKTOP",
|
|
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
|
|
"contract": after,
|
|
"sourceSha256": hashlib.sha256(json.dumps(after, sort_keys=True, separators=(",", ":")).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("wbv2-p1-004-desktop-ok generation=1->2 cancel=unpublished owners=released saveReopen=exact")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|