537 lines
21 KiB
Python
537 lines
21 KiB
Python
from copy import deepcopy
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from app.services import llm_model_catalog as discovery
|
|
from app.services import llm_provider_catalog as catalog
|
|
|
|
REAL_CLIENT = httpx.AsyncClient
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _clear_aggregator_cache():
|
|
discovery.clear_aggregator_catalog_cache()
|
|
yield
|
|
discovery.clear_aggregator_catalog_cache()
|
|
|
|
|
|
def mock_http(monkeypatch, handler):
|
|
transport = httpx.MockTransport(handler)
|
|
monkeypatch.setattr(
|
|
discovery.httpx, "AsyncClient", lambda **kw: REAL_CLIENT(transport=transport, **kw)
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize(
|
|
"provider,path,auth",
|
|
[
|
|
("minimax", "/anthropic/v1/models", "x-api-key"),
|
|
("anthropic", "/v1/models", "x-api-key"),
|
|
("openai", "/v1/models", "authorization"),
|
|
("deepseek", "/v1/models", "authorization"),
|
|
("alibaba", "/api/v1/models", "authorization"),
|
|
("moonshotai", "/v1/models", "authorization"),
|
|
("glm", "/api/paas/v4/models", "authorization"),
|
|
("meta", "/v1/models", "authorization"),
|
|
("gemini", "/v1beta/openai/models", "authorization"),
|
|
("grok", "/v1/models", "authorization"),
|
|
("openrouter", "/api/v1/models", None),
|
|
("opencode-go", "/zen/go/v1/models", None),
|
|
("ollama", "/api/tags", "authorization"),
|
|
],
|
|
)
|
|
async def test_official_catalog_requests(monkeypatch, provider, path, auth):
|
|
preset = catalog.get_fallback_llm_provider_preset(provider)
|
|
|
|
def handle(request):
|
|
assert request.url.path == path
|
|
assert request.url.host == httpx.URL(preset["base_url"]).host
|
|
if auth is None:
|
|
assert "authorization" not in request.headers
|
|
assert "x-api-key" not in request.headers
|
|
else:
|
|
assert request.headers[auth] == (
|
|
"test-key" if auth == "x-api-key" else "Bearer test-key"
|
|
)
|
|
if provider == "alibaba":
|
|
assert request.url.params["capabilities"] == "TG"
|
|
return httpx.Response(
|
|
200, json={"output": {"total": 1, "models": [{"model": "latest"}]}}
|
|
)
|
|
if provider == "ollama":
|
|
return httpx.Response(200, json={"models": [{"name": "latest:7b"}]})
|
|
if provider == "gemini":
|
|
return httpx.Response(200, json={"data": [{"id": "models/latest"}]})
|
|
return httpx.Response(200, json={"data": [{"id": "latest"}]})
|
|
|
|
mock_http(monkeypatch, handle)
|
|
result = await catalog.refresh_llm_provider_preset(provider, api_key="test-key")
|
|
assert result["models"] == (["latest:7b"] if provider == "ollama" else ["latest"])
|
|
assert result["base_url"] == preset["base_url"]
|
|
assert "test-key" not in str(result)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"provider,base,api,path",
|
|
[
|
|
(
|
|
"minimax",
|
|
"https://api.minimax.io/anthropic/v1/",
|
|
"anthropic-messages",
|
|
"/anthropic/v1/models",
|
|
),
|
|
("anthropic", "https://api.anthropic.com", "anthropic-messages", "/v1/models"),
|
|
(
|
|
"alibaba",
|
|
"https://workspace.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
|
|
"openai-completions",
|
|
"/api/v1/models",
|
|
),
|
|
(
|
|
"alibaba",
|
|
"https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
|
|
"openai-completions",
|
|
"/api/v1/models",
|
|
),
|
|
("alibaba", "https://custom.test/gateway/v1", "openai-completions", "/gateway/v1/models"),
|
|
("moonshotai", "https://api.moonshot.cn/v1", "openai-completions", "/v1/models"),
|
|
("ollama", "http://localhost:11434/api", "ollama-generate", "/api/tags"),
|
|
],
|
|
)
|
|
def test_urls_preserve_region_and_gateway(provider, base, api, path):
|
|
url = httpx.URL(discovery.model_catalog_url(provider, base, api))
|
|
assert url.host == httpx.URL(base).host
|
|
assert url.path == path
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_anthropic_pagination_and_release_order(monkeypatch):
|
|
seen = []
|
|
|
|
def handle(request):
|
|
seen.append(request.url.params.get("after_id"))
|
|
if len(seen) == 1:
|
|
return httpx.Response(
|
|
200,
|
|
json={
|
|
"data": [{"id": "old", "created_at": "2025-01-01T00:00:00Z"}],
|
|
"has_more": True,
|
|
"last_id": "old",
|
|
},
|
|
)
|
|
return httpx.Response(
|
|
200,
|
|
json={"data": [{"id": "new", "created_at": "2026-06-01T00:00:00Z"}], "has_more": False},
|
|
)
|
|
|
|
mock_http(monkeypatch, handle)
|
|
result = await catalog.refresh_llm_provider_preset("anthropic", "test-key")
|
|
assert seen == [None, "old"]
|
|
assert result["models"] == ["new", "old"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_dashscope_pagination(monkeypatch):
|
|
def handle(request):
|
|
page = int(request.url.params["page_no"])
|
|
return httpx.Response(
|
|
200,
|
|
json={
|
|
"output": {
|
|
"total": 2,
|
|
"models": [
|
|
{"model": f"page-{page}", "published_time": f"2026-06-0{page} 00:00:00"}
|
|
],
|
|
}
|
|
},
|
|
)
|
|
|
|
mock_http(monkeypatch, handle)
|
|
result = await catalog.refresh_llm_provider_preset("alibaba", "test-key")
|
|
assert result["models"] == ["page-2", "page-1"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize(
|
|
"payload",
|
|
[
|
|
{},
|
|
{"data": []},
|
|
{"data": [None]},
|
|
{"data": [{}]},
|
|
{"data": [{"id": "same"}], "has_more": True, "last_id": "same"},
|
|
],
|
|
)
|
|
async def test_invalid_or_incomplete_catalog_fails(monkeypatch, payload):
|
|
mock_http(monkeypatch, lambda request: httpx.Response(200, json=payload))
|
|
with pytest.raises(discovery.LLMProviderCatalogError):
|
|
await catalog.refresh_llm_provider_preset("minimax", "test-key")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_all_models_retained_and_defaults_unchanged(monkeypatch):
|
|
before = deepcopy(catalog.FALLBACK_LLM_PROVIDER_PRESETS)
|
|
rows = [{"id": f"model-{i}", "created": i} for i in range(140)]
|
|
mock_http(monkeypatch, lambda request: httpx.Response(200, json={"data": rows}))
|
|
result = await catalog.refresh_llm_provider_preset("openai", "test-key")
|
|
assert len(result["models"]) == 140
|
|
assert result["models"][0] == "model-139"
|
|
assert catalog.FALLBACK_LLM_PROVIDER_PRESETS == before
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_empty_ollama_catalog_is_valid(monkeypatch):
|
|
mock_http(monkeypatch, lambda request: httpx.Response(200, json={"models": []}))
|
|
result = await catalog.refresh_llm_provider_preset("ollama")
|
|
assert result["models"] == []
|
|
assert result["model"] == ""
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_opencode_documented_protocols(monkeypatch):
|
|
models = [
|
|
"minimax-m3",
|
|
"qwen3.8-max",
|
|
"gpt-5.6-luna",
|
|
"grok-4.6",
|
|
"muse-spark-1.3-contributor",
|
|
"kimi-k3",
|
|
]
|
|
mock_http(
|
|
monkeypatch,
|
|
lambda request: httpx.Response(200, json={"data": [{"id": model} for model in models]}),
|
|
)
|
|
result = await catalog.refresh_llm_provider_preset("opencode-go")
|
|
assert list(result["model_provider_apis"].values()) == [
|
|
"anthropic-messages",
|
|
"anthropic-messages",
|
|
"openai-responses",
|
|
"openai-responses",
|
|
"openai-responses",
|
|
"openai-completions",
|
|
]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_retry_transient_error_only(monkeypatch):
|
|
calls = []
|
|
|
|
def handle(request):
|
|
calls.append(request)
|
|
return httpx.Response(503 if len(calls) == 1 else 200, json={"data": [{"id": "latest"}]})
|
|
|
|
mock_http(monkeypatch, handle)
|
|
await catalog.refresh_llm_provider_preset("minimax", "test-key")
|
|
assert len(calls) == 2
|
|
calls.clear()
|
|
|
|
def unauthorized(request):
|
|
calls.append(request)
|
|
return httpx.Response(401, text="secret-upstream-text")
|
|
|
|
mock_http(monkeypatch, unauthorized)
|
|
with pytest.raises(httpx.HTTPStatusError) as error:
|
|
await discovery.fetch_model_catalog(
|
|
"minimax",
|
|
"https://api.minimaxi.com/anthropic",
|
|
"anthropic-messages",
|
|
"test-key",
|
|
)
|
|
assert len(calls) == 1
|
|
assert "secret-upstream-text" not in discovery.catalog_error_message(error.value)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize(
|
|
"provider,custom_base",
|
|
[
|
|
("openrouter", "https://proxy.test/api/v1"),
|
|
("opencode-go", "https://proxy.test/zen/go/v1"),
|
|
],
|
|
)
|
|
async def test_custom_gateway_for_public_provider_requires_and_sends_key(
|
|
monkeypatch, provider, custom_base
|
|
):
|
|
with pytest.raises(discovery.LLMProviderCatalogConfigError):
|
|
await catalog.refresh_llm_provider_preset(provider, base_url=custom_base)
|
|
|
|
def handle(request):
|
|
assert request.url.host == "proxy.test"
|
|
assert request.headers["authorization"] == "Bearer custom-key"
|
|
return httpx.Response(200, json={"data": [{"id": "proxy-model"}]})
|
|
|
|
mock_http(monkeypatch, handle)
|
|
result = await catalog.refresh_llm_provider_preset(
|
|
provider, api_key="custom-key", base_url=custom_base
|
|
)
|
|
assert result["models"] == ["proxy-model"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_fetch_model_catalog_include_auth_for_connectivity_check(monkeypatch):
|
|
def handle(request):
|
|
assert request.headers["authorization"] == "Bearer check-key"
|
|
return httpx.Response(200, json={"data": [{"id": "glm-5.3"}]})
|
|
|
|
mock_http(monkeypatch, handle)
|
|
result = await discovery.fetch_model_catalog(
|
|
"opencode-go",
|
|
"https://opencode.ai/zen/go/v1",
|
|
"openai-completions",
|
|
api_key="check-key",
|
|
include_auth=True,
|
|
)
|
|
assert result.models == ["glm-5.3"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_ollama_openai_completions_refreshes_without_key(monkeypatch):
|
|
def handle(request):
|
|
assert request.url.path == "/v1/models"
|
|
assert "authorization" not in request.headers
|
|
return httpx.Response(200, json={"data": [{"id": "qwen2.5:7b"}]})
|
|
|
|
mock_http(monkeypatch, handle)
|
|
result = await catalog.refresh_llm_provider_preset(
|
|
"ollama", provider_api="openai-completions"
|
|
)
|
|
assert result["models"] == ["qwen2.5:7b"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_config_error_type_and_clean_upstream_error_messages(monkeypatch):
|
|
with pytest.raises(discovery.LLMProviderCatalogConfigError):
|
|
discovery.model_catalog_url("openai", "not-a-url", "openai-responses")
|
|
with pytest.raises(discovery.LLMProviderCatalogConfigError):
|
|
discovery.model_catalog_url("openai", "https://api.openai.com/v1", "unsupported-api")
|
|
|
|
mock_http(monkeypatch, lambda request: httpx.Response(200, json={"data": []}))
|
|
with pytest.raises(discovery.LLMProviderCatalogError) as exc:
|
|
await catalog.refresh_llm_provider_preset("openai", "test-key")
|
|
assert not isinstance(exc.value, discovery.LLMProviderCatalogConfigError)
|
|
assert "已保留上次模型列表" not in str(exc.value)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_keyless_official_providers_use_models_dev_cache_and_filter_non_text(monkeypatch):
|
|
calls = []
|
|
models_dev_payload = {
|
|
"minimax-cn": {"models": {"MiniMax-M3.1-Flash": {"release_date": "2026-10-19", "modalities": {"output": ["text"]}}}},
|
|
"openai": {"models": {"gpt-6.2-astra": {"release_date": "2026-11-17", "modalities": {"output": ["text"]}}}},
|
|
"anthropic": {"models": {"claude-fable-5-2": {"release_date": "2026-11-09", "modalities": {"output": ["text"]}}}},
|
|
"deepseek": {"models": {"deepseek-v4-pro": {"release_date": "2026-08-13", "modalities": {"output": ["text"]}}}},
|
|
"alibaba-cn": {"models": {"qwen4-max": {"release_date": "2026-11-16", "modalities": {"output": ["text"]}}}},
|
|
"moonshotai": {"models": {"kimi-k3.1-pro": {"release_date": "2026-10-23", "modalities": {"output": ["text"]}}}},
|
|
"zhipuai": {"models": {"glm-5.3": {"release_date": "2026-08-14", "modalities": {"output": ["text"]}}}},
|
|
"meta": {"models": {"muse-ember-1.0": {"release_date": "2026-11-09", "modalities": {"output": ["text"]}}}},
|
|
"google": {"models": {"gemini-4-neon": {"release_date": "2026-11-18", "modalities": {"output": ["text"]}}}},
|
|
"xai": {
|
|
"models": {
|
|
"grok-imagine-video": {"release_date": "2026-10-01", "modalities": {"output": ["video"]}},
|
|
"grok-4.6": {"release_date": "2026-08-12", "modalities": {"output": ["text"]}},
|
|
"grok-4.7": {"release_date": "2026-09-21", "modalities": {"output": ["text"]}},
|
|
"grok-legacy": {"release_date": "2026-11-01", "status": "deprecated", "modalities": {"output": ["text"]}},
|
|
}
|
|
},
|
|
}
|
|
|
|
def handle(request):
|
|
calls.append(str(request.url))
|
|
assert str(request.url) == discovery.MODELS_DEV_CATALOG_URL
|
|
return httpx.Response(200, json=models_dev_payload)
|
|
|
|
mock_http(monkeypatch, handle)
|
|
expected = {
|
|
"minimax": ["MiniMax-M3.1-Flash"],
|
|
"openai": ["gpt-6.2-astra"],
|
|
"anthropic": ["claude-fable-5-2"],
|
|
"deepseek": ["deepseek-v4-pro"],
|
|
"alibaba": ["qwen4-max"],
|
|
"moonshotai": ["kimi-k3.1-pro"],
|
|
"glm": ["glm-5.3"],
|
|
"meta": ["muse-ember-1.0"],
|
|
"gemini": ["gemini-4-neon"],
|
|
"grok": ["grok-4.7", "grok-4.6", "grok-legacy"],
|
|
}
|
|
for provider, models in expected.items():
|
|
result = await catalog.refresh_llm_provider_preset(provider)
|
|
assert result["models"] == models
|
|
assert result["source"].startswith(discovery.MODELS_DEV_CATALOG_URL)
|
|
assert len(calls) == 1
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_keyless_aggregator_falls_back_to_openrouter_when_models_dev_fails(monkeypatch):
|
|
seen_urls = []
|
|
|
|
def handle(request):
|
|
seen_urls.append(str(request.url))
|
|
if str(request.url) == discovery.MODELS_DEV_CATALOG_URL:
|
|
return httpx.Response(503, text="models.dev down")
|
|
if str(request.url) == discovery.OPENROUTER_CATALOG_URL:
|
|
return httpx.Response(
|
|
200,
|
|
json={
|
|
"data": [
|
|
{"id": "moonshotai/kimi-k3:batch", "created": 300},
|
|
{"id": "moonshotai/kimi-k3.1-pro", "created": 200},
|
|
{"id": "moonshotai/kimi-k3", "created": 100},
|
|
{"id": "z-ai/glm-5.3", "created": 150},
|
|
]
|
|
},
|
|
)
|
|
pytest.fail(f"unexpected URL {request.url}")
|
|
|
|
mock_http(monkeypatch, handle)
|
|
result = await catalog.refresh_llm_provider_preset("moonshotai")
|
|
assert result["models"] == ["kimi-k3.1-pro", "kimi-k3"]
|
|
assert result["source"] == f"{discovery.OPENROUTER_CATALOG_URL}#moonshotai"
|
|
assert discovery.MODELS_DEV_CATALOG_URL in seen_urls
|
|
assert discovery.OPENROUTER_CATALOG_URL in seen_urls
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_keyless_aggregator_fails_cleanly_and_official_vs_gateway_keyed_fallback(monkeypatch):
|
|
mock_http(monkeypatch, lambda request: httpx.Response(503, text="secret-upstream-error"))
|
|
with pytest.raises(discovery.LLMProviderCatalogError) as agg_exc:
|
|
await catalog.refresh_llm_provider_preset("glm")
|
|
assert not isinstance(agg_exc.value, discovery.LLMProviderCatalogConfigError)
|
|
|
|
# Keyed official host falling back to models.dev when official /models returns 401
|
|
seen_hosts = []
|
|
|
|
def deepseek_401_then_aggregator(request):
|
|
seen_hosts.append(request.url.host)
|
|
if request.url.host == "api.deepseek.com":
|
|
return httpx.Response(401, text="bad-key")
|
|
if str(request.url) == discovery.MODELS_DEV_CATALOG_URL:
|
|
return httpx.Response(
|
|
200,
|
|
json={
|
|
"deepseek": {
|
|
"models": {
|
|
"deepseek-chat": {"release_date": "2026-01-01"},
|
|
"deepseek-v4-flash": {"release_date": "2026-10-17"},
|
|
}
|
|
}
|
|
},
|
|
)
|
|
pytest.fail(f"unexpected URL {request.url}")
|
|
|
|
mock_http(monkeypatch, deepseek_401_then_aggregator)
|
|
ds_result = await catalog.refresh_llm_provider_preset("deepseek", api_key="stale-key")
|
|
assert seen_hosts == ["api.deepseek.com", "models.dev"]
|
|
assert ds_result["models"] == ["deepseek-v4-flash", "deepseek-chat"]
|
|
assert ds_result["source"] == f"{discovery.MODELS_DEV_CATALOG_URL}#deepseek"
|
|
|
|
# Keyed official host where both aggregators also fail preserves original 401 HTTPStatusError
|
|
seen_hosts.clear()
|
|
discovery.clear_aggregator_catalog_cache()
|
|
|
|
def official_and_aggregators_fail(request):
|
|
seen_hosts.append(request.url.host)
|
|
if request.url.host == "api.moonshot.ai":
|
|
return httpx.Response(401, text="bad-key")
|
|
return httpx.Response(503, text="aggregator-down")
|
|
|
|
mock_http(monkeypatch, official_and_aggregators_fail)
|
|
with pytest.raises(httpx.HTTPStatusError) as official_err:
|
|
await catalog.refresh_llm_provider_preset("moonshotai", api_key="invalid-key")
|
|
assert official_err.value.response.status_code == 401
|
|
assert seen_hosts[0] == "api.moonshot.ai"
|
|
|
|
# Keyed custom gateway never falls back to public aggregators
|
|
seen_hosts.clear()
|
|
discovery.clear_aggregator_catalog_cache()
|
|
|
|
def custom_gateway_bad_key(request):
|
|
seen_hosts.append(request.url.host)
|
|
return httpx.Response(401, text="bad-gateway-key")
|
|
|
|
mock_http(monkeypatch, custom_gateway_bad_key)
|
|
with pytest.raises(httpx.HTTPStatusError):
|
|
await catalog.refresh_llm_provider_preset(
|
|
"moonshotai",
|
|
api_key="invalid-key",
|
|
base_url="https://proxy.example.test/v1",
|
|
)
|
|
assert seen_hosts == ["proxy.example.test"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_openai_6_2_defaults_and_aggregator_chat_filtering_demotion(monkeypatch):
|
|
preset = catalog.get_fallback_llm_provider_preset("openai")
|
|
assert preset["model"] == "gpt-6.2-astra"
|
|
assert {"gpt-6.2-astra", "gpt-6.2-sol"}.issubset(set(preset["models"]))
|
|
assert preset["model_provider_apis"]["gpt-6.2-astra"] == "openai-responses"
|
|
assert preset["model_provider_apis"]["gpt-6.2-sol"] == "openai-responses"
|
|
|
|
models_dev_payload = {
|
|
"openai": {
|
|
"models": {
|
|
"gpt-6.2-sol-healthcare": {"release_date": "2026-11-24", "modalities": {"output": ["text"]}},
|
|
"gpt-daybreak-red-latest": {"release_date": "2026-11-24", "modalities": {"output": ["text"]}},
|
|
"gpt-6.2-sol": {"release_date": "2026-11-17", "modalities": {"output": ["text"]}},
|
|
"gpt-6.2-astra": {"release_date": "2026-11-17", "modalities": {"output": ["text"]}},
|
|
"gpt-chat-latest": {"release_date": "2026-11-20", "modalities": {"output": ["text"]}},
|
|
"text-embedding-3-small": {"release_date": "2026-11-20", "modalities": {"output": ["text"]}},
|
|
"chatgpt-image-latest": {"release_date": "2026-11-20", "modalities": {"output": ["text", "image"]}},
|
|
"gpt-image-1.5": {"release_date": "2026-11-20", "modalities": {"output": ["text", "image"]}},
|
|
"gpt-audio": {"release_date": "2026-11-20", "modalities": {"output": ["text", "audio"]}},
|
|
}
|
|
},
|
|
"zhipuai": {
|
|
"models": {
|
|
"glm-5.3-flashx-legal": {"release_date": "2026-11-24", "modalities": {"output": ["text"]}},
|
|
"glm-5.3": {"release_date": "2026-08-14", "modalities": {"output": ["text"]}},
|
|
}
|
|
},
|
|
"deepseek": {
|
|
"models": {
|
|
"deepseek-v4-flash": {"release_date": "2026-10-17", "modalities": {"output": ["text"]}},
|
|
"deepseek-chat": {"release_date": "2026-01-01", "modalities": {"output": ["text"]}},
|
|
}
|
|
},
|
|
}
|
|
mock_http(monkeypatch, lambda request: httpx.Response(200, json=models_dev_payload))
|
|
|
|
oai = await catalog.refresh_llm_provider_preset("openai")
|
|
assert oai["models"] == [
|
|
"gpt-6.2-sol",
|
|
"gpt-6.2-astra",
|
|
"gpt-daybreak-red-latest",
|
|
"gpt-6.2-sol-healthcare",
|
|
]
|
|
assert oai["model"] == "gpt-6.2-sol"
|
|
assert oai["model_provider_apis"]["gpt-6.2-sol"] == "openai-responses"
|
|
assert oai["model_provider_apis"]["gpt-6.2-astra"] == "openai-responses"
|
|
|
|
glm = await catalog.refresh_llm_provider_preset("glm")
|
|
assert glm["models"] == ["glm-5.3", "glm-5.3-flashx-legal"]
|
|
assert glm["model"] == "glm-5.3"
|
|
|
|
ds = await catalog.refresh_llm_provider_preset("deepseek")
|
|
assert ds["models"] == ["deepseek-v4-flash", "deepseek-chat"]
|
|
|
|
mock_http(
|
|
monkeypatch,
|
|
lambda request: httpx.Response(200, json={"data": [{"id": "gpt-6.2-astra"}, {"id": "gpt-6.2-sol"}]}),
|
|
)
|
|
gw = await catalog.refresh_llm_provider_preset(
|
|
"openai",
|
|
api_key="gw-key",
|
|
base_url="https://gateway.test/v1",
|
|
)
|
|
assert gw["model_provider_apis"] == {}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_keyless_custom_gateway_still_requires_api_key(monkeypatch):
|
|
mock_http(monkeypatch, lambda request: pytest.fail("must not call aggregator or proxy"))
|
|
with pytest.raises(discovery.LLMProviderCatalogConfigError):
|
|
await catalog.refresh_llm_provider_preset(
|
|
"moonshotai", base_url="https://proxy.example.test/v1"
|
|
)
|