The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(providers): resolve a plugin alias through the home-aware registry lookup
Teknium5dca2def3a36
diff --git a/hermes_cli/providers.py b/hermes_cli/providers.pyindex 157c2c4c669..0c323e36f7c 100644--- a/hermes_cli/providers.py+++ b/hermes_cli/providers.py@@ -263,15 +263,18 @@ def _plugin_alias_owner(canonical: str) -> str:``azure-foundry``) otherwise resolved to the bare models.dev entry whenever the catalogloaded and to the plugin when it did not, so ``--provider meta`` persisted a differentprovider depending on the network. ``hermes_cli.auth.resolve_provider`` already answers the- plugin id. Built-in ids and overlay profiles keep what ``normalize_provider`` gave them."""+ plugin id. Built-in ids and overlay profiles keep what ``normalize_provider`` gave them.+ The owner comes from the registry's own lookup, so the bound home's plugin claiming the alias+ wins over a bundled one, exactly as ``get_provider_profile`` would pick it."""if not canonical or _is_static_canonical(canonical):return canonical- from providers import list_providers- profiles = list_providers()- if any(prof.name == canonical for prof in profiles):+ from providers import get_provider_profile, list_providers+ if any(prof.name == canonical for prof in list_providers()):+ return canonical+ owner = get_provider_profile(canonical)+ if owner is None or canonical not in owner.aliases or owner.provider_overlay:return canonical- owner = next((prof for prof in profiles if canonical in prof.aliases), None)- return owner.name if owner is not None and not owner.provider_overlay else canonical+ return owner.namedef get_provider(name: str, *, allow_network: bool = True) -> Optional[ProviderDef]:diff --git a/tests/hermes_cli/test_provider_plugin_alias_identity.py b/tests/hermes_cli/test_provider_plugin_alias_identity.pyindex 54242fbbb3e..c0839db0cb0 100644--- a/tests/hermes_cli/test_provider_plugin_alias_identity.py+++ b/tests/hermes_cli/test_provider_plugin_alias_identity.py@@ -51,3 +51,56 @@ def test_user_provider_named_like_the_alias_still_wins(monkeypatch):assert pdef is not Noneassert pdef.base_url == "https://relay.example.com/v1"assert pdef.id != "meta-ai"+++_HOME_PLUGIN = '''+from providers import register_provider+from providers.base import ProviderProfile++register_provider(ProviderProfile(name="my-meta", aliases=("meta",), auth_type="api_key",+ env_vars=("MY_META_KEY",), base_url="https://relay.invalid/v1"))+'''+++def home_with_meta_plugin(tmp_path, monkeypatch):+ import sys++ import providers+ from hermes_cli import auth_plugin_providers as app+ from hermes_cli.auth import PROVIDER_REGISTRY+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override++ plugin = tmp_path / "plugins" / "model-providers" / "my-meta"+ plugin.mkdir(parents=True)+ (plugin / "__init__.py").write_text(_HOME_PLUGIN, encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ monkeypatch.setattr(providers, "_REGISTRY", dict(providers._REGISTRY))+ monkeypatch.setattr(providers, "_ALIASES", dict(providers._ALIASES))+ monkeypatch.setattr(providers, "_PROVIDER_LIST_CACHE", None)+ monkeypatch.setattr(providers, "_HOME_LAYERS", {})+ monkeypatch.setattr(providers, "_PLUGIN_DIR_STAMP_TTL_SECONDS", 0.0)+ monkeypatch.setattr(app, "PLUGIN_MIRRORED_PROVIDERS", set(app.PLUGIN_MIRRORED_PROVIDERS))+ rows = list(dict.items(PROVIDER_REGISTRY))+ token = set_hermes_home_override(tmp_path)+ yield+ reset_hermes_home_override(token)+ PROVIDER_REGISTRY.clear()+ PROVIDER_REGISTRY.update(rows)+ for mod in [m for m in sys.modules if m.startswith("_hermes_user_provider")]:+ del sys.modules[mod]++[email protected]("registry", [_CATALOG, {}], ids=["catalog", "offline"])+def test_home_plugin_claiming_the_alias_wins_over_the_bundled_one(monkeypatch, home_with_meta_plugin, registry):+ """The registry picks the home's plugin for an alias it declares; resolution must agree."""+ from providers import get_provider_profile++ monkeypatch.setattr("agent.models_dev.fetch_models_dev", lambda *a, **k: registry)++ pdef = resolve_provider_full("meta")++ assert get_provider_profile("meta").name == "my-meta"+ assert pdef is not None+ assert pdef.id == "my-meta"+ assert pdef.base_url == "https://relay.invalid/v1"