evaluate_gates.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/usr/bin/env python3
  2. """Evaluate run metas into honesty-preserving acceptance verdicts. Never invent PASS."""
  3. from __future__ import annotations
  4. import json
  5. import os
  6. from pathlib import Path
  7. def _st(rows: list[dict], *needles: str) -> str:
  8. hits = []
  9. for r in rows:
  10. name = (r.get("name") or "").lower()
  11. if all(n.lower() in name for n in needles):
  12. hits.append((r.get("status") or "UNKNOWN").upper())
  13. if not hits:
  14. return "NOT RUN"
  15. if any(h == "FAIL" for h in hits):
  16. return "FAIL"
  17. if any(h == "BLOCKED" for h in hits):
  18. return "BLOCKED"
  19. if all(h == "PASS" for h in hits):
  20. return "PASS"
  21. if any(h in {"NOT RUN", "NOT_RUN", "UNKNOWN"} for h in hits):
  22. return "NOT RUN"
  23. return "BLOCKED"
  24. def _all_named(rows: list[dict], names: tuple[str, ...]) -> str:
  25. sts = [_st(rows, n) for n in names]
  26. if any(s == "FAIL" for s in sts):
  27. return "FAIL"
  28. if any(s == "BLOCKED" for s in sts):
  29. return "BLOCKED"
  30. if all(s == "PASS" for s in sts):
  31. return "PASS"
  32. return "NOT RUN"
  33. def evaluate(rows: list[dict], *, soak_24h: str = "NOT RUN", hardware: str = "NOT RUN", expect_commit: str = "", expect_tree: str = "") -> dict[str, str]:
  34. go = _st(rows, "go-test")
  35. if go == "NOT RUN":
  36. go = _st(rows, "gotest")
  37. gofmt = _st(rows, "gofmt")
  38. race = _st(rows, "race")
  39. vet = _st(rows, "vet")
  40. static = _st(rows, "staticcheck")
  41. vuln = _st(rows, "govulncheck")
  42. buf_lint = _st(rows, "buf-lint")
  43. if buf_lint == "NOT RUN":
  44. buf_lint = _st(rows, "buf_lint")
  45. buf_break = _st(rows, "buf-breaking")
  46. if buf_break == "NOT RUN":
  47. buf_break = _st(rows, "buf_breaking")
  48. py = _st(rows, "python-matrix")
  49. if py == "NOT RUN":
  50. py = _st(rows, "python")
  51. pty = _st(rows, "pty")
  52. rtl_sim = _st(rows, "rtl-sim")
  53. if rtl_sim == "NOT RUN":
  54. rtl_sim = _st(rows, "rtl-accelerated")
  55. rtl_prod = _st(rows, "rtl-production")
  56. rtl = rtl_sim
  57. systemd = _st(rows, "systemd")
  58. fuzz = _all_named(
  59. rows,
  60. (
  61. "fuzz-parser",
  62. "fuzz-profile",
  63. "fuzz-config",
  64. "fuzz-assemble",
  65. "fuzz-telemetry",
  66. "fuzz-capture",
  67. "fuzz-replay",
  68. "fuzz-sdk-descriptor",
  69. ),
  70. )
  71. if fuzz == "NOT RUN":
  72. fuzz = _st(rows, "fuzz-15m")
  73. soak2h = _st(rows, "soak-2h")
  74. if soak2h == "NOT RUN":
  75. soak2h = _st(rows, "soak_2h")
  76. pkg = _st(rows, "package")
  77. if pkg == "NOT RUN":
  78. pkg = _st(rows, "self-verify")
  79. bind = "PASS"
  80. for r in rows:
  81. st = (r.get("status") or "").upper()
  82. if st != "PASS":
  83. continue
  84. c = r.get("commit") or r.get("git_commit") or ""
  85. tr = r.get("tree") or r.get("git_tree") or ""
  86. dirty = (r.get("dirty") or r.get("git_dirty_state") or "").lower()
  87. if expect_commit and c and c != expect_commit:
  88. bind = "BLOCKED"
  89. if expect_tree and tr and tr != expect_tree:
  90. bind = "BLOCKED"
  91. if dirty and dirty not in {"clean", ""}:
  92. bind = "BLOCKED"
  93. facade = _st(rows, "facade")
  94. if facade == "NOT RUN":
  95. facade = _st(rows, "algorithm-facade")
  96. kit = _st(rows, "algorithm-kit")
  97. if kit == "NOT RUN":
  98. kit = _st(rows, "algorithm-gates")
  99. if kit == "NOT RUN":
  100. kit = _st(rows, "kit-quickstart")
  101. if kit == "NOT RUN":
  102. kit = _st(rows, "python-kit-install")
  103. install = _st(rows, "algorithm-install")
  104. if install == "NOT RUN":
  105. install = _st(rows, "python-kit-install")
  106. portable = _st(rows, "portable")
  107. if portable == "NOT RUN":
  108. portable = _st(rows, "algorithm-portable")
  109. scen = _st(rows, "scenario")
  110. if scen == "NOT RUN":
  111. scen = facade
  112. replay = _st(rows, "replay")
  113. if replay == "NOT RUN":
  114. replay = facade
  115. daemon = _st(rows, "daemon-mock")
  116. if daemon == "NOT RUN":
  117. daemon = _st(rows, "python-matrix")
  118. algo_ready = all(
  119. s == "PASS" for s in (facade, kit, install, portable, scen, replay)
  120. ) and daemon in {"PASS", "NOT RUN"}
  121. 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"
  122. software = "PASS" if p0 else "BLOCKED"
  123. ready = "YES" if software == "PASS" else "NO"
  124. rc_ready = "NOT ASSESSED"
  125. prod = "NOT ASSESSED"
  126. return {
  127. "architecture_direction": "PASS",
  128. "algorithm_facade_acceptance": facade,
  129. "algorithm_kit_acceptance": kit,
  130. "algorithm_installation_acceptance": install,
  131. "algorithm_portable_kit_acceptance": portable,
  132. "mock_scenario_acceptance": scen,
  133. "replay_acceptance": replay,
  134. "daemon_mock_uds_acceptance": daemon,
  135. "pty_protocol_acceptance": pty,
  136. "rtl_cosim_acceptance": rtl_sim,
  137. "rtl_production_uart_acceptance": rtl_prod,
  138. "engineering_package_acceptance": pkg,
  139. "ready_for_algorithm_development": "YES" if algo_ready else "NO",
  140. "software_simulation_integration_acceptance": software,
  141. "software_safety_acceptance": software,
  142. "ready_for_controlled_hardware_validation": ready,
  143. "release_candidate_readiness": rc_ready,
  144. "production_readiness": prod,
  145. "hardware_validation": hardware,
  146. "hardware_validation_scope": "OUT OF CURRENT ROUND",
  147. "real_actuator_validation": "NOT RUN",
  148. "gates": {
  149. "go_test": go,
  150. "gofmt": gofmt,
  151. "race": race,
  152. "vet": vet,
  153. "staticcheck": static,
  154. "govulncheck": vuln,
  155. "buf_lint": buf_lint,
  156. "buf_breaking": buf_break,
  157. "python": py,
  158. "facade": facade,
  159. "algorithm_kit": kit,
  160. "algorithm_install": install,
  161. "algorithm_portable": portable,
  162. "pty": pty,
  163. "rtl": rtl_sim,
  164. "rtl_production": rtl_prod,
  165. "systemd": systemd,
  166. "fuzz": fuzz,
  167. "soak_2h": soak2h,
  168. "soak_24h": soak_24h,
  169. "package": pkg,
  170. "commit_tree_bind": bind,
  171. },
  172. }
  173. def main() -> int:
  174. run = Path(os.environ.get("HTH_RUN_DIR") or "")
  175. if not run.is_dir():
  176. raise SystemExit("set HTH_RUN_DIR")
  177. man = run / "run-manifest.json"
  178. rows = []
  179. payload: dict = {}
  180. if man.is_file():
  181. payload = json.loads(man.read_text(encoding="utf-8"))
  182. rows = payload.get("commands") or []
  183. commit = payload.get("git_commit") if isinstance(payload, dict) else ""
  184. tree = payload.get("git_tree") if isinstance(payload, dict) else ""
  185. if not commit:
  186. commit = os.environ.get("HTH_GIT_COMMIT", "")
  187. if not tree:
  188. tree = os.environ.get("HTH_GIT_TREE", "")
  189. verdict = evaluate(rows, expect_commit=commit, expect_tree=tree)
  190. (run / "acceptance-verdict.json").write_text(json.dumps(verdict, indent=2) + "\n", encoding="utf-8")
  191. print(json.dumps(verdict, indent=2))
  192. return 0
  193. if __name__ == "__main__":
  194. raise SystemExit(main())