Minor updates

This commit is contained in:
2026-08-25 07:11:22 +02:00
parent 50c64e0541
commit bd0abab759
5 changed files with 173 additions and 8 deletions
+18 -6
View File
@@ -85,15 +85,27 @@ class GatewayLLMTests(unittest.IsolatedAsyncioTestCase):
async def test_llm_endpoint_requires_api_key(self):
module = load_gateway_module(llm_enabled=True)
response = await self._request(
module,
"POST",
"/ai/chat",
json_payload={"messages": [{"role": "user", "content": "hello"}]},
)
with self.assertLogs("gateway", level="INFO") as captured:
response = await self._request(
module,
"POST",
"/ai/chat",
json_payload={"messages": [{"role": "user", "content": "hello"}]},
)
self.assertEqual(response.status_code, 401)
self.assertEqual(response.json()["error"]["code"], "unauthorized")
joined_logs = "\n".join(captured.output)
self.assertIn("incoming_request service=gateway", joined_logs)
self.assertIn("completed_request service=gateway", joined_logs)
self.assertIn("caller=127.0.0.1", joined_logs)
self.assertIn("method=POST", joined_logs)
self.assertIn("path=/ai/chat", joined_logs)
self.assertIn("status_code=401", joined_logs)
self.assertIn("response_time_ms=", joined_logs)
self.assertIn("cpu_time_ms=", joined_logs)
self.assertIn("cpu_percent=", joined_logs)
self.assertIn("rss_mb=", joined_logs)
async def test_llm_disabled_returns_503(self):
module = load_gateway_module(llm_enabled=False)
+14 -2
View File
@@ -44,8 +44,9 @@ class LLMServiceTests(unittest.IsolatedAsyncioTestCase):
)
transport = httpx.ASGITransport(app=module.app)
async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client:
response = await client.get("/health")
with self.assertLogs("llm", level="INFO") as captured:
async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client:
response = await client.get("/health")
self.assertEqual(response.status_code, 200)
self.assertEqual(
@@ -59,6 +60,17 @@ class LLMServiceTests(unittest.IsolatedAsyncioTestCase):
"gpu_layers": 0,
},
)
joined_logs = "\n".join(captured.output)
self.assertIn("incoming_request service=llm", joined_logs)
self.assertIn("completed_request service=llm", joined_logs)
self.assertIn("caller=127.0.0.1", joined_logs)
self.assertIn("method=GET", joined_logs)
self.assertIn("path=/health", joined_logs)
self.assertIn("status_code=200", joined_logs)
self.assertIn("response_time_ms=", joined_logs)
self.assertIn("cpu_time_ms=", joined_logs)
self.assertIn("cpu_percent=", joined_logs)
self.assertIn("rss_mb=", joined_logs)
async def test_health_reports_unavailable_when_process_is_down(self):
module = load_llm_module()