fix: narrow exception types in get_models, fix patch targets in tests, add type annotation
This commit is contained in:
parent
5939c67b9f
commit
12117ad0c6
3 changed files with 9 additions and 5 deletions
|
|
@ -12,6 +12,8 @@ Route prefixes when mounted at /api in api.py:
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
|
||||||
from app.cforch import router as _cforch_router
|
from app.cforch import router as _cforch_router
|
||||||
|
|
@ -28,7 +30,7 @@ router.include_router(_plans_router, prefix="/plans-bench")
|
||||||
router.include_router(_embed_router, prefix="/embed-bench")
|
router.include_router(_embed_router, prefix="/embed-bench")
|
||||||
|
|
||||||
|
|
||||||
def set_config_dir(path) -> None:
|
def set_config_dir(path: Path | None) -> None:
|
||||||
"""Propagate config dir override to all sub-modules -- used by tests."""
|
"""Propagate config dir override to all sub-modules -- used by tests."""
|
||||||
import app.cforch as _cforch_mod
|
import app.cforch as _cforch_mod
|
||||||
import app.style as _style_mod
|
import app.style as _style_mod
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,8 @@ def get_models() -> dict:
|
||||||
"name": entry.get("name", ""),
|
"name": entry.get("name", ""),
|
||||||
"size": entry.get("size", 0),
|
"size": entry.get("size", 0),
|
||||||
})
|
})
|
||||||
except Exception as exc:
|
except httpx.HTTPStatusError as exc:
|
||||||
logger.warning("Failed to list Ollama models: %s", exc)
|
logger.warning("Ollama /api/tags returned HTTP %s: %s", exc.response.status_code, exc)
|
||||||
|
except httpx.RequestError as exc:
|
||||||
|
logger.warning("Failed to reach Ollama for model list: %s", exc)
|
||||||
return {"models": models, "ollama_url": ollama}
|
return {"models": models, "ollama_url": ollama}
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ def test_models_returns_list_with_mock(client, tmp_path):
|
||||||
}
|
}
|
||||||
mock_resp.raise_for_status = MagicMock()
|
mock_resp.raise_for_status = MagicMock()
|
||||||
|
|
||||||
with patch("httpx.get", return_value=mock_resp):
|
with patch("app.eval.embed_bench.httpx.get", return_value=mock_resp):
|
||||||
r = client.get("/api/embed-bench/models")
|
r = client.get("/api/embed-bench/models")
|
||||||
|
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
|
|
@ -85,7 +85,7 @@ def test_models_returns_list_with_mock(client, tmp_path):
|
||||||
def test_models_returns_empty_on_ollama_error(client, tmp_path):
|
def test_models_returns_empty_on_ollama_error(client, tmp_path):
|
||||||
"""GET /api/embed-bench/models returns empty list if Ollama unreachable."""
|
"""GET /api/embed-bench/models returns empty list if Ollama unreachable."""
|
||||||
import httpx
|
import httpx
|
||||||
with patch("httpx.get", side_effect=httpx.ConnectError("refused")):
|
with patch("app.eval.embed_bench.httpx.get", side_effect=httpx.ConnectError("refused")):
|
||||||
r = client.get("/api/embed-bench/models")
|
r = client.get("/api/embed-bench/models")
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert r.json()["models"] == []
|
assert r.json()["models"] == []
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue