101 lines
5.8 KiB
Python
101 lines
5.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate the blocked-but-locatable S8-02 real case startup 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_sim_case_startup_s8_02.mjs")
|
|
INPUTS = (
|
|
"linuxcnc/configs/sim/axis/minimal_xyz.ini",
|
|
"linuxcnc/configs/sim/axis/corexy/corexy_base.inc",
|
|
"linuxcnc/configs/sim/axis/corexy/corexy_by_kins.ini",
|
|
"coverage/configuration-resource-remediation.report.json",
|
|
"coverage/native-linuxcnc-case-conditions.report.json",
|
|
"web/workspace/sim-case-loader.mjs",
|
|
"web/workspace/hal-configuration.mjs",
|
|
"linuxcnc/configs/sim/axis/sim.var",
|
|
"linuxcnc/configs/sim/axis/tool.tbl",
|
|
"linuxcnc/configs/sim/axis/corexy/linuxcnc.var",
|
|
"linuxcnc/configs/sim/axis/corexy/tool.tbl",
|
|
"linuxcnc/configs/sim/axis/minimal_xyz_cmds.hal",
|
|
"web/worker/sim-session.mjs",
|
|
"web/worker/test_sim_case_startup_s8_02.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()), "status": "present"}
|
|
|
|
|
|
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("fixture_policy") == "user-authorized-runtime-copy" and sample.get("cases", {}).get("minimal_xyz", {}).get("state") == "TASK_READY" and sample.get("cases", {}).get("corexy_by_kins", {}).get("state") == "TASK_READY"
|
|
report: dict[str, Any] = {
|
|
"schema": "sim-case-startup-s8-02-report.v1",
|
|
"task_id": "S8-02",
|
|
"context_id": CONTEXT_ID,
|
|
"status": "verified" if passed else "failed",
|
|
"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},
|
|
"checks": {
|
|
"minimal_xyz_runtime_fixture": {"status": "verified" if passed else "blocked", "generated_hal": "linuxcnc/configs/sim/axis/minimal_xyz_cmds.hal", "parameter_file": "linuxcnc/configs/sim/axis/sim.var"},
|
|
"corexy_runtime_fixtures": {"status": "verified" if passed else "blocked", "paths": ["linuxcnc/configs/sim/axis/corexy/linuxcnc.var", "linuxcnc/configs/sim/axis/corexy/tool.tbl"]},
|
|
"no_unrelated_basename_substitution": {"status": "verified" if passed else "blocked"},
|
|
"worker_startup_ready": {"status": "verified" if passed else "blocked"},
|
|
},
|
|
"fixture_sources": [
|
|
{"target": "linuxcnc/configs/sim/axis/sim.var", "source_kind": "real-linuxcnc-runtime-generated", "source_evidence": "coverage/native-linuxcnc-case-conditions.report.json:cases.minimal_xyz.generated_files"},
|
|
{"target": "linuxcnc/configs/sim/axis/minimal_xyz_cmds.hal", "source_kind": "real-linuxcnc-basic_sim-generated", "source_evidence": "coverage/native-linuxcnc-case-conditions.report.json:cases.minimal_xyz.generated_files"},
|
|
{"target": "linuxcnc/configs/sim/axis/tool.tbl", "source_kind": "existing-axis-sim-case", "source_path": "linuxcnc/configs/sim/axis/sim.tbl"},
|
|
{"target": "linuxcnc/configs/sim/axis/corexy/linuxcnc.var", "source_kind": "real-linuxcnc-runtime-generated", "source_evidence": "coverage/native-linuxcnc-case-conditions.report.json:cases.corexy_with_temporary_fixture.generated_files"},
|
|
{"target": "linuxcnc/configs/sim/axis/corexy/tool.tbl", "source_kind": "existing-axis-sim-case", "source_path": "linuxcnc/configs/sim/axis/sim.tbl"},
|
|
],
|
|
"inputs": [artifact(root, path) for path in INPUTS],
|
|
"boundaries": ["runtime fixtures are user-authorized copies produced/required by real LinuxCNC simulation", "fixture source and target hashes are retained", "no ABI/protocol/schema change", "other cases with missing resources remain blocked"],
|
|
}
|
|
report["report_sha256"] = hashlib.sha256(canonical({key: value for key, value in report.items() if key != "report_sha256"}).encode()).hexdigest()
|
|
destination = output if output.is_absolute() else root / output
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
destination.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/sim-case-startup-s8-02.report.json"))
|
|
args = parser.parse_args()
|
|
report = generate(args.repo_root.resolve(), args.report)
|
|
print(f"sim_case_startup_s8_02={report['status']} implementation={report['implementation_status']} report_sha256={report['report_sha256']}")
|
|
return 0 if report["status"] == "verified" and report["implementation_status"] == "verified" else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|