From 60f41dd67553dc376eadd52de580b4022cfb0d71 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 29 Oct 2026 20:13:54 +0200 Subject: [PATCH] fix(training): show progress while building info summary --- VERSION | 2 +- bot.py | 10 ++++++++-- tests/test_writer_features.py | 9 +++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index e26493d..25fea79 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0+73 +0.1.0+74 diff --git a/bot.py b/bot.py index f12109f..5fa8d32 100644 --- a/bot.py +++ b/bot.py @@ -636,8 +636,14 @@ async def training_info_command(message: Message, state: FSMContext) -> None: profile = await asyncio.to_thread(get_tone_of_voice, message.from_user.id) if profile.strip(): notes = await asyncio.to_thread(get_training_notes, message.from_user.id) - await _refresh_training_summary(message.from_user.id, profile, notes) - summary = await asyncio.to_thread(get_training_summary, message.from_user.id) + status = await OperationStatus.start( + message, "⏳ Собираю краткую выжимку…", kind="training" + ) + try: + await _refresh_training_summary(message.from_user.id, profile, notes) + summary = await asyncio.to_thread(get_training_summary, message.from_user.id) + finally: + await status.finish(None) rich_html = training_info_rich_html(summary) if not rich_html: await message.answer( diff --git a/tests/test_writer_features.py b/tests/test_writer_features.py index abdb134..c87a8d2 100644 --- a/tests/test_writer_features.py +++ b/tests/test_writer_features.py @@ -1204,6 +1204,15 @@ class TrainingSummaryTests(unittest.IsolatedAsyncioTestCase): send.assert_awaited_once() self.assertIn("Канал про автоматизацию", send.await_args.args[1]) + async def test_info_command_generates_missing_summary(self) -> None: + user_store.save_tone_of_voice(13, "профиль аккаунта", self.db_path) + with patch.object(bot, "create_training_summary", new=AsyncMock(return_value={"about": "про ИИ"})) as gen, \ + patch.object(bot, "send_rich_message", new=AsyncMock()) as send: + await bot.training_info_command(cast(Any, self._message(13)), cast(Any, _StubState("training"))) + gen.assert_awaited_once() + send.assert_awaited_once() + self.assertIn("про ИИ", send.await_args.args[1]) + async def test_info_command_without_data_explains_training(self) -> None: with patch.object(bot, "send_rich_message", new=AsyncMock()) as send: await bot.training_info_command(cast(Any, self._message(12)), cast(Any, _StubState("training")))