Files
linuxcncWebWASM/scripts/generate_xyzac_trt_web_wasm_parity_report.py

109 lines
5.6 KiB
Python

#!/usr/bin/env python3
"""Aggregate the selected xyzac-trt.ini Web/WASM parity evidence."""
from __future__ import annotations
import hashlib
import json
from pathlib import Path
from typing import Any
ROOT = Path(__file__).resolve().parents[1]
REPORT = ROOT / "coverage/xyzac-trt-web-wasm-parity.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"
REPORT_PATHS = [
"coverage/xyzac-trt-source-slice-inventory.report.json",
"coverage/xyzac-trt-wasm-authority-audit.report.json",
"coverage/xyzac-trt-startup.report.json",
"coverage/xyzac-trt-gate-matrix.report.json",
"coverage/xyzac-trt-program-preview.report.json",
"coverage/xyzac-trt-workflow.report.json",
"coverage/xyzac-trt-manual-control.report.json",
"coverage/xyzac-trt-hal-tool-alarm.report.json",
"coverage/xyzac-trt-rtcp.report.json",
"coverage/xyzac-trt-trace-parity.report.json",
"coverage/xyzac-trt-protocol-react.report.json",
"coverage/xyzac-trt-threejs.report.json",
"coverage/xyzac-trt-tool-preview.report.json",
"coverage/xyzac-trt-recovery.report.json",
]
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:
reports: dict[str, dict[str, Any]] = {}
missing = []
mismatched_case = []
for path in REPORT_PATHS:
file = ROOT / path
if not file.is_file():
missing.append(path)
continue
value = json.loads(file.read_text(encoding="utf-8"))
reports[path] = value
case = value.get("case")
case_path = case.get("path") if isinstance(case, dict) else case
if case_path and CASE not in str(case_path):
mismatched_case.append(path)
task_status = {path: value.get("status") for path, value in reports.items()}
failed = [path for path, status in task_status.items() if status != "verified"]
status = "verified" if not missing and not mismatched_case and not failed else "blocked"
report: dict[str, Any] = {
"schema": "xyzac-trt-web-wasm-parity-report.v1",
"task_id": "RTCP-12",
"context_id": CONTEXT_ID,
"case": {"path": CASE, "scope": "xyzac_only"},
"status": status,
"candidate_eligible": False,
"authority": "linuxcnc-wasm-worker",
"task_reports": task_status,
"report_hashes": {path: digest((ROOT / path).read_bytes()) for path in reports},
"parity": {
"trace_levels": reports.get("coverage/xyzac-trt-trace-parity.report.json", {}).get("levels", []),
"native_wasm": reports.get("coverage/xyzac-trt-trace-parity.report.json", {}).get("native_wasm", {}).get("status"),
"native_worker": reports.get("coverage/xyzac-trt-trace-parity.report.json", {}).get("native_worker", {}).get("status"),
"first_divergent_tick": reports.get("coverage/xyzac-trt-trace-parity.report.json", {}).get("first_divergent_tick"),
"positive_divergence_tick": reports.get("coverage/xyzac-trt-trace-parity.report.json", {}).get("positive_divergence_sample", {}).get("first_divergent_tick"),
},
"browser_matrix": reports.get("coverage/xyzac-trt-threejs.report.json", {}).get("browser_matrix", {}),
"recovery": reports.get("coverage/xyzac-trt-recovery.report.json", {}).get("endpoint", {}),
"authority_audit": reports.get("coverage/xyzac-trt-wasm-authority-audit.report.json", {}).get("authority", {}),
"source_coverage": reports.get("coverage/xyzac-trt-source-slice-inventory.report.json", {}).get("counts", {}),
"blocker_identity": {
"missing_reports": missing,
"failed_reports": failed,
"case_mismatches": mismatched_case,
"host_excluded": ["Safari", "physical power loss", "host hardware"],
"release_status": "STOP_RELEASE",
},
"checks": {
"all_reports_present": not missing,
"all_selected_case": not mismatched_case,
"all_reports_verified": not failed,
"trace_first_divergent_tick_null": reports.get("coverage/xyzac-trt-trace-parity.report.json", {}).get("first_divergent_tick") is None,
"browser_desktop_mobile": bool(reports.get("coverage/xyzac-trt-threejs.report.json", {}).get("browser_matrix")),
"recovery_endpoint_equal": reports.get("coverage/xyzac-trt-recovery.report.json", {}).get("endpoint", {}).get("at_checkpoint_equal") is True,
},
"failure_samples": [] if status == "verified" else [{"code": "XYZAC_PARITY_REPORT_INCOMPLETE", "missing": missing, "failed": failed, "case_mismatches": mismatched_case}],
"known_blockers": ["HOST_EXCLUDED: Safari not in project scope", "REAL-EXCLUDED: physical power loss not simulated"] if status == "verified" else [],
"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, "reports": len(reports), "missing": missing, "failed": failed, "report_sha256": report["report_sha256"]}, ensure_ascii=False))
return 0 if status == "verified" else 1
if __name__ == "__main__":
raise SystemExit(main())