fix(telegram): keep info callbacks nonfatal
All checks were successful
Code Review / ai-code-review (push) Successful in 19s
CD Pipeline / tests (push) Successful in 1m10s
CD Pipeline / build-and-deploy (push) Successful in 3m41s
CD Pipeline / post-deploy-checks (push) Successful in 1m21s

This commit is contained in:
Your Name
2026-05-18 09:47:40 +08:00
parent ae18751d17
commit 0dd4b486c5
3 changed files with 85 additions and 7 deletions

View File

@@ -195,6 +195,35 @@ async def test_send_html_line_message_attaches_awooop_markup_to_first_chunk(monk
assert all("reply_markup" not in payload for _, payload in sent_requests[1:])
@pytest.mark.asyncio
async def test_info_callback_sends_history_when_answer_callback_is_stale(monkeypatch):
"""Telegram answerCallbackQuery 400 不得阻斷詳情/歷史 DB truth-chain reply。"""
gateway = TelegramGateway()
sent_history = []
monkeypatch.setattr(gateway._security, "is_whitelisted", lambda _user_id: True)
async def stale_answer(*_args, **_kwargs):
raise telegram_gateway_module.TelegramGatewayError("HTTP error: 400")
async def fake_history(incident_id: str):
sent_history.append(incident_id)
monkeypatch.setattr(gateway, "_answer_callback", stale_answer)
monkeypatch.setattr(gateway, "_send_incident_history", fake_history)
result = await gateway.handle_callback(
callback_query_id="stale-callback",
callback_data="history:INC-20260513-79ED5E",
user_id=123456,
message_id=789,
)
assert result["success"] is True
assert result["info_action"] is True
assert sent_history == ["INC-20260513-79ED5E"]
class TestTelegramMessageFormat:
"""測試現有 TelegramMessage 格式化"""