Spaces:
Sleeping
Sleeping
| """Verify a deployed IncidentCommander Space is healthy and stepping correctly. | |
| Hits the live Space URL with the standard OpenEnv loop: | |
| GET /health | |
| POST /reset | |
| POST /step (one read-only call, one fix) | |
| GET /state | |
| Use this immediately after ``deploy_to_space.py`` finishes building the Space. | |
| Usage:: | |
| python scripts/verify_space.py https://glitchghost-incident-commander.hf.space | |
| """ | |
| from __future__ import annotations | |
| import json | |
| import sys | |
| import time | |
| from typing import Any | |
| import httpx | |
| def verify(base_url: str) -> int: | |
| base_url = base_url.rstrip("/") | |
| print(f"checking {base_url}/health ...") | |
| deadline = time.time() + 240 | |
| while True: | |
| try: | |
| r = httpx.get(f"{base_url}/health", timeout=10) | |
| if r.status_code == 200 and r.json().get("status") == "healthy": | |
| print(" /health OK") | |
| break | |
| except Exception as exc: # noqa: BLE001 | |
| print(" not ready:", exc) | |
| if time.time() > deadline: | |
| print("ERROR: /health never went healthy", file=sys.stderr) | |
| return 2 | |
| time.sleep(8) | |
| with httpx.Client(base_url=base_url, timeout=30) as c: | |
| obs = c.post("/reset", json={"seed": 42, "stage": 3}).json() | |
| print("\n/reset alert:", obs["alert"][:120]) | |
| step1 = c.post( | |
| "/step", | |
| json={"action": {"tool": "trace_request", "args": {"path": "/checkout"}}}, | |
| ).json() | |
| print( | |
| "\n/step trace_request reward =", step1["reward"], " breakdown =", | |
| json.dumps(step1["info"]["breakdown"], indent=2), | |
| ) | |
| step2 = c.post( | |
| "/step", | |
| json={"action": {"tool": "get_metrics", "args": {"service": "payments"}}}, | |
| ).json() | |
| print( | |
| "\n/step get_metrics reward =", step2["reward"], " result =", | |
| step2["info"]["result"], | |
| ) | |
| state = c.get("/state").json() | |
| print( | |
| "\n/state total_reward =", state["total_reward"], | |
| " steps =", state["steps_taken"], | |
| ) | |
| print("\nSpace looks healthy and stepping correctly.") | |
| return 0 | |
| if __name__ == "__main__": | |
| if len(sys.argv) < 2: | |
| print("usage: python scripts/verify_space.py <base_url>", file=sys.stderr) | |
| raise SystemExit(2) | |
| raise SystemExit(verify(sys.argv[1])) | |