Files
hermes-agent/tests/hermes_cli/test_startup_model_routing.py
T
teknium1 d10bb2ab6f test: make tests/ mirror the source tree; drop issue numbers from filenames
`scripts/run_tests.sh tests/<dir>/` is how a change gets its regression
coverage run, so a test filed under the wrong directory is a test nobody
runs when that code changes. Two kinds of drift had accumulated.

Parallel directories for one source package, folded into the mirror:
  tests/acp        -> tests/acp_adapter   (its __init__/conftest move with it)
  tests/cli        -> tests/hermes_cli    (prompt_toolkit fixture merged into
                                           hermes_cli/conftest.py)
  tests/run_agent  -> tests/agent         (backoff fixture becomes
                                           agent/conftest.py)
  tests/relay      -> tests/gateway/relay
  tests/state      -> tests/hermes_state

246 loose files at tests/ root, routed by the package they import/patch:
hermes_cli, hermes_state, agent, gateway, tools, plugins, tui_gateway, cron.
Installer and desktop-update script tests go to tests/scripts/{install,
desktop_update}/. 43 tests of root-level modules (batch_runner, utils,
hermes_constants, packaging) stay at the root.

Filenames drop their issue numbers (95 files: test_89315_x.py -> test_x.py);
the number stays in the module docstring where it has context.

Collisions: test_cli_skin_integration.py existed in both tests/ and tests/cli
with different subsets — merged into one (10 tests, all kept);
run_agent/test_pre_compress_memory_context.py -> agent/..._handoff.py;
tests/test_account_usage.py -> agent/test_account_usage_fetch.py;
tests/test_web_server.py -> hermes_cli/test_web_server_ws_ping.py.
Deleted: test_minisweagent_path.py (empty since PR #2804),
test_model_picker_scroll.py (tested a private copy of the logic, imported
nothing), test_process_loop_event_loop_warning.py (asserted asyncio behaviour,
imported nothing from Hermes).

Repo-root path arithmetic (Path(__file__).parents[N], dirname chains) is
bumped for the 202 files that changed depth and verified by evaluating every
such expression against the new location. classify_changes' desktop-updater
lane prefix, tests-os.yml's ignore glob and every in-tree path comment follow
the moves. tests/test_tests_tree_layout.py keeps the tree from drifting back.
2026-09-13 09:18:02 -07:00

152 lines
5.2 KiB
Python

"""Regression tests for startup model/provider routing (#87189)."""
from hermes_cli import model_switch
def test_startup_route_uses_configured_nous_provider(monkeypatch):
monkeypatch.setattr(model_switch, "DIRECT_ALIASES", {})
route = model_switch.resolve_startup_model_route(
"nous/deepseek-v4-pro",
user_providers={"nous": {"base_url": "https://inference.example/v1"}},
)
assert route == model_switch.StartupModelRoute("deepseek-v4-pro", "nous", "")
def test_startup_route_keeps_configured_custom_provider_name(monkeypatch):
monkeypatch.setattr(model_switch, "DIRECT_ALIASES", {})
route = model_switch.resolve_startup_model_route(
"ollama/qwen3.5:4b",
user_providers={"ollama": {"base_url": "http://localhost:11434/v1"}},
)
assert route == model_switch.StartupModelRoute("qwen3.5:4b", "ollama", "")
def test_startup_route_does_not_consume_aggregator_namespace(monkeypatch):
monkeypatch.setattr(model_switch, "DIRECT_ALIASES", {})
route = model_switch.resolve_startup_model_route(
"openrouter/anthropic/claude-sonnet",
user_providers={"openrouter": {"base_url": "https://openrouter.ai/api/v1"}},
)
assert route is None
def test_startup_route_aggregator_native_slug_stays_on_aggregator(monkeypatch):
"""On OpenRouter, ``anthropic/claude-...`` is an aggregator-native slug.
A ``providers.anthropic`` block in the same config must NOT steal the
route — bare vendor slugs resolve WITHIN the aggregator first
(aggregator-aware resolution contract).
"""
monkeypatch.setattr(model_switch, "DIRECT_ALIASES", {})
monkeypatch.setattr(
"hermes_cli.models._find_openrouter_slug",
lambda name: "anthropic/claude-opus-4.6",
)
route = model_switch.resolve_startup_model_route(
"anthropic/claude-opus-4.6",
current_provider="openrouter",
user_providers={"anthropic": {"apiKey": "sk-test"}},
)
assert route is None
def test_startup_route_non_aggregator_current_provider_still_routes(monkeypatch):
monkeypatch.setattr(model_switch, "DIRECT_ALIASES", {})
route = model_switch.resolve_startup_model_route(
"nous/deepseek-v4-pro",
current_provider="anthropic",
user_providers={"nous": {"base_url": "https://inference.example/v1"}},
)
assert route == model_switch.StartupModelRoute("deepseek-v4-pro", "nous", "")
def test_startup_route_resolves_dict_alias_and_preserves_endpoint(monkeypatch):
monkeypatch.setattr(
model_switch,
"DIRECT_ALIASES",
{
"localqwen": model_switch.DirectAlias(
"qwen3.5:4b", "custom", "http://localhost:11434/v1"
)
},
)
route = model_switch.resolve_startup_model_route("localqwen")
assert route == model_switch.StartupModelRoute(
"qwen3.5:4b", "custom", "http://localhost:11434/v1"
)
def test_startup_route_url_alias_never_keeps_foreign_provider_label(monkeypatch):
"""A URL-bearing alias labelled ``anthropic`` must resolve as ``custom``.
Keeping the label would let the alias reach the anthropic
explicit-runtime branch with a foreign base_url and put the live vendor
token on the alias host's wire (#28660 / #83612).
"""
monkeypatch.setattr(
model_switch,
"DIRECT_ALIASES",
{
"urlalias": model_switch.DirectAlias(
"qwen3.5:4b", "anthropic", "http://localhost:11434/v1"
)
},
)
route = model_switch.resolve_startup_model_route("urlalias")
assert route is not None
assert route.provider == "custom"
assert route.base_url == "http://localhost:11434/v1"
def test_startup_route_alias_carries_own_api_key(monkeypatch):
monkeypatch.setattr(
model_switch,
"DIRECT_ALIASES",
{
"keyed": model_switch.DirectAlias(
"some-model",
"custom",
"https://proxy.example/v1",
api_key="sk-alias-key",
)
},
)
route = model_switch.resolve_startup_model_route("keyed")
assert route is not None
assert route.api_key == "sk-alias-key"
def test_startup_route_explicit_provider_wins_over_alias_label(monkeypatch):
monkeypatch.setattr(
model_switch,
"DIRECT_ALIASES",
{"ds": model_switch.DirectAlias("deepseek-chat", "deepseek", "")},
)
route = model_switch.resolve_startup_model_route(
"ds", explicit_provider="openrouter"
)
assert route is not None
assert route.provider == "openrouter"
assert route.model == "deepseek-chat"
def test_model_aliases_dict_entries_are_loaded(monkeypatch):
monkeypatch.setattr(
"hermes_cli.config.load_config",
lambda: {
"model": {
"aliases": {
"localqwen": {
"model": "qwen3.5:4b",
"provider": "custom",
"base_url": "http://localhost:11434/v1",
}
}
}
},
)
aliases = model_switch._load_direct_aliases()
assert aliases["localqwen"] == model_switch.DirectAlias(
"qwen3.5:4b", "custom", "http://localhost:11434/v1"
)