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).
63 lines
2 KiB
Python
63 lines
2 KiB
Python
"""Session transcript stores are read-only to agent file tools.
|
|
|
|
Inspired by Claude Code 2.1.205's auto-mode rule preventing transcript
|
|
manipulation. Hermes keeps canonical conversation history in state.db and may
|
|
also emit legacy JSON snapshots under sessions/; agent tools must not rewrite
|
|
or delete either store.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture()
|
|
def fake_homes(tmp_path, monkeypatch):
|
|
"""Point HERMES_HOME at a temp profile dir.
|
|
|
|
Uses the real env-var resolution chain (get_hermes_home /
|
|
get_default_hermes_root) instead of monkeypatching private helpers —
|
|
a stale monkeypatch on a since-deleted helper broke CI in July 2026
|
|
(monkeypatch.setattr raises AttributeError on missing attributes).
|
|
HERMES_HOME=<root>/profiles/<name> makes get_default_hermes_root()
|
|
derive <root> via the `profiles` parent-dir rule, so both the
|
|
profile-scoped and root-scoped deny lists resolve into tmp_path.
|
|
"""
|
|
root = tmp_path / ".hermes"
|
|
profile = root / "profiles" / "work"
|
|
profile.mkdir(parents=True)
|
|
monkeypatch.setenv("HERMES_HOME", str(profile))
|
|
return root, profile
|
|
|
|
|
|
@pytest.mark.parametrize("relative", ["state.db", "sessions/session_abc.json"])
|
|
def test_session_state_paths_are_write_denied(fake_homes, relative):
|
|
from agent.file_safety import is_write_denied
|
|
|
|
_root, profile = fake_homes
|
|
target = profile / relative
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.write_text("existing transcript", encoding="utf-8")
|
|
|
|
assert is_write_denied(str(target)) is True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_write_file_tool_preserves_existing_session_snapshot(fake_homes):
|
|
import tools.file_tools as ft
|
|
|
|
_root, profile = fake_homes
|
|
target = profile / "sessions" / "session_abc.json"
|
|
target.parent.mkdir(parents=True)
|
|
target.write_text("original transcript", encoding="utf-8")
|
|
|
|
result = json.loads(ft.write_file_tool(str(target), "tampered"))
|
|
|
|
assert "error" in result
|
|
assert target.read_text(encoding="utf-8") == "original transcript"
|