tests: turn.combat.test.js (deterministic RED for BUG-5), deprecate audits

REAL test audit should have been. jest, seeded RNG, mirrors replay-combat.js
op sequence exactly. Asserts per-round invariants: rotation-dupe, turnOrder
dup-id, currentTurn valid+active, HP bounds.

Result: 13 rotation-dupes / 100 rounds. First at round 4 (Cleric twice).
Deterministic, reproducible every run. BUG-5 locked.

Deprecate tests/audit/*.js: random sim gave false 0-violations while
this exact test reproduces bug. Commented early-return. Kept for reference,
delete later when log analyzer + unit tests cover ground.

TODO: BUG-5 added (mid-round addParticipant/revive corrupts rotation).

Root cause hypothesis: computeTurnOrderAfterAddition appends id to
turnOrderIds end. Round wrap re-sorts by initiative. currentTurn pointer
stale after sort → drifts → nextTurn revisits.

Test RED by design (documents live bug). Pre-push will block on push.
This commit is contained in:
david raistrick
2026-06-30 12:33:56 -04:00
parent d48ecf1460
commit 08c6146cf7
4 changed files with 316 additions and 2 deletions
+16
View File
@@ -63,6 +63,22 @@
- Test: render App + DisplayView, toggle hide-HP, assert display still shows
encounter (not paused).
## Pipeline
### BUG-5: mid-round addParticipant/revive corrupts rotation (deterministic test)
- Test: `shared/tests/turn.combat.test.js` (jest, seeded RNG, RED).
- 13 rotation-dupes / 100 rounds. First at round 4 (Cleric twice).
- Pattern: Reinforce/Summon added mid-round → appears in rotation same round
→ round wrap re-sorts by initiative → currentTurnParticipantId pointer
stale → nextTurn revisits.
- Root cause: `computeTurnOrderAfterAddition` appends id to turnOrderIds
end + `togglePause` resume rebuilds order via sort but doesn't re-anchor
currentTurn to its new position. After several mid-round adds the pointer
drifts.
- This is the test audit should have been. Mirrors replay-combat.js op
sequence exactly (damage, heal, conditions, toggleActive, deathSave,
remove, add, edit, pause/resume, reorder, revive-between-rounds).
## Pipeline
- [ ] Red test: dead participant still in turnOrderIds, turn still advances to them
- [ ] Fix `shared/turn.js`: don't drop dead from turn order