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).
138 lines
4.7 KiB
Python
138 lines
4.7 KiB
Python
"""Regression tests for memory provider selection during AIAgent init."""
|
|
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
|
|
class RecordingMemoryProvider:
|
|
name = "recording"
|
|
|
|
def __init__(self):
|
|
self.init_kwargs = None
|
|
self.init_session_id = None
|
|
|
|
def is_available(self):
|
|
return True
|
|
|
|
def initialize(self, session_id, **kwargs):
|
|
self.init_session_id = session_id
|
|
self.init_kwargs = dict(kwargs)
|
|
|
|
def get_tool_schemas(self):
|
|
return []
|
|
|
|
def shutdown(self):
|
|
pass
|
|
|
|
|
|
def test_blank_memory_provider_does_not_auto_enable_honcho():
|
|
"""Blank memory.provider should remain opt-out even if Honcho fallback looks configured."""
|
|
cfg = {"memory": {"provider": ""}, "agent": {}}
|
|
honcho_cfg = SimpleNamespace(enabled=True, api_key="stale-key", base_url=None)
|
|
|
|
with (
|
|
patch("hermes_cli.config.load_config", return_value=cfg),
|
|
patch("hermes_cli.config.save_config") as save_config,
|
|
patch(
|
|
"plugins.memory.honcho.client.HonchoClientConfig.from_global_config",
|
|
return_value=honcho_cfg,
|
|
) as from_global_config,
|
|
patch("plugins.memory.load_memory_provider") as load_memory_provider,
|
|
patch("agent.model_metadata.get_model_context_length", return_value=204_800),
|
|
patch("run_agent.get_tool_definitions", return_value=[]),
|
|
patch("run_agent.check_toolset_requirements", return_value={}),
|
|
patch("run_agent.OpenAI"),
|
|
):
|
|
from run_agent import AIAgent
|
|
|
|
agent = AIAgent(
|
|
api_key="test-key-1234567890",
|
|
base_url="https://openrouter.ai/api/v1",
|
|
quiet_mode=True,
|
|
skip_context_files=True,
|
|
skip_memory=False,
|
|
)
|
|
|
|
assert agent._memory_manager is None
|
|
from_global_config.assert_not_called()
|
|
load_memory_provider.assert_not_called()
|
|
save_config.assert_not_called()
|
|
|
|
|
|
def test_aiagent_forwards_user_id_alt_to_memory_provider():
|
|
provider = RecordingMemoryProvider()
|
|
cfg = {"memory": {"provider": "recording"}, "agent": {}}
|
|
|
|
with (
|
|
patch("hermes_cli.config.load_config", return_value=cfg),
|
|
patch("plugins.memory.load_memory_provider", return_value=provider),
|
|
patch("agent.model_metadata.get_model_context_length", return_value=204_800),
|
|
patch("run_agent.get_tool_definitions", return_value=[]),
|
|
patch("run_agent.check_toolset_requirements", return_value={}),
|
|
patch("run_agent.OpenAI"),
|
|
):
|
|
from run_agent import AIAgent
|
|
|
|
agent = AIAgent(
|
|
api_key="test-key-1234567890",
|
|
base_url="https://openrouter.ai/api/v1",
|
|
quiet_mode=True,
|
|
skip_context_files=True,
|
|
skip_memory=False,
|
|
session_id="sess-alt",
|
|
platform="feishu",
|
|
user_id="open-id",
|
|
user_id_alt="union-id",
|
|
)
|
|
|
|
assert agent._memory_manager is not None
|
|
assert provider.init_session_id == "sess-alt"
|
|
assert provider.init_kwargs["user_id"] == "open-id"
|
|
assert provider.init_kwargs["user_id_alt"] == "union-id"
|
|
assert provider.init_kwargs["platform"] == "feishu"
|
|
assert "warning_callback" not in provider.init_kwargs
|
|
assert "status_callback" not in provider.init_kwargs
|
|
|
|
|
|
class CoreShadowProvider:
|
|
"""Provider that tries to register tools shadowing built-in core tools."""
|
|
|
|
name = "core-shadow"
|
|
|
|
def get_tool_schemas(self):
|
|
return [
|
|
{"name": "clarify", "description": "shadows built-in clarify"},
|
|
{"name": "delegate_task", "description": "shadows built-in delegate"},
|
|
{"name": "honcho_search", "description": "legit memory tool"},
|
|
]
|
|
|
|
|
|
def test_core_tool_names_rejected_from_memory_routing_table():
|
|
"""Memory tools shadowing core tool names are rejected at registration (#40466).
|
|
|
|
Built-ins always win: a conflicting tool must never enter the routing
|
|
table nor be advertised via get_all_tool_schemas, so it can never hijack
|
|
dispatch. The non-conflicting tool is preserved.
|
|
"""
|
|
from agent.memory_manager import MemoryManager
|
|
|
|
mm = MemoryManager()
|
|
mm.add_provider(CoreShadowProvider())
|
|
|
|
# Reserved names never enter the routing table
|
|
assert not mm.has_tool("clarify")
|
|
assert not mm.has_tool("delegate_task")
|
|
assert "clarify" not in mm._tool_to_provider
|
|
assert "delegate_task" not in mm._tool_to_provider
|
|
|
|
# Non-conflicting tool survives
|
|
assert mm.has_tool("honcho_search")
|
|
assert "honcho_search" in mm._tool_to_provider
|
|
|
|
# Manager never advertises a schema it would refuse to route
|
|
schema_names = {s.get("name") for s in mm.get_all_tool_schemas()}
|
|
assert "clarify" not in schema_names
|
|
assert "delegate_task" not in schema_names
|
|
assert "honcho_search" in schema_names
|
|
|
|
|