#!/usr/bin/env python3 """Generate the full simulation longitudinal regression report.""" from __future__ import annotations import hashlib import json import subprocess from pathlib import Path ROOT = Path(__file__).resolve().parents[1] OUTPUT = ROOT / "coverage/full-simulation-s4.report.json" DOMAIN_REPORTS = ( "coverage/configuration-batch-s2.report.json", "coverage/hal-s2.report.json", "coverage/device-io-s2.report.json", "coverage/python-api-s3.report.json", "coverage/python-callbacks-s3.report.json", "coverage/recovery-s3.report.json", "coverage/browser-simulation-s3.report.json", "coverage/configuration-startup-runtime.report.json", "coverage/rs274-interpreter-closure.report.json", "coverage/tp-blend.report.json", "coverage/task-program-state.report.json", "coverage/motion-state.report.json", "coverage/kinematics-base.report.json", "coverage/hal-graph.report.json", "coverage/plc-runtime.report.json", "coverage/device-twin.report.json", "coverage/io-ack.report.json", "coverage/python-runtime-closure.report.json", "coverage/trace-export.report.json", "coverage/reconciliation.report.json", "coverage/offline-migration.report.json", "coverage/worker-protocol.report.json", "coverage/editor-workflow.report.json", "coverage/authoritative-panels.report.json", "coverage/machine-view.report.json", "coverage/recovery-ux.report.json", "coverage/native-oracle-closure.report.json", "coverage/startup-matrix-closure.report.json", "coverage/determinism.report.json", "coverage/browser-matrix-closure.report.json", ) def digest(data: bytes) -> str: return hashlib.sha256(data).hexdigest() def canonical(value: object) -> bytes: return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode("utf-8") def run(command: list[str]) -> dict[str, object]: result = subprocess.run(command, cwd=ROOT, text=True, capture_output=True, check=False) sample = None for line in reversed(result.stdout.splitlines()): if line.lstrip().startswith("{"): try: sample = json.loads(line) break except json.JSONDecodeError: continue return {"command": command, "returncode": result.returncode, "status": "verified" if result.returncode == 0 else "blocked", "stdout_sha256": digest(result.stdout.encode()), "stderr_sha256": digest(result.stderr.encode()), "sample": sample} def generate(output: Path = OUTPUT) -> dict[str, object]: context = json.loads((ROOT / "context-lock.json").read_text(encoding="utf-8")) regression = run(["node", "web/worker/test_full_simulation_s4.mjs"]) domain = [] missing = [] for path in DOMAIN_REPORTS: full = ROOT / path if not full.is_file(): missing.append(path); continue value = json.loads(full.read_text(encoding="utf-8")) domain.append({"path": path, "schema": value.get("schema"), "task_id": value.get("task_id"), "status": value.get("status"), "implementation_status": value.get("implementation_status"), "report_sha256": value.get("report_sha256"), "file_sha256": digest(full.read_bytes())}) sample = regression["sample"] or {} parity = sample.get("parity", {}) report: dict[str, object] = { "schema": "full-simulation-s4-report.v1", "task_id": "S4-01", "context_id": context["context_id"], "status": "verified" if regression["status"] == "verified" and sample.get("status") == "verified" and parity.get("one_x_fast_equal") is True and parity.get("recovery_status") == "recovered" and not missing else "blocked", "domain_reports": domain, "domain_report_count": len(domain), "missing_domain_reports": missing, "regression": regression, "modes": ["1x", "fast", "single_step", "recover"], "parity": parity, "boundaries": ["official LinuxCNC oracle and release ownership remain blocked", "browser engines outside current matrix remain out of scope", "REAL-EXCLUDED host devices are not part of simulation regression"], "release": {"action": "STOP_RELEASE", "candidate_eligible": False}, "report_sha256": None, } report["report_sha256"] = digest(canonical({key: value for key, value in report.items() if key != "report_sha256"})) 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 if __name__ == "__main__": report = generate() print(f"full_simulation_s4={report['status']} domains={report['domain_report_count']}")