refactor(sessions)!: retire the global shared session (#6621)

Co-authored-by: chengyongru <chengyongru.ai@gmail.com>
This commit is contained in:
Xubin Renandchengyongru authored and GitHub committed 2026-11-12 09:55:55 +08:00
1 parent 28d73b6942
commit e6b0aec2a8
77 files changed
+311 -1255

No files matched your search

+27
View File
@@ -6,6 +6,7 @@ import json
import os
from contextlib import suppress
from pathlib import Path
from unittest.mock import AsyncMock
import pytest
@@ -275,6 +276,32 @@ def test_recover_processing_deliveries_requeues_claimed_delivery(tmp_path: Path)
assert reclaimed[0].last_error == "delivery was recovered from interrupted processing"
@pytest.mark.asyncio
async def test_trigger_delivers_to_its_saved_session(tmp_path: Path) -> None:
store = LocalTriggerStore(tmp_path)
trigger = store.create(
name="Old trigger", channel="websocket", chat_id="chat-1",
session_key="unified:default",
)
store.enqueue(trigger.id, "Process this delivery")
submit_turn = AsyncMock()
task = asyncio.create_task(run_local_trigger_queue(
store=store, submit_turn=submit_turn, is_channel_enabled=_channel_is_enabled,
))
try:
async with asyncio.timeout(3):
while not (current := store.get(trigger.id)) or current.last_status != "ok":
await asyncio.sleep(0.01)
message = submit_turn.await_args.args[0]
assert message.session_key == "unified:default"
assert (message.channel, message.chat_id) == ("websocket", "chat-1")
finally:
task.cancel()
with suppress(asyncio.CancelledError):
await task
@pytest.mark.asyncio
async def test_local_trigger_queue_submits_bound_inbound_message(tmp_path: Path) -> None:
store = LocalTriggerStore(tmp_path)