feat(gateway): add authenticated runtime readiness checks

This commit is contained in:
teknium1 2026-07-09 18:42:21 -07:00 committed by Teknium
parent aac77f1686
commit f9728af5e2
4 changed files with 298 additions and 2 deletions

View file

@ -764,7 +764,8 @@ class TestHealthDetailedEndpoint:
resp = await cli.get("/health/detailed")
assert resp.status == 200
data = await resp.json()
assert data["status"] == "ok"
assert data["status"] == "degraded"
assert data["readiness"]["checks"]["gateway"]["status"] == "degraded"
assert data["gateway_state"] is None
assert data["platforms"] == {}
# No runtime file ⇒ state None ⇒ not busy, not drainable.
@ -789,6 +790,36 @@ class TestHealthDetailedEndpoint:
resp = await cli.get("/health/detailed", headers=headers)
assert resp.status == 200
@pytest.mark.asyncio
async def test_health_detailed_reports_runtime_readiness(self, adapter):
"""Detailed health exposes bounded readiness probes without changing /health."""
app = _create_app(adapter)
expected = {
"status": "degraded",
"checks": {
"state_db": {"status": "ok"},
"config": {"status": "degraded", "detail": "using last-known-good"},
},
}
with patch("gateway.status.read_runtime_status", return_value={"gateway_state": "running"}), \
patch("gateway.platforms.api_server.collect_runtime_readiness", return_value=expected):
async with TestClient(TestServer(app)) as cli:
resp = await cli.get("/health/detailed")
assert resp.status == 200
data = await resp.json()
assert data["status"] == "degraded"
assert data["readiness"] == expected
@pytest.mark.asyncio
async def test_public_health_does_not_run_readiness_probes(self, adapter):
app = _create_app(adapter)
with patch("gateway.platforms.api_server.collect_runtime_readiness") as probe:
async with TestClient(TestServer(app)) as cli:
resp = await cli.get("/health")
assert resp.status == 200
assert (await resp.json())["status"] == "ok"
probe.assert_not_called()
# ---------------------------------------------------------------------------
# /v1/models endpoint