Files
linuxcncWebWASM/scripts/generate_xyzac_trt_manual_control_report.py

50 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""Generate XYZAC-only RTCP-06 manual control 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-manual-control.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"
def canonical(value: Any) -> str: return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
def main() -> int:
command = ["node", "web/worker/test_xyzac_manual_control.mjs"]
result = subprocess.run(command, cwd=ROOT, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, check=False)
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-manual-control-rtcp-06.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-manual-control-rtcp-06.v1", "task_id": "RTCP-06", "context_id": CONTEXT_ID,
"case": {"path": CASE, "sha256": hashlib.sha256((ROOT / CASE).read_bytes()).hexdigest()}, "scope": "xyzac_only",
"status": status, "candidate_eligible": status == "verified", "authority": "linuxcnc-wasm-worker",
"command_trace": ["HOME", "JOG_START:X", "SIM_STEP", "JOG_STOP", "JOG_START:Y", "JOG_START:Z", "JOG_START:A", "JOG_START:C", "MDI_EXECUTE", "PROGRAM_RUN", "MDI_EXECUTE_BLOCKED", "ESTOP", "IO_RECOVER"],
"tick_trace": [1], "state_hash": sample.get("state_hash") if sample else None,
"axes": sample.get("jog") if sample else [], "home": sample.get("home") if sample else None,
"mdi": sample.get("mdi") if sample else "blocked", "estop_recovery": sample.get("estop_recovery") if sample else "blocked",
"boundary": sample.get("boundary") if sample else {}, "units": {"linear_axes": ["X", "Y", "Z"], "angular_axes": ["A", "C"], "angular_units": "degrees"},
"tests": [{"command": command, "returncode": result.returncode, "status": status, "output_sha256": hashlib.sha256(result.stdout.encode()).hexdigest()}],
"failure_samples": [] if status == "verified" else [{"code": "BLOCKED_MANUAL_CONTROL", "detail": "XYZAC manual control test failed"}],
"release_status": "STOP_RELEASE", "report_sha256": None,
}
report["report_sha256"] = hashlib.sha256(canonical({key: value for key, value in report.items() if key != "report_sha256"}).encode()).hexdigest()
REPORT.parent.mkdir(parents=True, exist_ok=True); 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": report["status"], "report_sha256": report["report_sha256"], "state_hash": report["state_hash"]}, ensure_ascii=False))
return 0 if status == "verified" else 1
if __name__ == "__main__": raise SystemExit(main())