Implement AXIS parity UI and execution baseline
This commit is contained in:
82
scripts/generate_source_do_s7_01.py
Normal file
82
scripts/generate_source_do_s7_01.py
Normal file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate deterministic S7-01 DO/ENDDO/BREAK 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_do_s7_01.mjs")
|
||||
INPUTS = (
|
||||
"coverage/simulation-alignment-s7.report.json",
|
||||
"coverage/linuxcnc-source-interp-s5.report.json",
|
||||
"linuxcnc/tests/interp/do-while-break/test.ngc",
|
||||
"linuxcnc/tests/interp/do-while-break/expected",
|
||||
"linuxcnc/tests/interp/do-while-break/test.sh",
|
||||
"web/worker/program-runner.mjs",
|
||||
"web/worker/sim-session.mjs",
|
||||
"wasm-core/src/sim_interpreter.c",
|
||||
)
|
||||
|
||||
|
||||
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 is not None and sample.get("status") == "verified" and sample.get("recovery", {}).get("equal") is True
|
||||
report: dict[str, Any] = {
|
||||
"schema": "linuxcnc-source-do-s7-01-report.v1",
|
||||
"task_id": "S7-01",
|
||||
"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/do-while-break/test.ngc", "adapter": "WORKER_WASM_PROGRAM_RUNNER", "control_flow": ["DO", "ENDDO", "BREAK", "named_parameters"]},
|
||||
"checks": {
|
||||
"normal_nested_do": {"status": "verified" if passed and sample.get("normal", {}).get("status") == "completed" else "blocked"},
|
||||
"pause_resume": {"status": "verified" if passed and sample.get("pause_resume", {}).get("hash_equal") else "blocked"},
|
||||
"error_boundaries": {"status": "verified" if passed and sample.get("errors", {}).get("malformed_enddo") == "program_enddo_without_do" and sample.get("errors", {}).get("depth") == "program_control_depth" 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; this 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", "G64/G61 remains a follow-up source adapter", "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-do-s7-01.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_do_s7_01={report['status']} recovery={report['checks']['recovery']['status']}")
|
||||
return 0 if report["status"] == "verified" else 1
|
||||
|
||||
|
||||
if __name__ == "__main__": raise SystemExit(main())
|
||||
Reference in New Issue
Block a user