`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.
134 lines
5.4 KiB
Python
134 lines
5.4 KiB
Python
"""Tests for the low context length warning in the CLI banner."""
|
|
|
|
import os
|
|
from types import SimpleNamespace
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from agent.model_metadata import MINIMUM_CONTEXT_LENGTH
|
|
|
|
|
|
@pytest.fixture
|
|
def _isolate(tmp_path, monkeypatch):
|
|
"""Isolate HERMES_HOME so tests don't touch real config."""
|
|
home = tmp_path / ".hermes"
|
|
home.mkdir()
|
|
monkeypatch.setenv("HERMES_HOME", str(home))
|
|
|
|
|
|
@pytest.fixture
|
|
def cli_obj(_isolate):
|
|
"""Create a minimal HermesCLI instance for banner testing."""
|
|
with patch("cli.load_cli_config", return_value={
|
|
"display": {"tool_progress": "new"},
|
|
"terminal": {},
|
|
}), patch("cli.get_tool_definitions", return_value=[]), \
|
|
patch("hermes_cli.banner.build_welcome_banner"):
|
|
from cli import HermesCLI
|
|
obj = HermesCLI.__new__(HermesCLI)
|
|
obj.model = "test-model"
|
|
obj.enabled_toolsets = ["hermes-core"]
|
|
obj.compact = False
|
|
obj.console = MagicMock()
|
|
obj.session_id = None
|
|
obj.api_key = "test"
|
|
obj.base_url = ""
|
|
obj.provider = "test"
|
|
obj._provider_source = None
|
|
# Mock agent with context compressor
|
|
obj.agent = SimpleNamespace(
|
|
context_compressor=SimpleNamespace(context_length=None)
|
|
)
|
|
return obj
|
|
|
|
|
|
class TestLowContextWarning:
|
|
"""Tests that the CLI warns about low context lengths."""
|
|
|
|
def test_warning_for_below_minimum_context(self, cli_obj):
|
|
"""Warning shown when context is below Hermes' minimum."""
|
|
cli_obj.agent.context_compressor.context_length = 32768
|
|
with patch("cli.get_tool_definitions", return_value=[]), \
|
|
patch("hermes_cli.banner.build_welcome_banner"):
|
|
cli_obj.show_banner()
|
|
|
|
calls = [str(c) for c in cli_obj.console.print.call_args_list]
|
|
warning_calls = [c for c in calls if "too low" in c]
|
|
assert len(warning_calls) == 1
|
|
minimum_calls = [c for c in calls if f"{MINIMUM_CONTEXT_LENGTH:,}" in c]
|
|
assert minimum_calls
|
|
|
|
|
|
def test_warning_for_2048_context(self, cli_obj):
|
|
"""Warning shown for 2048 tokens (common LM Studio default)."""
|
|
cli_obj.agent.context_compressor.context_length = 2048
|
|
with patch("cli.get_tool_definitions", return_value=[]), \
|
|
patch("hermes_cli.banner.build_welcome_banner"):
|
|
cli_obj.show_banner()
|
|
|
|
calls = [str(c) for c in cli_obj.console.print.call_args_list]
|
|
warning_calls = [c for c in calls if "too low" in c]
|
|
assert len(warning_calls) == 1
|
|
|
|
def test_no_warning_at_boundary(self, cli_obj):
|
|
"""No warning at exactly Hermes' minimum context length."""
|
|
cli_obj.agent.context_compressor.context_length = MINIMUM_CONTEXT_LENGTH
|
|
with patch("cli.get_tool_definitions", return_value=[]), \
|
|
patch("hermes_cli.banner.build_welcome_banner"):
|
|
cli_obj.show_banner()
|
|
|
|
calls = [str(c) for c in cli_obj.console.print.call_args_list]
|
|
warning_calls = [c for c in calls if "too low" in c]
|
|
assert len(warning_calls) == 0
|
|
|
|
def test_no_warning_above_boundary(self, cli_obj):
|
|
"""No warning above Hermes' minimum context length."""
|
|
cli_obj.agent.context_compressor.context_length = MINIMUM_CONTEXT_LENGTH + 1
|
|
with patch("cli.get_tool_definitions", return_value=[]), \
|
|
patch("hermes_cli.banner.build_welcome_banner"):
|
|
cli_obj.show_banner()
|
|
|
|
calls = [str(c) for c in cli_obj.console.print.call_args_list]
|
|
warning_calls = [c for c in calls if "too low" in c]
|
|
assert len(warning_calls) == 0
|
|
|
|
def test_ollama_specific_hint(self, cli_obj):
|
|
"""Ollama-specific fix shown when port 11434 detected."""
|
|
cli_obj.agent.context_compressor.context_length = 4096
|
|
cli_obj.base_url = "http://localhost:11434/v1"
|
|
with patch("cli.get_tool_definitions", return_value=[]), \
|
|
patch("hermes_cli.banner.build_welcome_banner"):
|
|
cli_obj.show_banner()
|
|
|
|
calls = [str(c) for c in cli_obj.console.print.call_args_list]
|
|
ollama_hints = [c for c in calls if "OLLAMA_CONTEXT_LENGTH" in c]
|
|
assert len(ollama_hints) == 1
|
|
assert str(MINIMUM_CONTEXT_LENGTH) in ollama_hints[0]
|
|
|
|
|
|
def test_generic_hint_for_other_servers(self, cli_obj):
|
|
"""Generic fix shown for unknown servers."""
|
|
cli_obj.agent.context_compressor.context_length = 4096
|
|
cli_obj.base_url = "http://localhost:8080/v1"
|
|
with patch("cli.get_tool_definitions", return_value=[]), \
|
|
patch("hermes_cli.banner.build_welcome_banner"):
|
|
cli_obj.show_banner()
|
|
|
|
calls = [str(c) for c in cli_obj.console.print.call_args_list]
|
|
generic_hints = [c for c in calls if "config.yaml" in c]
|
|
assert len(generic_hints) == 1
|
|
|
|
|
|
def test_compact_banner_does_not_crash_on_narrow_terminal(self, cli_obj):
|
|
"""Compact mode should still have ctx_len defined for warning logic."""
|
|
cli_obj.agent.context_compressor.context_length = 4096
|
|
|
|
with patch("shutil.get_terminal_size", return_value=os.terminal_size((70, 40))), \
|
|
patch("cli._build_compact_banner", return_value="compact banner"):
|
|
cli_obj.show_banner()
|
|
|
|
calls = [str(c) for c in cli_obj.console.print.call_args_list]
|
|
warning_calls = [c for c in calls if "too low" in c]
|
|
assert len(warning_calls) == 1
|