fix(pheby): migrate bridge to the new persistence repository API
The Hermes update replaced SessionDB with the persistence layer; raw SQL (_read_all), create_session/append_message/delete_sessions, get_messages_as_conversation and set_session_yolo are gone. Use sessions.search_sessions (client-side session_key filter), messages .read_conversation(ConversationRequest) with as_openai_message rows, sessions.create/append/delete/get/set_yolo instead. Update test fakes and open the storage interface directly in the cron delivery tests.
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
import pytest
|
||||
|
||||
from gateway.config import PlatformConfig
|
||||
from hermes_state import SessionDB
|
||||
from persistence.conversation.messages import NewMessage
|
||||
from persistence.conversation.sessions import NewSession, SessionId
|
||||
from pheby import hermes_bridge as hb, protocol as proto
|
||||
from pheby.adapter import PhebyAdapter
|
||||
from pheby.server import PhebyServer
|
||||
@@ -10,7 +11,11 @@ from pheby.server import PhebyServer
|
||||
|
||||
@pytest.fixture
|
||||
def delivery_stack(tmp_path, monkeypatch):
|
||||
db = SessionDB(tmp_path / "state.db")
|
||||
# SessionDB is deprecated; open the storage interface directly for the
|
||||
# test profile (context-local HERMES_HOME drives profile_scope()).
|
||||
from persistence_assembly import open_persistence, profile_scope
|
||||
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
||||
db = open_persistence(profile_scope(), eager=True)
|
||||
monkeypatch.setattr(hb, "_session_db", lambda: db)
|
||||
monkeypatch.setattr(hb, "_session_store", lambda: None)
|
||||
adapter = PhebyAdapter(PlatformConfig(enabled=True, extra={"secret": "test-secret"}))
|
||||
@@ -30,8 +35,9 @@ async def test_cron_delivery_survives_reopen_without_touching_active_turn(delive
|
||||
adapter, server, db = delivery_stack
|
||||
cid = "home"
|
||||
key = hb._session_key_for(cid)
|
||||
db.create_session("active-session", "pheby", session_key=key)
|
||||
db.append_message("active-session", "user", "My ongoing question")
|
||||
db.sessions.create(NewSession(
|
||||
session_id=SessionId("active-session"), source="pheby", session_key=key))
|
||||
db.messages.append("active-session", NewMessage(role="user", content="My ongoing question"))
|
||||
adapter._drafts[cid] = {"message_id": "draft-active", "text": "Still thinking"}
|
||||
hb._ACTIVE_RUNS[cid] = {"run_id": "active-run", "started": 0}
|
||||
|
||||
@@ -44,7 +50,7 @@ async def test_cron_delivery_survives_reopen_without_touching_active_turn(delive
|
||||
assert found and not has_more
|
||||
assert hb.active_run_id(cid) == "active-run"
|
||||
assert adapter._drafts[cid]["message_id"] == "draft-active"
|
||||
assert [m["content"] for m in db.get_messages_as_conversation("active-session")] == ["My ongoing question"]
|
||||
assert [m.content for m in db.messages.read_conversation("active-session")] == ["My ongoing question"]
|
||||
assert await server.router.get_name(cid) is not None
|
||||
conversations = await hb.list_conversations(server)
|
||||
assert conversations[0]["conversation_id"] == cid
|
||||
@@ -67,7 +73,7 @@ async def test_cron_delivery_does_not_claim_success_when_save_fails(delivery_sta
|
||||
raise OSError("disk unavailable")
|
||||
|
||||
monkeypatch.setattr(server, "broadcast", broadcast)
|
||||
monkeypatch.setattr(db, "append_message", fail)
|
||||
monkeypatch.setattr(db.messages, "append", fail)
|
||||
result = await adapter.send("home", "A report", metadata={"job_id": "daily"})
|
||||
assert not result.success
|
||||
assert broadcasts == []
|
||||
|
||||
Reference in New Issue
Block a user