fix: keep VK bot alive across long poll failures

This commit is contained in:
nyan404 committed 2026-10-08 14:09:20 +03:00
1 parent e33de2114a
commit 2d9aa2126c
8 files changed
+157 -15

No files matched your search

+19
View File
@@ -4,6 +4,7 @@ from tempfile import TemporaryDirectory
from app.belki.identity import Identity, IdentityDirectory
from app.belki.vk_bot import HELP_TEXT, BelkiDialog, inspect_bulk_text, parse_text_command
from app.belki.vk_scheduler import VkConversationStore
class VkConversationTests(unittest.TestCase):
@@ -223,6 +224,24 @@ class VkConversationTests(unittest.TestCase):
self.assertIn("Серолап", confirmation)
self.assertIn("подтверд", confirmation.lower())
def test_dialog_state_and_photo_survive_bot_recreation(self):
with TemporaryDirectory() as directory:
store = VkConversationStore(sqlite_path=f"{directory}/vk.sqlite3")
first = BelkiDialog(state_store=store)
first.handle(204, "/осмотр")
first.handle(204, "дупло")
first.handle(204, "1")
first.handle(204, "Серолап [1617140]")
first.handle(204, "без ресурсов")
first.queue_attachments(204, [{"type": "photo", "url": "https://example.test/history.jpg"}])
recreated = BelkiDialog(state_store=store)
confirmation = recreated.handle(204, "готово")
self.assertIn("Серолап", confirmation)
self.assertIn("подтверд", confirmation.lower())
self.assertEqual(recreated._states[204]["attachments"][0]["url"], "https://example.test/history.jpg")
def test_inspection_character_without_directory_offers_pairing(self):
dialog = BelkiDialog(IdentityDirectory())
dialog.handle(105, "/осмотр")