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
21 changes: 21 additions & 0 deletions tests/tools/test_kanban_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2100,6 +2100,7 @@ def _sub_index(subs):
"chat_id": getattr(s, "chat_id", None),
"thread_id": getattr(s, "thread_id", None),
"user_id": getattr(s, "user_id", None),
"notifier_profile": getattr(s, "notifier_profile", None),
})
return out

Expand Down Expand Up @@ -2132,6 +2133,26 @@ def test_create_subscribes_gateway_session(monkeypatch, worker_env):
assert s["user_id"] == "user-9"


def test_create_subscription_falls_back_to_active_profile(monkeypatch, worker_env):
"""A gateway subscription must never be left ownerless in a fleet."""
from hermes_cli import profiles
from tools import kanban_tools as kt

monkeypatch.setenv("HERMES_SESSION_PLATFORM", "telegram")
monkeypatch.setenv("HERMES_SESSION_CHAT_ID", "chat-42")
monkeypatch.delenv("HERMES_SESSION_PROFILE", raising=False)
monkeypatch.delenv("HERMES_PROFILE", raising=False)
monkeypatch.setattr(profiles, "get_active_profile_name", lambda: "spanorama")

payload = json.loads(kt._handle_create({
"title": "owned subscription",
"assignee": "peer",
}))

subs = _sub_index(_list_subs_for_task(payload["task_id"]))
assert subs[0]["notifier_profile"] == "spanorama"


def test_create_subscribes_tui_session_via_session_key(monkeypatch, worker_env):
"""TUI / desktop sessions don't have a platform/chat_id (single
local channel), but the parent process exports HERMES_SESSION_KEY.
Expand Down
3 changes: 3 additions & 0 deletions tools/kanban_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,9 @@ def _maybe_auto_subscribe(conn: Any, task_id: str) -> bool:
get_session_env("HERMES_SESSION_PROFILE", "")
or os.environ.get("HERMES_PROFILE")
)
if not notifier_profile:
from hermes_cli.profiles import get_active_profile_name
notifier_profile = get_active_profile_name()

# Lazy-import to keep the module-level dependency light
from hermes_cli import kanban_db as _kb
Expand Down