63 lines
4.5 KiB
Python
63 lines
4.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate deterministic S7-05 source configuration alignment 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_configuration_corexy_s7_05.mjs")
|
|
INPUTS = (
|
|
"coverage/authoritative-kinematics-s7-04.report.json",
|
|
"coverage/full-configuration-startup-matrix.report.json",
|
|
"linuxcnc/configs/sim/axis/corexy/corexy_by_kins.ini",
|
|
"linuxcnc/configs/sim/axis/corexy/corexy_base.inc",
|
|
"linuxcnc/configs/sim/axis/corexy/3joint_xyz.hal",
|
|
"web/workspace/ini-parser.mjs",
|
|
"web/workspace/hal-configuration.mjs",
|
|
"web/workspace/configuration-startup.mjs",
|
|
"web/worker/test_configuration_corexy_s7_05.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: pass
|
|
passed = result.returncode == 0 and sample and sample.get("status") == "verified" and sample.get("hal_preflight", {}).get("blocked_count") == 0 and sample.get("runtime_startup", {}).get("state") == "BLOCKED"
|
|
report: dict[str, Any] = {
|
|
"schema": "configuration-corexy-s7-05-report.v1", "task_id": "S7-05", "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": {"entrypoint": "linuxcnc/configs/sim/axis/corexy/corexy_by_kins.ini", "source_compatible": ["#INCLUDE", "HAL continuation", "INI section variable expansion"], "runtime_state": "BLOCKED_MISSING_RESOURCE"},
|
|
"checks": {"include_graph": {"status": "verified" if passed and len(sample.get("include_graph", [])) == 2 else "blocked"}, "hal_variable_preflight": {"status": "verified" if passed else "blocked", "record_count": sample.get("hal_preflight", {}).get("record_count") if sample else None}, "missing_resource_diagnostic": {"status": "verified" if passed and sample.get("runtime_startup", {}).get("blocked_resources") == ["linuxcnc/configs/sim/axis/corexy/linuxcnc.var", "linuxcnc/configs/sim/axis/corexy/tool.tbl"] else "blocked"}, "ready_promotion_guard": {"status": "verified" if passed and sample.get("runtime_startup", {}).get("state") == "BLOCKED" else "blocked"}},
|
|
"inputs": [artifact(root, path) for path in INPUTS],
|
|
"boundaries": ["#INCLUDE and HAL variable/continuation parsing are verified", "runtime is correctly BLOCKED on missing linuxcnc.var/tool.tbl", "no resource substitution or static READY promotion is fabricated", "official oracle and other configuration gaps remain"],
|
|
}
|
|
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/configuration-corexy-s7-05.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"configuration_corexy_s7_05={report['status']} runtime={report['scope']['runtime_state']}"); return 0 if report["status"] == "verified" else 1
|
|
|
|
|
|
if __name__ == "__main__": raise SystemExit(main())
|