fix(tg): QA fixes — stream_message, topic_created, archive reply

- sdk/mock.py: stream_message was async def (coroutine), must be async
  generator with yield — caused TypeError on every user message
- topic_events.py: on_topic_created now skips bot-created topics
  (from_user.id == bot.id); cmd_new already registers them under the
  correct human user_id
- commands.py: cmd_archive now sends "Чат архивирован." confirmation
- test_topic_events.py: add bot=SimpleNamespace(id=BOT_ID) to fixture
This commit is contained in:
Mikhail Putilovskij 2026-04-02 14:14:19 +03:00
parent 8901e60f6a
commit d5ab527f5d
4 changed files with 20 additions and 13 deletions

View file

@ -54,6 +54,7 @@ async def cmd_archive(message: Message) -> None:
except TelegramBadRequest as e:
logger.warning("cmd_archive_bot_error", error=str(e))
db.archive_chat(user_id=user_id, thread_id=thread_id)
await message.answer("Чат архивирован.")
logger.info("cmd_archive", user_id=user_id, thread_id=thread_id)

View file

@ -13,7 +13,13 @@ router = Router(name="topic_events")
@router.message(F.forum_topic_created)
async def on_topic_created(message: Message) -> None:
"""User created a topic via Telegram UI — register it as a new chat."""
"""User created a topic via Telegram UI — register it as a new chat.
Skip topics created by the bot itself those are already registered
by cmd_new at the time create_forum_topic() is called.
"""
if message.from_user is None or message.from_user.id == message.bot.id:
return
user_id = message.from_user.id
thread_id = message.message_thread_id
name = message.forum_topic_created.name