Skip to content

Commit ac80bd6

Browse files
committed
test: add regression tests for custom_providers multi-model dedup and grouping
Tests for salvaged PRs #9233 and #8011.
1 parent ec9bf9e commit ac80bd6

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

tests/hermes_cli/test_config.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,30 @@ def test_dedup_across_legacy_and_providers(self, tmp_path):
564564
# Legacy entry wins (read first)
565565
assert compatible[0]["api_key"] == "legacy-key"
566566

567+
def test_dedup_preserves_entries_with_different_models(self, tmp_path):
568+
"""Entries with same name+URL but different models must not be collapsed."""
569+
config_path = tmp_path / "config.yaml"
570+
config_path.write_text(
571+
yaml.safe_dump(
572+
{
573+
"_config_version": 17,
574+
"custom_providers": [
575+
{"name": "Ollama Cloud", "base_url": "https://ollama.com/v1", "model": "qwen3-coder"},
576+
{"name": "Ollama Cloud", "base_url": "https://ollama.com/v1", "model": "glm-5.1"},
577+
{"name": "Ollama Cloud", "base_url": "https://ollama.com/v1", "model": "kimi-k2.5"},
578+
],
579+
}
580+
),
581+
encoding="utf-8",
582+
)
583+
584+
with patch.dict(os.environ, {"HERMES_HOME": str(tmp_path)}):
585+
compatible = get_compatible_custom_providers()
586+
587+
assert len(compatible) == 3
588+
models = [e.get("model") for e in compatible]
589+
assert models == ["qwen3-coder", "glm-5.1", "kimi-k2.5"]
590+
567591

568592
class TestInterimAssistantMessageConfig:
569593
"""Test the explicit gateway interim-message config gate."""

tests/hermes_cli/test_model_switch_custom_providers.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,57 @@ def test_switch_model_accepts_explicit_named_custom_provider(monkeypatch):
102102
assert result.new_model == "rotator-openrouter-coding"
103103
assert result.base_url == "http://127.0.0.1:4141/v1"
104104
assert result.api_key == "no-key-required"
105+
106+
107+
def test_list_groups_same_name_custom_providers_into_one_row(monkeypatch):
108+
"""Multiple custom_providers entries sharing a name should produce one row
109+
with all models collected, not N duplicate rows."""
110+
monkeypatch.setattr("agent.models_dev.fetch_models_dev", lambda: {})
111+
monkeypatch.setattr(providers_mod, "HERMES_OVERLAYS", {})
112+
113+
providers = list_authenticated_providers(
114+
current_provider="openrouter",
115+
user_providers={},
116+
custom_providers=[
117+
{"name": "Ollama Cloud", "base_url": "https://ollama.com/v1", "model": "qwen3-coder:480b-cloud"},
118+
{"name": "Ollama Cloud", "base_url": "https://ollama.com/v1", "model": "glm-5.1:cloud"},
119+
{"name": "Ollama Cloud", "base_url": "https://ollama.com/v1", "model": "kimi-k2.5"},
120+
{"name": "Ollama Cloud", "base_url": "https://ollama.com/v1", "model": "minimax-m2.7:cloud"},
121+
{"name": "Moonshot", "base_url": "https://api.moonshot.ai/v1", "model": "kimi-k2-thinking"},
122+
],
123+
max_models=50,
124+
)
125+
126+
ollama_rows = [p for p in providers if p["name"] == "Ollama Cloud"]
127+
assert len(ollama_rows) == 1, f"Expected 1 Ollama Cloud row, got {len(ollama_rows)}"
128+
assert ollama_rows[0]["models"] == [
129+
"qwen3-coder:480b-cloud", "glm-5.1:cloud", "kimi-k2.5", "minimax-m2.7:cloud"
130+
]
131+
assert ollama_rows[0]["total_models"] == 4
132+
133+
moonshot_rows = [p for p in providers if p["name"] == "Moonshot"]
134+
assert len(moonshot_rows) == 1
135+
assert moonshot_rows[0]["models"] == ["kimi-k2-thinking"]
136+
137+
138+
def test_list_deduplicates_same_model_in_group(monkeypatch):
139+
"""Duplicate model entries under the same provider name should not produce
140+
duplicate entries in the models list."""
141+
monkeypatch.setattr("agent.models_dev.fetch_models_dev", lambda: {})
142+
monkeypatch.setattr(providers_mod, "HERMES_OVERLAYS", {})
143+
144+
providers = list_authenticated_providers(
145+
current_provider="openrouter",
146+
user_providers={},
147+
custom_providers=[
148+
{"name": "MyProvider", "base_url": "http://localhost:11434/v1", "model": "llama3"},
149+
{"name": "MyProvider", "base_url": "http://localhost:11434/v1", "model": "llama3"},
150+
{"name": "MyProvider", "base_url": "http://localhost:11434/v1", "model": "mistral"},
151+
],
152+
max_models=50,
153+
)
154+
155+
my_rows = [p for p in providers if p["name"] == "MyProvider"]
156+
assert len(my_rows) == 1
157+
assert my_rows[0]["models"] == ["llama3", "mistral"]
158+
assert my_rows[0]["total_models"] == 2

0 commit comments

Comments
 (0)