Files
ttrpg-initiative-tracker/scripts
david raistrick a8e88cf0f0 tooling: audit-state pause+resume paired, guard advance-while-paused
Audit bug: pause fired turn%12, no resume in same iter. nextTurn then
called on paused encounter → threw 'Encounter not running'. Throw is
correct feature behavior (nextTurn refuses when paused); audit misuse.

Fix: togglePause twice (pause+resume) in one iteration, plus guard
'advance-while-paused' check before nextTurn call.

Result: 6 audit artifacts → 0 violations / 100 rounds.
Confirms BUG-1 resolved as side effect of BUG-2 dup-id fix.

Replay verify: 10 rounds, 103 turns, no skip/dupe.

TODO: BUG-1 + BUG-2 marked RESOLVED/FIXED.
2026-06-29 16:36:43 -04:00
..

scripts/

Manual tools. NOT unit tests. Math.random, non-deterministic.

Used to FIND bugs. Unit tests (in */tests/) LOCK them.

replay-combat.js

Drives full combat through live backend via ws adapter (same contract as App). Player display live-updates. Use to watch UI react to state changes.

# start backend + frontend first (see docs/DEVELOPMENT.md)
node scripts/replay-combat.js [rounds] [delayMs]
# defaults: 100 rounds, 200ms/step

Coverage per round: damage, heal, all 22 conditions, toggleActive, removeParticipant, addParticipant (reinforcements), updateParticipant, pause/resume, reorderParticipants, endEncounter. Revives dead each round to sustain full round count.

audit-rotation.js

Pure turn.js simulation of replay op sequence. Detects rotation violations (skip/dupe per round). Pinpointed BUG-1 (addParticipant + pause corrupts).

node scripts/audit-rotation.js

Bisect: comment/uncomment op blocks to isolate triggering combo.

audit-state.js

Expanded invariant bug-finder. 9 check classes per round:

  1. rotation integrity
  2. HP bounds
  3. isActive consistency
  4. turnOrder no dup ids
  5. turnOrder ids all active
  6. currentTurn valid + active
  7. deathSave range + reset on revive
  8. removeParticipant orphans
  9. undo support
node scripts/audit-state.js [rounds]   # default 100

See TODO.md for bugs found.