fix(models): reject combatant ids that misparse the transcript format
This commit is contained in:
@@ -189,6 +189,22 @@ class TestCombatant:
|
||||
with pytest.raises(ValidationError):
|
||||
Combatant.model_validate(_combatant_dict(hit_dice="1d8"))
|
||||
|
||||
@pytest.mark.parametrize("bad_id", ["a: b", " goblin", "goblin ", ""])
|
||||
def test_rejects_transcript_hostile_id(self, bad_id: str) -> None:
|
||||
# Given an id that would misparse the "round N id: message" transcript
|
||||
# (contains ": ") or is empty / padded with whitespace
|
||||
# When/Then validation rejects it
|
||||
with pytest.raises(ValidationError):
|
||||
Combatant.model_validate(_combatant_dict(id=bad_id))
|
||||
|
||||
def test_accepts_id_with_colon_without_space(self) -> None:
|
||||
# Given an id using ":" as a separator but never ": " (weapon-style
|
||||
# ids are safe for the transcript parser)
|
||||
# When validated
|
||||
combatant = Combatant.model_validate(_combatant_dict(id="goblin:claw"))
|
||||
# Then it is accepted
|
||||
assert combatant.id == "goblin:claw"
|
||||
|
||||
def test_frozen(self) -> None:
|
||||
# Given a validated combatant
|
||||
combatant = Combatant.model_validate(_combatant_dict())
|
||||
|
||||
Reference in New Issue
Block a user