76 lines
4.0 KiB
Python
76 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate selected XYZAC checkpoint, journal and restart recovery evidence."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
REPORT = ROOT / "coverage/xyzac-trt-recovery.report.json"
|
|
CASE = "linuxcnc/configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzac-trt.ini"
|
|
CONTEXT_ID = "linuxcnc-2.10.0-pre0-wasm-m1-py-c1"
|
|
OUTPUTS = ["web/worker/test_xyzac_recovery.mjs", "web/worker/sim-session.mjs", "web/worker/wasm-program-runtime.mjs"]
|
|
|
|
|
|
def canonical(value: Any) -> str:
|
|
return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
|
|
|
|
|
def digest(value: str | bytes) -> str:
|
|
return hashlib.sha256(value.encode() if isinstance(value, str) else value).hexdigest()
|
|
|
|
|
|
def main() -> int:
|
|
command = ["node", "web/worker/test_xyzac_recovery.mjs"]
|
|
result = subprocess.run(command, cwd=ROOT, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, check=False, timeout=60)
|
|
sample = None
|
|
for line in reversed(result.stdout.splitlines()):
|
|
try:
|
|
value = json.loads(line)
|
|
except json.JSONDecodeError:
|
|
continue
|
|
if isinstance(value, dict) and value.get("schema") == "xyzac-recovery-rtcp-11.v1":
|
|
sample = value
|
|
break
|
|
status = "verified" if result.returncode == 0 and sample and sample.get("status") == "verified" else "blocked"
|
|
report: dict[str, Any] = {
|
|
"schema": "xyzac-trt-recovery-report.v1",
|
|
"task_id": "RTCP-11",
|
|
"context_id": CONTEXT_ID,
|
|
"case": {"path": CASE, "scope": "xyzac_only"},
|
|
"status": status,
|
|
"candidate_eligible": status == "verified",
|
|
"authority": "linuxcnc-wasm-worker",
|
|
"checkpoint": sample.get("checkpoint") if sample else {},
|
|
"endpoint": {
|
|
"continuous_hash": sample.get("continuous_endpoint_hash") if sample else None,
|
|
"restored_hash": sample.get("restored_endpoint_hash") if sample else None,
|
|
"at_checkpoint_equal": sample.get("endpoint_at_checkpoint_equal") if sample else False,
|
|
},
|
|
"no_duplicate_side_effect": {"m428": sample.get("no_duplicate_m428") if sample else False, "replayed_operation": sample.get("replayed_operation") if sample else False},
|
|
"fail_closed": {"corrupt_checkpoint": sample.get("corrupt_checkpoint") if sample else None, "schema_mismatch": sample.get("schema_mismatch") if sample else None, "journal_corrupt": sample.get("journal", {}).get("corrupt_status") if sample else None, "journal_schema": sample.get("journal", {}).get("schema_status") if sample else None},
|
|
"journal": sample.get("journal") if sample else {},
|
|
"opfs": sample.get("opfs") if sample else {},
|
|
"required_checkpoint_fields": sample.get("checkpoint", {}).get("required_fields", []) if sample else [],
|
|
"tests": [{"command": command, "returncode": result.returncode, "output_sha256": digest(result.stdout)}],
|
|
"outputs": [{"path": path, "sha256": digest((ROOT / path).read_bytes())} for path in OUTPUTS],
|
|
"first_divergent_tick": sample.get("first_divergent_tick") if sample else None,
|
|
"failure_samples": [] if status == "verified" else [{"code": "BLOCKED_XYZAC_RECOVERY", "detail": "XYZAC RTCP-11 recovery test failed"}],
|
|
"known_blockers": [],
|
|
"exclusions": ["xyzbc", "3axis", "other cases", "Safari", "physical power loss", "host hardware"],
|
|
"release_status": "STOP_RELEASE",
|
|
"report_sha256": None,
|
|
}
|
|
report["report_sha256"] = digest(canonical({key: value for key, value in report.items() if key != "report_sha256"}))
|
|
REPORT.write_text(json.dumps(report, ensure_ascii=False, sort_keys=True, indent=2) + "\n", encoding="utf-8")
|
|
print(json.dumps({"schema": report["schema"], "status": status, "endpoint_equal": report["endpoint"]["at_checkpoint_equal"], "report_sha256": report["report_sha256"]}, ensure_ascii=False))
|
|
return 0 if status == "verified" else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|