mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-30 19:09:28 +00:00
Systematic prune per AGENTS.md test policy, one pass over every major test tree (gateway, hermes_cli, tools, agent, run_agent, plugins, cli, cron, tui_gateway, honcho/openviking, root-level): - DELETE: source-reading tests (read_text/getsource on prod files), change-detector tests (exact catalog counts, model-name snapshots, config version literals), mock-echo tests (assert a mock returns what it was told), assertion-free/trivial tests, near-duplicate parametrizations (boundaries + one representative kept), async/sync twin duplicates, cosmetic within-file variations. - KEEP (mandatory): security/redaction/approval guards, message-role alternation invariants, prompt-caching/deterministic-call-id invariants, issue-number regression tests (deduped), E2E tests. - 6 test files deleted outright (script-style/no-assert or fully redundant); conftest.py, fakes/, fixtures/ untouched. - tests/acp/conftest.py added: autouse fixture stubs the live models.dev/GitHub/Copilot/Anthropic inventory fetches that ACP server tests performed on every session create — test_server.py 147s → 3.4s, and the tests are now genuinely hermetic. - Sleep-based slowness shrunk where safe (codex_ttfb_watchdog, compression_concurrent_fork, etc.); no wall-clock assertion tightened. Verification: full hermetic suite via scripts/run_tests.sh — 2439 files, 31,130 tests passed, 0 failed, 0 flaky retries, 315s wall (baseline: 583s wall, 13,564s subprocess CPU).
74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
"""Tests that _try_activate_fallback updates the context compressor."""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from run_agent import AIAgent
|
|
from agent.context_compressor import ContextCompressor
|
|
|
|
|
|
def _make_agent_with_compressor() -> AIAgent:
|
|
"""Build a minimal AIAgent with a context_compressor, skipping __init__."""
|
|
agent = AIAgent.__new__(AIAgent)
|
|
|
|
# Primary model settings
|
|
agent.model = "primary-model"
|
|
agent.provider = "openrouter"
|
|
agent.base_url = "https://openrouter.ai/api/v1"
|
|
agent.api_key = "sk-primary"
|
|
agent.api_mode = "chat_completions"
|
|
agent.client = MagicMock()
|
|
agent.quiet_mode = True
|
|
|
|
# Fallback config
|
|
agent._fallback_activated = False
|
|
agent._fallback_model = {
|
|
"provider": "openai",
|
|
"model": "gpt-4o",
|
|
}
|
|
agent._fallback_chain = [agent._fallback_model]
|
|
agent._fallback_index = 0
|
|
|
|
# Context compressor with primary model values
|
|
compressor = ContextCompressor(
|
|
model="primary-model",
|
|
threshold_percent=0.50,
|
|
base_url="https://openrouter.ai/api/v1",
|
|
api_key="sk-primary",
|
|
provider="openrouter",
|
|
quiet_mode=True,
|
|
)
|
|
agent.context_compressor = compressor
|
|
|
|
return agent
|
|
|
|
|
|
@patch("agent.auxiliary_client.resolve_provider_client")
|
|
@patch("agent.model_metadata.get_model_context_length", return_value=128_000)
|
|
def test_compressor_updated_on_fallback(mock_ctx_len, mock_resolve):
|
|
"""After fallback activation, the compressor must reflect the fallback model."""
|
|
agent = _make_agent_with_compressor()
|
|
|
|
assert agent.context_compressor.model == "primary-model"
|
|
|
|
fb_client = MagicMock()
|
|
fb_client.base_url = "https://api.openai.com/v1"
|
|
fb_client.api_key = "sk-fallback"
|
|
mock_resolve.return_value = (fb_client, None)
|
|
|
|
agent._is_direct_openai_url = lambda url: "api.openai.com" in url
|
|
agent._emit_status = lambda msg: None
|
|
|
|
result = agent._try_activate_fallback()
|
|
|
|
assert result is True
|
|
assert agent._fallback_activated is True
|
|
|
|
c = agent.context_compressor
|
|
assert c.model == "gpt-4o"
|
|
assert c.base_url == "https://api.openai.com/v1"
|
|
assert c.api_key == "sk-fallback"
|
|
assert c.provider == "openai"
|
|
assert c.context_length == 128_000
|
|
assert c.threshold_tokens == int(128_000 * c.threshold_percent)
|
|
|
|
|