#!/usr/bin/env python3 """Generate deterministic S1-02A TP arc/profile evidence.""" from __future__ import annotations import argparse,hashlib,json,subprocess from pathlib import Path from typing import Any OUTPUTS=(Path("wasm-core/src/sim_motion_queue.c"),Path("wasm-core/include/sim_motion_queue.h"),Path("wasm-core/src/sim_posemath.c"),Path("wasm-core/tests/sim_posemath_test.c"),Path("wasm-core/tests/sim_motion_queue_test.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]: native=run(root,[str(root/"build-native/sim_posemath_test")]);motion=run(root,[str(root/"build-native/sim_motion_queue_test")]);wasm=run(root,["node","build-wasm/sim_motion_queue_wasm_test.js"]) r={"schema":"tp-s1a-report.v1","task_id":"S1-02A","context_id":"linuxcnc-2.10.0-pre0-wasm-m1-py-c1","status":"verified" if all(x["status"]=="verified" for x in (native,motion,wasm)) else "blocked","features":["circular segment sampling","FIFO synchronized segments","lookahead blend profile","exact-stop profile","acceleration limit","jerk limit"],"tests":{"posemath":native,"motion_queue":motion,"wasm_motion_queue":wasm},"outputs":[{"path":p.as_posix(),"bytes":(root/p).stat().st_size,"sha256":sha256(root/p)} for p in OUTPUTS],"known_boundaries":["pause/resume canonical expansion is S1-02B","full motion/kinematics adapter is S1-03"]};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/tp-s1a.report.json"));a=p.parse_args();r=generate(a.repo_root.resolve(),a.repo_root.resolve()/a.report);print(f"tp_s1a={r['status']} features={len(r['features'])}");return 0 if r["status"]=="verified" else 1 if __name__=="__main__":raise SystemExit(main())