44 lines
3.4 KiB
Python
44 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate XYZAC-only RTCP-07 HAL/tool/alarm evidence."""
|
|
|
|
from __future__ import annotations
|
|
import hashlib, json, subprocess
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
REPORT = ROOT / "coverage/xyzac-trt-hal-tool-alarm.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_hal_tool_alarm.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-hal-tool-alarm-rtcp-07.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-hal-tool-alarm-rtcp-07.v1", "task_id": "RTCP-07", "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": ["MDI_EXECUTE:M429", "MDI_EXECUTE:M428", "MDI_EXECUTE:M430", "VCP_UPDATE:VISMACH_CLEAR", "HAL_SET_ALLOWED", "HAL_SET_DENIED", "SPINDLE_COMMAND", "COOLANT_COMMAND", "TOOL_PREPARE", "TOOL_CHANGE", "MDI:G43", "MDI:G49", "DEVICE_ACK", "DEVICE_ACK_TIMEOUT", "DEVICE_ACK_ABORT"],
|
|
"tick_trace": [0, 10, 30, 31], "state_hash": sample.get("state_hash") if sample else None,
|
|
"pyvcp": sample.get("pyvcp") if sample else [], "hal": sample.get("hal") if sample else {}, "tool": sample.get("tool") if sample else None,
|
|
"spindle_rpm": sample.get("spindle_rpm") if sample else None, "coolant": sample.get("coolant") if sample else {},
|
|
"ack": sample.get("ack") if sample else {}, "alarm": sample.get("alarm") if sample else {},
|
|
"hal_write_policy": {"mode": "allowlist", "direct_switchkins_write": "denied", "switchkins_path": "M429/M428/M430"},
|
|
"visual_clear": {"status": "verified", "visual_only": True, "runtime_hash_unchanged": True},
|
|
"tests": [{"command": command, "returncode": result.returncode, "status": status, "output_sha256": hashlib.sha256(result.stdout.encode()).hexdigest()}],
|
|
"failure_samples": [] if status == "verified" else [{"code": "BLOCKED_HAL_TOOL_ALARM", "detail": "XYZAC RTCP-07 test failed"}],
|
|
"release_status": "STOP_RELEASE", "report_sha256": None,
|
|
}
|
|
report["report_sha256"] = hashlib.sha256(canonical({k: v for k, v in report.items() if k != "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": 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())
|