Coverage for app / routers / health.py: 100%
21 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-31 11:23 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-31 11:23 +0000
1import hashlib
2from pathlib import Path
4from fastapi import APIRouter, Depends
5from sqlalchemy import text
6from sqlalchemy.orm import Session
8from app.common.settings import get_settings
9from app.dependency.base import get_db
10from app.util.fingerprint import code_fingerprint
12router = APIRouter(tags=["health"])
14#: Settings that change what an answer says, not only how it is served. The
15#: inference backend is one: the same model reached through Bedrock decodes
16#: structured output differently and runs where Bedrock runs it.
17ANSWERING_SETTINGS = (
18 "TRIAGE_MODEL",
19 "INFERENCE_BACKEND",
20 "BEDROCK_REGION",
21 "STRICT_BUILTIN_TOOLS",
22)
25def answering_fingerprint() -> str:
26 """What decides this process's answers: everything under ``app/``, and the
27 settings in ``ANSWERING_SETTINGS``. svc-core's platform benchmark re-runs
28 CHAINR Bot only when this, or its own code that builds the bot's request,
29 has changed."""
30 settings = get_settings()
31 material = "|".join(
32 [code_fingerprint(Path(__file__).resolve().parents[1])]
33 + [f"{name}={getattr(settings, name, '')}" for name in ANSWERING_SETTINGS]
34 )
35 return hashlib.sha256(material.encode()).hexdigest()[:16]
38#: Hashed once at start: neither the code nor the settings change while it runs.
39CODE_FINGERPRINT = answering_fingerprint()
42@router.get("/health")
43def health(db: Session = Depends(get_db)):
44 from app.services import inference_routes
46 from app.tools.web import health as web_health
48 db.execute(text("SELECT 1"))
49 return {
50 "status": "ok",
51 "db": "ok",
52 "code": CODE_FINGERPRINT,
53 # How models are reached: svc-core's benchmark re-measures a model
54 # whose results were taken by another route.
55 "backend": inference_routes.backend(),
56 # How web search is doing: an engine out of credit fails every search
57 # until someone acts, and no chat names the engine.
58 "web_search": web_health.status(get_settings()),
59 }