Files
hermes-agent/tests/tui_gateway/test_reasoning_config_per_model.py
T
teknium1 b91088d768 refactor(config): one effective-user-config loader replaces 9 hand-rolled raw→overlay→expand pipelines
Every defaults-free config reader (gateway runtime, TUI gateway, cron
scheduler + job snapshot, `hermes send` env bridge, doctor memory section,
hermes_cli/main early parse, hermes_time, hermes_logging, the gateway
fallback-chain refresh) re-implemented "read config.yaml + managed overlay +
${VAR} expansion" by hand, in three different orders, and none of them
replayed the model-key canonicalization or the last-known-good recovery that
load_config() gained. An admin-pinned `${VAR}` expanded on one surface and was
bridged literally on another; `model: {name: x}` resolved to an empty model
everywhere except the gateway.

hermes_cli/config_effective.py::load_user_config_effective is the one
primitive: user file → ${VAR} → managed overlay → _normalize_root_model_keys,
no DEFAULT_CONFIG merge, sharing read_raw_config's parse cache and serving the
last good parse (in-process, then backups/config/*.good.*) on torn YAML;
`fail_closed=True` raises for the one caller that keeps its own last-good
state (the fallback-chain refresh). gateway/run.py::_load_gateway_runtime_config
is deleted — it was _load_gateway_config plus expansion, and _load_gateway_config
now expands.

Behavior change: _load_bridge_config, send_cmd._load_hermes_env and
doctor_state._doctor_memory_config expanded BEFORE the overlay; they now match
load_config (managed `${VAR}` expands against the process env only). All nine
sites gain model-key canonicalization and last-good recovery.
send_cmd._load_hermes_env now routes its .env read through
env_loader._load_dotenv_with_fallback so the credential sanitizer runs.
2026-09-13 05:09:06 -07:00

83 lines
3.0 KiB
Python

"""Tests for per-model reasoning_effort override in TUI gateway _load_reasoning_config."""
import pytest
import tui_gateway.server as tui_server
class TestTUIPerModelReasoningConfig:
"""Test tui_gateway _load_reasoning_config respects per-model overrides."""
def test_per_model_override_takes_precedence(self, monkeypatch):
"""Per-model override wins over global reasoning_effort."""
fake_cfg = {
"model": {"default": "anthropic/claude-opus-4.5"},
"agent": {
"reasoning_effort": "medium",
"reasoning_overrides": {
"anthropic/claude-opus-4.5": "xhigh",
},
},
}
monkeypatch.setattr(tui_server, "_load_cfg", lambda: fake_cfg)
result = tui_server._load_reasoning_config()
assert result is not None
assert result["enabled"] is True
assert result["effort"] == "xhigh"
def test_global_fallback_when_no_override(self, monkeypatch):
"""Global reasoning_effort applies when no per-model override matches."""
fake_cfg = {
"model": {"default": "gpt-5"},
"agent": {
"reasoning_effort": "high",
"reasoning_overrides": {
"anthropic/claude-opus-4.5": "xhigh",
},
},
}
monkeypatch.setattr(tui_server, "_load_cfg", lambda: fake_cfg)
result = tui_server._load_reasoning_config()
assert result is not None
assert result["effort"] == "high"
def test_spelling_tolerant_match(self, monkeypatch):
"""Override matches even with different spelling (provider prefix)."""
fake_cfg = {
"model": {"default": "claude-opus-4.5"},
"agent": {
"reasoning_effort": "medium",
"reasoning_overrides": {
"anthropic/claude-opus-4.5": "high", # key has prefix, model doesn't
},
},
}
monkeypatch.setattr(tui_server, "_load_cfg", lambda: fake_cfg)
result = tui_server._load_reasoning_config()
assert result is not None
assert result["effort"] == "high"
def test_parity_with_gateway_loader(self, monkeypatch):
"""TUI and gateway loaders return identical results for same config."""
import gateway.run as gateway_run
fake_cfg = {
"model": {"default": "openrouter/anthropic/claude-sonnet-4.6"},
"agent": {
"reasoning_effort": "low",
"reasoning_overrides": {
"claude-sonnet-4.6": "high",
},
},
}
monkeypatch.setattr(tui_server, "_load_cfg", lambda: fake_cfg)
monkeypatch.setattr(gateway_run, "_load_gateway_config", lambda: fake_cfg)
tui_result = tui_server._load_reasoning_config()
gw_result = gateway_run.GatewayRunner._load_reasoning_config()
assert tui_result == gw_result