Codexcoder commited on
Commit
48dc38f
Β·
verified Β·
1 Parent(s): 2f361bf

integration: add scripts/production_check.py

Browse files
Files changed (1) hide show
  1. scripts/production_check.py +122 -0
scripts/production_check.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Production readiness check β€” the "production" gate of the agent
4
+ build/deploy workflow. Verifies: package imports, API route surfaces,
5
+ registry cross-references, test suite health, docker/deploy assets.
6
+
7
+ Usage:
8
+ python3 scripts/production_check.py
9
+
10
+ Exits 0 (PASS) or 1 (FAIL) with a structured report.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import subprocess
16
+ import sys
17
+ from pathlib import Path
18
+
19
+ ROOT = Path(__file__).resolve().parent.parent
20
+ sys.path.insert(0, str(ROOT))
21
+ sys.path.insert(0, str(ROOT / "src")) # src-layout for the sovereign package
22
+
23
+ CHECKS: list[tuple[str, callable]] = []
24
+
25
+
26
+ def check(name: str, fn) -> None:
27
+ CHECKS.append((name, fn))
28
+
29
+
30
+ def run(cmd: list[str], timeout: int = 300) -> subprocess.CompletedProcess:
31
+ return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout,
32
+ cwd=ROOT)
33
+
34
+
35
+ # ── Imports ───────────────────────────────────────────────────────────────
36
+ def _imports() -> bool:
37
+ import importlib
38
+ import os
39
+
40
+ # The orchestrator requires a JWT secret at import; production supplies
41
+ # it via env β€” the check only verifies importability.
42
+ os.environ.setdefault("JWT_SECRET", "production-check-dummy")
43
+
44
+ for mod in ["sovereign.main", "kyrexis.core", "kyrexis.api.routes",
45
+ "pec5d.core", "pec5d.api.routes", "coldcase.api.routes",
46
+ "chat.core", "chat.api.routes"]:
47
+ importlib.import_module(mod)
48
+ return True
49
+
50
+
51
+ check("imports (all modules)", _imports)
52
+
53
+
54
+ # ── Route surfaces ────────────────────────────────────────────────────────
55
+ def _routes() -> bool:
56
+ from kyrexis.api.routes import router as k
57
+ from pec5d.api.routes import router as p
58
+ from coldcase.api.routes import router as c
59
+ from chat.api.routes import router as t
60
+
61
+ counts = {"kyrexis": len(k.routes), "pec5d": len(p.routes),
62
+ "coldcase": len(c.routes), "chat": len(t.routes)}
63
+ return counts["kyrexis"] == 19 and counts["pec5d"] == 22 and counts["chat"] == 5
64
+
65
+
66
+ check("API routes (kyrexis 19 Β· pec5d 22 Β· chat 5)", _routes)
67
+
68
+
69
+ # ── Registry validator ────────────────────────────────────────────────────
70
+ def _registries() -> bool:
71
+ proc = run([sys.executable, "scripts/verify_registries.py"])
72
+ return "ALL REGISTRY CROSS-REFERENCES VALID" in proc.stdout
73
+
74
+
75
+ check("registry cross-references", _registries)
76
+
77
+
78
+ # ── Test suite health ─────────────────────────────────────────────────────
79
+ def _tests() -> bool:
80
+ proc = run([str(ROOT / ".venv/bin/pytest"), "tests/", "-q",
81
+ "--ignore=tests/test_72h_closed_loop.py"])
82
+ return proc.returncode == 0 and "passed" in proc.stdout
83
+
84
+
85
+ check("fast test suite (140+)", _tests)
86
+
87
+
88
+ # ── Deploy assets ─────────────────────────────────────────────────────────
89
+ def _assets() -> bool:
90
+ required = [
91
+ "docker/Dockerfile.kyrexis", "docker-compose.kyrexis.yml",
92
+ "site/manifest.webmanifest", "site/sw.js", "site/chat.html",
93
+ "site/store.html", "scripts/build_agents.py", "proofs/theory_proofs.py",
94
+ ]
95
+ return all((ROOT / p).exists() for p in required)
96
+
97
+
98
+ check("deploy assets present", _assets)
99
+
100
+
101
+ def main() -> int:
102
+ print("🏭 Production Readiness Check")
103
+ print("=" * 56)
104
+ results = []
105
+ for name, fn in CHECKS:
106
+ try:
107
+ ok = bool(fn())
108
+ except Exception as exc: # noqa: BLE001
109
+ ok = False
110
+ print(f" ❌ {name} β€” raised {exc}")
111
+ else:
112
+ print(f" {'βœ…' if ok else '❌'} {name}")
113
+ results.append(ok)
114
+ passed = sum(results)
115
+ status = "PASS" if passed == len(results) else "FAIL"
116
+ print("=" * 56)
117
+ print(f" PRODUCTION: {status} ({passed}/{len(results)})")
118
+ return 0 if status == "PASS" else 1
119
+
120
+
121
+ if __name__ == "__main__":
122
+ sys.exit(main())