Files
hermes-agent/tests/agent/test_skip_memory_store_65429.py
T
Teknium 2a95791992 simplify(compat): run_agent/model_tools/toolsets/acp/providers — drop 42 re-exports/aliases, repoint 15 callers + 99 test files
run_agent.py: delete the `# noqa: F401` re-export block (agent.process_bootstrap
OpenAI/_SafeWriter/_get_proxy_*, model_tools get_tool_definitions/
handle_function_call/check_toolset_requirements, FailoverReason,
_qwen_portal_headers/_routermint_headers, session_persistence names,
estimate_request_tokens_rough, ContextCompressor + friends, jittered_backoff,
prompt_builder names, message_sanitization names, tool_dispatch_helpers
names) — 41 names run_agent never used itself — and the `_STREAM_DIAG_HEADERS`
back-compat class alias (no in-tree reader). run_agent now imports only what
it uses (get_toolset_for_tool, is_local_endpoint, coalesce/uniquify tool-call
ids, cleanup_vm/get_active_env from terminal_tool_lifecycle).

agent/*: `_ra().X` late-binds that only reached a re-export now import the
defining module directly (agent_runtime_helpers -> process_bootstrap.OpenAI,
model_tools.handle_function_call, session_persistence._safe_session_filename_component;
agent_init -> model_tools.get_tool_definitions/check_toolset_requirements,
_lazy_headers("agent.client_lifecycle", ...) for qwen/routermint;
system_prompt -> agent.prompt_builder / model_tools directly, dropping its
own _ra() shim and the `_r` parameter threading). `_ra()` stays for
run_agent-resident names (logger, AIAgent, _hermes_home, _set_interrupt, ...).

toolsets.py: remove resolve_multiple_toolsets (shim-only, restored by
34abf954bd); tests/test_toolsets.py pins the same union behavior via
resolve_toolset over each name.

providers/__init__.py: drop the OMIT_TEMPERATURE re-export (no callers via the
package); ProviderProfile stays because __init__ uses it for annotations —
2 tests repointed to providers.base.

agent/iteration_budget.py: drop the "run_agent re-exports the class"
docstring pointer; 4 tests import IterationBudget from its home.

model_tools.py (arg_coercion names), agent/tool_executor.py, and
hermes_cli/cli_session_mixin.py repoints landed via a sibling commit on this
shared worktree.

Callers repointed: gateway/run.py, hermes_cli/cli_chat_turn_mixin.py,
hermes_cli/cli_tui_mixin.py, tui_gateway/session_workdir.py,
agent/transports/codex.py (one-line imports) + comment pointers in
tools/file_state.py, tools/schema_sanitizer.py, scripts/tool_search_livetest.py.
Tests: patch("run_agent.X") / monkeypatch.setattr(run_agent, "X") /
`from run_agent import X` -> defining module across 99 test files.
2026-09-03 13:28:22 -07:00

135 lines
4.6 KiB
Python

"""Regression test for issue #65429.
An agent built with ``skip_memory=True`` AND ``enabled_toolsets=["memory"]``
used to get a memory tool wired to ``store=None`` (the built-in
``MemoryStore`` was skipped along with the external provider), so every
memory call failed silently and the main auto-capture path was dead.
The fix creates the built-in store whenever memory is enabled in config OR the
memory toolset is explicitly enabled, while the external-provider block stays
gated on ``skip_memory``.
"""
import pytest
from run_agent import AIAgent
class _FakeOpenAI:
def __init__(self, **kw):
self.api_key = kw.get("api_key", "test")
self.base_url = kw.get("base_url", "http://test")
def close(self):
pass
def _make_agent(
monkeypatch, enabled_toolsets=None, disabled_toolsets=None, skip_memory=True
):
monkeypatch.setattr("model_tools.get_tool_definitions", lambda **kw: [])
monkeypatch.setattr("model_tools.check_toolset_requirements", lambda: {})
monkeypatch.setattr("agent.process_bootstrap.OpenAI", _FakeOpenAI)
return AIAgent(
api_key="test-key",
base_url="http://test",
provider="openrouter",
api_mode="chat_completions",
max_iterations=1,
quiet_mode=True,
skip_context_files=True,
skip_memory=skip_memory,
enabled_toolsets=enabled_toolsets,
disabled_toolsets=disabled_toolsets,
)
def test_skip_memory_with_memory_toolset_creates_store(monkeypatch, tmp_path):
monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hm"))
agent = _make_agent(monkeypatch, enabled_toolsets=["memory"], skip_memory=True)
assert agent._memory_store is not None, (
"memory toolset enabled despite skip_memory=True must still build "
"the built-in store (#65429)"
)
def test_skip_memory_memory_tool_handler_works_and_provider_skipped(
monkeypatch, tmp_path
):
"""End-to-end behavioral check for #65429.
The memory tool handler must actually WORK (not return the
"Memory is not available" store=None error) on a skip_memory=True agent
with the memory toolset enabled, while the external memory provider
sync/prefetch stays skipped (no MemoryManager is created).
"""
import json
monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hm"))
agent = _make_agent(monkeypatch, enabled_toolsets=["memory"], skip_memory=True)
# Provider sync/prefetch must remain skipped: skip_memory still gates the
# external memory provider block.
assert agent._memory_manager is None, (
"skip_memory=True must still skip the external memory provider"
)
# Dispatch through the same entry point the tool executor uses
# (agent/tool_executor.py wires store=agent._memory_store).
from tools.memory_tool import memory_tool
raw = memory_tool(
action="add",
target="memory",
content="User prefers concise answers.",
store=agent._memory_store,
)
result = json.loads(raw)
assert result.get("success") is True, (
f"memory tool handler must work with skip_memory=True + memory "
f"toolset (#65429), got: {raw}"
)
assert "Memory is not available" not in raw
# The write must actually persist to the profile-scoped memories dir.
memory_md = tmp_path / "hm" / "memories" / "MEMORY.md"
assert memory_md.exists()
assert "User prefers concise answers." in memory_md.read_text()
def test_skip_memory_disabled_toolset_does_not_load_store(monkeypatch, tmp_path):
"""Cron shape: skip_memory=True, memory named in enabled AND disabled.
#65429 must not load MEMORY.md just because the default cron toolset
still lists memory while the denylist hides the tool.
"""
home = tmp_path / "hm"
monkeypatch.setenv("HERMES_HOME", str(home))
mem_dir = home / "memories"
mem_dir.mkdir(parents=True)
secret = "cron-should-never-see-this-memory"
(mem_dir / "MEMORY.md").write_text(secret + "\n")
(mem_dir / "USER.md").write_text("cron-should-never-see-this-profile\n")
agent = _make_agent(
monkeypatch,
enabled_toolsets=["memory", "file"],
disabled_toolsets=["memory"],
skip_memory=True,
)
assert agent._memory_store is None
assert agent._memory_manager is None
assert agent._memory_enabled is False
assert agent._user_profile_enabled is False
from agent.system_prompt import build_system_prompt_parts
parts = build_system_prompt_parts(agent)
blob = " ".join(str(v) for v in parts.values())
assert secret not in blob
assert "cron-should-never-see-this-profile" not in blob