mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +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).
101 lines
4.4 KiB
Python
101 lines
4.4 KiB
Python
"""Tests for /tools slash command handler in the interactive CLI."""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from cli import HermesCLI
|
|
|
|
|
|
def _make_cli(enabled_toolsets=None):
|
|
"""Build a minimal HermesCLI stub without running __init__."""
|
|
cli_obj = HermesCLI.__new__(HermesCLI)
|
|
cli_obj.enabled_toolsets = set(enabled_toolsets or ["web", "memory"])
|
|
cli_obj._command_running = False
|
|
cli_obj.console = MagicMock()
|
|
return cli_obj
|
|
|
|
|
|
# ── /tools (no subcommand) ──────────────────────────────────────────────────
|
|
|
|
|
|
class TestToolsSlashNoSubcommand:
|
|
|
|
def test_bare_tools_shows_tool_list(self):
|
|
cli_obj = _make_cli()
|
|
with patch.object(cli_obj, "show_tools") as mock_show:
|
|
cli_obj._handle_tools_command("/tools")
|
|
mock_show.assert_called_once()
|
|
|
|
|
|
|
|
# ── /tools list ─────────────────────────────────────────────────────────────
|
|
|
|
|
|
class TestToolsSlashList:
|
|
|
|
def test_list_calls_backend(self, capsys):
|
|
cli_obj = _make_cli()
|
|
with patch("hermes_cli.tools_config.load_config",
|
|
return_value={"platform_toolsets": {"cli": ["web"]}}), \
|
|
patch("hermes_cli.tools_config.save_config"):
|
|
cli_obj._handle_tools_command("/tools list")
|
|
out = capsys.readouterr().out
|
|
assert "web" in out
|
|
|
|
|
|
|
|
# ── /tools disable (session reset) ──────────────────────────────────────────
|
|
|
|
|
|
class TestToolsSlashDisableWithReset:
|
|
|
|
def test_disable_applies_directly_and_resets_session(self):
|
|
"""Disable applies immediately (no confirmation prompt) and resets session."""
|
|
cli_obj = _make_cli(["web", "memory"])
|
|
with patch("hermes_cli.tools_config.load_config",
|
|
return_value={"platform_toolsets": {"cli": ["web", "memory"]}}), \
|
|
patch("hermes_cli.tools_config.save_config"), \
|
|
patch("hermes_cli.tools_config._get_platform_tools", return_value={"memory"}), \
|
|
patch("hermes_cli.config.load_config", return_value={}), \
|
|
patch.object(cli_obj, "new_session") as mock_reset:
|
|
cli_obj._handle_tools_command("/tools disable web")
|
|
mock_reset.assert_called_once()
|
|
assert "web" not in cli_obj.enabled_toolsets
|
|
|
|
|
|
def test_disable_always_resets_session(self):
|
|
"""Even without a confirmation prompt, disable always resets the session."""
|
|
cli_obj = _make_cli(["web", "memory"])
|
|
with patch("hermes_cli.tools_config.load_config",
|
|
return_value={"platform_toolsets": {"cli": ["web", "memory"]}}), \
|
|
patch("hermes_cli.tools_config.save_config"), \
|
|
patch("hermes_cli.tools_config._get_platform_tools", return_value={"memory"}), \
|
|
patch("hermes_cli.config.load_config", return_value={}), \
|
|
patch.object(cli_obj, "new_session") as mock_reset:
|
|
cli_obj._handle_tools_command("/tools disable web")
|
|
mock_reset.assert_called_once()
|
|
|
|
|
|
|
|
# ── /tools enable (session reset) ───────────────────────────────────────────
|
|
|
|
|
|
class TestToolsSlashEnableWithReset:
|
|
|
|
def test_enable_applies_directly_and_resets_session(self):
|
|
"""Enable applies immediately (no confirmation prompt) and resets session."""
|
|
cli_obj = _make_cli(["memory"])
|
|
with patch("hermes_cli.tools_config.load_config",
|
|
return_value={"platform_toolsets": {"cli": ["memory"]}}), \
|
|
patch("hermes_cli.tools_config.save_config"), \
|
|
patch("hermes_cli.tools_config._get_platform_tools", return_value={"memory", "web"}), \
|
|
patch("hermes_cli.config.load_config", return_value={}), \
|
|
patch.object(cli_obj, "new_session") as mock_reset:
|
|
cli_obj._handle_tools_command("/tools enable web")
|
|
mock_reset.assert_called_once()
|
|
assert "web" in cli_obj.enabled_toolsets
|
|
|
|
def test_enable_missing_name_prints_usage(self, capsys):
|
|
cli_obj = _make_cli()
|
|
cli_obj._handle_tools_command("/tools enable")
|
|
out = capsys.readouterr().out
|
|
assert "Usage" in out
|