feat(telegram): add chat session mode (#102)

This commit is contained in:
banteg
2026-01-12 19:05:39 +04:00
committed by GitHub
parent 7825dd73a9
commit 637a9fc3e2
18 changed files with 622 additions and 30 deletions
+38
View File
@@ -0,0 +1,38 @@
import pytest
from takopi.model import ResumeToken
from takopi.telegram.chat_sessions import ChatSessionStore
@pytest.mark.anyio
async def test_chat_sessions_store_roundtrip(tmp_path) -> None:
path = tmp_path / "telegram_chat_sessions_state.json"
store = ChatSessionStore(path)
await store.set_session_resume(1, None, ResumeToken(engine="codex", value="abc123"))
await store.set_session_resume(1, 42, ResumeToken(engine="claude", value="res-1"))
stored_private = await store.get_session_resume(1, None, "codex")
stored_group = await store.get_session_resume(1, 42, "claude")
assert stored_private == ResumeToken(engine="codex", value="abc123")
assert stored_group == ResumeToken(engine="claude", value="res-1")
store2 = ChatSessionStore(path)
stored_private_2 = await store2.get_session_resume(1, None, "codex")
stored_group_2 = await store2.get_session_resume(1, 42, "claude")
assert stored_private_2 == ResumeToken(engine="codex", value="abc123")
assert stored_group_2 == ResumeToken(engine="claude", value="res-1")
@pytest.mark.anyio
async def test_chat_sessions_store_clear(tmp_path) -> None:
path = tmp_path / "telegram_chat_sessions_state.json"
store = ChatSessionStore(path)
await store.set_session_resume(2, None, ResumeToken(engine="codex", value="one"))
await store.set_session_resume(2, 77, ResumeToken(engine="codex", value="two"))
await store.clear_sessions(2, None)
assert await store.get_session_resume(2, None, "codex") is None
assert await store.get_session_resume(2, 77, "codex") == ResumeToken(
engine="codex",
value="two",
)