4a268c9e4a
- _session_count: back to main's raw sqlite mode=ro COUNT(*) via as_uri() — routing it through SessionDB(read_only=True) both re-introduced the raw f-string URI ('?'/'#' in the home path truncate it) and queries columns (s.archived) an unmigrated store lacks, so doctor would report a healthy DB as broken.
- _write_health_reason: snapshot source URI built with as_uri() for the same reason; the --fix live probe (_db_opens_cleanly runs BEGIN IMMEDIATE) now falls back to the snapshot unless live_writer_holds_db proves the store quiet, matching _state_db_wal — hermes doctor --fix never becomes a second writer against a gateway's state.db (#103339).
- SessionDB._connect_read_only: same as_uri() form so every read-only opener is safe in a home containing '?' or '#'.
- test_sessions_export_output_dir: fixture accepts the read_only kwarg the PR introduced.
- Drop the two doctor tests that pinned the SessionDB factory kwargs; main's URI-reserved-chars test covers _session_count.
Co-authored-by: Ahmett101 <Ahmett101@users.noreply.github.com>
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
"""`hermes sessions export` single-file formats accept a directory as OUTPUT."""
|
|
|
|
import json
|
|
import sys
|
|
|
|
import hermes_state
|
|
import hermes_cli.main as main_mod
|
|
|
|
|
|
class _FakeDB:
|
|
def resolve_session_id(self, session_id):
|
|
return "sess-123"
|
|
|
|
def export_session(self, session_id):
|
|
return {"id": "sess-123", "source": "cli", "messages": [{"role": "user", "content": "hi"}]}
|
|
|
|
def close(self):
|
|
pass
|
|
|
|
|
|
def _export(monkeypatch, *argv):
|
|
monkeypatch.setattr(hermes_state, "SessionDB", lambda *args, **kwargs: _FakeDB())
|
|
monkeypatch.setattr(sys, "argv", ["hermes", "sessions", "export", "--session-id", "sess", *argv])
|
|
main_mod.main()
|
|
|
|
|
|
def test_jsonl_export_into_directory_writes_default_named_file(monkeypatch, tmp_path):
|
|
out_dir = tmp_path / "saved"
|
|
out_dir.mkdir()
|
|
|
|
_export(monkeypatch, f"{out_dir}/")
|
|
|
|
written = out_dir / "hermes_session_sess-123.jsonl"
|
|
assert json.loads(written.read_text(encoding="utf-8"))["id"] == "sess-123"
|
|
|
|
|
|
def test_jsonl_export_to_file_path_is_unchanged(monkeypatch, tmp_path):
|
|
target = tmp_path / "one.jsonl"
|
|
|
|
_export(monkeypatch, str(target))
|
|
|
|
assert json.loads(target.read_text(encoding="utf-8"))["id"] == "sess-123"
|
|
assert target.is_file() and not (tmp_path / "hermes_session_sess-123.jsonl").exists()
|