mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +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.
89 lines
3.3 KiB
Python
89 lines
3.3 KiB
Python
"""Tests for the unified profile→machine dashboard launch routing.
|
|
|
|
`<profile> dashboard` routes to ONE machine-level dashboard instead of
|
|
spawning a per-profile server: attach (open browser at ?profile=) when one
|
|
is already listening, else re-exec as the machine dashboard with the
|
|
launching profile preselected. `--isolated` opts out.
|
|
"""
|
|
import sys
|
|
import types
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def main_mod():
|
|
import hermes_cli.main as main_mod
|
|
return main_mod
|
|
|
|
|
|
def _args(**kw):
|
|
defaults = dict(
|
|
status=False, stop=False, host="127.0.0.1", port=9119,
|
|
no_open=True, insecure=False, skip_build=False,
|
|
isolated=False, open_profile="",
|
|
)
|
|
defaults.update(kw)
|
|
return types.SimpleNamespace(**defaults)
|
|
|
|
|
|
class TestUnifiedDashboardRouting:
|
|
|
|
|
|
def test_profile_launch_reexecs_machine_dashboard(self, main_mod, monkeypatch):
|
|
monkeypatch.delenv("HERMES_HOME", raising=False)
|
|
monkeypatch.setattr(
|
|
"hermes_cli.profiles.get_active_profile_name", lambda: "worker_x"
|
|
)
|
|
monkeypatch.setattr(main_mod, "_dashboard_listening", lambda host, port: False)
|
|
execs = []
|
|
|
|
def fake_exec(exe, argv, env):
|
|
execs.append((exe, argv, env))
|
|
raise SystemExit(0) # execvpe never returns
|
|
|
|
monkeypatch.setattr(main_mod.os, "execvpe", fake_exec)
|
|
|
|
with pytest.raises(SystemExit):
|
|
main_mod.cmd_dashboard(_args())
|
|
|
|
assert len(execs) == 1
|
|
exe, argv, env = execs[0]
|
|
assert exe == sys.executable
|
|
# Pinned to the default profile + launching profile preselected.
|
|
assert "-p" in argv and argv[argv.index("-p") + 1] == "default"
|
|
assert "--open-profile" in argv
|
|
assert argv[argv.index("--open-profile") + 1] == "worker_x"
|
|
# The child is pinned to the machine ROOT, not the launching profile's
|
|
# HERMES_HOME. For a standard install (HERMES_HOME unset) that root is
|
|
# the platform-native default (~/.hermes), NOT dropped — see the Docker
|
|
# test below for why we resolve explicitly instead of popping.
|
|
from hermes_constants import get_default_hermes_root
|
|
assert env.get("HERMES_HOME") == str(get_default_hermes_root())
|
|
|
|
|
|
def test_desktop_profile_backend_skips_machine_dashboard_reroute(self, main_mod, monkeypatch):
|
|
"""A desktop-spawned named-profile backend (HERMES_DESKTOP=1) must NOT
|
|
reroute into the machine dashboard. The reroute re-execs as the default
|
|
profile and exits, so the desktop never sees a ready backend → boot
|
|
loop. The guard keeps desktop pool backends per-profile."""
|
|
monkeypatch.setenv("HERMES_DESKTOP", "1")
|
|
monkeypatch.setattr(
|
|
"hermes_cli.profiles.get_active_profile_name", lambda: "worker_x"
|
|
)
|
|
listening_calls = []
|
|
monkeypatch.setattr(
|
|
main_mod, "_dashboard_listening",
|
|
lambda host, port: listening_calls.append(1) or False,
|
|
)
|
|
execs = []
|
|
monkeypatch.setattr(main_mod.os, "execvpe", lambda *a, **k: execs.append(a))
|
|
monkeypatch.setitem(sys.modules, "fastapi", None)
|
|
|
|
with pytest.raises((SystemExit, AttributeError, ImportError, TypeError)):
|
|
main_mod.cmd_dashboard(_args())
|
|
assert listening_calls == []
|
|
assert execs == []
|
|
|
|
|
|
|
|
|