The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: exercise CLI exports against real read-only session storage
Teknium96782704a006
diff --git a/tests/hermes_cli/test_session_export.py b/tests/hermes_cli/test_session_export.pyindex 54e3f380402..7b1bb0f2677 100644--- a/tests/hermes_cli/test_session_export.py+++ b/tests/hermes_cli/test_session_export.py@@ -95,25 +95,18 @@ def test_export_record_count_switches_unit_for_prompt_only_exports():)-def test_sessions_export_cli_prompt_only_stdout(monkeypatch, capsys):+def test_sessions_export_cli_prompt_only_stdout(monkeypatch, capsys, tmp_path):import hermes_cli.main as main_modimport hermes_state- captured = {}-- class FakeDB:- def resolve_session_id(self, session_id):- captured["resolved_from"] = session_id- return "sess-123"-- def export_session(self, session_id):- captured["exported"] = session_id- return _sample_session()-- def close(self):- captured["closed"] = True-- monkeypatch.setattr(hermes_state, "SessionDB", lambda: FakeDB())+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ path = tmp_path / "state.db"+ db = hermes_state.SessionDB(db_path=path)+ db.create_session("sess-123", "cli")+ for message in _sample_session()["messages"]:+ db.append_message("sess-123", message["role"], message["content"])+ db.close()+ before = path.read_bytes()monkeypatch.setattr(sys,"argv",@@ -128,10 +121,6 @@ def test_sessions_export_cli_prompt_only_stdout(monkeypatch, capsys):"Why is login broken?","Only show me the prompts.",]- assert captured == {- "resolved_from": "sess",- "exported": "sess-123",- "closed": True,- }+ assert path.read_bytes() == beforediff --git a/tests/hermes_cli/test_sessions_export_md_cli.py b/tests/hermes_cli/test_sessions_export_md_cli.pyindex b5347780bf6..ea610d9402d 100644--- a/tests/hermes_cli/test_sessions_export_md_cli.py+++ b/tests/hermes_cli/test_sessions_export_md_cli.py@@ -1,130 +1,61 @@import sys+from hermes_state import SessionDB+def test_sessions_export_md_writes_single_session(monkeypatch, tmp_path, capsys):import hermes_cli.main as main_mod- import hermes_state-- captured = {}-- class FakeDB:- def resolve_session_id(self, session_id):- captured["resolved_from"] = session_id- return "20260706_123456_abcd1234"-- def export_session(self, session_id):- captured["exported"] = session_id- return {- "id": session_id,- "title": "Export CLI Test",- "source": "cli",- "message_count": 1,- "messages": [{"role": "user", "content": "hello"}],- }-- def delete_session(self, *args, **kwargs):- raise AssertionError("markdown export must not delete sessions")-- def prune_sessions(self, *args, **kwargs):- raise AssertionError("markdown export must not prune sessions")- def close(self):- captured["closed"] = True-- monkeypatch.setattr(hermes_state, "SessionDB", lambda: FakeDB())- monkeypatch.setattr(- sys,- "argv",- [- "hermes",- "sessions",- "export",- "--format",- "md",- "--session-id",- "20260706_123456",- str(tmp_path),- ],- )+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ path = tmp_path / "state.db"+ db = SessionDB(db_path=path)+ sid = "20260706_123456_abcd1234"+ db.create_session(sid, "cli")+ db.set_session_title(sid, "Export CLI Test")+ db.append_message(sid, "user", "hello")+ db.close()+ before = path.read_bytes()+ monkeypatch.setattr(sys, "argv", [+ "hermes", "sessions", "export", "--format", "md",+ "--session-id", "20260706_123456", str(tmp_path / "exports"),+ ])main_mod.main()output = capsys.readouterr().out- files = list(tmp_path.glob("*.md"))+ files = list((tmp_path / "exports").glob("*.md"))assert len(files) == 1text = files[0].read_text(encoding="utf-8")assert "# Export CLI Test" in textassert "hello" in text- assert captured == {- "resolved_from": "20260706_123456",- "exported": "20260706_123456_abcd1234",- "closed": True,- }+ assert path.read_bytes() == beforeassert "Exported 1 session" in outputassert "1 message" in outputassert str(files[0]) in outputdef test_sessions_export_redact_scrubs_secrets(monkeypatch, tmp_path):- """--redact runs exported content through force-mode secret redaction."""+ """Redaction affects the exported file, never the stored transcript."""import hermes_cli.main as main_mod- import hermes_state+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))secret = "sk-proj-Zz12345678901234567890123456789012345678"-- class FakeDB:- def resolve_session_id(self, session_id):- return "s1"-- def export_session(self, session_id):- return {- "id": "s1",- "title": "Redact",- "messages": [- {"role": "tool", "name": "terminal", "content": f"api key: {secret}"}- ],- }-- def close(self):- pass-- monkeypatch.setattr(hermes_state, "SessionDB", lambda: FakeDB())- monkeypatch.setattr(- sys,- "argv",- [- "hermes", "sessions", "export", "--format", "md",- "--session-id", "s1", "--redact", str(tmp_path),- ],- )+ path = tmp_path / "state.db"+ db = SessionDB(db_path=path)+ db.create_session("s1", "cli")+ db.append_message("s1", "tool", f"api key: {secret}", tool_name="terminal")+ db.close()+ before = path.read_bytes()+ monkeypatch.setattr(sys, "argv", [+ "hermes", "sessions", "export", "--format", "md",+ "--session-id", "s1", "--redact", str(tmp_path / "exports"),+ ])main_mod.main()- text = next(tmp_path.glob("*.md")).read_text(encoding="utf-8")+ files = list((tmp_path / "exports").glob("*.md"))+ assert len(files) == 1+ text = files[0].read_text(encoding="utf-8")assert secret not in textassert "api key:" in text---def _trace_fake_db(captured):- class FakeDB:- def resolve_session_id(self, session_id):- return "s1"-- def get_session(self, session_id):- return {"id": session_id, "model": "test-model"}-- def get_messages_as_conversation(self, session_id):- captured["conv"] = session_id- return [- {"role": "user", "content": "hello trace"},- {"role": "assistant", "content": "hi"},- ]-- def close(self):- captured["closed"] = True-- return FakeDB()----+ assert path.read_bytes() == before