fix(models): reject combatant ids that misparse the transcript format

This commit is contained in:
2026-09-20 17:51:40 +02:00
parent bce0a59e60
commit 53c6dc0b43
2 changed files with 30 additions and 0 deletions
+14
View File
@@ -410,6 +410,20 @@ class Combatant(_FrozenModel):
raise ValueError(msg)
return value
@field_validator("id")
@classmethod
def _validate_id(cls, value: str) -> str:
# The transcript line format is "round N <id>: <message>"; an id
# containing ": " would be mis-split by cli._parse_transcript_line,
# and leading/trailing whitespace breaks the "id: " join.
if not value or value != value.strip():
msg = f"combatant id must be non-empty without surrounding whitespace, got {value!r}"
raise ValueError(msg)
if ": " in value:
msg = f"combatant id must not contain ': ' (breaks transcript parsing), got {value!r}"
raise ValueError(msg)
return value
@property
def is_lawful(self) -> bool:
"""Law axis: LG/LN/LE."""