fix(trigger): require names for trigger creation

This commit is contained in:
chengyongru
2026-07-02 13:32:46 +08:00
committed by Xubin Ren
parent 7178ea3f13
commit b690a48336
10 changed files with 60 additions and 19 deletions
+29 -1
View File
@@ -45,5 +45,33 @@ 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_without_name_returns_usage_only(tmp_path: Path) -> None:
router = CommandRouter()
register_builtin_commands(router)
store = ExternalTriggerStore(tmp_path)
loop = SimpleNamespace(workspace=tmp_path, external_trigger_store=store)
msg = InboundMessage(
channel="websocket",
sender_id="user",
chat_id="chat-1",
content="/trigger@nanobot_bot",
metadata={"webui": True},
)
ctx = CommandContext(
msg=msg,
session=None,
key="websocket:chat-1",
raw="/trigger@nanobot_bot",
loop=loop,
)
response = await router.dispatch(ctx)
assert response is not None
assert "Usage: /trigger <name>" in response.content
assert store.list_for_session("websocket:chat-1") == []
def test_trigger_command_is_in_help_text() -> None:
assert "/trigger [name]" in build_help_text()
assert "/trigger <name>" in build_help_text()