Skip to content

The agent that grows with you

test(sessions): keep two invariant tests for the export-then-delete fence

kshitijk4poor56b37fd3d245
diff --git a/tests/hermes_cli/test_save_transcript_history.py b/tests/hermes_cli/test_save_transcript_history.py
index 1416fbcf10b..97949a005ab 100644
--- a/tests/hermes_cli/test_save_transcript_history.py
+++ b/tests/hermes_cli/test_save_transcript_history.py
@@ -1,4 +1,4 @@
-"""Human-readable /save mirrors display history; JSON remains import-safe live context."""
+"""/save md (CLI and gateway) carries the display history, compaction-archived turns included."""
import asyncio
from datetime import datetime
from types import SimpleNamespace
@@ -57,12 +57,11 @@ def _gateway_save(db, fmt, out):
@pytest.mark.parametrize("save", [_cli_save, _gateway_save], ids=["cli", "gateway"])
[email protected]("fmt, expected", [("md", 6), ("html", 6), ("json", 1)])
-def test_save_transcript_holds_display_history(tmp_path, monkeypatch, save, fmt, expected):
+def test_save_transcript_holds_display_history(tmp_path, monkeypatch, save):
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
db = _compacted_store(tmp_path / "state.db")
try:
- text = save(db, fmt, tmp_path / f"saved.{fmt}")
+ text = save(db, "md", tmp_path / "saved.md")
finally:
db.close()
- assert sum(f"answer {i}" in text for i in range(1, 7)) == expected
+ assert [f"answer {i}" in text for i in range(1, 7)] == [True] * 6
diff --git a/tests/hermes_cli/test_sessions_export_md_cli.py b/tests/hermes_cli/test_sessions_export_md_cli.py
index aa5739b3890..5673a7d5601 100644
--- a/tests/hermes_cli/test_sessions_export_md_cli.py
+++ b/tests/hermes_cli/test_sessions_export_md_cli.py
@@ -194,59 +194,3 @@ def test_delete_after_verified_rejects_same_count_content_change(monkeypatch, tm
assert db.get_messages("s1")[0]["content"] == "changed after export"
finally:
db.close()
-
-
-def test_delete_after_verified_rechecks_history_at_the_delete_boundary(monkeypatch, tmp_path, capsys):
- """A writer landing after any caller-side precheck must still block the destructive transaction."""
- open_db = _real_store(monkeypatch, tmp_path)
- _seed_six_turns(open_db, "s1", compact=False)
- original_delete = open_db.delete_session
- injected = False
-
- def delete_after_late_append(self, *args, **kwargs):
- nonlocal injected
- if not injected:
- writer = open_db()
- try:
- writer.append_message("s1", "user", "landed at delete boundary")
- finally:
- writer.close()
- injected = True
- return original_delete(self, *args, **kwargs)
-
- monkeypatch.setattr(open_db, "delete_session", delete_after_late_append)
- _export_delete(monkeypatch, tmp_path / "out", "s1")
-
- text = next((tmp_path / "out").glob("*.md")).read_text(encoding="utf-8")
- output = capsys.readouterr().out
- assert "landed at delete boundary" not in text
- assert "was not deleted because its history or delegate set changed after export" in output
- db = open_db()
- try:
- assert db.get_session("s1") is not None
- assert db.get_messages("s1")[-1]["content"] == "landed at delete boundary"
- finally:
- db.close()
-
-
[email protected]("argv, marker, expected", [
- pytest.param(["--format", "html", "--session-id", "s1"], "answer", 6, id="html"),
- pytest.param(["--format", "html"], "answer", 6, id="html-all"),
- pytest.param(["--format", "md", "--only", "user-prompts", "--session-id", "s1"], "question", 6, id="only"),
- pytest.param(
- ["--format", "jsonl", "--only", "user-prompts", "--session-id", "s1"],
- "question", 6, id="only-jsonl",
- ),
- pytest.param(["--format", "jsonl", "--session-id", "s1"], "answer", 1, id="jsonl-live"),
-])
-def test_human_readable_exports_use_display_history(monkeypatch, tmp_path, argv, marker, expected):
- import hermes_cli.main as main_mod
-
- open_db = _real_store(monkeypatch, tmp_path)
- _seed_six_turns(open_db, "s1", compact=True)
- out = tmp_path / "export.out"
- monkeypatch.setattr(sys, "argv", ["hermes", "sessions", "export", *argv, str(out)])
- main_mod.main()
-
- text = out.read_text(encoding="utf-8")
- assert sum(f"{marker} {i}" in text for i in range(1, 7)) == expected