Add the clarify text-fallback invariant. It drives the real TelegramAdapter send through text_fallback_coro and fails on base, where the send carries disable_notification=True. Drop the runner metadata test: it only pins that the metadata did not change from base. The _notification_kwargs parametrize already fails on base for is_approval_prompt, which keeps the stack at two invariant tests.
44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
"""Telegram notification-mode gating (#132516): "important" mode silences ordinary sends, but a
|
|
human-decision prompt (``is_approval_prompt``) must always push — a silently delivered prompt is
|
|
indistinguishable from "no prompt" and costs the full approvals.timeout before the command is refused.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from plugins.platforms.telegram.adapter import TelegramAdapter
|
|
|
|
|
|
@pytest.mark.parametrize("mode,metadata,expected", [
|
|
("important", None, {"disable_notification": True}),
|
|
("important", {"thread_id": "t1"}, {"disable_notification": True}),
|
|
("important", {"notify": True}, {}),
|
|
("important", {"thread_id": "t1", "is_approval_prompt": True}, {}),
|
|
("all", None, {}),
|
|
("all", {"is_approval_prompt": True}, {}),
|
|
])
|
|
def test_notification_kwargs(mode, metadata, expected):
|
|
adapter = object.__new__(TelegramAdapter)
|
|
adapter._notifications_mode = mode
|
|
assert adapter._notification_kwargs(metadata) == expected
|
|
|
|
|
|
def test_clarify_text_fallback_pushes_in_important_mode():
|
|
"""A failed native clarify card retries as base numbered text via adapter.send(); that
|
|
human-decision prompt must not go out with disable_notification=True."""
|
|
import asyncio
|
|
from types import SimpleNamespace
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
from gateway.config import PlatformConfig
|
|
from gateway.run_turn_runner_clarify_delivery import text_fallback_coro
|
|
|
|
adapter = TelegramAdapter(PlatformConfig(enabled=True, token="t", extra={}))
|
|
adapter._bot, adapter._app = AsyncMock(), MagicMock()
|
|
adapter._bot.send_message = AsyncMock(return_value=SimpleNamespace(message_id=1))
|
|
adapter._notifications_mode = "important"
|
|
|
|
asyncio.run(text_fallback_coro(
|
|
adapter, chat_id="123", question="Which env?", choices=None, clarify_id="c1", session_key="s", metadata=None))
|
|
|
|
assert adapter._bot.send_message.await_args.kwargs.get("disable_notification") is None
|