#!/usr/bin/env python3 """ Production readiness check — the "production" gate of the agent build/deploy workflow. Verifies: package imports, API route surfaces, registry cross-references, test suite health, docker/deploy assets. Usage: python3 scripts/production_check.py Exits 0 (PASS) or 1 (FAIL) with a structured report. """ from __future__ import annotations import subprocess import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT)) sys.path.insert(0, str(ROOT / "src")) # src-layout for the sovereign package CHECKS: list[tuple[str, callable]] = [] def check(name: str, fn) -> None: CHECKS.append((name, fn)) def run(cmd: list[str], timeout: int = 300) -> subprocess.CompletedProcess: return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout, cwd=ROOT) # ── Imports ─────────────────────────────────────────────────────────────── def _imports() -> bool: import importlib import os # The orchestrator requires a JWT secret at import; production supplies # it via env — the check only verifies importability. os.environ.setdefault("JWT_SECRET", "production-check-dummy") for mod in ["sovereign.main", "kyrexis.core", "kyrexis.api.routes", "pec5d.core", "pec5d.api.routes", "coldcase.api.routes", "chat.core", "chat.api.routes"]: importlib.import_module(mod) return True check("imports (all modules)", _imports) # ── Route surfaces ──────────────────────────────────────────────────────── def _routes() -> bool: from kyrexis.api.routes import router as k from pec5d.api.routes import router as p from coldcase.api.routes import router as c from chat.api.routes import router as t counts = {"kyrexis": len(k.routes), "pec5d": len(p.routes), "coldcase": len(c.routes), "chat": len(t.routes)} return counts["kyrexis"] == 19 and counts["pec5d"] == 22 and counts["chat"] == 5 check("API routes (kyrexis 19 · pec5d 22 · chat 5)", _routes) # ── Registry validator ──────────────────────────────────────────────────── def _registries() -> bool: proc = run([sys.executable, "scripts/verify_registries.py"]) return "ALL REGISTRY CROSS-REFERENCES VALID" in proc.stdout check("registry cross-references", _registries) # ── Test suite health ───────────────────────────────────────────────────── def _tests() -> bool: proc = run([str(ROOT / ".venv/bin/pytest"), "tests/", "-q", "--ignore=tests/test_72h_closed_loop.py"]) return proc.returncode == 0 and "passed" in proc.stdout check("fast test suite (140+)", _tests) # ── Deploy assets ───────────────────────────────────────────────────────── def _assets() -> bool: required = [ "docker/Dockerfile.kyrexis", "docker-compose.kyrexis.yml", "site/manifest.webmanifest", "site/sw.js", "site/chat.html", "site/store.html", "scripts/build_agents.py", "proofs/theory_proofs.py", ] return all((ROOT / p).exists() for p in required) check("deploy assets present", _assets) def main() -> int: print("🏭 Production Readiness Check") print("=" * 56) results = [] for name, fn in CHECKS: try: ok = bool(fn()) except Exception as exc: # noqa: BLE001 ok = False print(f" ❌ {name} — raised {exc}") else: print(f" {'✅' if ok else '❌'} {name}") results.append(ok) passed = sum(results) status = "PASS" if passed == len(results) else "FAIL" print("=" * 56) print(f" PRODUCTION: {status} ({passed}/{len(results)})") return 0 if status == "PASS" else 1 if __name__ == "__main__": sys.exit(main())