-
Notifications
You must be signed in to change notification settings - Fork 1
feat(server): add health check endpoint with tests #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,6 +124,43 @@ def get_client(self, invoke_agent): | |
|
|
||
| return TestClient(app) | ||
|
|
||
| async def test_health_check(self): | ||
| """测试 /health 健康检查路由""" | ||
|
|
||
| client = self.get_client(self.get_invoke_agent_non_streaming()) | ||
|
|
||
| response = client.get("/health") | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json() == {"status": "ok"} | ||
|
|
||
| async def test_health_check_post_not_allowed(self): | ||
| """测试 POST /health 不被允许""" | ||
|
|
||
| client = self.get_client(self.get_invoke_agent_non_streaming()) | ||
|
|
||
| response = client.post("/health") | ||
|
|
||
| # FastAPI 对不匹配的方法返回 405 | ||
| assert response.status_code == 405 | ||
|
|
||
| async def test_health_check_with_custom_protocols(self): | ||
| """测试自定义协议列表时 /health 仍可用""" | ||
| from agentrun.server.openai_protocol import OpenAIProtocolHandler | ||
|
|
||
| server = AgentRunServer( | ||
| invoke_agent=self.get_invoke_agent_non_streaming(), | ||
| protocols=[OpenAIProtocolHandler()], | ||
| ) | ||
|
Comment on lines
+148
to
+154
|
||
| from fastapi.testclient import TestClient | ||
|
|
||
| client = TestClient(server.as_fastapi_app()) | ||
|
|
||
| response = client.get("/health") | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json() == {"status": "ok"} | ||
|
|
||
| async def test_server_non_streaming_protocols(self): | ||
| """测试非流式的 OpenAI 和 AGUI 服务器响应功能""" | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AgentRunServernow always registers a rootGET /healthroute. Note thatAGUIProtocolHandleralready definesGET /healthon its router; if the AG-UI prefix is configured to an empty string (or a custom protocol mounts at root with the same path), the protocol’s/healthwill be shadowed by the server-level route, leading to ambiguous/unreachable behavior depending on route order. Consider guarding registration (skip if an existing GET /health route already exists), or using a dedicated non-conflicting path (e.g./_health) for the server-level endpoint.