fix(parser): keep invalid free text repairable

This commit is contained in:
nyan404 committed 2026-08-25 03:49:35 +03:00
1 parent 9859994deb
commit 1c2bfa9594
3 files changed
+14 -1

No files matched your search

+7 -1
View File
@@ -414,7 +414,13 @@ def parse_natural_bulk(text: str) -> tuple[dict[str, Any], list[str]] | None:
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"])
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
+1
View File
@@ -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: несколько котят
+6
View File
@@ -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())