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).
95 lines
3 KiB
Python
95 lines
3 KiB
Python
"""Tests for the `hermes memory reset` CLI command.
|
|
|
|
Covers:
|
|
- Reset both stores (MEMORY.md + USER.md)
|
|
- Reset individual stores (--target memory / --target user)
|
|
- Skip confirmation with --yes
|
|
- Graceful handling when no memory files exist
|
|
- Profile-scoped reset (uses HERMES_HOME)
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def memory_env(tmp_path, monkeypatch):
|
|
"""Set up a fake HERMES_HOME with memory files."""
|
|
hermes_home = tmp_path / ".hermes"
|
|
memories = hermes_home / "memories"
|
|
memories.mkdir(parents=True)
|
|
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
|
|
|
|
# Create sample memory files
|
|
(memories / "MEMORY.md").write_text(
|
|
"§\nHermes repo is at ~/.hermes/hermes-agent\n§\nUser prefers dark themes",
|
|
encoding="utf-8",
|
|
)
|
|
(memories / "USER.md").write_text(
|
|
"§\nUser is Teknium\n§\nTimezone: US Pacific",
|
|
encoding="utf-8",
|
|
)
|
|
return hermes_home, memories
|
|
|
|
|
|
def _run_memory_reset(target="all", yes=False, monkeypatch=None, confirm_input="no"):
|
|
"""Invoke the memory reset logic from cmd_memory in main.py.
|
|
|
|
Simulates what happens when `hermes memory reset` is run.
|
|
"""
|
|
from hermes_constants import get_hermes_home
|
|
|
|
mem_dir = get_hermes_home() / "memories"
|
|
files_to_reset = []
|
|
if target in {"all", "memory"}:
|
|
files_to_reset.append(("MEMORY.md", "agent notes"))
|
|
if target in {"all", "user"}:
|
|
files_to_reset.append(("USER.md", "user profile"))
|
|
|
|
existing = [(f, desc) for f, desc in files_to_reset if (mem_dir / f).exists()]
|
|
if not existing:
|
|
return "nothing"
|
|
|
|
if not yes:
|
|
if confirm_input != "yes":
|
|
return "cancelled"
|
|
|
|
for f, desc in existing:
|
|
(mem_dir / f).unlink()
|
|
|
|
return "deleted"
|
|
|
|
|
|
class TestMemoryReset:
|
|
"""Tests for `hermes memory reset` subcommand."""
|
|
|
|
def test_reset_all_with_yes_flag(self, memory_env):
|
|
"""--yes flag should skip confirmation and delete both files."""
|
|
hermes_home, memories = memory_env
|
|
assert (memories / "MEMORY.md").exists()
|
|
assert (memories / "USER.md").exists()
|
|
|
|
result = _run_memory_reset(target="all", yes=True)
|
|
assert result == "deleted"
|
|
assert not (memories / "MEMORY.md").exists()
|
|
assert not (memories / "USER.md").exists()
|
|
|
|
|
|
def test_reset_no_files_exist(self, tmp_path, monkeypatch):
|
|
"""Should return 'nothing' when no memory files exist."""
|
|
hermes_home = tmp_path / ".hermes"
|
|
(hermes_home / "memories").mkdir(parents=True)
|
|
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
|
|
|
|
result = _run_memory_reset(target="all", yes=True)
|
|
assert result == "nothing"
|
|
|
|
|
|
def test_reset_partial_files(self, memory_env):
|
|
"""Reset should work when only one memory file exists."""
|
|
hermes_home, memories = memory_env
|
|
(memories / "USER.md").unlink()
|
|
|
|
result = _run_memory_reset(target="all", yes=True)
|
|
assert result == "deleted"
|
|
assert not (memories / "MEMORY.md").exists()
|
|
|