mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
Second, deeper pass over tools/gateway/hermes_cli plus first pass over the trees wave 1 missed (acp, acp_adapter, skills, computer_use, docker, dashboard, conformance, monitoring, secret_sources, hermes_state, providers). Same rubric as wave 1 (AGENTS.md test policy); security, alternation/caching invariants, issue-number regressions, and E2E kept. Real test-quality fixes found and rooted out along the way: - tests/tools/test_command_guards.py made real auxiliary-LLM HTTPS calls (DEFAULT_CONFIG smart-approval leaked in) — pinned approval mode=manual via autouse fixture: 17.4s → 0.4s. - test_model_switch_custom_providers.py / test_user_providers_model_switch.py silently probed live provider catalogs (~2s/test) — stubbed cached_provider_model_ids/provider_model_ids/fetch_api_models. - test_telegram_noise_filter.py: 15-platform copy-paste matrix over shared gateway.run logic → 3 representative platforms (55s → 3.9s). - test_gateway_shutdown.py: stop()'s 5s interrupt-deadline loop spun on MagicMock agents — interrupt.side_effect now clears _running_agents (22s → 1.0s). - test_gateway_inactivity_timeout.py poll-harness timings shrunk 3-5x (24s → 1.1s); test_mcp_stability.py backoff/SIGTERM-grace sleeps patched (15.4s → 2.5s); test_async_delegation.py negative-drain wait 5s → 0.5s. - test_telegram_init_deadline.py: loop-block margin restored to 1.0s with rationale comment — the watchdog-dump assertion needs the loop blocked well past deadline+grace under parallel load (flaked once in the 40-worker verification run at a 0.2s margin). Verification: full hermetic suite via scripts/run_tests.sh — 2,438 files, 21,718 tests passed, 0 failed, 293.9s wall. Suite totals vs original baseline: 46,820 → 19,757 test functions (−57.8%), wall 583.5s → 293.9s (−50%), subprocess CPU 13,564s → 11,623s.
132 lines
4.5 KiB
Python
132 lines
4.5 KiB
Python
"""Single-owner /model parsing + effective-model resolution tests.
|
|
|
|
Covers the consolidation of the 7 historical parsing/resolution variants
|
|
into hermes_cli.model_switch (parse_model_switch_args +
|
|
resolve_effective_model), including the 7dd00bb47d regression class
|
|
(api_server discarding session-persisted models) as a permanent parity
|
|
test against the pre-consolidation logic captured from origin/main.
|
|
|
|
Real imports throughout (AGENTS.md: no mocks for resolution chains).
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from hermes_cli.model_switch import (
|
|
MODEL_SWITCH_ERR_ONCE_REQUIRES_TARGET,
|
|
MODEL_SWITCH_ERR_ONCE_WITH_GLOBAL,
|
|
MODEL_SWITCH_ERROR_TEXT,
|
|
ModelSwitchRequest,
|
|
parse_model_flags_detailed,
|
|
parse_model_switch_args,
|
|
resolve_effective_model,
|
|
)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# parse_model_switch_args — the ONE parser
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def test_provider_flag_and_scopes():
|
|
req = parse_model_switch_args("sonnet --provider anthropic --global")
|
|
assert req.target == "sonnet"
|
|
assert req.explicit_provider == "anthropic"
|
|
assert req.is_global is True
|
|
assert req.scope == "global"
|
|
assert req.errors == ()
|
|
|
|
assert parse_model_switch_args("sonnet --session").scope == "session"
|
|
assert parse_model_switch_args("sonnet --once").scope == "once"
|
|
assert parse_model_switch_args("--refresh").force_refresh is True
|
|
|
|
|
|
def test_once_with_global_conflict():
|
|
req = parse_model_switch_args("sonnet --once --global")
|
|
assert MODEL_SWITCH_ERR_ONCE_WITH_GLOBAL in req.errors
|
|
assert (
|
|
MODEL_SWITCH_ERROR_TEXT[MODEL_SWITCH_ERR_ONCE_WITH_GLOBAL]
|
|
== "/model --once cannot be combined with --global"
|
|
)
|
|
assert "/model --once cannot be combined with --global" in req.error_messages()
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# resolve_effective_model — session > channel/session-persisted > global
|
|
# ---------------------------------------------------------------------------
|
|
|
|
class _ChannelOverride:
|
|
def __init__(self, model):
|
|
self.model = model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Parity: run.py-style channel resolution (old logic from origin/main)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def _old_run_py_resolve(override, global_model):
|
|
# Captured from origin/main gateway/run.py:_resolve_model_for_channel:
|
|
# if override and override.model:
|
|
# return override.model
|
|
# return _resolve_gateway_model(user_config)
|
|
if override and override.model:
|
|
return override.model
|
|
return global_model
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Parity: api_server-style resolution (old logic from origin/main)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def _clean(value):
|
|
# api_server._clean_request_string equivalent for the parity harness.
|
|
if value is None:
|
|
return None
|
|
text = str(value).strip()
|
|
return text or None
|
|
|
|
|
|
def _old_api_server_resolve(session_override, session_row_model, global_model):
|
|
# Captured from origin/main gateway/platforms/api_server.py:_create_agent
|
|
# (post-7dd00bb47d — session /model override > session-persisted model >
|
|
# global default):
|
|
model = global_model
|
|
if session_override:
|
|
model = (_clean(session_override.get("model")) or model)
|
|
elif _clean(session_row_model):
|
|
model = _clean(session_row_model)
|
|
return model
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"session_override,session_row_model,global_model",
|
|
[
|
|
(None, None, "global-model"),
|
|
(None, "session-persisted", "global-model"), # the 7dd00bb47d regression
|
|
({"model": "override-model"}, "session-persisted", "global-model"),
|
|
({"model": ""}, "session-persisted", "global-model"),
|
|
({"model": "override-model"}, None, "global-model"),
|
|
(None, " ", "global-model"),
|
|
],
|
|
)
|
|
def test_api_server_resolution_parity(session_override, session_row_model, global_model):
|
|
# New logic mirrors the migrated api_server code path exactly:
|
|
if session_override:
|
|
new = resolve_effective_model(session_override, None, global_model)
|
|
elif _clean(session_row_model):
|
|
new = resolve_effective_model(None, session_row_model, global_model)
|
|
else:
|
|
new = global_model
|
|
assert new == _old_api_server_resolve(session_override, session_row_model, global_model)
|
|
|
|
|