#!/usr/bin/env python3 """Generate S8-08 Delta machine-family startup/kinematics 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_machine_families_s8_08.mjs") INPUTS = ( "coverage/sim-display-families-s8-07.report.json", "coverage/sim-case-matrix-s8-06.report.json", "coverage/delta-kinematics.report.json", "linuxcnc/configs/sim/axis/ldelta.ini", "linuxcnc/configs/sim/axis/rdelta.ini", "linuxcnc/lib/hallib/sim_ldelta.hal", "linuxcnc/lib/hallib/sim_rdelta.hal", "linuxcnc/configs/sim/axis/sim.var", "linuxcnc/configs/sim/axis/sim.tbl", "web/workspace/sim-case-loader.mjs", "web/worker/authoritative-runtime.mjs", "web/worker/test_machine_families_s8_08.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 len(sample.get("cases", [])) == 2 and all(row.get("startup") == "TASK_READY" and row.get("mode_parity", {}).get("equal") is True and row.get("recovery", {}).get("equal") is True for row in sample["cases"]) report: dict[str, Any] = { "schema": "machine-families-s8-08-report.v1", "task_id": "S8-08", "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": {"delta_startup": {"status": "verified" if passed else "blocked"}, "delta_joints": {"status": "verified" if passed else "blocked", "lineardelta": [300, 300, 300], "rotarydelta": [10, 10, 10]}, "mode_parity": {"status": "verified" if passed else "blocked"}, "recovery_parity": {"status": "verified" if passed else "blocked"}}, "inputs": [artifact(path) for path in INPUTS], "boundaries": ["lineardelta/rotarydelta representative cases only", "official kinematics oracle remains blocked", "TRT/robot/Tripod/Pentapod/Hexapod remain later machine-family slices"], } 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/machine-families-s8-08.report.json")); args = parser.parse_args(); report = generate(args.report); print(f"machine_families_s8_08={report['status']} report_sha256={report['report_sha256']}"); return 0 if report["status"] == "verified" else 1 if __name__ == "__main__": raise SystemExit(main())