astrbot_plugin_imagestudio/tests/test_chat_session_service.py

20 行
906 B
Python

from backend.services.chat_session_service import ChatSessionStore
import time
def test_chat_session_store_binds_and_pops_session(tmp_path):
path = tmp_path / "sessions.json"
store = ChatSessionStore(ttl_seconds=60, max_sessions=2, persistence_path=path)
store.put("qq:group:user", "select_image", {"images": ["img-1"]})
restored = ChatSessionStore(ttl_seconds=60, max_sessions=2, persistence_path=path)
assert restored.get("qq:group:user").action == "select_image"
assert store.get("qq:group:user").payload["images"] == ["img-1"]
assert store.pop("qq:group:user").action == "select_image"
assert store.get("qq:group:user") is None
def test_chat_session_expires(tmp_path):
store = ChatSessionStore(ttl_seconds=0, max_sessions=2, persistence_path=tmp_path / "expired.json")
store.put("key", "confirm", {})
time.sleep(0.01)
assert store.get("key") is None