All checks were successful
CI / test (pull_request) Successful in 3m55s
4.1 新增三个评估场景(急诊分诊、慢病管理、健康咨询),各 3 个用例,
全部使用无模型绑定依赖的规则;急诊场景编码 <20s 延迟验收标准
4.2 ModelGateway 由每次请求新建 httpx.AsyncClient 改为单实例共享客户端
(复用 TCP/TLS 连接),引擎与模型连通性测试端点负责关闭;
tutu 通道已具备同等优化,无需改动
4.3 Reports.tsx 单次报告顶部新增上线评估横幅:go/no-go/conditional
三态 banner + 各验收标准达标情况标签
版本号升至 1.3.1(v1.3.1-final)。
门禁:pytest tests/unit 709 passed;ruff 全绿;
前端 tsc --noEmit + vitest 232 passed。
附带修复 RunList 测试时区缺陷:started_at 用 UTC 日期构造,
本地 00:00-08:00 之间会被默认"今天"过滤器排除导致误报失败。
64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
"""Phase 4 (v1.3.1) wiring tests: scenario coverage expansion and gateway client reuse."""
|
|
|
|
from datetime import datetime
|
|
|
|
import httpx
|
|
import pytest
|
|
from agenteval.model_gateway import ModelGateway
|
|
from agenteval.models import ModelCapability
|
|
from agenteval.services.model_configs import ModelRuntimeConfig
|
|
|
|
|
|
def _runtime_config() -> ModelRuntimeConfig:
|
|
return ModelRuntimeConfig(
|
|
id="cfg-1",
|
|
name="judge",
|
|
provider="openai_compatible",
|
|
capability=ModelCapability.CHAT,
|
|
endpoint_url="https://models.example.com/v1/chat/completions",
|
|
model_name="test-model",
|
|
api_key="k",
|
|
updated_at=datetime(2026, 8, 25),
|
|
)
|
|
|
|
|
|
def _handler(request: httpx.Request) -> httpx.Response:
|
|
return httpx.Response(200, json={"choices": [{"message": {"content": "ok"}}]})
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_gateway_reuses_single_http_client(monkeypatch):
|
|
created = 0
|
|
real_client = httpx.AsyncClient
|
|
|
|
def factory(*args, **kwargs):
|
|
nonlocal created
|
|
created += 1
|
|
return real_client(*args, **kwargs)
|
|
|
|
monkeypatch.setattr(httpx, "AsyncClient", factory)
|
|
|
|
gateway = ModelGateway(transport=httpx.MockTransport(_handler))
|
|
await gateway.chat(_runtime_config(), [{"role": "user", "content": "a"}])
|
|
await gateway.chat(_runtime_config(), [{"role": "user", "content": "b"}])
|
|
await gateway.chat(_runtime_config(), [{"role": "user", "content": "c"}])
|
|
|
|
assert created == 1, "gateway must reuse a single httpx client across calls"
|
|
await gateway.close()
|
|
assert gateway._client is None
|
|
|
|
|
|
def test_new_scenarios_load_and_cover_expected_domains():
|
|
from pathlib import Path
|
|
|
|
from agenteval.scenarios.loader import load_scenario_file
|
|
|
|
root = Path(__file__).resolve().parents[2] / "data" / "scenarios"
|
|
expected = {"emergency.yaml", "chronic_care.yaml", "health_consultation.yaml"}
|
|
for name in expected:
|
|
scenario = load_scenario_file(root / name)
|
|
assert scenario.cases, f"{name} must define cases"
|
|
assert len(scenario.cases) >= 3, f"{name} should broaden case coverage"
|
|
for case in scenario.cases:
|
|
assert case.eval_rules, f"{name}:{case.id} must define eval_rules"
|