82 lines
4.7 KiB
Python
82 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate deterministic S7-02 G64/G61 source-adapter evidence."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
|
|
CONTEXT_ID = "linuxcnc-2.10.0-pre0-wasm-m1-py-c1"
|
|
RUNNER = ("node", "web/worker/test_source_g6164_s7_02.mjs")
|
|
INPUTS = (
|
|
"coverage/simulation-alignment-s7.report.json",
|
|
"coverage/linuxcnc-source-interp-s5.report.json",
|
|
"linuxcnc/tests/interp/g6164/test.ngc",
|
|
"linuxcnc/tests/interp/g6164/expected",
|
|
"linuxcnc/tests/interp/g6164/test.sh",
|
|
"web/worker/program-runner.mjs",
|
|
"web/worker/sim-session.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(root: Path, 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())}
|
|
|
|
|
|
def generate(root: Path, output: Path) -> dict[str, Any]:
|
|
root = root.resolve()
|
|
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 sample.get("recovery", {}).get("equal") is True and len(sample.get("controls", [])) == 5
|
|
report: dict[str, Any] = {
|
|
"schema": "linuxcnc-source-g6164-s7-02-report.v1",
|
|
"task_id": "S7-02",
|
|
"context_id": CONTEXT_ID,
|
|
"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},
|
|
"scope": {"source_fixture": "linuxcnc/tests/interp/g6164/test.ngc", "adapter": "WORKER_MOTION_CONTROL_MODAL", "modes": ["continuous", "exact_path", "exact_stop"]},
|
|
"checks": {
|
|
"modal_sequence": {"status": "verified" if passed and [row["mode"] for row in sample.get("controls", [])] == ["continuous", "continuous", "continuous", "exact_path", "exact_stop"] else "blocked"},
|
|
"tolerance_mapping": {"status": "verified" if passed and sample["controls"][2]["path_tolerance"] == 1 and sample["controls"][2]["naive_cam_tolerance"] == 2 else "blocked"},
|
|
"error_boundaries": {"status": "verified" if passed and sample.get("errors", {}).get("negative_tolerance") == "program_motion_control_range" and sample.get("errors", {}).get("unsupported_g61") == "program_motion_control_syntax" else "blocked"},
|
|
"recovery": {"status": "verified" if passed and sample.get("recovery", {}).get("equal") else "blocked", "first_difference": sample.get("recovery", {}).get("difference") if sample else None},
|
|
"source_expected_comparison": {"status": "SOURCE_BLOCKED", "reason": "upstream canonical logger expected output is retained and hashed; modal Worker adapter does not fabricate byte-for-byte canonical parity"},
|
|
},
|
|
"inputs": [artifact(root, path) for path in INPUTS],
|
|
"boundaries": ["LinuxCNC canonical expected output remains SOURCE_BLOCKED", "TP blend/exact-stop numeric parity remains a follow-up", "host/Python/real hardware capabilities remain unchanged"],
|
|
}
|
|
report["report_sha256"] = hashlib.sha256(canonical({key: value for key, value in report.items() if key != "report_sha256"}).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(description=__doc__)
|
|
parser.add_argument("--repo-root", type=Path, default=Path(__file__).resolve().parents[1])
|
|
parser.add_argument("--report", type=Path, default=Path("coverage/source-g6164-s7-02.report.json"))
|
|
args = parser.parse_args()
|
|
root = args.repo_root.resolve()
|
|
output = args.report if args.report.is_absolute() else root / args.report
|
|
report = generate(root, output)
|
|
print(f"source_g6164_s7_02={report['status']} recovery={report['checks']['recovery']['status']}")
|
|
return 0 if report["status"] == "verified" else 1
|
|
|
|
|
|
if __name__ == "__main__": raise SystemExit(main())
|