Files
hermes-agent/tests/test_guest_durability_barriers.py
T
Teknium 53db597201 simplify(compat): hermes_state — drop 81 re-exports + 3 registry aliases + 3 shims, repoint 45 callers + 60 test files
hermes_state.py: delete every '# noqa: F401 (re-exported...)' import block (hermes_state_common/errors/guard/
readpool/sessions/fts/dbfile/wal/repair/registry + agent.context_compressor _DB_PERSISTED_MARKER_KEY); keep
only the names hermes_state.py itself uses, without noqa.
hermes_state_registry.py: drop get_shared_session_db/release_shared_session_db/close_shared_session_dbs
aliases; every caller (gateway/, tools/, tui_gateway/, cron/, mcp_serve, run_agent, tests) now imports
acquire/release/close_all/release_or_close from hermes_state_registry.
hermes_state_titles.py: drop set_auto_title_if_empty shim (title_generator keeps its getattr fallback).
Re-remove shim-only names restored by 34abf954bd: latest_user_message_row_id (tests call
latest_message_row_id(key, role='user'); role-targeting assertions kept) and get_session_activity (tests
build the snapshot via agent.session_activity.build_activity_snapshot over db.get_session(sid)).
hermes_state_wal._log_once resolves its dedupe sets as module globals instead of via hermes_state;
hermes_state_repair helpers call module globals directly (tests patch hermes_state_repair.<name>).
Frozen updater surface untouched (update_cmd_maint imports only SessionDB from hermes_state).
2026-09-03 13:46:50 -07:00

69 lines
2.3 KiB
Python

"""Guest ledger connections must inherit the configured database.synchronous.
apply_durability_barriers() is the guest-connection entry point (secondary
state.db users that must NOT touch journal mode). The configured
``database.synchronous`` level normally rides on apply_database_pragmas()
during the owner's journal-mode setup — a path guests deliberately skip — so
the guest entry point applies it directly.
"""
import sqlite3
import pytest
import hermes_state
from hermes_state_repair import apply_durability_barriers
def _config(monkeypatch, database_section):
import hermes_cli.config as config_mod
cfg = {"database": database_section}
monkeypatch.setattr(config_mod, "load_config_readonly", lambda *a, **k: cfg)
return cfg
def test_guest_barriers_apply_configured_synchronous(monkeypatch, tmp_path):
_config(monkeypatch, {"synchronous": "FULL"})
conn = sqlite3.connect(tmp_path / "state.db")
try:
conn.execute("PRAGMA journal_mode=DELETE")
conn.execute("PRAGMA synchronous=1")
apply_durability_barriers(conn)
assert conn.execute("PRAGMA synchronous").fetchone()[0] == 2
# And the journal mode was NOT touched — that is the whole contract.
assert (
str(conn.execute("PRAGMA journal_mode").fetchone()[0]).lower()
== "delete"
)
finally:
conn.close()
def test_guest_barriers_leave_synchronous_alone_when_unset(monkeypatch, tmp_path):
_config(monkeypatch, {})
conn = sqlite3.connect(tmp_path / "state.db")
try:
conn.execute("PRAGMA journal_mode=DELETE")
conn.execute("PRAGMA synchronous=1")
apply_durability_barriers(conn)
assert conn.execute("PRAGMA synchronous").fetchone()[0] == 1
finally:
conn.close()
def test_guest_barriers_survive_config_failure(monkeypatch, tmp_path):
import hermes_cli.config as config_mod
def _boom(*a, **k):
raise RuntimeError("config unavailable")
monkeypatch.setattr(config_mod, "load_config_readonly", _boom)
conn = sqlite3.connect(tmp_path / "state.db")
try:
conn.execute("PRAGMA journal_mode=DELETE")
# Must not raise; best-effort like every other pragma path.
apply_durability_barriers(conn)
finally:
conn.close()