add health endpoint for gateway and everos
This commit is contained in:
@ -13,11 +13,16 @@ from core.repository import MemoryRepository
|
||||
|
||||
|
||||
class FakeEverOSClient:
|
||||
def __init__(self, search_results: list[dict[str, Any]] | None = None) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
search_results: list[dict[str, Any]] | None = None,
|
||||
health_error: Exception | None = None,
|
||||
) -> None:
|
||||
self.add_calls: list[dict[str, Any]] = []
|
||||
self.flush_calls: list[dict[str, str]] = []
|
||||
self.search_calls: list[dict[str, Any]] = []
|
||||
self.search_results = search_results or []
|
||||
self.health_error = health_error
|
||||
|
||||
async def add_memory(self, payload: dict[str, Any]) -> dict[str, Any]:
|
||||
self.add_calls.append(payload)
|
||||
@ -38,6 +43,11 @@ class FakeEverOSClient:
|
||||
self.search_calls.append(payload)
|
||||
return {"request_id": "search", "data": {"episodes": self.search_results}}
|
||||
|
||||
async def health_check(self) -> dict[str, Any]:
|
||||
if self.health_error is not None:
|
||||
raise self.health_error
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config(tmp_path: Path) -> GatewayConfig:
|
||||
@ -72,6 +82,43 @@ async def create_user(client: httpx.AsyncClient, user_id: str = "u_123") -> str:
|
||||
return body["user_key"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_health_reports_api_and_everos_ok(
|
||||
config: GatewayConfig,
|
||||
) -> None:
|
||||
everos = FakeEverOSClient()
|
||||
async with app_client(config, everos) as client:
|
||||
response = await client.get("/health")
|
||||
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json() == {
|
||||
"status": "ok",
|
||||
"api": {"status": "ok"},
|
||||
"everos": {
|
||||
"status": "ok",
|
||||
"base_url": "http://everos.test",
|
||||
"data": {"status": "ok"},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_health_reports_degraded_when_everos_fails(
|
||||
config: GatewayConfig,
|
||||
) -> None:
|
||||
everos = FakeEverOSClient(health_error=RuntimeError("everos down"))
|
||||
async with app_client(config, everos) as client:
|
||||
response = await client.get("/health")
|
||||
|
||||
assert response.status_code == 200, response.text
|
||||
body = response.json()
|
||||
assert body["status"] == "degraded"
|
||||
assert body["api"] == {"status": "ok"}
|
||||
assert body["everos"]["status"] == "unavailable"
|
||||
assert body["everos"]["base_url"] == "http://everos.test"
|
||||
assert body["everos"]["error"] == "everos down"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_user_generates_and_persists_user_key(
|
||||
config: GatewayConfig,
|
||||
|
||||
Reference in New Issue
Block a user