From f6d4f3c37daddc88040dd44d68399400ac12df29 Mon Sep 17 00:00:00 2001 From: Frowtek Date: Sun, 10 May 2026 16:33:07 +0300 Subject: [PATCH] fix(kanban): route gateway create auto-subscribe to explicit board --- gateway/run.py | 24 +++++++++++-- tests/hermes_cli/test_kanban_notify.py | 50 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/gateway/run.py b/gateway/run.py index d685e9849aa..7b2d7dea333 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -8329,6 +8329,7 @@ class GatewayRunner: """ import asyncio import re + import shlex from hermes_cli.kanban import run_slash text = (event.text or "").strip() @@ -8338,7 +8339,26 @@ class GatewayRunner: 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) @@ -8365,7 +8385,7 @@ class GatewayRunner: 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, diff --git a/tests/hermes_cli/test_kanban_notify.py b/tests/hermes_cli/test_kanban_notify.py index e1c421594aa..ddfa4b40aa2 100644 --- a/tests/hermes_cli/test_kanban_notify.py +++ b/tests/hermes_cli/test_kanban_notify.py @@ -2,6 +2,7 @@ import asyncio 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 @@ -429,3 +430,52 @@ async def test_notifier_delivers_subscription_owned_by_current_profile(kanban_ho finally: conn.close() assert subs == [] + + +@pytest.mark.asyncio +async def test_gateway_create_autosubscribes_on_explicit_board(kanban_home): + """`/kanban --board 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()