refactor(sessions)!: retire the global shared session (#6621)
Co-authored-by: chengyongru <chengyongru.ai@gmail.com>
This commit is contained in:
1 parent
28d73b6942
commit
e6b0aec2a8
77 files changed
+311
-1255
No files matched your search
@@ -257,7 +257,7 @@ async def test_compact_during_active_turn_waits_for_the_session_lock(loop, comma
|
||||
)
|
||||
lock = loop._get_session_lock(key)
|
||||
async with lock:
|
||||
await loop._dispatch_command_inline(msg, key, msg.content, loop.commands.dispatch)
|
||||
await loop._dispatch_command_inline(msg, msg.content, loop.commands.dispatch)
|
||||
tasks = list(loop._active_tasks[key])
|
||||
assert len(tasks) == 1
|
||||
await asyncio.sleep(0)
|
||||
@@ -285,7 +285,7 @@ async def test_stop_completes_a_compact_command_waiting_for_the_session_lock(loo
|
||||
completions = []
|
||||
loop.bus.subscribe(completions.append, TurnCompleted)
|
||||
async with loop._get_session_lock(key):
|
||||
await loop._dispatch_command_inline(msg, key, msg.content, loop.commands.dispatch)
|
||||
await loop._dispatch_command_inline(msg, msg.content, loop.commands.dispatch)
|
||||
reply = await cmd_stop(CommandContext(
|
||||
msg=msg, session=None, key=key, raw="/stop", loop=loop,
|
||||
))
|
||||
@@ -330,7 +330,7 @@ async def test_compact_is_a_fifo_barrier_during_an_active_turn(loop, command_tex
|
||||
channel="cli", sender_id="u", chat_id="test", content="before compaction",
|
||||
)))
|
||||
command = InboundMessage(channel="cli", sender_id="u", chat_id="test", content=command_text)
|
||||
await loop._dispatch_command_inline(command, key, command.content, loop.commands.dispatch)
|
||||
await loop._dispatch_command_inline(command, command.content, loop.commands.dispatch)
|
||||
(await loop._enqueue_session_message(InboundMessage(
|
||||
channel="cli", sender_id="u", chat_id="test", content="after compaction",
|
||||
)))
|
||||
@@ -375,7 +375,7 @@ async def test_stop_completes_compact_queued_behind_an_active_turn(loop, command
|
||||
channel="websocket", sender_id="u", chat_id="test", content=command_text,
|
||||
metadata={"webui_turn_id": "queued-compact"},
|
||||
)
|
||||
await loop._dispatch_command_inline(command, key, command.content, loop.commands.dispatch)
|
||||
await loop._dispatch_command_inline(command, command.content, loop.commands.dispatch)
|
||||
await cmd_stop(CommandContext(msg=command, session=None, key=key, raw="/stop", loop=loop))
|
||||
|
||||
assert task.cancelled()
|
||||
|
||||
@@ -8,7 +8,6 @@ import pytest
|
||||
from nanobot.bus.events import InboundMessage
|
||||
from nanobot.command.application import build_help_text, register_builtin_commands
|
||||
from nanobot.command.router import CommandContext, CommandRouter
|
||||
from nanobot.session.keys import UNIFIED_SESSION_KEY
|
||||
from nanobot.triggers.local_store import LocalTriggerStore
|
||||
|
||||
|
||||
@@ -47,7 +46,7 @@ async def test_trigger_command_creates_session_bound_local_trigger(tmp_path: Pat
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_trigger_command_binds_inbound_session_when_unified_session_is_active(
|
||||
async def test_trigger_command_binds_explicit_topic_session(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
router = CommandRouter()
|
||||
@@ -55,16 +54,16 @@ async def test_trigger_command_binds_inbound_session_when_unified_session_is_act
|
||||
store = LocalTriggerStore(tmp_path)
|
||||
loop = SimpleNamespace(workspace=tmp_path, local_trigger_store=store)
|
||||
msg = InboundMessage(
|
||||
channel="websocket",
|
||||
channel="telegram",
|
||||
sender_id="user",
|
||||
chat_id="chat-1",
|
||||
content="/trigger PR review",
|
||||
session_key_override="websocket:chat-1:thread-a",
|
||||
session_key_override="telegram:chat-1:topic:5",
|
||||
)
|
||||
ctx = CommandContext(
|
||||
msg=msg,
|
||||
session=None,
|
||||
key=UNIFIED_SESSION_KEY,
|
||||
key=msg.session_key,
|
||||
raw="/trigger PR review",
|
||||
loop=loop,
|
||||
)
|
||||
@@ -72,9 +71,9 @@ async def test_trigger_command_binds_inbound_session_when_unified_session_is_act
|
||||
response = await router.dispatch(ctx)
|
||||
|
||||
assert response is not None
|
||||
trigger = store.list_for_session("websocket:chat-1:thread-a")[0]
|
||||
assert trigger.session_key == "websocket:chat-1:thread-a"
|
||||
assert store.list_for_session(UNIFIED_SESSION_KEY) == []
|
||||
trigger = store.list_for_session("telegram:chat-1:topic:5")[0]
|
||||
assert trigger.session_key == "telegram:chat-1:topic:5"
|
||||
assert store.list_for_session("telegram:chat-1") == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in new issue
Block a user