test(telegram): cover exec-approval keyboard row pairing

Assert the full set renders as 2x2 and the three-button case keeps Deny on
its own second row.
This commit is contained in:
HexLab98 2026-07-24 14:29:56 +07:00 committed by kshitij
parent fecceec11e
commit 116a44f46e

View file

@ -148,6 +148,54 @@ class TestTelegramExecApproval:
assert buttons == ["✅ Allow Once", "✅ Session", "❌ Deny"]
@pytest.mark.asyncio
async def test_full_approval_keyboard_is_two_by_two(self, monkeypatch):
"""Regression: d48bf743f flattened all buttons into one row (4x1)."""
adapter = _make_adapter()
adapter._bot.send_message = AsyncMock(return_value=SimpleNamespace(message_id=42))
captured_rows = []
monkeypatch.setattr(
"plugins.platforms.telegram.adapter.InlineKeyboardButton",
lambda text, callback_data: text,
)
monkeypatch.setattr(
"plugins.platforms.telegram.adapter.InlineKeyboardMarkup",
lambda rows: captured_rows.extend(rows) or rows,
)
await adapter.send_exec_approval(
chat_id="12345", command="curl example.test", session_key="s",
)
assert captured_rows == [
["✅ Allow Once", "✅ Session"],
["✅ Always", "❌ Deny"],
]
@pytest.mark.asyncio
async def test_three_button_keyboard_pairs_then_singleton(self, monkeypatch):
adapter = _make_adapter()
adapter._bot.send_message = AsyncMock(return_value=SimpleNamespace(message_id=42))
captured_rows = []
monkeypatch.setattr(
"plugins.platforms.telegram.adapter.InlineKeyboardButton",
lambda text, callback_data: text,
)
monkeypatch.setattr(
"plugins.platforms.telegram.adapter.InlineKeyboardMarkup",
lambda rows: captured_rows.extend(rows) or rows,
)
await adapter.send_exec_approval(
chat_id="12345", command="curl example.test", session_key="s",
allow_permanent=False,
)
assert captured_rows == [
["✅ Allow Once", "✅ Session"],
["❌ Deny"],
]
@pytest.mark.asyncio
async def test_stores_approval_state(self):
adapter = _make_adapter()