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).
104 lines
2.7 KiB
Python
104 lines
2.7 KiB
Python
"""Behavior tests for the built-in memory → external provider bridge.
|
|
|
|
The bridge lives behind the MemoryManager interface
|
|
(``MemoryManager.notify_memory_tool_write``): the agent loop hands over the raw
|
|
built-in memory tool result + args, and the manager decides whether/what to
|
|
mirror to external providers. These tests drive that method with a fake
|
|
external provider and assert which ``on_memory_write`` calls land.
|
|
"""
|
|
|
|
import json
|
|
|
|
import pytest
|
|
|
|
from agent.memory_manager import MemoryManager
|
|
from agent.memory_provider import MemoryProvider
|
|
|
|
|
|
class _RecordingProvider(MemoryProvider):
|
|
"""Minimal external provider that records on_memory_write calls."""
|
|
|
|
def __init__(self) -> None:
|
|
self.calls = []
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
return "recording"
|
|
|
|
def is_available(self) -> bool:
|
|
return True
|
|
|
|
def initialize(self, session_id: str, **kwargs) -> None:
|
|
pass
|
|
|
|
def get_tool_schemas(self):
|
|
return []
|
|
|
|
def shutdown(self) -> None:
|
|
pass
|
|
|
|
def on_memory_write(self, action, target, content, metadata=None):
|
|
self.calls.append({
|
|
"action": action,
|
|
"target": target,
|
|
"content": content,
|
|
"metadata": dict(metadata or {}),
|
|
})
|
|
|
|
|
|
def _manager_with_provider():
|
|
mgr = MemoryManager()
|
|
provider = _RecordingProvider()
|
|
mgr.add_provider(provider)
|
|
return mgr, provider
|
|
|
|
|
|
def test_notifies_remove_with_old_text_after_success():
|
|
mgr, provider = _manager_with_provider()
|
|
mgr.notify_memory_tool_write(
|
|
json.dumps({"success": True}),
|
|
{"action": "remove", "target": "memory", "old_text": "stale preference entry"},
|
|
)
|
|
assert provider.calls == [
|
|
{
|
|
"action": "remove",
|
|
"target": "memory",
|
|
"content": "",
|
|
"metadata": {"old_text": "stale preference entry"},
|
|
}
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("tool_result", [None, [], object(), "not-json"])
|
|
def test_skips_unrecognized_tool_result_shape(tool_result):
|
|
mgr, provider = _manager_with_provider()
|
|
mgr.notify_memory_tool_write(
|
|
tool_result,
|
|
{"action": "add", "target": "memory", "content": "new fact"},
|
|
)
|
|
assert provider.calls == []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_build_metadata_callback_is_merged_per_op():
|
|
mgr, provider = _manager_with_provider()
|
|
mgr.notify_memory_tool_write(
|
|
json.dumps({"success": True}),
|
|
{"action": "add", "target": "memory", "content": "fact"},
|
|
build_metadata=lambda: {"session_id": "s1", "tool_name": "memory"},
|
|
)
|
|
assert provider.calls == [
|
|
{
|
|
"action": "add",
|
|
"target": "memory",
|
|
"content": "fact",
|
|
"metadata": {"session_id": "s1", "tool_name": "memory"},
|
|
}
|
|
]
|