#!/usr/bin/env python3 """Generate S8-04 minimal XYZ fixed-tick/UI vertical evidence.""" from __future__ import annotations import argparse import hashlib import json import subprocess from pathlib import Path from typing import Any ROOT = Path(__file__).resolve().parents[1] RUNNER = ("node", "web/worker/test_minimal_xyz_vertical_s8_04.mjs") INPUTS = ( "coverage/sim-case-startup-s8-02.report.json", "linuxcnc/configs/sim/axis/minimal_xyz.ini", "linuxcnc/configs/sim/axis/minimal_xyz_cmds.hal", "linuxcnc/configs/sim/axis/sim.var", "linuxcnc/configs/sim/axis/tool.tbl", "web/workspace/sim-case-loader.mjs", "web/worker/sim-session.mjs", "web/worker/test_minimal_xyz_vertical_s8_04.mjs", "web/app/app.mjs", "web/app/state-panel.mjs", "web/app/machine-view.mjs", ) def canonical(value: Any) -> str: return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")) def digest(value: bytes) -> str: return hashlib.sha256(value).hexdigest() def artifact(path: str) -> dict[str, Any]: value = ROOT / path return {"path": path, "status": "missing"} if not value.is_file() else {"path": path, "bytes": value.stat().st_size, "sha256": digest(value.read_bytes()), "status": "present"} def generate(output: Path) -> dict[str, Any]: result = subprocess.run(RUNNER, cwd=ROOT, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False) sample = None for line in reversed(result.stdout.decode("utf-8", errors="replace").splitlines()): if line.lstrip().startswith("{"): try: sample = json.loads(line) break except json.JSONDecodeError: continue passed = result.returncode == 0 and sample and sample.get("status") == "verified" and sample.get("startup_state") == "TASK_READY" and sample.get("recovery", {}).get("parity", {}).get("equal") is True and sample.get("estop", {}).get("recovered") == "READY" report: dict[str, Any] = { "schema": "minimal-xyz-vertical-s8-04-report.v1", "task_id": "S8-04", "context_id": "linuxcnc-2.10.0-pre0-wasm-m1-py-c1", "status": "verified" if passed else "blocked", "implementation_status": "verified" if passed else "blocked", "execution": {"command": list(RUNNER), "returncode": result.returncode, "status": "PASSED" if result.returncode == 0 else "FAILED", "stdout_sha256": digest(result.stdout), "stderr_sha256": digest(result.stderr), "sample": sample}, "checks": { "startup_task_ready": {"status": "verified" if passed else "blocked"}, "home_jog_override": {"status": "verified" if passed else "blocked"}, "program_pause_resume_abort_mdi": {"status": "verified" if passed else "blocked"}, "checkpoint_recovery_parity": {"status": "verified" if passed else "blocked", "endpoint_equal": sample.get("recovery", {}).get("parity", {}).get("equal") if sample else None}, "estop_recover": {"status": "verified" if passed else "blocked", "blocked_code": sample.get("estop", {}).get("blocked_code") if sample else None}, "frontend_authority_inputs": {"status": "verified" if passed else "blocked", "sources": ["web/app/app.mjs", "web/app/state-panel.mjs", "web/app/machine-view.mjs"]}, }, "inputs": [artifact(path) for path in INPUTS], "boundaries": ["minimal XYZ/trivkins only", "browser controls consume Worker authoritative state", "real hardware timing remains excluded", "other case families remain in queued/blocked tasks"], } report["report_sha256"] = hashlib.sha256(canonical({key: value for key, value in report.items() if key != "report_sha256"}).encode()).hexdigest() destination = output if output.is_absolute() else ROOT / output destination.parent.mkdir(parents=True, exist_ok=True) destination.write_text(json.dumps(report, ensure_ascii=False, sort_keys=True, indent=2) + "\n", encoding="utf-8") return report def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("--report", type=Path, default=Path("coverage/minimal-xyz-vertical-s8-04.report.json")) args = parser.parse_args() report = generate(args.report) print(f"minimal_xyz_vertical_s8_04={report['status']} report_sha256={report['report_sha256']}") return 0 if report["status"] == "verified" else 1 if __name__ == "__main__": raise SystemExit(main())