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-005-StorageJournalContract"
|
|
|
|
|
|
def read_contract():
|
|
text = bpy.data.texts.get(TEXT_NAME)
|
|
if text is None:
|
|
raise RuntimeError("STORAGE_JOURNAL_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-005-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_opfs_indexeddb_journal_recovery":
|
|
raise RuntimeError("STORAGE_JOURNAL_CONTRACT_INVALID: contract id drift")
|
|
if before["journal"]["oldProjectUsable"] is not True or before["hash"]["mismatch"] != "QUARANTINED":
|
|
raise RuntimeError("STORAGE_JOURNAL_CONTRACT_INVALID: recovery policy drift")
|
|
if any(before["storage"][store]["afterRecovery"] != 0 for store in ("opfs", "indexeddb")):
|
|
raise RuntimeError("STORAGE_JOURNAL_CONTRACT_INVALID: storage budget not released")
|
|
if canonical_hash(before) != before.get("schemaHash"):
|
|
raise RuntimeError("STORAGE_JOURNAL_CONTRACT_INVALID: schema hash drift")
|
|
|
|
descriptor, temporary = tempfile.mkstemp(prefix="wbv2-p1-005-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("STORAGE_JOURNAL_CONTRACT_INVALID: desktop save/reopen drift")
|
|
value = {
|
|
"schemaVersion": 1,
|
|
"task": "WBV2-P1-005",
|
|
"operation": "STORAGE_JOURNAL_RECOVERY_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-005-desktop-ok interrupted=old-project-usable hash-mismatch=quarantined restart=recovered saveReopen=exact")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|