refactor(state): flatten registry acquire flow; restore mirror cleanup assertion
Post-merge review follow-ups on #100201: - acquire(): drop the never-iterating 'while True' and the redundant 'existing is not generation' half of the race check — after the retire path, generation is always None on the fresh-open leg, so 'existing is not None' is the complete condition. Same behavior, flat flow. - test_mirror: the conversion to the shared registry dropped the cleanup assertion entirely; restore it by patching hermes_state.release_or_close and asserting the handle is released exactly once after _append_to_sqlite.
This commit is contained in:
@@ -119,18 +119,21 @@ class TestMirrorToSession:
|
||||
|
||||
|
||||
class TestAppendToSqlite:
|
||||
def test_connection_is_closed_after_use(self, tmp_path):
|
||||
"""Verify _append_to_sqlite releases the shared SessionDB handle."""
|
||||
def test_connection_is_released_after_use(self, tmp_path):
|
||||
"""Verify _append_to_sqlite returns the shared SessionDB reference."""
|
||||
from gateway.mirror import _append_to_sqlite
|
||||
mock_db = MagicMock()
|
||||
released = []
|
||||
|
||||
with patch("hermes_state.get_shared_session_db", return_value=mock_db):
|
||||
with patch("hermes_state.get_shared_session_db", return_value=mock_db), \
|
||||
patch(
|
||||
"hermes_state.release_or_close",
|
||||
side_effect=lambda db: released.append(db),
|
||||
):
|
||||
_append_to_sqlite("sess_1", {"role": "assistant", "content": "hello"})
|
||||
|
||||
mock_db.append_message.assert_called_once()
|
||||
# Shared instances are released (not closed) — the registry owns close().
|
||||
# release_shared_session_db is a module-level function, so verify the
|
||||
# mock was passed to it by checking that append_message was called
|
||||
# (the real release_shared_session_db on a MagicMock is a no-op since
|
||||
# the mock isn't in the registry).
|
||||
assert released == [mock_db], (
|
||||
"the shared handle must be released exactly once after use"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user