Files
linuxcncWebWASM/scripts/generate_axis3_tutorial_tool_io_report.py

45 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""Generate the selected-case tool/spindle/coolant/probe 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/axis3-tutorial-tool-io.report.json"
def canonical(value: Any) -> str:
return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
def generate() -> dict[str, Any]:
result = subprocess.run(["node", "web/worker/test_axis3_tutorial_tool_io.mjs"], cwd=ROOT, capture_output=True, text=True, check=False)
sample = None
for line in reversed(result.stdout.splitlines()):
try: value = json.loads(line)
except json.JSONDecodeError: continue
if value.get("schema") == "axis3-tutorial-tool-io.v1": sample = value; break
report: dict[str, Any] = {
"schema": "axis3-tutorial-tool-io-report.v1",
"task_id": "TUTORIAL-11",
"context_id": "linuxcnc-2.10.0-pre0-wasm-m1-py-c1",
"case": "linuxcnc/configs/sim/axis/vismach/3axis-tutorial",
"status": "verified" if result.returncode == 0 and sample else "blocked",
"test": {"command": ["node", "web/worker/test_axis3_tutorial_tool_io.mjs"], "returncode": result.returncode, "stdout_sha256": hashlib.sha256(result.stdout.encode()).hexdigest(), "stderr_sha256": hashlib.sha256(result.stderr.encode()).hexdigest(), "sample": sample},
"coverage": ["tool.tbl T1 prepare/change", "spindle command/ramp/at-speed/stop", "mist/flood coolant and fault", "probe arm/update/trip/disarm", "ESTOP and IO_RECOVER"],
"known_boundaries": ["native manual toolchange dialog is completed through the source-defined change_button HAL acknowledgement; Worker uses the same handshake semantics", "real spindle/physical probe hardware is excluded", "full native same-sequence recorder is TUTORIAL-12"],
}
report["report_sha256"] = hashlib.sha256(canonical(report).encode()).hexdigest()
REPORT.write_text(json.dumps(report, ensure_ascii=False, sort_keys=True, indent=2) + "\n", encoding="utf-8")
print(f"axis3_tutorial_tool_io={report['status']} report_sha256={report['report_sha256']}")
return report
if __name__ == "__main__":
raise SystemExit(0 if generate()["status"] == "verified" else 1)