From 1c2bfa9594fb13ba4244bc8ae39a61d7cd841287 Mon Sep 17 00:00:00 2001 From: Nyan404 Date: Tue, 25 Aug 2026 03:49:35 +0300 Subject: [PATCH] fix(parser): keep invalid free text repairable --- app/belki/vk_bot.py | 10 ++++++++-- structure_and_data.md | 1 + tests/test_vk_conversation.py | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/belki/vk_bot.py b/app/belki/vk_bot.py index a120483..a60324e 100644 --- a/app/belki/vk_bot.py +++ b/app/belki/vk_bot.py @@ -413,8 +413,14 @@ def parse_natural_bulk(text: str) -> tuple[dict[str, Any], list[str]] | None: if extra_kittens: primary = fields.get("kitten_independence", "самостоятельно") fields["extra_kittens"] = [(name, kitten_id, primary) for name, kitten_id in extra_kittens] - if skill: - _validate_independence(skill, primary, fields["extra_kittens"]) + if skill: + try: + _validate_independence(skill, fields.get("kitten_independence", "самостоятельно"), fields.get("extra_kittens", ())) + except ValueError as exc: + # A free-form message must lead to a repairable dialog state, not + # escape from the VK event handler with a validation exception. + fields.pop("kitten_independence", None) + questions.append(str(exc) + " Укажите статус ещё раз.") return fields, questions diff --git a/structure_and_data.md b/structure_and_data.md index 5cf19f7..6fed2b6 100644 --- a/structure_and_data.md +++ b/structure_and_data.md @@ -69,6 +69,7 @@ - 2026-08-25: one-line VK/web recognition now gives explicit role labels priority over position. `сопровождающий`/`наставник`/`учитель` identify the escort, while `ученик`/`котёнок`/`бельчонок`/`подопечный` identify the ward; unlabeled pairs retain the original order-based fallback. - 2026-08-25: corrected Russian UX copy in the VK help and attachment flow; the web identity hint now accurately says that a manually completed pair applies only to the current calculation. - 2026-08-25: natural input normalizes Unicode spaces, dash variants, `ID`/`№` prefixes, spaced IDs, common date/time separators, and close role-label typos before extracting structured fields. Natasha was evaluated for Russian NER through Context7 but not added: game nicknames are better anchored by user-provided IDs and local role context than a generic person model. +- 2026-08-25: impossible status combinations discovered in free text (for example, non-self-sufficient ЗУ) now remain a repairable clarification in the dialogue instead of raising out of the VK handler. - 2026-08-25: `/api/admin/auth` now permits five password attempts per source in a rolling 15-minute window and clears that local budget after a successful sign-in. Edge rate limiting and TLS remain required deployment controls. # Обновление 2026-08-16: несколько котят diff --git a/tests/test_vk_conversation.py b/tests/test_vk_conversation.py index a10864e..45d3fb6 100644 --- a/tests/test_vk_conversation.py +++ b/tests/test_vk_conversation.py @@ -157,6 +157,12 @@ class VkConversationTests(unittest.TestCase): self.assertEqual((inspected["fields"]["escort_name"], inspected["fields"]["escort_id"]), ("Дикая Вишня", 1604614)) self.assertEqual((inspected["fields"]["kitten_name"], inspected["fields"]["kitten_id"]), ("Серопопик", 1346767)) + def test_natural_zu_with_nonself_status_becomes_a_clarification_not_an_exception(self): + inspected = inspect_bulk_text("24.08 ЗУ 21:00 22:00 Белка [1] Ученик [2] несам") + self.assertEqual(inspected["status"], "needs_clarification") + self.assertNotIn("kitten_independence", inspected["fields"]) + self.assertIn("Для ЗУ", " ".join(inspected["questions"])) + def test_training_supports_stepwise_and_natural_bulk(self): dialog = BelkiDialog() self.assertIn("сопровождающ", dialog.handle(102, "/урок").lower())