Files
linuxcncWebWASM/scripts/generate_rs274_s1b_report.py

53 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""Generate deterministic S1-01B rs274 G/M/cycle/coordinate evidence."""
from __future__ import annotations
import argparse
import hashlib
import json
import subprocess
from pathlib import Path
from typing import Any
OUTPUTS = (Path("wasm-core/src/sim_interpreter.c"), Path("wasm-core/tests/sim_interpreter_test.c"), Path("web/worker/test_sim_runner.mjs"))
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 run(root: Path, command: list[str]) -> dict[str, Any]:
result = subprocess.run(command, cwd=root, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
return {"status": "verified" if result.returncode == 0 else "blocked", "returncode": result.returncode, "stdout_sha256": hashlib.sha256(result.stdout).hexdigest(), "stderr_sha256": hashlib.sha256(result.stderr).hexdigest()}
def generate(root: Path, output: Path) -> dict[str, Any]:
native = run(root, [str(root / "build-native/sim_interpreter_test")])
worker = run(root, ["node", "web/worker/test_sim_runner.mjs"])
report = {
"schema": "rs274-s1b-report.v1",
"task_id": "S1-01B",
"context_id": "linuxcnc-2.10.0-pre0-wasm-m1-py-c1",
"status": "verified" if native["status"] == "verified" and worker["status"] == "verified" else "blocked",
"features": ["G10 L2 coordinate offsets", "G54-G59 coordinate selection", "G40-G43 cutter/tool compensation", "G80-G89 canned cycle modal", "M6-M9 coolant/tool modal", "M19 spindle orient", "M48-M73 IO/override modal"],
"tests": {"native": native, "worker": worker},
"outputs": [{"path": path.as_posix(), "bytes": (root / path).stat().st_size, "sha256": sha256(root / path)} for path in OUTPUTS],
"known_boundaries": ["full canned-cycle canonical expansion continues in S1-02", "complete LinuxCNC M-code side effects continue in S2-03"],
}
report["report_sha256"] = hashlib.sha256(canonical(report).encode()).hexdigest()
output.parent.mkdir(parents=True, exist_ok=True)
output.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("--repo-root", type=Path, default=Path(__file__).resolve().parents[1])
parser.add_argument("--report", type=Path, default=Path("coverage/rs274-s1b.report.json"))
args = parser.parse_args()
report = generate(args.repo_root.resolve(), args.repo_root.resolve() / args.report)
print(f"rs274_s1b={report['status']} features={len(report['features'])}")
return 0 if report["status"] == "verified" else 1
if __name__ == "__main__":
raise SystemExit(main())