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
2.8 KiB
Python
88 lines
2.8 KiB
Python
from types import ModuleType, SimpleNamespace
|
|
from unittest.mock import MagicMock, patch
|
|
import json
|
|
import sys
|
|
|
|
from run_agent import AIAgent
|
|
|
|
|
|
def _mock_response(*, usage: dict, content: str = "done"):
|
|
msg = SimpleNamespace(content=content, tool_calls=None)
|
|
choice = SimpleNamespace(message=msg, finish_reason="stop")
|
|
return SimpleNamespace(
|
|
choices=[choice],
|
|
model="test/model",
|
|
usage=SimpleNamespace(**usage),
|
|
)
|
|
|
|
|
|
def _make_agent(session_db, *, platform: str):
|
|
with (
|
|
patch("run_agent.get_tool_definitions", return_value=[]),
|
|
patch("run_agent.check_toolset_requirements", return_value={}),
|
|
patch("run_agent.OpenAI"),
|
|
):
|
|
agent = AIAgent(
|
|
api_key="test-key",
|
|
base_url="https://openrouter.ai/api/v1",
|
|
quiet_mode=True,
|
|
skip_context_files=True,
|
|
skip_memory=True,
|
|
session_db=session_db,
|
|
session_id=f"{platform}-session",
|
|
platform=platform,
|
|
)
|
|
agent.client = MagicMock()
|
|
agent.client.chat.completions.create.return_value = _mock_response(
|
|
usage={
|
|
"prompt_tokens": 11,
|
|
"completion_tokens": 7,
|
|
"total_tokens": 18,
|
|
}
|
|
)
|
|
return agent
|
|
|
|
|
|
def test_run_conversation_persists_tokens_for_telegram_sessions():
|
|
session_db = MagicMock()
|
|
agent = _make_agent(session_db, platform="telegram")
|
|
|
|
result = agent.run_conversation("hello")
|
|
|
|
assert result["final_response"] == "done"
|
|
# Per-call deltas are enqueued for the SessionDB background writer
|
|
# (queue_token_counts) rather than written inline on the turn thread.
|
|
session_db.queue_token_counts.assert_called_once()
|
|
assert session_db.queue_token_counts.call_args.args[0] == "telegram-session"
|
|
|
|
|
|
|
|
|
|
def test_session_search_lazily_opens_db_when_entrypoint_did_not_pass_one(monkeypatch):
|
|
sentinel_db = object()
|
|
captured = {}
|
|
|
|
class FakeSessionDB:
|
|
def __new__(cls):
|
|
return sentinel_db
|
|
|
|
hermes_state = ModuleType("hermes_state")
|
|
hermes_state.SessionDB = FakeSessionDB
|
|
monkeypatch.setitem(sys.modules, "hermes_state", hermes_state)
|
|
|
|
session_search_mod = ModuleType("tools.session_search_tool")
|
|
|
|
def fake_session_search(**kwargs):
|
|
captured.update(kwargs)
|
|
return json.dumps({"success": True, "results": []})
|
|
|
|
session_search_mod.session_search = fake_session_search
|
|
monkeypatch.setitem(sys.modules, "tools.session_search_tool", session_search_mod)
|
|
|
|
agent = _make_agent(None, platform="acp")
|
|
result = json.loads(agent._invoke_tool("session_search", {"query": "Hermes"}, "task-id"))
|
|
|
|
assert result["success"] is True
|
|
assert captured["db"] is sentinel_db
|
|
assert captured["query"] == "Hermes"
|
|
assert agent._session_db is sentinel_db
|