The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): model-switch validation trusts a profile-owned catalog
teknium1ce6f064ec36a
diff --git a/hermes_cli/models_validate.py b/hermes_cli/models_validate.pyindex 7e98b402b5a..4a39d15db4f 100644--- a/hermes_cli/models_validate.py+++ b/hermes_cli/models_validate.py@@ -437,11 +437,26 @@ def _nous_portal_recommended_names() -> set[str]:return set()+def _profile_owns_catalog(normalized: str) -> bool:+ """True when the registered profile's catalog is not the generic ``{base_url}/models`` listing —+ it overrides ``fetch_models`` or points ``models_url`` elsewhere — so that listing is not+ authoritative for it (a relay may 200 with a different product catalog, #101705)."""+ from providers import get_provider_profile+ from providers.base import ProviderProfile++ profile = get_provider_profile(normalized)+ return profile is not None and (+ type(profile).fetch_models is not ProviderProfile.fetch_models or bool(profile.models_url))++def _validate_live_listing(req: _Request) -> Optional[dict[str, Any]]:"""Generic live /v1/models probe. Returns None when the API was unreachable (the caller then- tries Bedrock discovery / the curated catalog)."""+ tries Bedrock discovery / the curated catalog). A profile that owns its catalog is validated+ against that catalog (``provider_model_ids`` — the picker's list) before the generic listing."""from hermes_cli import models as _m+ if _profile_owns_catalog(req.normalized) and _match_in_catalog(req.lookup, _static_catalog(req.normalized)).exact:+ return _accept()api_models = _m.fetch_api_models(req.api_key, req.base_url)if api_models is None:return Nonediff --git a/tests/hermes_cli/test_setup_provider_catalog.py b/tests/hermes_cli/test_setup_provider_catalog.pyindex f0d16c00e41..db87d617ed8 100644--- a/tests/hermes_cli/test_setup_provider_catalog.py+++ b/tests/hermes_cli/test_setup_provider_catalog.py@@ -115,3 +115,26 @@ def test_setup_matches_picker_when_catalog_fetch_fails(monkeypatch):profile.name, SimpleNamespace(name="Down"), "synthetic-test-key", "", profile.base_url)assert setup_rows == ["declared-a", "declared-b"] == models.provider_model_ids(profile.name)+++def test_switch_validation_trusts_profile_owned_catalog(monkeypatch):+ """A plugin whose ``fetch_models`` is the catalog (#101705): the model the picker offers is+ accepted even when the generic ``/v1/models`` 200s with a different product catalog; a model in+ neither is still rejected."""+ import providers+ from providers.base import ProviderProfile+ from hermes_cli import models, models_validate++ class PlanProfile(ProviderProfile):+ def fetch_models(self, *, api_key=None, base_url=None, timeout=8.0):+ return ["plan/model-1"]++ profile = PlanProfile(name="scout-plan", auth_type="api_key", env_vars=("SCOUT_PLAN_TEST_KEY",),+ base_url="https://plan.example.invalid/v1")+ monkeypatch.setitem(providers._REGISTRY, profile.name, profile)+ monkeypatch.setattr(models, "_api_key_credentials", lambda *_: ("synthetic-test-key", ""))+ monkeypatch.setattr(models, "fetch_api_models", lambda *_a, **_k: ["other-vendor/model-a"])++ kw = dict(provider=profile.name, api_key="synthetic-test-key", base_url=profile.base_url)+ assert models_validate.validate_requested_model("plan/model-1", **kw)["accepted"] is True+ assert models_validate.validate_requested_model("plan/model-9", **kw)["accepted"] is False