/ tests / hermes_cli / test_opencode_go_in_model_list.py
test_opencode_go_in_model_list.py
 1  """Test that opencode-go appears in /model list when credentials are set."""
 2  
 3  import os
 4  from unittest.mock import patch
 5  
 6  from hermes_cli.model_switch import list_authenticated_providers
 7  
 8  
 9  # Minimum set of models that must be present for opencode-go no matter
10  # whether the picker sourced its list from curated-only or curated+models.dev.
11  # The curated list in hermes_cli/models.py defines the floor; models.dev only
12  # ever adds names on top of it via _merge_with_models_dev.
13  _OPENCODE_GO_REQUIRED = {
14      "kimi-k2.6",
15      "kimi-k2.5",
16      "glm-5.1",
17      "glm-5",
18      "mimo-v2-pro",
19      "mimo-v2-omni",
20      "minimax-m2.7",
21      "minimax-m2.5",
22  }
23  
24  
25  @patch.dict(os.environ, {"OPENCODE_GO_API_KEY": "test-key"}, clear=False)
26  def test_opencode_go_appears_when_api_key_set():
27      """opencode-go should appear in list_authenticated_providers when OPENCODE_GO_API_KEY is set."""
28      providers = list_authenticated_providers(current_provider="openrouter", max_models=50)
29  
30      # Find opencode-go in results
31      opencode_go = next((p for p in providers if p["slug"] == "opencode-go"), None)
32  
33      assert opencode_go is not None, "opencode-go should appear when OPENCODE_GO_API_KEY is set"
34      # Behavior check: the curated floor must be present. The list may also
35      # include extra models.dev entries (e.g. mimo-v2.5-pro) when the registry
36      # is reachable — that's the whole point of the models.dev-preferred merge
37      # introduced for opencode-go, so don't pin to an exact list here.
38      present = set(opencode_go["models"])
39      missing = _OPENCODE_GO_REQUIRED - present
40      assert not missing, (
41          f"opencode-go picker should include the curated floor; missing: {sorted(missing)}. "
42          f"Got: {opencode_go['models']}"
43      )
44      # opencode-go can appear as "built-in" (from PROVIDER_TO_MODELS_DEV when
45      # models.dev is reachable) or "hermes" (from HERMES_OVERLAYS fallback when
46      # the API is unavailable, e.g. in CI).
47      assert opencode_go["source"] in ("built-in", "hermes")
48  
49  
50  def test_opencode_go_not_appears_when_no_creds():
51      """opencode-go should NOT appear when no credentials are set."""
52      # Ensure OPENCODE_GO_API_KEY is not set
53      env_without_key = {k: v for k, v in os.environ.items() if k != "OPENCODE_GO_API_KEY"}
54  
55      with patch.dict(os.environ, env_without_key, clear=True):
56          providers = list_authenticated_providers(current_provider="openrouter")
57  
58          # opencode-go should not be in results
59          opencode_go = next((p for p in providers if p["slug"] == "opencode-go"), None)
60          assert opencode_go is None, "opencode-go should not appear without credentials"