#!/usr/bin/env python3 """Evaluate run metas into honesty-preserving acceptance verdicts. Never invent PASS.""" from __future__ import annotations import json import os from pathlib import Path def _st(rows: list[dict], *needles: str) -> str: hits = [] for r in rows: name = (r.get("name") or "").lower() if all(n.lower() in name for n in needles): hits.append((r.get("status") or "UNKNOWN").upper()) if not hits: return "NOT RUN" if any(h == "FAIL" for h in hits): return "FAIL" if any(h == "BLOCKED" for h in hits): return "BLOCKED" if all(h == "PASS" for h in hits): return "PASS" if any(h in {"NOT RUN", "NOT_RUN", "UNKNOWN"} for h in hits): return "NOT RUN" return "BLOCKED" def _all_named(rows: list[dict], names: tuple[str, ...]) -> str: sts = [_st(rows, n) for n in names] if any(s == "FAIL" for s in sts): return "FAIL" if any(s == "BLOCKED" for s in sts): return "BLOCKED" if all(s == "PASS" for s in sts): return "PASS" return "NOT RUN" def evaluate(rows: list[dict], *, soak_24h: str = "NOT RUN", hardware: str = "NOT RUN") -> dict[str, str]: go = _st(rows, "go-test") if go == "NOT RUN": go = _st(rows, "gotest") gofmt = _st(rows, "gofmt") race = _st(rows, "race") vet = _st(rows, "vet") static = _st(rows, "staticcheck") vuln = _st(rows, "govulncheck") buf_lint = _st(rows, "buf-lint") if buf_lint == "NOT RUN": buf_lint = _st(rows, "buf_lint") buf_break = _st(rows, "buf-breaking") if buf_break == "NOT RUN": buf_break = _st(rows, "buf_breaking") py = _st(rows, "python") pty = _st(rows, "pty") rtl = _st(rows, "rtl") systemd = _st(rows, "systemd") fuzz = _all_named( rows, ( "fuzz-parser", "fuzz-profile", "fuzz-config", "fuzz-assemble", "fuzz-telemetry", "fuzz-capture", "fuzz-replay", "fuzz-sdk-descriptor", ), ) if fuzz == "NOT RUN": fuzz = _st(rows, "fuzz-15m") soak2h = _st(rows, "soak-2h") if soak2h == "NOT RUN": soak2h = _st(rows, "soak_2h") pkg = _st(rows, "package") if pkg == "NOT RUN": pkg = _st(rows, "self-verify") p0 = all(s == "PASS" for s in (go, gofmt, race, vet, static, vuln, buf_lint, buf_break, py, pty, rtl, systemd, fuzz, soak2h, pkg)) software = "PASS" if p0 else "BLOCKED" ready = "YES" if software == "PASS" else "NO" rc_ready = "YES" if software == "PASS" and soak_24h == "PASS" and hardware == "PASS" else "NO" prod = "NO" return { "architecture_direction": "PASS", "software_simulation_integration_acceptance": software, "software_safety_acceptance": software, "ready_for_controlled_hardware_validation": ready, "release_candidate_readiness": rc_ready, "production_readiness": prod, "hardware_validation": hardware, "real_actuator_validation": "NOT RUN", "gates": { "go_test": go, "gofmt": gofmt, "race": race, "vet": vet, "staticcheck": static, "govulncheck": vuln, "buf_lint": buf_lint, "buf_breaking": buf_break, "python": py, "pty": pty, "rtl": rtl, "systemd": systemd, "fuzz": fuzz, "soak_2h": soak2h, "soak_24h": soak_24h, "package": pkg, }, } def main() -> int: run = Path(os.environ.get("HTH_RUN_DIR") or "") if not run.is_dir(): raise SystemExit("set HTH_RUN_DIR") man = run / "run-manifest.json" rows = [] if man.is_file(): payload = json.loads(man.read_text(encoding="utf-8")) rows = payload.get("commands") or [] verdict = evaluate(rows) (run / "acceptance-verdict.json").write_text(json.dumps(verdict, indent=2) + "\n", encoding="utf-8") print(json.dumps(verdict, indent=2)) return 0 if __name__ == "__main__": raise SystemExit(main())