- 新增 app_metadata 模型、仓储与服务 - 将默认 edge 验证步骤改为由 app_metadata 驱动生成 - 新增 chat_session / chat_message 会话层模型与 chat service - 新增 demo chat API,支持会话创建、消息发送、任务确认 - 新增最小 Web Demo 页面,形成聊天式演示入口 - 增强任务报告,补充 audit_summary 与更细粒度 task_metrics - 增强 edge-agent 执行器:tcp_probe、日志时间范围过滤、进程指标与更灵活健康检查 - 更新 README 与当前进度总结,MVP 进度推进到约 94%
70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
from __future__ import annotations
|
|
|
|
from unittest.mock import patch
|
|
|
|
from app.executors.http_executor import HttpHealthCheckExecutor
|
|
|
|
|
|
class DummyResponse:
|
|
def __init__(self, status_code: int, reason_phrase: str, text: str) -> None:
|
|
self.status_code = status_code
|
|
self.reason_phrase = reason_phrase
|
|
self.text = text
|
|
|
|
|
|
class DummyClient:
|
|
def __init__(self, *args, **kwargs) -> None:
|
|
self.kwargs = kwargs
|
|
|
|
def __enter__(self) -> "DummyClient":
|
|
return self
|
|
|
|
def __exit__(self, exc_type, exc, tb) -> None:
|
|
return None
|
|
|
|
def request(self, method: str, url: str, headers: dict | None = None) -> DummyResponse:
|
|
if "down" in url:
|
|
return DummyResponse(500, "Internal Server Error", '{"status":"DOWN"}')
|
|
if "ready" in url:
|
|
return DummyResponse(200, "OK", '{"status":"READY"}')
|
|
return DummyResponse(200, "OK", '{"status":"UP"}')
|
|
|
|
|
|
def test_http_health_check_executor_success() -> None:
|
|
with patch("app.executors.http_executor.httpx.Client", DummyClient):
|
|
success, message, data, evidence = HttpHealthCheckExecutor().execute(
|
|
{"url": "http://service.test/health", "timeout_ms": 3000}
|
|
)
|
|
assert success is True
|
|
assert message == "200 OK"
|
|
assert data["status_code"] == 200
|
|
assert data["latency_ms"] is not None
|
|
assert evidence["response_body"] == '{"status":"UP"}'
|
|
|
|
|
|
def test_http_health_check_executor_failure() -> None:
|
|
with patch("app.executors.http_executor.httpx.Client", DummyClient):
|
|
success, message, data, evidence = HttpHealthCheckExecutor().execute(
|
|
{"url": "http://service.test/down", "timeout_ms": 3000}
|
|
)
|
|
assert success is False
|
|
assert message == "500 Internal Server Error"
|
|
assert data["status_code"] == 500
|
|
assert evidence["response_body"] == '{"status":"DOWN"}'
|
|
|
|
|
|
def test_http_health_check_executor_body_contains() -> None:
|
|
with patch("app.executors.http_executor.httpx.Client", DummyClient):
|
|
success, message, data, evidence = HttpHealthCheckExecutor().execute(
|
|
{
|
|
"url": "http://service.test/ready",
|
|
"timeout_ms": 3000,
|
|
"expected_status": 200,
|
|
"body_contains": "READY",
|
|
}
|
|
)
|
|
assert success is True
|
|
assert message == "200 OK"
|
|
assert data["method"] == "GET"
|
|
assert evidence["response_json"]["status"] == "READY"
|