65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
import httpx
|
|
import pytest
|
|
|
|
from app.services import llm_provider_catalog as catalog
|
|
|
|
|
|
def mock_catalog(monkeypatch, payload):
|
|
client_type = httpx.AsyncClient
|
|
transport = httpx.MockTransport(lambda request: httpx.Response(200, json=payload))
|
|
monkeypatch.setattr(
|
|
catalog.httpx, "AsyncClient", lambda **kwargs: client_type(transport=transport, **kwargs)
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_refresh_orders_by_release_date_before_choosing_default(monkeypatch):
|
|
mock_catalog(
|
|
monkeypatch,
|
|
{
|
|
"minimax": {
|
|
"models": {
|
|
"MiniMax-M2": {"release_date": "2025-10-27"},
|
|
"MiniMax-M3": {"release_date": "2026-06-01"},
|
|
"MiniMax-M2.7": {"release_date": "2026-03-18"},
|
|
"undated-model": {},
|
|
}
|
|
}
|
|
},
|
|
)
|
|
|
|
refreshed = await catalog.refresh_llm_provider_preset("minimax")
|
|
|
|
assert refreshed["model"] == "MiniMax-M3"
|
|
assert refreshed["models"] == ["MiniMax-M3", "MiniMax-M2.7", "MiniMax-M2", "undated-model"]
|
|
assert refreshed["source"] == catalog.MODELS_DEV_URL
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_refresh_does_not_truncate_new_models(monkeypatch):
|
|
models = {f"older-{index}": {"release_date": "2025-01-01"} for index in range(85)}
|
|
models["latest"] = {"release_date": "2026-06-01"}
|
|
mock_catalog(monkeypatch, {"minimax": {"models": models}})
|
|
|
|
refreshed = await catalog.refresh_llm_provider_preset("minimax")
|
|
|
|
assert refreshed["model"] == "latest"
|
|
assert len(refreshed["models"]) == 86
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize("payload", [{}, {"minimax": {"models": {}}}, {"minimax": []}])
|
|
async def test_invalid_catalog_fails_instead_of_claiming_fallback_is_fresh(monkeypatch, payload):
|
|
mock_catalog(monkeypatch, payload)
|
|
|
|
with pytest.raises(catalog.LLMProviderCatalogError):
|
|
await catalog.refresh_llm_provider_preset("minimax")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_empty_opencode_catalog_is_a_refresh_failure(monkeypatch):
|
|
mock_catalog(monkeypatch, {"data": []})
|
|
|
|
with pytest.raises(catalog.LLMProviderCatalogError):
|
|
await catalog.refresh_llm_provider_preset("opencode-go", api_key="test-key")
|