test(model_switch): update regression to reflect bare-custom guard

This commit is contained in:
Teknium 2026-04-30 03:10:52 -07:00
parent 61fec7689d
commit 3fc4c63d38

View file

@ -296,7 +296,34 @@ def test_list_authenticated_providers_groups_same_endpoint(monkeypatch):
def test_list_authenticated_providers_current_endpoint_uses_current_slug(monkeypatch):
"""When current_base_url matches the grouped endpoint, the slug must
equal current_provider so picker selection routes through the live
credential pipeline."""
credential pipeline provided current_provider is a real slug, not
the corrupt bare "custom" (see #17478)."""
monkeypatch.setattr("agent.models_dev.fetch_models_dev", lambda: {})
monkeypatch.setattr(providers_mod, "HERMES_OVERLAYS", {})
providers = list_authenticated_providers(
current_provider="custom:ollama",
current_base_url="http://localhost:11434/v1",
user_providers={},
custom_providers=[
{"name": "Ollama — GLM 5.1", "base_url": "http://localhost:11434/v1",
"api_key": "ollama", "model": "glm-5.1"},
],
max_models=50,
)
matches = [p for p in providers if p.get("is_user_defined")]
assert len(matches) == 1
group = matches[0]
assert group["slug"] == "custom:ollama"
assert group["is_current"] is True
def test_list_authenticated_providers_bare_custom_slug_recovers(monkeypatch):
"""Regression for #17478: when a prior failed switch left the bare
literal "custom" in model.provider, the picker must NOT propagate
that broken slug. It must fall back to the canonical
``custom:<name>`` form so the picker stays usable."""
monkeypatch.setattr("agent.models_dev.fetch_models_dev", lambda: {})
monkeypatch.setattr(providers_mod, "HERMES_OVERLAYS", {})
@ -314,8 +341,8 @@ def test_list_authenticated_providers_current_endpoint_uses_current_slug(monkeyp
matches = [p for p in providers if p.get("is_user_defined")]
assert len(matches) == 1
group = matches[0]
assert group["slug"] == "custom"
assert group["is_current"] is True
# Canonical slug, NOT the bare "custom" that caused #17478
assert group["slug"] == "custom:ollama"
def test_list_authenticated_providers_distinct_endpoints_stay_separate(monkeypatch):