mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-30 19:09:28 +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.
170 lines
8 KiB
Python
170 lines
8 KiB
Python
from types import SimpleNamespace
|
|
|
|
from hermes_cli.status import show_status
|
|
|
|
|
|
def test_show_status_all_does_not_print_tavily_key_value(monkeypatch, capsys, tmp_path):
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
sentinel = "NONSECRET_SENTINEL_VALUE_DO_NOT_PRINT_123456"
|
|
monkeypatch.setenv("TAVILY_API_KEY", sentinel)
|
|
|
|
show_status(SimpleNamespace(all=True, deep=False))
|
|
|
|
output = capsys.readouterr().out
|
|
assert "Tavily" in output
|
|
assert sentinel not in output
|
|
|
|
|
|
def test_show_status_termux_gateway_section_skips_systemctl(monkeypatch, capsys, tmp_path):
|
|
from hermes_cli import status as status_mod
|
|
import hermes_cli.auth as auth_mod
|
|
import hermes_cli.gateway as gateway_mod
|
|
|
|
monkeypatch.setenv("TERMUX_VERSION", "0.118.3")
|
|
monkeypatch.setenv("PREFIX", "/data/data/com.termux/files/usr")
|
|
monkeypatch.setattr(status_mod, "get_env_path", lambda: tmp_path / ".env", raising=False)
|
|
monkeypatch.setattr(status_mod, "get_hermes_home", lambda: tmp_path, raising=False)
|
|
monkeypatch.setattr(status_mod, "load_config", lambda: {"model": "gpt-5.4"}, raising=False)
|
|
monkeypatch.setattr(status_mod, "resolve_requested_provider", lambda requested=None: "openai-codex", raising=False)
|
|
monkeypatch.setattr(status_mod, "resolve_provider", lambda requested=None, **kwargs: "openai-codex", raising=False)
|
|
monkeypatch.setattr(status_mod, "provider_label", lambda provider: "OpenAI Codex", raising=False)
|
|
monkeypatch.setattr(auth_mod, "get_nous_auth_status_local", lambda: {}, raising=False)
|
|
monkeypatch.setattr(auth_mod, "get_codex_auth_status", lambda: {}, raising=False)
|
|
monkeypatch.setattr(auth_mod, "get_xai_oauth_auth_status", lambda: {}, raising=False)
|
|
monkeypatch.setattr(gateway_mod, "find_gateway_pids", lambda exclude_pids=None: [], raising=False)
|
|
|
|
def _unexpected_systemctl(*args, **kwargs):
|
|
raise AssertionError("systemctl should not be called in the Termux status view")
|
|
|
|
monkeypatch.setattr(status_mod.subprocess, "run", _unexpected_systemctl)
|
|
|
|
status_mod.show_status(SimpleNamespace(all=False, deep=False))
|
|
|
|
output = capsys.readouterr().out
|
|
assert "Manager: Termux / manual process" in output
|
|
assert "Start with: hermes gateway" in output
|
|
assert "systemd (user)" not in output
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Helpers shared by xAI OAuth status tests
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def _base_xai_mocks(monkeypatch, tmp_path):
|
|
"""Set up the minimal environment for show_status, returning status_mod."""
|
|
from hermes_cli import status as status_mod
|
|
import hermes_cli.auth as auth_mod
|
|
import hermes_cli.gateway as gateway_mod
|
|
|
|
monkeypatch.setattr(status_mod, "get_env_path", lambda: tmp_path / ".env", raising=False)
|
|
monkeypatch.setattr(status_mod, "get_hermes_home", lambda: tmp_path, raising=False)
|
|
monkeypatch.setattr(status_mod, "load_config", lambda: {"model": "gpt-5.4"}, raising=False)
|
|
monkeypatch.setattr(status_mod, "resolve_requested_provider", lambda requested=None: "openai-codex", raising=False)
|
|
monkeypatch.setattr(status_mod, "resolve_provider", lambda requested=None, **kwargs: "openai-codex", raising=False)
|
|
monkeypatch.setattr(status_mod, "provider_label", lambda provider: "OpenAI Codex", raising=False)
|
|
monkeypatch.setattr(auth_mod, "get_nous_auth_status_local", lambda: {}, raising=False)
|
|
monkeypatch.setattr(auth_mod, "get_codex_auth_status", lambda: {}, raising=False)
|
|
monkeypatch.setattr(auth_mod, "get_qwen_auth_status", lambda: {}, raising=False)
|
|
monkeypatch.setattr(auth_mod, "get_minimax_oauth_auth_status", lambda: {}, raising=False)
|
|
monkeypatch.setattr(gateway_mod, "find_gateway_pids", lambda exclude_pids=None: [], raising=False)
|
|
return status_mod
|
|
|
|
|
|
class TestShowStatusXaiOAuth:
|
|
"""xAI OAuth row in hermes status."""
|
|
|
|
# ------------------------------------------------------------------
|
|
# Logged-in branch
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
def test_logged_in_shows_auth_store(self, monkeypatch, capsys, tmp_path):
|
|
import hermes_cli.auth as auth_mod
|
|
status_mod = _base_xai_mocks(monkeypatch, tmp_path)
|
|
monkeypatch.setattr(auth_mod, "get_xai_oauth_auth_status",
|
|
lambda: {"logged_in": True, "auth_store": "/home/u/.hermes/auth.json"},
|
|
raising=False)
|
|
|
|
status_mod.show_status(SimpleNamespace(all=False, deep=False))
|
|
out = capsys.readouterr().out
|
|
|
|
assert "Auth file: /home/u/.hermes/auth.json" in out
|
|
|
|
|
|
def test_no_auth_store_line_when_field_absent(self, monkeypatch, capsys, tmp_path):
|
|
"""Auth file line must not appear when auth_store is missing."""
|
|
import hermes_cli.auth as auth_mod
|
|
status_mod = _base_xai_mocks(monkeypatch, tmp_path)
|
|
monkeypatch.setattr(auth_mod, "get_xai_oauth_auth_status",
|
|
lambda: {"logged_in": True},
|
|
raising=False)
|
|
|
|
status_mod.show_status(SimpleNamespace(all=False, deep=False))
|
|
out = capsys.readouterr().out
|
|
|
|
xai_section = out.split("xAI OAuth", 1)[1].split("◆", 1)[0]
|
|
assert "Auth file:" not in xai_section
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
# Not-logged-in branch
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
# Resilience: import failure and runtime exception
|
|
# ------------------------------------------------------------------
|
|
|
|
def test_import_failure_does_not_crash_show_status(self, monkeypatch, capsys, tmp_path):
|
|
"""show_status must complete even when get_xai_oauth_auth_status cannot be imported."""
|
|
import hermes_cli.auth as auth_mod
|
|
status_mod = _base_xai_mocks(monkeypatch, tmp_path)
|
|
monkeypatch.delattr(auth_mod, "get_xai_oauth_auth_status", raising=False)
|
|
|
|
status_mod.show_status(SimpleNamespace(all=False, deep=False))
|
|
out = capsys.readouterr().out
|
|
|
|
assert "◆ Auth Providers" in out
|
|
|
|
def test_import_failure_does_not_break_other_oauth_providers(self, monkeypatch, capsys, tmp_path):
|
|
"""Nous/Codex/MiniMax rows must still appear when xAI import fails."""
|
|
import hermes_cli.auth as auth_mod
|
|
status_mod = _base_xai_mocks(monkeypatch, tmp_path)
|
|
monkeypatch.setattr(auth_mod, "get_nous_auth_status_local",
|
|
lambda: {"logged_in": True}, raising=False)
|
|
monkeypatch.delattr(auth_mod, "get_xai_oauth_auth_status", raising=False)
|
|
|
|
status_mod.show_status(SimpleNamespace(all=False, deep=False))
|
|
out = capsys.readouterr().out
|
|
|
|
assert "Nous Portal" in out
|
|
assert "MiniMax OAuth" in out
|
|
|
|
def test_status_function_exception_does_not_crash(self, monkeypatch, capsys, tmp_path):
|
|
"""show_status must not propagate an exception raised by get_xai_oauth_auth_status."""
|
|
import hermes_cli.auth as auth_mod
|
|
status_mod = _base_xai_mocks(monkeypatch, tmp_path)
|
|
|
|
def _raises():
|
|
raise RuntimeError("backend unreachable")
|
|
|
|
monkeypatch.setattr(auth_mod, "get_xai_oauth_auth_status", _raises, raising=False)
|
|
|
|
status_mod.show_status(SimpleNamespace(all=False, deep=False))
|
|
out = capsys.readouterr().out
|
|
|
|
assert "◆ Auth Providers" in out
|
|
|
|
def test_status_function_returns_none_does_not_crash(self, monkeypatch, capsys, tmp_path):
|
|
"""get_xai_oauth_auth_status returning None must be handled gracefully."""
|
|
import hermes_cli.auth as auth_mod
|
|
status_mod = _base_xai_mocks(monkeypatch, tmp_path)
|
|
monkeypatch.setattr(auth_mod, "get_xai_oauth_auth_status",
|
|
lambda: None, raising=False)
|
|
|
|
status_mod.show_status(SimpleNamespace(all=False, deep=False))
|
|
out = capsys.readouterr().out
|
|
|
|
assert "xAI OAuth" in out
|
|
assert "not logged in (run: hermes auth add xai-oauth)" in out
|