@@ -124,6 +124,43 @@ def get_client(self, invoke_agent):
124124
125125 return TestClient (app )
126126
127+ async def test_health_check (self ):
128+ """测试 /health 健康检查路由"""
129+
130+ client = self .get_client (self .get_invoke_agent_non_streaming ())
131+
132+ response = client .get ("/health" )
133+
134+ assert response .status_code == 200
135+ assert response .json () == {"status" : "ok" }
136+
137+ async def test_health_check_post_not_allowed (self ):
138+ """测试 POST /health 不被允许"""
139+
140+ client = self .get_client (self .get_invoke_agent_non_streaming ())
141+
142+ response = client .post ("/health" )
143+
144+ # FastAPI 对不匹配的方法返回 405
145+ assert response .status_code == 405
146+
147+ async def test_health_check_with_custom_protocols (self ):
148+ """测试自定义协议列表时 /health 仍可用"""
149+ from agentrun .server .openai_protocol import OpenAIProtocolHandler
150+
151+ server = AgentRunServer (
152+ invoke_agent = self .get_invoke_agent_non_streaming (),
153+ protocols = [OpenAIProtocolHandler ()],
154+ )
155+ from fastapi .testclient import TestClient
156+
157+ client = TestClient (server .as_fastapi_app ())
158+
159+ response = client .get ("/health" )
160+
161+ assert response .status_code == 200
162+ assert response .json () == {"status" : "ok" }
163+
127164 async def test_server_non_streaming_protocols (self ):
128165 """测试非流式的 OpenAI 和 AGUI 服务器响应功能"""
129166
0 commit comments