|
| 1 | +"""Tests for hermes_cli.model_normalize — provider-aware model name normalization. |
| 2 | +
|
| 3 | +Covers issue #5211: opencode-go model names with dots (e.g. minimax-m2.7) |
| 4 | +must NOT be mangled to hyphens (minimax-m2-7). |
| 5 | +""" |
| 6 | +import pytest |
| 7 | + |
| 8 | +from hermes_cli.model_normalize import ( |
| 9 | + normalize_model_for_provider, |
| 10 | + _DOT_TO_HYPHEN_PROVIDERS, |
| 11 | + _AGGREGATOR_PROVIDERS, |
| 12 | + detect_vendor, |
| 13 | +) |
| 14 | + |
| 15 | + |
| 16 | +# ── Regression: issue #5211 ──────────────────────────────────────────── |
| 17 | + |
| 18 | +class TestIssue5211OpenCodeGoDotPreservation: |
| 19 | + """OpenCode Go model names with dots must pass through unchanged.""" |
| 20 | + |
| 21 | + @pytest.mark.parametrize("model,expected", [ |
| 22 | + ("minimax-m2.7", "minimax-m2.7"), |
| 23 | + ("minimax-m2.5", "minimax-m2.5"), |
| 24 | + ("glm-4.5", "glm-4.5"), |
| 25 | + ("kimi-k2.5", "kimi-k2.5"), |
| 26 | + ("some-model-1.0.3", "some-model-1.0.3"), |
| 27 | + ]) |
| 28 | + def test_opencode_go_preserves_dots(self, model, expected): |
| 29 | + result = normalize_model_for_provider(model, "opencode-go") |
| 30 | + assert result == expected, f"Expected {expected!r}, got {result!r}" |
| 31 | + |
| 32 | + def test_opencode_go_not_in_dot_to_hyphen_set(self): |
| 33 | + """opencode-go must NOT be in the dot-to-hyphen provider set.""" |
| 34 | + assert "opencode-go" not in _DOT_TO_HYPHEN_PROVIDERS |
| 35 | + |
| 36 | + |
| 37 | +# ── Anthropic dot-to-hyphen conversion (regression) ──────────────────── |
| 38 | + |
| 39 | +class TestAnthropicDotToHyphen: |
| 40 | + """Anthropic API still needs dots→hyphens.""" |
| 41 | + |
| 42 | + @pytest.mark.parametrize("model,expected", [ |
| 43 | + ("claude-sonnet-4.6", "claude-sonnet-4-6"), |
| 44 | + ("claude-opus-4.5", "claude-opus-4-5"), |
| 45 | + ]) |
| 46 | + def test_anthropic_converts_dots(self, model, expected): |
| 47 | + result = normalize_model_for_provider(model, "anthropic") |
| 48 | + assert result == expected |
| 49 | + |
| 50 | + def test_anthropic_strips_vendor_prefix(self): |
| 51 | + result = normalize_model_for_provider("anthropic/claude-sonnet-4.6", "anthropic") |
| 52 | + assert result == "claude-sonnet-4-6" |
| 53 | + |
| 54 | + |
| 55 | +# ── OpenCode Zen regression ──────────────────────────────────────────── |
| 56 | + |
| 57 | +class TestOpenCodeZenDotToHyphen: |
| 58 | + """OpenCode Zen follows Anthropic convention (dots→hyphens).""" |
| 59 | + |
| 60 | + @pytest.mark.parametrize("model,expected", [ |
| 61 | + ("claude-sonnet-4.6", "claude-sonnet-4-6"), |
| 62 | + ("glm-4.5", "glm-4-5"), |
| 63 | + ]) |
| 64 | + def test_zen_converts_dots(self, model, expected): |
| 65 | + result = normalize_model_for_provider(model, "opencode-zen") |
| 66 | + assert result == expected |
| 67 | + |
| 68 | + def test_zen_strips_vendor_prefix(self): |
| 69 | + result = normalize_model_for_provider("opencode-zen/claude-sonnet-4.6", "opencode-zen") |
| 70 | + assert result == "claude-sonnet-4-6" |
| 71 | + |
| 72 | + |
| 73 | +# ── Copilot dot preservation (regression) ────────────────────────────── |
| 74 | + |
| 75 | +class TestCopilotDotPreservation: |
| 76 | + """Copilot preserves dots in model names.""" |
| 77 | + |
| 78 | + @pytest.mark.parametrize("model,expected", [ |
| 79 | + ("claude-sonnet-4.6", "claude-sonnet-4.6"), |
| 80 | + ("gpt-5.4", "gpt-5.4"), |
| 81 | + ]) |
| 82 | + def test_copilot_preserves_dots(self, model, expected): |
| 83 | + result = normalize_model_for_provider(model, "copilot") |
| 84 | + assert result == expected |
| 85 | + |
| 86 | + |
| 87 | +# ── Aggregator providers (regression) ────────────────────────────────── |
| 88 | + |
| 89 | +class TestAggregatorProviders: |
| 90 | + """Aggregators need vendor/model slugs.""" |
| 91 | + |
| 92 | + def test_openrouter_prepends_vendor(self): |
| 93 | + result = normalize_model_for_provider("claude-sonnet-4.6", "openrouter") |
| 94 | + assert result == "anthropic/claude-sonnet-4.6" |
| 95 | + |
| 96 | + def test_nous_prepends_vendor(self): |
| 97 | + result = normalize_model_for_provider("gpt-5.4", "nous") |
| 98 | + assert result == "openai/gpt-5.4" |
| 99 | + |
| 100 | + def test_vendor_already_present(self): |
| 101 | + result = normalize_model_for_provider("anthropic/claude-sonnet-4.6", "openrouter") |
| 102 | + assert result == "anthropic/claude-sonnet-4.6" |
| 103 | + |
| 104 | + |
| 105 | +# ── detect_vendor ────────────────────────────────────────────────────── |
| 106 | + |
| 107 | +class TestDetectVendor: |
| 108 | + @pytest.mark.parametrize("model,expected", [ |
| 109 | + ("claude-sonnet-4.6", "anthropic"), |
| 110 | + ("gpt-5.4-mini", "openai"), |
| 111 | + ("minimax-m2.7", "minimax"), |
| 112 | + ("glm-4.5", "z-ai"), |
| 113 | + ("kimi-k2.5", "moonshotai"), |
| 114 | + ]) |
| 115 | + def test_detects_known_vendors(self, model, expected): |
| 116 | + assert detect_vendor(model) == expected |
0 commit comments