18 lines
2.3 KiB
Python
18 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate deterministic S1-03 motion/feedback/home/limit evidence."""
|
|
from __future__ import annotations
|
|
import argparse,hashlib,json,subprocess
|
|
from pathlib import Path
|
|
from typing import Any
|
|
OUTPUTS=(Path("web/worker/motion-state.mjs"),Path("web/worker/test_motion_state.mjs"),Path("wasm-core/src/sim_kinematics_motion.c"),Path("wasm-core/src/sim_kinematics_feedback.c"),Path("wasm-core/src/sim_kinematics_home_limit.c"))
|
|
def canonical(v:Any)->str:return json.dumps(v,ensure_ascii=False,sort_keys=True,separators=(",",":"))
|
|
def sha256(p:Path)->str:return hashlib.sha256(p.read_bytes()).hexdigest()
|
|
def run(root:Path,cmd:list[str])->dict[str,Any]:
|
|
r=subprocess.run(cmd,cwd=root,stdout=subprocess.PIPE,stderr=subprocess.PIPE,check=False);return {"status":"verified" if r.returncode==0 else "blocked","returncode":r.returncode,"stdout_sha256":hashlib.sha256(r.stdout).hexdigest(),"stderr_sha256":hashlib.sha256(r.stderr).hexdigest()}
|
|
def generate(root:Path,out:Path)->dict[str,Any]:
|
|
w=run(root,["node","web/worker/test_motion_state.mjs"]); n=run(root,[str(root/"build-native/sim_kinematics_motion_test")]); f=run(root,[str(root/"build-native/sim_kinematics_feedback_test")]); h=run(root,[str(root/"build-native/sim_kinematics_home_limit_test")])
|
|
r={"schema":"motion-s1-report.v1","task_id":"S1-03","context_id":"linuxcnc-2.10.0-pre0-wasm-m1-py-c1","status":"verified" if all(x["status"]=="verified" for x in (w,n,f,h)) else "blocked","features":["jog","override","home","joint limits","following error","estop fault","FK feedback","IK motion adapter"],"tests":{"worker":w,"motion":n,"feedback":f,"home_limit":h},"outputs":[{"path":p.as_posix(),"bytes":(root/p).stat().st_size,"sha256":sha256(root/p)} for p in OUTPUTS]};r["report_sha256"]=hashlib.sha256(canonical(r).encode()).hexdigest();out.parent.mkdir(parents=True,exist_ok=True);out.write_text(json.dumps(r,ensure_ascii=False,sort_keys=True,indent=2)+"\n");return r
|
|
def main()->int:
|
|
p=argparse.ArgumentParser();p.add_argument("--repo-root",type=Path,default=Path(__file__).resolve().parents[1]);p.add_argument("--report",type=Path,default=Path("coverage/motion-s1.report.json"));a=p.parse_args();r=generate(a.repo_root.resolve(),a.repo_root.resolve()/a.report);print(f"motion_s1={r['status']} features={len(r['features'])}");return 0 if r["status"]=="verified" else 1
|
|
if __name__=="__main__":raise SystemExit(main())
|