fix: clear chat sessions on cwd change (#172)

This commit is contained in:
banteg
2026-01-20 13:23:07 +04:00
committed by GitHub
parent 0291a066b3
commit e2bb9fb717
4 changed files with 61 additions and 0 deletions
+31
View File
@@ -1,3 +1,5 @@
from pathlib import Path
import pytest
from takopi.model import ResumeToken
@@ -36,3 +38,32 @@ async def test_chat_sessions_store_clear(tmp_path) -> None:
engine="codex",
value="two",
)
@pytest.mark.anyio
async def test_chat_sessions_store_drops_sessions_on_cwd_change(
tmp_path, monkeypatch
) -> None:
path = tmp_path / "telegram_chat_sessions_state.json"
dir1 = tmp_path / "dir1"
dir2 = tmp_path / "dir2"
dir1.mkdir()
dir2.mkdir()
monkeypatch.chdir(dir1)
store = ChatSessionStore(path)
await store.set_session_resume(1, None, ResumeToken(engine="codex", value="abc123"))
assert await store.get_session_resume(1, None, "codex") == ResumeToken(
engine="codex", value="abc123"
)
store2 = ChatSessionStore(path)
assert await store2.sync_startup_cwd(Path.cwd()) is False
assert await store2.get_session_resume(1, None, "codex") == ResumeToken(
engine="codex", value="abc123"
)
monkeypatch.chdir(dir2)
store3 = ChatSessionStore(path)
assert await store3.sync_startup_cwd(Path.cwd()) is True
assert await store3.get_session_resume(1, None, "codex") is None