Skip to content

The agent that grows with you

fix(cli): honor excluded_providers in the TUI /model picker's unconfigured rows

PRATHAMESH7593ca74c3bba0
diff --git a/hermes_cli/inventory.py b/hermes_cli/inventory.py
index 34cbd278773..2175b781e8b 100644
--- a/hermes_cli/inventory.py
+++ b/hermes_cli/inventory.py
@@ -692,15 +692,26 @@ def _append_unconfigured_rows(
"""Empty setup skeletons for canonical providers missing from ``rows`` — except the *current* one:
if config.yaml still points at it but credentials are gone, keep a row carrying the saved model so
GUI pickers don't silently snap to another provider."""
- from hermes_cli.models import _model_requires_account_discovery
+ from hermes_cli.models import _PROVIDER_ALIASES, _model_requires_account_discovery
from hermes_cli.models_catalog_static import listed_canonical_providers
seen = {r["slug"].lower() for r in rows}
cur = (ctx.current_provider or "").lower()
cur_model = str(ctx.current_model or "").strip()
+ # Honor ``model_catalog.excluded_providers`` like ``list_authenticated_providers`` does — unconditionally,
+ # even for the current provider — or ``include_unconfigured`` pickers (TUI ``/model``) resurrect every
+ # excluded provider as a skeleton row (#68816). A slug is hidden when it or any alias is excluded, so an
+ # alias exclusion (``google`` → ``gemini``) can't leak the canonical row back.
+ excluded = {str(p).strip().lower() for p in (ctx.excluded_providers or []) if p}
+ names_for: dict[str, set[str]] = {}
+ for alias, canon in _PROVIDER_ALIASES.items():
+ names_for.setdefault(canon.lower(), {canon.lower()}).add(alias.lower())
extras: list[dict] = []
for entry in listed_canonical_providers():
- if entry.slug.lower() in seen:
+ slug = entry.slug.lower()
+ if slug in seen:
+ continue
+ if names_for.get(slug, {slug}) & excluded:
continue
if current_only and entry.slug.lower() != cur:
continue
diff --git a/tests/hermes_cli/test_model_picker_excluded_providers.py b/tests/hermes_cli/test_model_picker_excluded_providers.py
index ccc72452fae..e0c6ad4f8a8 100644
--- a/tests/hermes_cli/test_model_picker_excluded_providers.py
+++ b/tests/hermes_cli/test_model_picker_excluded_providers.py
@@ -117,3 +117,106 @@ def test_cli_picker_hides_excluded_provider_by_alias(config_home):
)
+def test_cli_picker_empty_excluded_is_noop(config_home):
+ """An empty ``excluded_providers`` list must not change the menu."""
+ _write_config(config_home, **{"model_catalog": {"excluded_providers": []}})
+ excluded_labels = _capture_provider_labels(config_home)
+
+ _write_config(config_home)
+ baseline_labels = _capture_provider_labels(config_home)
+
+ assert excluded_labels == baseline_labels
+
+
+# ─── include_unconfigured (in-session TUI ``/model``) path ────────────────────
+# The TUI picker calls ``build_models_payload(include_unconfigured=True)``, which
+# appends ``CANONICAL_PROVIDERS`` skeleton rows via ``_append_unconfigured_rows``.
+# That loop must honor ``excluded_providers`` too, or excluded providers reappear
+# in the TUI ``/model`` picker even though ``hermes model`` hides them (#68816).
+
+
+def _picker_ctx(excluded=None, *, current_provider="", current_model=""):
+ from hermes_cli.inventory import ConfigContext
+
+ return ConfigContext(
+ current_provider=current_provider,
+ current_model=current_model,
+ current_base_url="",
+ user_providers={},
+ custom_providers=[],
+ excluded_providers=excluded,
+ )
+
+
+def test_unconfigured_rows_hide_excluded_provider():
+ from hermes_cli.inventory import _append_unconfigured_rows
+
+ baseline = {r["slug"].lower() for r in _append_unconfigured_rows([], _picker_ctx())}
+ assert "openrouter" in baseline, "sanity: openrouter should be a canonical skeleton row"
+
+ slugs = {
+ r["slug"].lower()
+ for r in _append_unconfigured_rows([], _picker_ctx(excluded=["openrouter"]))
+ }
+ assert "openrouter" not in slugs, "excluded provider must not be re-added as a skeleton row"
+ assert slugs == baseline - {"openrouter"}, "only the excluded provider should be removed"
+
+
+def test_unconfigured_rows_exclusion_is_case_insensitive():
+ from hermes_cli.inventory import _append_unconfigured_rows
+
+ slugs = {
+ r["slug"].lower()
+ for r in _append_unconfigured_rows([], _picker_ctx(excluded=["OpenRouter"]))
+ }
+ assert "openrouter" not in slugs
+
+
+def test_unconfigured_rows_hide_excluded_provider_by_alias():
+ """Excluding by an *alias* (not the canonical slug) must also drop the
+ canonical skeleton row, matching ``hermes model`` and
+ ``list_authenticated_providers``. Comparing the raw exclusion strings
+ against ``entry.slug`` alone would leak the canonical row back in."""
+ from hermes_cli.inventory import _append_unconfigured_rows
+ from hermes_cli.models import CANONICAL_PROVIDERS, _PROVIDER_ALIASES
+
+ # Pick an alias whose canonical target is an actual skeleton row.
+ baseline = {r["slug"].lower() for r in _append_unconfigured_rows([], _picker_ctx())}
+ target_slug = None
+ target_alias = None
+ for alias, canon in _PROVIDER_ALIASES.items():
+ if canon and canon.lower() in baseline and any(p.slug == canon for p in CANONICAL_PROVIDERS):
+ target_slug = canon
+ target_alias = alias
+ break
+ if target_slug is None:
+ pytest.skip("no aliased canonical provider present as an unconfigured row")
+
+ slugs = {
+ r["slug"].lower()
+ for r in _append_unconfigured_rows([], _picker_ctx(excluded=[target_alias]))
+ }
+ assert target_slug.lower() not in slugs, (
+ f"excluding alias {target_alias!r} should hide canonical {target_slug!r}; got {slugs}"
+ )
+
+
+def test_unconfigured_rows_exclude_current_provider_matches_cli():
+ """``list_authenticated_providers`` drops an excluded provider even when it is
+ the current one; the skeleton loop must not re-surface it as the
+ ``configured-current`` warning row."""
+ from hermes_cli.inventory import _append_unconfigured_rows
+
+ rows = _append_unconfigured_rows(
+ [], _picker_ctx(excluded=["openrouter"], current_provider="openrouter", current_model="some-model")
+ )
+ assert "openrouter" not in {r["slug"].lower() for r in rows}
+
+
+def test_unconfigured_rows_empty_excluded_is_noop():
+ from hermes_cli.inventory import _append_unconfigured_rows
+
+ base = {r["slug"].lower() for r in _append_unconfigured_rows([], _picker_ctx())}
+ empty = {r["slug"].lower() for r in _append_unconfigured_rows([], _picker_ctx(excluded=[]))}
+ none = {r["slug"].lower() for r in _append_unconfigured_rows([], _picker_ctx(excluded=None))}
+ assert base == empty == none