"""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"