fix(domain): reject duplicate report participants

This commit is contained in:
nyan404 committed 2026-08-25 04:09:52 +03:00
1 parent f106d706e4
commit 9dbf98fee1
4 files changed
+16

No files matched your search

+1
View File
@@ -48,6 +48,7 @@
- 2026-08-25: free-text parsing normalizes common punctuation, spaced IDs, ID markers and close role-label typos. Do not add generic Russian NER solely for CatWar nicknames: ID and role context are the more reliable authority.
- 2026-08-25: public reports cap coaching at 50 kittens and inspections at 100 resource rows, 100000 inspections and 100000 units per resource; enforce the limits in the shared domain rather than only in one transport.
- 2026-08-25: strict API conversion also covers nested extra-kitten IDs and inspection resources; no boolean coercion or unbounded resource conversion occurs before domain validation.
- 2026-08-25: the domain rejects duplicate participant IDs in coaching and requires a distinct escort and kitten for training, preventing duplicate-input score inflation.
- 2026-08-25: free-form input also accepts Russian written dates and month abbreviations, normalizing them to `ДД.ММ`; report dates are then calendar-validated in the domain before storage.
- 2026-08-25: application validation limits text, rows, per-row feather amounts, and attachments across web and VK. Persisted media/review links require HTTPS, and a profile link is accepted only for a VK host.
- 2026-08-25: authenticated admin refresh WebSockets use a separate pool of eight slots so they cannot consume the bounded general HTTP worker pool. History sorting normalizes old string IDs with current numeric IDs.
+5
View File
@@ -110,6 +110,9 @@ class CoachingSession:
raise ValueError("Некорректный статус самостоятельности")
if 1 + len(self.extra_kittens) > MAX_COACHING_KITTENS:
raise ValueError(f"В одном заходе может участвовать не более {MAX_COACHING_KITTENS} котят")
participant_ids = (self.escort_id, self.kitten_id) + tuple(kitten_id for _, kitten_id, _ in self.extra_kittens)
if len(set(participant_ids)) != len(participant_ids):
raise ValueError("ID участников одного захода не должны повторяться")
statuses = (self.kitten_independence,) + tuple(independence for _, _, independence in self.extra_kittens)
nonself_count = sum(status == "несамостоятельно" for status in statuses)
if self.skill == "ЗУ" and any(s != "самостоятельно" for s in statuses):
@@ -240,6 +243,8 @@ class TrainingSession:
raise ValueError("Имена участников не могут быть пустыми")
_positive_id(self.escort_id, "ID сопровождающего")
_positive_id(self.kitten_id, "ID котёнка")
if self.escort_id == self.kitten_id:
raise ValueError("Сопровождающий и котёнок должны быть разными персонажами")
@dataclass(frozen=True)
+1
View File
@@ -73,6 +73,7 @@
- 2026-08-25: application numeric fields explicitly reject JSON booleans, which Python would otherwise coerce to `1` or `0`.
- 2026-08-25: admin history sorting now tolerates legacy records whose IDs were stored as strings, preserving numeric order for valid IDs instead of failing the complete history view.
- 2026-08-25: coaching sessions now validate a real calendar date in `ДД.ММ` form before any calculation or persistence; free-form dates remain accepted after parser normalization.
- 2026-08-25: coaching and training reports reject a repeated participant ID, including an escort submitted as their own kitten, so duplicate input cannot inflate a result.
- 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: a self-sufficiency marker directly beside a labelled ward now belongs to that ward, so one natural line can describe different statuses for several kittens.
- 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.
+9
View File
@@ -93,6 +93,15 @@ class CalculationTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, "не более 100 ресурсов"):
InspectionReport("Белка", 1, "дупло", 1, tuple(("вьюнок", 1) for _ in range(101)))
def test_sessions_reject_duplicate_participant_ids(self):
with self.assertRaisesRegex(ValueError, "не должны повторяться"):
CoachingSession(
"15.08", "ЛУ", "11:00", "12:00", "Белка", 1, "Первый", 2,
extra_kittens=(("Дубль", 2, "самостоятельно"),),
)
with self.assertRaisesRegex(ValueError, "разными персонажами"):
TrainingSession("Белка", 1, "Белка", 1)
def test_zu_rejects_non_self_kitten(self):
with self.assertRaisesRegex(ValueError, "Для ЗУ все котята должны быть самостоятельными"):
CoachingSession(