36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
|
|
"""Tests for the /health endpoint (no auth required, MCP failure tolerant)."""
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
|
||
|
|
pytestmark = pytest.mark.asyncio
|
||
|
|
|
||
|
|
|
||
|
|
async def test_health_no_auth_required(app_client):
|
||
|
|
"""GET /health must return 200 without any Authorization header."""
|
||
|
|
resp = await app_client.get("/health")
|
||
|
|
assert resp.status_code == 200, resp.text
|
||
|
|
|
||
|
|
|
||
|
|
async def test_health_returns_agent_count(app_client, seed_agent):
|
||
|
|
"""Body must include `agents >= 1` and an `agent_ids` list."""
|
||
|
|
resp = await app_client.get("/health")
|
||
|
|
assert resp.status_code == 200
|
||
|
|
body = resp.json()
|
||
|
|
assert "agents" in body
|
||
|
|
assert "agent_ids" in body
|
||
|
|
assert isinstance(body["agent_ids"], list)
|
||
|
|
assert body["agents"] >= 1
|
||
|
|
assert "test_agent" in body["agent_ids"]
|
||
|
|
assert body["status"] == "ok"
|
||
|
|
assert body["mcp_server"] == "reachable"
|
||
|
|
|
||
|
|
|
||
|
|
async def test_health_mcp_unreachable_still_200(app_client_mcp_down, seed_agent):
|
||
|
|
"""If MCP health raises CancelledError, /health still returns 200 with mcp_server=unreachable."""
|
||
|
|
resp = await app_client_mcp_down.get("/health")
|
||
|
|
assert resp.status_code == 200, resp.text
|
||
|
|
body = resp.json()
|
||
|
|
assert body["status"] == "ok"
|
||
|
|
assert body["mcp_server"] == "unreachable"
|
||
|
|
assert body["agents"] >= 1
|