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()