The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(model-switch): pin --provider ownership of direct aliases
teknium1af80401f4e45
diff --git a/tests/hermes_cli/test_ollama_cloud_auth.py b/tests/hermes_cli/test_ollama_cloud_auth.pyindex 56733adc05d..858714cda43 100644--- a/tests/hermes_cli/test_ollama_cloud_auth.py+++ b/tests/hermes_cli/test_ollama_cloud_auth.py@@ -284,3 +284,59 @@ class TestSwitchModelDirectAliasOverride:assert result.successassert result.api_key == "no-key-required"assert result.base_url == "http://localhost:11434/v1"++ @staticmethod+ def _explicit_switch_to_provider_b(monkeypatch, aliases):+ """``/model shared-model --provider provider-b`` against a real config.yaml, with the+ given direct aliases loaded. Only model validation is stubbed (no network)."""+ import os+ from pathlib import Path++ import hermes_cli.model_switch as ms+ from hermes_cli.config import load_config++ monkeypatch.setenv("PROVIDER_B_KEY", "sk-provider-b")+ (Path(os.environ["HERMES_HOME"]) / "config.yaml").write_text(+ "model:\n provider: provider-a\n default: old-model\n"+ "providers:\n"+ " provider-a:\n base_url: https://api-a.example.com/v1\n"+ " provider-b:\n base_url: https://api-b.example.com/v1\n key_env: PROVIDER_B_KEY\n")+ monkeypatch.setattr(ms, "DIRECT_ALIASES", aliases)+ monkeypatch.setattr("hermes_cli.models_validate.validate_requested_model",+ lambda *a, **kw: {"accepted": True, "persist": True, "recognized": True, "message": None})+ return ms.switch_model(+ "shared-model", "provider-a", "old-model",+ current_base_url="https://api-a.example.com/v1", current_api_key="sk-provider-a",+ explicit_provider="provider-b", user_providers=load_config()["providers"])++ def test_explicit_provider_never_adopts_alias_bound_to_another_provider(self, monkeypatch):+ """An alias on another provider's endpoint that targets the same model id must not+ outrank --provider: the turn and the credential stay on the provider the user named."""+ from hermes_cli.model_switch import DirectAlias++ result = self._explicit_switch_to_provider_b(monkeypatch, {+ "a-alias": DirectAlias("shared-model", "custom", "https://alias-host.example.com/v1",+ api_key="sk-alias-host"),+ })++ assert result.success, result.error_message+ assert result.target_provider == "provider-b"+ assert result.base_url == "https://api-b.example.com/v1"+ assert result.api_key == "sk-provider-b"+ assert result.resolved_via_alias == ""++ def test_explicit_provider_prefers_its_own_alias_for_a_shared_model(self, monkeypatch):+ """Several aliases expose one model id: the one owned by the named provider wins,+ whatever the mapping order (provider spelling is normalized)."""+ from hermes_cli.model_switch import DirectAlias++ result = self._explicit_switch_to_provider_b(monkeypatch, {+ "a-alias": DirectAlias("shared-model", "custom", "https://alias-host.example.com/v1",+ api_key="sk-alias-host"),+ "b-alias": DirectAlias("shared-model", "Provider-B", "https://api-b.example.com/v2"),+ })++ assert result.success, result.error_message+ assert result.resolved_via_alias == "b-alias"+ assert result.base_url == "https://api-b.example.com/v2"+ assert result.api_key != "sk-alias-host"