Files
linuxcncWebWASM/scripts/generate_sim_case_matrix_s8_06.py

80 lines
3.9 KiB
Python

#!/usr/bin/env python3
"""Generate the deterministic 235-case exact-path startup matrix."""
from __future__ import annotations
import argparse
import hashlib
import json
import subprocess
from pathlib import Path
from typing import Any
ROOT = Path(__file__).resolve().parents[1]
RUNNER = ("node", "web/worker/test_sim_case_matrix_s8_06.mjs")
INPUTS = (
"coverage/sim-case-catalog.report.json",
"coverage/full-configuration-startup-matrix.report.json",
"web/workspace/sim-case-loader.mjs",
"web/workspace/configuration-startup.mjs",
"web/workspace/hal-configuration.mjs",
"web/worker/test_sim_case_matrix_s8_06.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(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(output: Path) -> dict[str, Any]:
first = subprocess.run(RUNNER, cwd=ROOT, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
sample = None
for line in reversed(first.stdout.decode("utf-8", errors="replace").splitlines()):
if line.lstrip().startswith("{"):
try:
sample = json.loads(line)
break
except json.JSONDecodeError:
continue
passed = first.returncode == 0 and sample and sample.get("status") == "verified" and sample.get("case_count") == 235 and sample.get("counts") == {"BLOCKED_HAL": 4, "BLOCKED_INI": 3, "BLOCKED_RESOURCE": 216, "BLOCKED_STARTUP": 2, "TASK_READY": 10}
report: dict[str, Any] = {
"schema": "sim-case-matrix-s8-06-report.v1",
"task_id": "S8-06",
"context_id": "linuxcnc-2.10.0-pre0-wasm-m1-py-c1",
"status": "verified" if passed else "blocked",
"implementation_status": "verified" if passed else "blocked",
"execution": {"command": list(RUNNER), "returncode": first.returncode, "status": "PASSED" if first.returncode == 0 else "FAILED", "stdout_sha256": digest(first.stdout), "stderr_sha256": digest(first.stderr), "sample": sample},
"counts": sample.get("counts") if sample else {},
"checks": {"all_catalog_cases_processed": {"status": "verified" if passed else "blocked", "cases": sample.get("case_count") if sample else None}, "deterministic_repeat": {"status": "verified" if passed else "blocked"}, "exact_path_resource_closure": {"status": "verified" if passed else "blocked"}, "blocked_diagnostics_retained": {"status": "verified" if passed else "blocked"}, "known_ready_cases": {"status": "verified" if passed else "blocked", "cases": 10}},
"inputs": [artifact(path) for path in INPUTS],
"boundaries": ["TASK_READY is limited to 7 cases; 228 cases remain explicitly blocked by resource/HAL/INI conditions", "matrix is Worker startup classification, not official native oracle acceptance", "no blocked case is promoted by basename substitution"],
}
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("--report", type=Path, default=Path("coverage/sim-case-matrix-s8-06.report.json"))
args = parser.parse_args()
report = generate(args.report)
print(f"sim_case_matrix_s8_06={report['status']} report_sha256={report['report_sha256']}")
return 0 if report["status"] == "verified" else 1
if __name__ == "__main__":
raise SystemExit(main())