Files
pic/scripts/sanity_check.py
T
roof 3d594025d2
Unit Tests / test (push) Successful in 11m24s
fix: remove legacy service dirs from setup_cell, update sanity_check for optional services
setup_cell.py no longer creates mail/radicale/webdav config and data dirs —
those are managed by ServiceComposer when services are installed. Added
data/services/ for ServiceComposer. sanity_check.py now uses stdlib urllib
and discovers installed services via /api/services/active before checking
their status routes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 17:22:42 -04:00

65 lines
1.8 KiB
Python

import json
import sys
import urllib.request
import urllib.error
BASE = "http://127.0.0.1:3000"
CORE_CHECKS = [
{"name": "API health", "path": "/health"},
{"name": "API status", "path": "/api/status"},
{"name": "Active services", "path": "/api/services/active"},
]
OPTIONAL_SERVICE_CHECKS = {
"email": {"name": "Email status", "path": "/api/email/status"},
"calendar": {"name": "Calendar status", "path": "/api/calendar/status"},
"files": {"name": "Files status", "path": "/api/files/status"},
}
def get(path):
try:
resp = urllib.request.urlopen(BASE + path, timeout=5)
body = resp.read().decode()
return resp.status, body
except urllib.error.HTTPError as e:
return e.code, e.read().decode()
except Exception as e:
return None, str(e)
def main():
print("=== PIC Sanity Check ===")
for chk in CORE_CHECKS:
code, body = get(chk["path"])
if code == 200:
print(f"[OK] {chk['name']}")
else:
print(f"[FAIL] {chk['name']} — HTTP {code}: {body[:120]}")
# Discover installed services and check only those
code, body = get("/api/services/active")
installed_ids = set()
if code == 200:
try:
installed_ids = {svc["id"] for svc in json.loads(body)}
except Exception:
pass
print()
print("Optional services:")
for svc_id, chk in OPTIONAL_SERVICE_CHECKS.items():
if svc_id not in installed_ids:
print(f"[SKIP] {chk['name']} — not installed")
continue
code, body = get(chk["path"])
if code == 200:
print(f"[OK] {chk['name']}")
else:
print(f"[FAIL] {chk['name']} — HTTP {code}: {body[:120]}")
if __name__ == "__main__":
main()