Files
hermes-agent/tests/agent/test_switch_model_reasoning_override.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

127 lines
4.9 KiB
Python

"""Tests for per-model reasoning_effort override during /model switch.
Tests that switch_model:
1. Re-resolves reasoning_config when switching to a model with an override
2. Falls back to global when switching to a model without an override
3. Saves reasoning_config into _primary_runtime for fallback recovery
"""
import pytest
from unittest.mock import MagicMock, patch
class TestSwitchModelReasoningOverride:
"""Test switch_model re-resolves reasoning_config on model switch."""
def _make_fake_agent(self, model="gpt-5", provider="openai"):
"""Create a minimal fake agent for switch_model testing."""
agent = MagicMock()
agent.model = model
agent.provider = provider
agent.base_url = "https://api.openai.com/v1"
agent.api_mode = "openai"
agent.api_key = "test-key"
agent._client_kwargs = {"api_key": "test-key", "base_url": "https://api.openai.com/v1"}
agent._use_prompt_caching = False
agent._use_native_cache_layout = False
agent.reasoning_config = {"enabled": True, "effort": "medium"}
agent._fallback_activated = False
agent._fallback_index = 0
agent._fallback_chain = []
agent._fallback_model = None
agent._config_context_length = None
agent._transport_cache = {}
agent.context_compressor = None
agent._cached_system_prompt = None
agent._anthropic_api_key = ""
agent._anthropic_base_url = None
agent._is_anthropic_oauth = False
agent._anthropic_prompt_cache_policy = MagicMock(
return_value=(False, False)
)
agent._ensure_lmstudio_runtime_loaded = MagicMock()
agent._create_openai_client = MagicMock(return_value=MagicMock())
return agent
def test_primary_runtime_includes_reasoning_config(self):
"""After switch_model, _primary_runtime should contain reasoning_config key."""
from agent.agent_runtime_helpers import switch_model
agent = self._make_fake_agent()
fake_cfg = {
"model": {"default": "claude-opus-4.5"},
"agent": {
"reasoning_effort": "medium",
"reasoning_overrides": {
"claude-opus-4.5": "xhigh",
},
},
}
with patch("hermes_cli.config.load_config", return_value=fake_cfg):
try:
switch_model(
agent,
new_model="claude-opus-4.5",
new_provider="anthropic",
base_url="https://api.anthropic.com",
api_mode="anthropic_messages",
)
except Exception:
# Client creation may fail in test env; check _primary_runtime was set
pass
assert hasattr(agent, "_primary_runtime")
assert "reasoning_config" in agent._primary_runtime
def test_restore_primary_runtime_restores_reasoning(self):
"""restore_primary_runtime should restore reasoning_config from snapshot."""
from agent.agent_runtime_helpers import restore_primary_runtime
agent = MagicMock()
agent._primary_runtime = {
"model": "claude-opus-4.5",
"provider": "anthropic",
"base_url": "https://api.anthropic.com",
"api_mode": "anthropic_messages",
"api_key": "key",
"client_kwargs": {},
"use_prompt_caching": True,
"use_native_cache_layout": False,
"reasoning_config": {"enabled": True, "effort": "xhigh"},
"compressor_model": "claude-opus-4.5",
"compressor_base_url": "",
"compressor_api_key": "",
"compressor_provider": "",
"compressor_context_length": 0,
"compressor_api_mode": "",
"compressor_threshold_tokens": 0,
"anthropic_api_key": "key",
"anthropic_base_url": "https://api.anthropic.com",
"is_anthropic_oauth": False,
}
agent._fallback_activated = True
agent._fallback_index = 0
agent._fallback_chain = []
agent._fallback_model = None
agent._transport_cache = {}
agent._config_context_length = None
agent._rate_limited_until = 0
agent.model = "fallback-model"
agent.provider = "openai"
agent.reasoning_config = {"enabled": True, "effort": "medium"}
agent.context_compressor = MagicMock()
agent.base_url = ""
# Mock the methods restore_primary_runtime calls
agent._anthropic_prompt_cache_policy = MagicMock(return_value=(True, False))
agent._create_openai_client = MagicMock(return_value=MagicMock())
agent._ensure_lmstudio_runtime_loaded = MagicMock()
result = restore_primary_runtime(agent)
assert result is True
assert agent.reasoning_config == {"enabled": True, "effort": "xhigh"}