Salvage follow-up to the previous commit (#114397 by @Finn763): - Codex/Copilot rows went through cached_provider_model_ids directly, so a cold cache on the non-blocking read path rendered an EMPTY Copilot row (live repro: copilot:0). Route them through _live_or_curated_ids like every other built-in so the curated list fills the first open. - Drop the catalog_pending row flag, provider_catalogs_refreshing and _mark_catalogs_pending: no surface consumes it and it would have needed a gateway contract regen. Drop the _spawn_background_warm wrapper: the ollama-cloud row's own SWR refresh already warms that cache. - Z.AI endpoint detection only persists a SUCCESS, so a key that 429s on every endpoint re-ran four chat-completion probes on every credential-pool load (load_pool("zai") runs several times per picker open; the reporter's logs show exactly these repeated POSTs). Memoize the failure in-process for 5 minutes. Copilot already has the same negative cache for its token exchange. - Tests trimmed to two invariants (degraded provider cannot stall the open + row still renders; explicit refresh still probes) plus one for the Z.AI negative cache; a rigid test fake gains **kw for the widened cached_provider_model_ids signature. - Docs: how GUI pickers source per-provider lists and what Refresh does. Live repro (temp HERMES_HOME, five built-ins pointed at a stalling /v1/models stand-in, Z.AI key set): refresh=False 50.5s on origin/main -> 3.7s on this head; without Z.AI 43.7s -> 1.3s.
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
"""Regression tests for OpenCode Zen model picker limits."""
|
|
|
|
import os
|
|
from unittest.mock import patch
|
|
|
|
import hermes_cli.providers as providers_mod
|
|
from hermes_cli.model_switch import list_authenticated_providers
|
|
|
|
|
|
def test_opencode_zen_lists_all_models_while_other_providers_remain_capped(monkeypatch):
|
|
"""OpenCode Zen is an aggregator product, so the picker must expose its full catalog."""
|
|
zen_models = [f"zen-model-{i}" for i in range(57)]
|
|
deepseek_models = [f"deepseek-model-{i}" for i in range(57)]
|
|
|
|
monkeypatch.setattr(
|
|
"agent.models_dev.PROVIDER_TO_MODELS_DEV",
|
|
{
|
|
"opencode-zen": "opencode",
|
|
"deepseek": "deepseek",
|
|
},
|
|
)
|
|
monkeypatch.setattr(
|
|
"agent.models_dev.fetch_models_dev",
|
|
lambda: {"opencode": {}, "deepseek": {}},
|
|
)
|
|
monkeypatch.setattr(providers_mod, "HERMES_OVERLAYS", {})
|
|
monkeypatch.setattr(
|
|
"hermes_cli.models.cached_provider_model_ids",
|
|
lambda provider, **_: {
|
|
"opencode-zen": zen_models,
|
|
"deepseek": deepseek_models,
|
|
}.get(provider, []),
|
|
)
|
|
|
|
with patch.dict(
|
|
os.environ,
|
|
{
|
|
"OPENCODE_ZEN_API_KEY": "test-zen-key",
|
|
"DEEPSEEK_API_KEY": "test-deepseek-key",
|
|
},
|
|
clear=False,
|
|
):
|
|
providers = list_authenticated_providers(max_models=50)
|
|
|
|
opencode_zen = next(p for p in providers if p["slug"] == "opencode-zen")
|
|
deepseek = next(p for p in providers if p["slug"] == "deepseek")
|
|
|
|
assert opencode_zen["models"] == zen_models
|
|
assert opencode_zen["total_models"] == len(zen_models)
|
|
assert deepseek["models"] == deepseek_models[:50]
|
|
assert deepseek["total_models"] == len(deepseek_models)
|