refactor(trigger): share automation turn delivery

This commit is contained in:
chengyongru
2026-07-02 13:32:46 +08:00
committed by Xubin Ren
parent afef27dd6c
commit acb0e853ff
16 changed files with 413 additions and 299 deletions
+32
View File
@@ -8,6 +8,7 @@ import pytest
from nanobot.bus.events import InboundMessage
from nanobot.command.builtin 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
@@ -45,6 +46,37 @@ async def test_trigger_command_creates_session_bound_local_trigger(tmp_path: Pat
assert f"nanobot trigger {trigger.id} \"message\"" in response.content
@pytest.mark.asyncio
async def test_trigger_command_binds_inbound_session_when_unified_session_is_active(
tmp_path: Path,
) -> None:
router = CommandRouter()
register_builtin_commands(router)
store = LocalTriggerStore(tmp_path)
loop = SimpleNamespace(workspace=tmp_path, local_trigger_store=store)
msg = InboundMessage(
channel="websocket",
sender_id="user",
chat_id="chat-1",
content="/trigger PR review",
session_key_override="websocket:chat-1:thread-a",
)
ctx = CommandContext(
msg=msg,
session=None,
key=UNIFIED_SESSION_KEY,
raw="/trigger PR review",
loop=loop,
)
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) == []
@pytest.mark.asyncio
async def test_trigger_command_without_name_returns_usage_only(tmp_path: Path) -> None:
router = CommandRouter()