Files
linuxcncWebWASM/scripts/generate_advanced_kinematics_report.py

69 lines
3.5 KiB
Python

#!/usr/bin/env python3
"""Aggregate deterministic P3-07 advanced kinematics evidence."""
from __future__ import annotations
import argparse
import hashlib
import json
import subprocess
from pathlib import Path
from typing import Any
TESTS = (
"test_fiveaxis_report.py", "test_trt_report.py", "test_robot_kinematics_report.py", "test_genser_report.py",
"test_delta_kinematics_report.py", "test_tripod_kinematics_report.py", "test_genhex_kinematics_report.py",
"test_pentapod_kinematics_report.py", "test_switchkins_report.py", "test_userkins_report.py",
)
OUTPUTS = tuple(Path(name) for name in (
"wasm-core/src/sim_kinematics.c", "wasm-core/src/sim_switchkins.c", "wasm-core/src/sim_userkins.c",
"wasm-core/tests/sim_kinematics_test.c", "wasm-core/tests/sim_switchkins_test.c", "wasm-core/tests/sim_userkins_test.c",
))
def canonical(value: Any) -> str:
return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
def sha256(path: Path) -> str:
return hashlib.sha256(path.read_bytes()).hexdigest()
def generate(root: Path, report_path: Path) -> dict[str, Any]:
tests = []
for name in TESTS:
result = subprocess.run(["python3", f"scripts/{name}"], cwd=root, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
tests.append({"test": name, "status": "verified" if result.returncode == 0 else "blocked", "returncode": result.returncode, "stderr": result.stderr.decode("utf-8", errors="replace")[-1000:]})
report: dict[str, Any] = {
"schema": "advanced-kinematics-report.v1",
"task_id": "P3-07",
"context_id": "linuxcnc-2.10.0-pre0-wasm-m1-py-c1",
"status": "verified" if all(item["status"] == "verified" for item in tests) else "blocked",
"families": ["5axiskins", "xyzac-trt", "xyzbc-trt", "scara", "puma", "scorbot", "genser", "lineardelta", "rotarydelta", "tripod", "genhex", "pentapod", "switchkins", "userk"],
"boundaries": ["branch", "singularity", "nonfinite", "iteration_limit", "max_error", "limit", "dynamic_path_rejected", "missing_module", "switch_abort"],
"determinism": {"native_wasm_state_hash": True, "fixed_float": True, "wall_clock": False, "random": False},
"tests": tests,
"outputs": [{"path": path.as_posix(), "bytes": (root / path).stat().st_size, "sha256": sha256(root / path)} for path in OUTPUTS],
"oracle": {"status": "blocked", "reason": "linuxcnc/unit_tests/kinematics/** is absent from locked source; no advanced golden is fabricated"},
"known_boundaries": ["official kinematics oracle remains release blocker", "P4 HAL/IO and P8 matrix consume these adapters"],
}
report["report_sha256"] = hashlib.sha256(canonical(report).encode("utf-8")).hexdigest()
report_path.parent.mkdir(parents=True, exist_ok=True)
report_path.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(description=__doc__)
parser.add_argument("--repo-root", type=Path, default=Path(__file__).resolve().parents[1])
parser.add_argument("--report", type=Path, default=Path("coverage/advanced-kinematics.report.json"))
args = parser.parse_args()
report = generate(args.repo_root.resolve(), args.repo_root.resolve() / args.report)
print(f"advanced_kinematics={report['status']} tests={len(report['tests'])} oracle={report['oracle']['status']}")
return 0 if report["status"] == "verified" else 1
if __name__ == "__main__":
raise SystemExit(main())