All checks were successful
CD Pipeline / deploy (push) Successful in 8m50s
Webhook (Flask) and polling (momo-telegram-bot) consumed the same Telegram update_id, causing /menu callbacks to fire twice. Add a shared dedup module backed by telegram_update_dedup table (300s TTL, 60s cleanup) with in-memory fallback, wired into both paths. Polling launcher now skips startup when webhook is configured to prevent dual-consumption at the source. 38 tests across webhook, menu keyboards, telegram_api, dedup guard, and trend bot service. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
27 lines
880 B
Python
27 lines
880 B
Python
from time import time
|
||
|
||
|
||
def test_update_guard_detects_duplicate_key():
|
||
from services import telegram_update_guard as guard
|
||
|
||
# 使用可變動 key,避免被歷史資料干擾
|
||
unique = f"unit-test-{int(time() * 1000)}"
|
||
|
||
# 清掉本機快取,避免測試順序影響
|
||
guard._seen_update_ids.clear()
|
||
guard._seen_update_id_set.clear()
|
||
|
||
assert guard.is_duplicate_update(unique, namespace="pytest") is False
|
||
assert guard.is_duplicate_update(unique, namespace="pytest") is True
|
||
|
||
|
||
def test_update_guard_separates_namespace():
|
||
from services import telegram_update_guard as guard
|
||
|
||
guard._seen_update_ids.clear()
|
||
guard._seen_update_id_set.clear()
|
||
|
||
event_id = f"namespace-check-{int(time() * 1000)}"
|
||
assert guard.is_duplicate_update(event_id, namespace="a") is False
|
||
assert guard.is_duplicate_update(event_id, namespace="b") is False
|