- read risk_level with risk fallback (was: risk only → "unknown" for all actions written by supervisor which uses risk_level key) - include description field in alert format (was: alert_only payloads' substance was invisible — description carried the full message) - extract _format_pending_action() pure helper to enable unit testing without a live Telegram connection - 8 tests: risk_level present, risk fallback, both absent, description shown/absent, truncation, full HA alert_only shape, no-description no-crash - flagged during Phase 5 review of ha-diag-agent supervisor routing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""Stub telegram before bot.py is imported so pytest doesn't need the real package."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import types
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
def _make_telegram_stub() -> types.ModuleType:
|
|
mod = types.ModuleType("telegram")
|
|
mod.Update = MagicMock
|
|
mod.InlineKeyboardButton = MagicMock
|
|
mod.InlineKeyboardMarkup = MagicMock
|
|
return mod
|
|
|
|
|
|
def _make_telegram_ext_stub() -> types.ModuleType:
|
|
mod = types.ModuleType("telegram.ext")
|
|
mod.ApplicationBuilder = MagicMock
|
|
|
|
# ContextTypes.DEFAULT_TYPE is referenced as a type annotation at class-body
|
|
# evaluation time, so it must be a real attribute, not a dynamic MagicMock attr.
|
|
ContextTypesMock = MagicMock()
|
|
ContextTypesMock.DEFAULT_TYPE = type(None)
|
|
mod.ContextTypes = ContextTypesMock
|
|
|
|
mod.CommandHandler = MagicMock
|
|
mod.CallbackQueryHandler = MagicMock
|
|
mod.MessageHandler = MagicMock
|
|
mod.filters = MagicMock()
|
|
return mod
|
|
|
|
|
|
# Insert before any import of bot.py
|
|
if "telegram" not in sys.modules:
|
|
sys.modules["telegram"] = _make_telegram_stub()
|
|
if "telegram.ext" not in sys.modules:
|
|
sys.modules["telegram.ext"] = _make_telegram_ext_stub()
|