#!/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", expect_commit: str = "", expect_tree: str = "") -> 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-matrix") if py == "NOT RUN": py = _st(rows, "python") pty = _st(rows, "pty") rtl_sim = _st(rows, "rtl-sim") if rtl_sim == "NOT RUN": rtl_sim = _st(rows, "rtl-accelerated") rtl_prod = _st(rows, "rtl-production") rtl = rtl_sim 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") bind = "PASS" for r in rows: st = (r.get("status") or "").upper() if st != "PASS": continue c = r.get("commit") or r.get("git_commit") or "" tr = r.get("tree") or r.get("git_tree") or "" dirty = (r.get("dirty") or r.get("git_dirty_state") or "").lower() if expect_commit and c and c != expect_commit: bind = "BLOCKED" if expect_tree and tr and tr != expect_tree: bind = "BLOCKED" if dirty and dirty not in {"clean", ""}: bind = "BLOCKED" facade = _st(rows, "facade") if facade == "NOT RUN": facade = _st(rows, "algorithm-facade") kit = _st(rows, "algorithm-kit") if kit == "NOT RUN": kit = _st(rows, "algorithm-gates") if kit == "NOT RUN": kit = _st(rows, "kit-quickstart") if kit == "NOT RUN": kit = _st(rows, "python-kit-install") install = _st(rows, "algorithm-install") if install == "NOT RUN": install = _st(rows, "python-kit-install") portable = _st(rows, "portable") if portable == "NOT RUN": portable = _st(rows, "algorithm-portable") scen = _st(rows, "scenario") if scen == "NOT RUN": scen = facade replay = _st(rows, "replay") if replay == "NOT RUN": replay = facade daemon = _st(rows, "daemon-mock") if daemon == "NOT RUN": daemon = _st(rows, "python-matrix") algo_ready = all( s == "PASS" for s in (facade, kit, install, portable, scen, replay) ) and daemon in {"PASS", "NOT RUN"} p0 = all(s == "PASS" for s in (go, gofmt, race, vet, static, vuln, buf_lint, buf_break, py, pty, rtl, systemd, fuzz, soak2h, pkg)) and bind == "PASS" software = "PASS" if p0 else "BLOCKED" ready = "YES" if software == "PASS" else "NO" rc_ready = "NOT ASSESSED" prod = "NOT ASSESSED" return { "architecture_direction": "PASS", "algorithm_facade_acceptance": facade, "algorithm_kit_acceptance": kit, "algorithm_installation_acceptance": install, "algorithm_portable_kit_acceptance": portable, "mock_scenario_acceptance": scen, "replay_acceptance": replay, "daemon_mock_uds_acceptance": daemon, "pty_protocol_acceptance": pty, "rtl_cosim_acceptance": rtl_sim, "rtl_production_uart_acceptance": rtl_prod, "engineering_package_acceptance": pkg, "ready_for_algorithm_development": "YES" if algo_ready else "NO", "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, "hardware_validation_scope": "OUT OF CURRENT ROUND", "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, "facade": facade, "algorithm_kit": kit, "algorithm_install": install, "algorithm_portable": portable, "pty": pty, "rtl": rtl_sim, "rtl_production": rtl_prod, "systemd": systemd, "fuzz": fuzz, "soak_2h": soak2h, "soak_24h": soak_24h, "package": pkg, "commit_tree_bind": bind, }, } 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 = [] payload: dict = {} if man.is_file(): payload = json.loads(man.read_text(encoding="utf-8")) rows = payload.get("commands") or [] commit = payload.get("git_commit") if isinstance(payload, dict) else "" tree = payload.get("git_tree") if isinstance(payload, dict) else "" if not commit: commit = os.environ.get("HTH_GIT_COMMIT", "") if not tree: tree = os.environ.get("HTH_GIT_TREE", "") verdict = evaluate(rows, expect_commit=commit, expect_tree=tree) (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())