Implement configuration, runtime, frontend, and task governance closure
This commit is contained in:
41
scripts/generate_recovery_offline_fault_matrix.py
Normal file
41
scripts/generate_recovery_offline_fault_matrix.py
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate deterministic recovery/offline fault matrix evidence."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
CONTEXT = Path("context-lock.json")
|
||||
REG01 = Path("coverage/full-configuration-startup-matrix.report.json")
|
||||
SESSION = Path("coverage/workspace-session-integration.report.json")
|
||||
RECOVERY = Path("coverage/workspace-recovery.report.json")
|
||||
MIGRATION = Path("coverage/workspace-migration.report.json")
|
||||
GATE = Path("coverage/release-candidate-gate.report.json")
|
||||
OUTPUT = Path("coverage/recovery-offline-fault-matrix.report.json")
|
||||
|
||||
def canonical(value: Any) -> str: return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
||||
def digest(value: Any) -> str: return hashlib.sha256(canonical(value).encode()).hexdigest()
|
||||
def artifact(root: Path, path: Path, role: str) -> dict[str, Any]:
|
||||
full = root / path
|
||||
if not full.is_file(): return {"path": path.as_posix(), "role": role, "status": "missing"}
|
||||
return {"path": path.as_posix(), "role": role, "status": "present", "bytes": full.stat().st_size, "sha256": hashlib.sha256(full.read_bytes()).hexdigest()}
|
||||
def run(root: Path) -> tuple[dict[str, Any], dict[str, Any]]:
|
||||
outputs = []
|
||||
for _ in range(2):
|
||||
result = subprocess.run(["node", "web/worker/test_recovery_offline_faults.mjs"], cwd=root, check=False, capture_output=True, text=True)
|
||||
outputs.append({"status": "passed" if result.returncode == 0 else "blocked", "exit_code": result.returncode, "stdout": result.stdout.strip(), "stdout_sha256": digest(result.stdout), "stderr_sha256": digest(result.stderr)})
|
||||
return outputs[0], outputs[1]
|
||||
def generate(root: Path, output: Path = OUTPUT) -> dict[str, Any]:
|
||||
root = root.resolve(); lock = json.loads((root / CONTEXT).read_text()); reg = json.loads((root / REG01).read_text()); session = json.loads((root / SESSION).read_text()); recovery = json.loads((root / RECOVERY).read_text()); migration = json.loads((root / MIGRATION).read_text()); gate = json.loads((root / GATE).read_text()); first, second = run(root)
|
||||
checks = {"reg01_dependency": {"status": "verified" if reg.get("implementation_status") == "verified" else "blocked"}, "session_dependency": {"status": "verified" if session.get("implementation_status") == "verified" else "blocked"}, "recovery_dependency": {"status": "verified" if recovery.get("implementation_status") == "verified" else "blocked"}, "migration_dependency": {"status": "verified" if migration.get("implementation_status") == "verified" else "blocked"}, "fault_runner": {"status": "verified" if first["status"] == "passed" else "blocked"}, "repeat_determinism": {"status": "verified" if first == second else "blocked"}, "release_stop_preserved": {"status": "verified" if gate.get("release_action") == "STOP_RELEASE" and gate.get("candidate_eligible") is False else "blocked", "release_action": gate.get("release_action")}}
|
||||
ok = all(value["status"] == "verified" for value in checks.values())
|
||||
report: dict[str, Any] = {"schema": "recovery-offline-fault-matrix.v1", "context_id": lock.get("context_id"), "task_id": "REG-03", "status": "partial" if ok else "blocked", "implementation_status": "verified" if ok else "blocked", "candidate_eligible": False, "release_action": "STOP_RELEASE", "inputs": [artifact(root, CONTEXT, "context_lock"), artifact(root, REG01, "full_configuration_matrix"), artifact(root, SESSION, "workspace_session_integration"), artifact(root, RECOVERY, "workspace_recovery"), artifact(root, MIGRATION, "workspace_migration"), artifact(root, GATE, "release_candidate_gate")], "checks": checks, "sample": {"first": first, "second": second}, "scenarios": ["half_commit", "checkpoint_hash_mismatch", "event_gap", "offline_missing_resource", "online_network_required"], "next_transition": "execute REG-04 browser and performance matrix", "report_sha256": None}
|
||||
report["report_sha256"] = digest({key: value for key, value in report.items() if key != "report_sha256"}); 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"); return report
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(); parser.add_argument("--repo-root", type=Path, default=Path(__file__).resolve().parents[1]); parser.add_argument("--output", type=Path, default=OUTPUT); args = parser.parse_args(); report = generate(args.repo_root.resolve(), args.output); print(f"recovery_offline_fault_matrix={report['status']} scenarios={len(report['scenarios'])}"); return 0
|
||||
if __name__ == "__main__": raise SystemExit(main())
|
||||
Reference in New Issue
Block a user