Spaces:
Sleeping
Sleeping
File size: 1,481 Bytes
09da05c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | """API startup behavior checks."""
from threading import Event
import pytest
fastapi = pytest.importorskip("fastapi")
unused_fastapi = fastapi
def test_lazy_qa_service_initializes_on_first_use():
from adsp.app.api_server import LazyQAService
calls: list[str] = []
class FakeQA:
def __init__(self) -> None:
calls.append("init")
self.orchestrator = object()
def ask(self, persona_id: str, query: str) -> str:
return f"{persona_id}:{query}"
lazy = LazyQAService(factory=FakeQA)
assert lazy.status == "idle"
assert calls == []
assert lazy.ask("p1", "hello") == "p1:hello"
assert calls == ["init"]
assert lazy.status == "ready"
def test_health_does_not_wait_for_qa_warmup(monkeypatch: pytest.MonkeyPatch):
from fastapi.testclient import TestClient
from adsp.app.api_server import create_app
started = Event()
release = Event()
class BlockingQA:
def __init__(self) -> None:
started.set()
release.wait(timeout=2.0)
self.orchestrator = object()
monkeypatch.setattr("adsp.app.api_server.QAService", BlockingQA)
with TestClient(create_app()) as client:
assert started.wait(timeout=1.0)
response = client.get("/health")
payload = response.json()
release.set()
assert response.status_code == 200
assert payload["status"] == "ok"
assert payload["qa_status"] == "warming"
|