Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7776,6 +7776,7 @@ async def _handle_kanban_command(self, event: MessageEvent) -> str:
"""
import asyncio
import re
import shlex
from hermes_cli.kanban import run_slash

text = (event.text or "").strip()
Expand All @@ -7785,7 +7786,26 @@ async def _handle_kanban_command(self, event: MessageEvent) -> str:
if text.startswith("kanban"):
text = text[len("kanban"):].lstrip()

is_create = text.split(None, 1)[:1] == ["create"]
tokens = shlex.split(text) if text else []
requested_board = None
action = None
i = 0
while i < len(tokens):
tok = tokens[i]
if tok == "--board":
if i + 1 >= len(tokens):
break
requested_board = tokens[i + 1]
i += 2
continue
if tok.startswith("--board="):
requested_board = tok.split("=", 1)[1]
i += 1
continue
action = tok
break

is_create = action == "create"

try:
output = await asyncio.to_thread(run_slash, text)
Expand All @@ -7812,7 +7832,7 @@ async def _handle_kanban_command(self, event: MessageEvent) -> str:
if platform_str and chat_id:
def _sub():
from hermes_cli import kanban_db as _kb
conn = _kb.connect()
conn = _kb.connect(board=requested_board)
try:
_kb.add_notify_sub(
conn, task_id=task_id,
Expand Down
50 changes: 50 additions & 0 deletions tests/hermes_cli/test_kanban_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest

from pathlib import Path
from types import SimpleNamespace
from hermes_cli import kanban_db as kb
from unittest.mock import AsyncMock, MagicMock, patch

Expand Down Expand Up @@ -301,3 +302,52 @@ def _spy_init_db(*args, **kwargs):
"_kanban_notifier_watcher must not call _kb.init_db(board=slug) — "
"see issue #21378."
)


@pytest.mark.asyncio
async def test_gateway_create_autosubscribes_on_explicit_board(kanban_home):
"""`/kanban --board <slug> create ...` must subscribe on that board.

The gateway handler currently auto-subscribes after `/kanban create`,
but the create detection must still work when the shared `--board`
flag appears before the subcommand, and the subscription must land in
that board's DB rather than the ambient/default board.
"""
from gateway.run import GatewayRunner
from gateway.config import Platform

kb.create_board("projx")

runner = object.__new__(GatewayRunner)
source = SimpleNamespace(
platform=Platform.TELEGRAM,
chat_id="chat1",
thread_id="th1",
user_id="u1",
)
event = SimpleNamespace(
text='/kanban --board projx create "hello" --assignee alice',
source=source,
)

out = await GatewayRunner._handle_kanban_command(runner, event)

assert "subscribed" in out.lower()

conn = kb.connect(board="projx")
try:
subs = kb.list_notify_subs(conn)
tasks = kb.list_tasks(conn)
finally:
conn.close()

assert [t.title for t in tasks] == ["hello"]
assert len(subs) == 1
assert subs[0]["chat_id"] == "chat1"
assert subs[0]["thread_id"] == "th1"

conn = kb.connect(board="default")
try:
assert kb.list_notify_subs(conn) == []
finally:
conn.close()