fix(BATON-007): add validate_bot_token() for startup detection and fix test mocks
- Add validate_bot_token() to backend/telegram.py: calls getMe on startup, logs ERROR if token is invalid (never raises per #1215 contract) - Call validate_bot_token() in lifespan() after db.init_db() for early detection - Update conftest.py make_app_client() to mock getMe endpoint - Add 3 tests for validate_bot_token (200, 401, network error cases) Root cause: CHAT_ID=5190015988 (positive) was wrong — fixed to -5190015988 on server per decision #1212. Group "Big Red Button" confirmed via getChat. Service restarted. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8ee9782737
commit
51f1943c55
4 changed files with 75 additions and 1 deletions
|
|
@ -71,6 +71,11 @@ async def lifespan(app: FastAPI):
|
|||
await db.init_db()
|
||||
logger.info("Database initialized")
|
||||
|
||||
if not await telegram.validate_bot_token():
|
||||
logger.error(
|
||||
"CRITICAL: BOT_TOKEN is invalid — Telegram delivery is broken. Update .env and restart."
|
||||
)
|
||||
|
||||
if config.WEBHOOK_ENABLED:
|
||||
await telegram.set_webhook(url=config.WEBHOOK_URL, secret=config.WEBHOOK_SECRET)
|
||||
logger.info("Webhook registered")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue