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).
109 lines
3.4 KiB
Python
109 lines
3.4 KiB
Python
"""Tests for CLI /status command behavior."""
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from cli import HermesCLI
|
|
from hermes_cli.commands import resolve_command
|
|
|
|
|
|
def _make_cli():
|
|
cli_obj = HermesCLI.__new__(HermesCLI)
|
|
cli_obj.config = {}
|
|
cli_obj.console = MagicMock()
|
|
cli_obj.agent = None
|
|
cli_obj.conversation_history = []
|
|
cli_obj.session_id = "session-123"
|
|
cli_obj._pending_input = MagicMock()
|
|
cli_obj._status_bar_visible = True
|
|
cli_obj.model = "openai/gpt-5.4"
|
|
cli_obj.provider = "openai"
|
|
cli_obj.session_start = datetime(2026, 4, 9, 19, 24)
|
|
cli_obj._agent_running = False
|
|
cli_obj._session_db = MagicMock()
|
|
cli_obj._session_db.get_session.return_value = None
|
|
return cli_obj
|
|
|
|
|
|
def test_status_command_is_available_in_cli_registry():
|
|
cmd = resolve_command("status")
|
|
assert cmd is not None
|
|
assert cmd.gateway_only is False
|
|
|
|
|
|
def test_egress_command_is_available_in_cli_registry():
|
|
cmd = resolve_command("egress")
|
|
assert cmd is not None
|
|
assert cmd.gateway_only is False
|
|
assert "status" in cmd.subcommands
|
|
|
|
|
|
|
|
|
|
def test_process_command_egress_prints_proxy_status(monkeypatch):
|
|
cli_obj = _make_cli()
|
|
monkeypatch.setattr(
|
|
"hermes_cli.proxy_cli.format_status_text",
|
|
lambda: "Egress proxy status\nEnabled: no",
|
|
)
|
|
|
|
assert cli_obj.process_command("/egress") is True
|
|
|
|
cli_obj.console.print.assert_called()
|
|
printed = "\n".join(str(call.args[0]) for call in cli_obj.console.print.call_args_list)
|
|
assert "Egress proxy status" in printed
|
|
|
|
|
|
|
|
|
|
def test_status_prefix_prefers_status_command_over_statusbar_toggle():
|
|
cli_obj = _make_cli()
|
|
|
|
with patch.object(cli_obj, "_show_session_status") as mock_status:
|
|
assert cli_obj.process_command("/sta") is True
|
|
|
|
mock_status.assert_called_once_with()
|
|
assert cli_obj._status_bar_visible is True
|
|
|
|
|
|
def test_show_session_status_prints_gateway_style_summary():
|
|
cli_obj = _make_cli()
|
|
cli_obj.agent = SimpleNamespace(
|
|
session_total_tokens=321,
|
|
session_api_calls=4,
|
|
)
|
|
cli_obj._session_db.get_session.return_value = {
|
|
"title": "My titled session",
|
|
"started_at": 1775791440,
|
|
}
|
|
|
|
with patch("cli.display_hermes_home", return_value="~/.hermes"):
|
|
cli_obj._show_session_status()
|
|
|
|
printed = "\n".join(str(call.args[0]) for call in cli_obj.console.print.call_args_list)
|
|
assert "Hermes CLI Status" in printed
|
|
assert "Session ID: session-123" in printed
|
|
assert "Path: ~/.hermes" in printed
|
|
assert "Title: My titled session" in printed
|
|
assert "Model: openai/gpt-5.4 (openai)" in printed
|
|
assert "Tokens: 321" in printed
|
|
assert "Agent Running: No" in printed
|
|
_, kwargs = cli_obj.console.print.call_args
|
|
assert kwargs.get("highlight") is False
|
|
assert kwargs.get("markup") is False
|
|
|
|
|
|
def test_profile_command_reports_custom_root_profile(monkeypatch, tmp_path, capsys):
|
|
"""Profile detection works for custom-root deployments (not under ~/.hermes)."""
|
|
cli_obj = _make_cli()
|
|
profile_home = tmp_path / "profiles" / "coder"
|
|
|
|
monkeypatch.setenv("HERMES_HOME", str(profile_home))
|
|
monkeypatch.setattr(Path, "home", lambda: tmp_path / "unrelated-home")
|
|
|
|
cli_obj._handle_profile_command()
|
|
|
|
out = capsys.readouterr().out
|
|
assert "Profile: coder" in out
|
|
assert f"Home: {profile_home}" in out
|