mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-30 19:09:28 +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).
88 lines
3.1 KiB
Python
88 lines
3.1 KiB
Python
"""Dashboard Hermes Console websocket tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
from urllib.parse import urlencode
|
|
|
|
import pytest
|
|
from starlette.testclient import TestClient
|
|
from starlette.websockets import WebSocketDisconnect
|
|
|
|
from hermes_cli import web_server
|
|
|
|
|
|
@pytest.fixture
|
|
def console_client(monkeypatch, _isolate_hermes_home):
|
|
previous_auth_required = getattr(web_server.app.state, "auth_required", None)
|
|
previous_bound_host = getattr(web_server.app.state, "bound_host", None)
|
|
web_server.app.state.auth_required = False
|
|
web_server.app.state.bound_host = None
|
|
monkeypatch.setattr(web_server, "_DASHBOARD_EMBEDDED_CHAT_ENABLED", True)
|
|
|
|
client = TestClient(web_server.app)
|
|
try:
|
|
yield client
|
|
finally:
|
|
close = getattr(client, "close", None)
|
|
if close is not None:
|
|
close()
|
|
if previous_auth_required is None:
|
|
if hasattr(web_server.app.state, "auth_required"):
|
|
delattr(web_server.app.state, "auth_required")
|
|
else:
|
|
web_server.app.state.auth_required = previous_auth_required
|
|
if previous_bound_host is None:
|
|
if hasattr(web_server.app.state, "bound_host"):
|
|
delattr(web_server.app.state, "bound_host")
|
|
else:
|
|
web_server.app.state.bound_host = previous_bound_host
|
|
|
|
|
|
def _url(token: str | None = None, **params: str) -> str:
|
|
query = {"token": web_server._SESSION_TOKEN, **params}
|
|
if token is not None:
|
|
query["token"] = token
|
|
return f"/api/console?{urlencode(query)}"
|
|
|
|
|
|
def _recv_until(conn, frame_type: str, *, status: str | None = None) -> dict:
|
|
deadline = time.monotonic() + 5.0
|
|
while time.monotonic() < deadline:
|
|
frame = conn.receive_json()
|
|
if frame.get("type") != frame_type:
|
|
continue
|
|
if status is not None and frame.get("status") != status:
|
|
continue
|
|
return frame
|
|
raise AssertionError(f"Timed out waiting for {frame_type} frame")
|
|
|
|
|
|
def test_console_ws_rejects_missing_or_bad_token(console_client):
|
|
with pytest.raises(WebSocketDisconnect) as exc:
|
|
with console_client.websocket_connect("/api/console"):
|
|
pass
|
|
assert exc.value.code == 4401
|
|
|
|
with pytest.raises(WebSocketDisconnect) as exc:
|
|
with console_client.websocket_connect(_url(token="wrong")):
|
|
pass
|
|
assert exc.value.code == 4401
|
|
|
|
|
|
def test_console_ws_cancel_returns_to_prompt(console_client, monkeypatch):
|
|
from hermes_cli.console_engine import ConsoleResult, HermesConsoleEngine
|
|
|
|
def slow_execute(self, line: str, *, confirmed: bool = False):
|
|
time.sleep(0.2)
|
|
return ConsoleResult("ok", output="late", command=line)
|
|
|
|
monkeypatch.setattr(HermesConsoleEngine, "execute", slow_execute)
|
|
|
|
with console_client.websocket_connect(_url()) as conn:
|
|
assert conn.receive_json()["type"] == "ready"
|
|
conn.send_json({"type": "input", "line": "status"})
|
|
conn.send_json({"type": "cancel"})
|
|
|
|
complete = _recv_until(conn, "complete", status="cancelled")
|
|
assert complete["prompt"] == "hermes> "
|