File size: 4,363 Bytes
48dc38f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/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())