fix(runner): disambiguation suffix skips ids already taken by explicit combatants

This commit is contained in:
2026-09-20 17:33:35 +02:00
parent de9309ca43
commit e9c2a63122
2 changed files with 35 additions and 4 deletions
+24
View File
@@ -178,6 +178,30 @@ def test_build_states_disambiguates_duplicate_ids() -> None:
assert all(s.hp == s.combatant.hp_max for s in states)
def test_build_states_suffix_skips_explicitly_taken_ids() -> None:
"""A -N suffix must never land on an id another combatant already owns.
Two "gob" docs plus an explicit "gob-2" used to yield two states named
"gob-2" (the per-base counter ignored explicit ids), merging their
attrition in the engine's by-id stats keys.
"""
spec = EncounterSpec(
map=make_map(),
sides=(
Side(
name="players",
combatants=(make_combatant("gob"), make_combatant("gob-2")),
zone="A",
),
Side(name="monsters", combatants=(make_combatant("gob"),), zone="B"),
),
)
states = build_states(spec)
ids = [s.combatant.id for s in states]
assert ids == ["gob", "gob-2", "gob-3"]
assert len(set(ids)) == 3
def test_build_states_rejects_too_many_combatants_for_zone() -> None:
"""A zone with fewer cells than combatants is a spec error, not a runtime surprise."""
spec = EncounterSpec(