The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(model): cover numeric YAML provider keys in picker and CRUD
Brooklyn Nicholson2119ed7b4af9
diff --git a/tests/hermes_cli/test_inventory.py b/tests/hermes_cli/test_inventory.pyindex 1441beaa84d..b4bf1fb92a1 100644--- a/tests/hermes_cli/test_inventory.py+++ b/tests/hermes_cli/test_inventory.py@@ -40,8 +40,34 @@ def _cfg(model=None, providers=None, custom_providers=None) -> dict:}+def test_load_picker_context_coerces_numeric_yaml_provider():+ """PyYAML parses unquoted `provider: 2070` as int; picker context must be str.-+ Desktop GET /api/model/options crashed when a custom endpoint was named+ after a GPU: current_provider.strip() and providers dict keys .lower().+ """+ cfg = _cfg(+ model={+ "provider": 2070,+ "default": "Qwen3.5-9B-Q4_K_M.gguf",+ "base_url": "http://192.168.1.10:8082/v1",+ },+ providers={+ 2070: {+ "name": 2070,+ "base_url": "http://192.168.1.10:8082/v1",+ "model": "Qwen3.5-9B-Q4_K_M.gguf",+ }+ },+ )+ with patch("hermes_cli.config.load_config", return_value=cfg):+ ctx = load_picker_context()+ assert ctx.current_provider == "2070"+ assert isinstance(ctx.current_provider, str)+ assert list(ctx.user_providers) == ["2070"]+ assert all(isinstance(k, str) for k in ctx.user_providers)+ assert ctx.current_model == "Qwen3.5-9B-Q4_K_M.gguf"+ assert ctx.current_base_url == "http://192.168.1.10:8082/v1"# ─── with_overrides ────────────────────────────────────────────────────diff --git a/tests/hermes_cli/test_model_switch_custom_providers.py b/tests/hermes_cli/test_model_switch_custom_providers.pyindex 8e3822316e5..0a42a3795c2 100644--- a/tests/hermes_cli/test_model_switch_custom_providers.py+++ b/tests/hermes_cli/test_model_switch_custom_providers.py@@ -116,6 +116,61 @@ def test_list_authenticated_providers_includes_custom_providers(monkeypatch):+def test_list_authenticated_providers_numeric_yaml_provider_dict_key(monkeypatch):+ """Unquoted YAML `providers: {2070: ...}` must not 500 the Model tab."""+ monkeypatch.setattr("agent.models_dev.fetch_models_dev", lambda: {})+ monkeypatch.setattr(providers_mod, "HERMES_OVERLAYS", {})+ monkeypatch.setattr("hermes_cli.models.fetch_api_models", lambda *a, **k: [])++ rows = list_authenticated_providers(+ current_provider=2070,+ current_base_url="http://192.168.1.10:8082/v1",+ current_model="Qwen3.5-9B-Q4_K_M.gguf",+ user_providers={+ 2070: {+ "name": 2070,+ "base_url": "http://192.168.1.10:8082/v1",+ "model": "Qwen3.5-9B-Q4_K_M.gguf",+ }+ },+ custom_providers=[],+ max_models=0,+ probe_custom_providers=False,+ )++ match = next(p for p in rows if str(p.get("slug")) == "2070")+ assert match["name"] == "2070"+ assert match.get("is_current") is True+++def test_list_authenticated_providers_numeric_custom_provider_name(monkeypatch):+ """Legacy custom_providers list with name: 2070 (int) must not .strip() crash."""+ monkeypatch.setattr("agent.models_dev.fetch_models_dev", lambda: {})+ monkeypatch.setattr(providers_mod, "HERMES_OVERLAYS", {})+ monkeypatch.setattr("hermes_cli.models.fetch_api_models", lambda *a, **k: [])++ rows = list_authenticated_providers(+ current_provider=2070,+ current_base_url="http://192.168.1.10:8082/v1",+ current_model="Qwen3.5-9B-Q4_K_M.gguf",+ user_providers={},+ custom_providers=[+ {+ "name": 2070,+ "base_url": "http://192.168.1.10:8082/v1",+ "model": "Qwen3.5-9B-Q4_K_M.gguf",+ }+ ],+ max_models=0,+ probe_custom_providers=False,+ )++ assert any(+ str(p.get("name")) == "2070" or "2070" in str(p.get("slug"))+ for p in rows+ )++def test_providers_singular_model_does_not_suppress_ollama_native_discovery(monkeypatch):"""A saved selection in ``providers:`` is not an explicit catalog."""monkeypatch.setattr("agent.models_dev.fetch_models_dev", lambda: {})diff --git a/tests/hermes_cli/test_provider_config_validation.py b/tests/hermes_cli/test_provider_config_validation.pyindex c022ddcfbc8..892a8876c62 100644--- a/tests/hermes_cli/test_provider_config_validation.py+++ b/tests/hermes_cli/test_provider_config_validation.py@@ -68,3 +68,23 @@ class TestNormalizeCustomProviderEntry:assert result["base_url"] == "${PROVIDER_A_BASE_URL}"+ def test_numeric_yaml_name_and_key_become_strings(self):+ """Unquoted YAML `name: 2070` / key 2070 must not be dropped as non-str."""+ from hermes_cli.config import find_provider_entry, stringify_provider_map++ result = _normalize_custom_provider_entry(+ {"name": 2070, "base_url": "http://192.168.1.10:8082/v1"},+ provider_key=2070,+ )+ assert result is not None+ assert result["name"] == "2070"+ assert result["provider_key"] == "2070"++ mapped = stringify_provider_map({2070: {"base_url": "http://x"}})+ assert list(mapped) == ["2070"]++ stored, entry = find_provider_entry({2070: {"base_url": "http://x"}}, "2070")+ assert stored == 2070+ assert entry == {"base_url": "http://x"}++diff --git a/tests/hermes_cli/test_web_server.py b/tests/hermes_cli/test_web_server.pyindex d7b63608984..d6feee8ab68 100644--- a/tests/hermes_cli/test_web_server.py+++ b/tests/hermes_cli/test_web_server.py@@ -1742,6 +1742,46 @@ class TestWebServerEndpoints:assert not get_env_value(env_var), "deleted endpoint's key still in .env"+ def test_numeric_yaml_provider_key_can_be_activated_and_deleted(self):+ """Hand-edited `providers: 2070:` (YAML int key) must still activate.++ PyYAML loads unquoted 2070 as int; string lookup then 404ed, so+ Desktop could list the endpoint but not assign or delete it.+ """+ from hermes_cli.config import get_config_path, load_config++ get_config_path().write_text(+ "model:\n"+ " provider: 2070\n"+ " default: Qwen.gguf\n"+ " base_url: http://192.168.1.10:8082/v1\n"+ "providers:\n"+ " 2070:\n"+ " name: 2070\n"+ " base_url: http://192.168.1.10:8082/v1\n"+ " model: Qwen.gguf\n",+ encoding="utf-8",+ )++ listed = self.client.get("/api/providers/custom-endpoints")+ assert listed.status_code == 200+ assert "2070" in [e["id"] for e in listed.json()["endpoints"]]++ activate = self.client.post(+ "/api/providers/custom-endpoints/2070/activate", json={}+ )+ assert activate.status_code == 200, activate.text+ assert activate.json()["provider"] == "2070"++ deleted = self.client.request(+ "DELETE", "/api/providers/custom-endpoints/2070"+ )+ assert deleted.status_code == 200, deleted.text+ providers = load_config().get("providers") or {}+ assert 2070 not in providers+ assert "2070" not in providers++def test_custom_endpoint_save_scopes_to_the_requested_profile(self):"""``?profile=<name>`` must write into that profile's config.yaml.