WIP: BUG-5 slot-array fix + FEAT-1 dead-not-skipped + skip parser

WORK IN PROGRESS — fix not complete. analyze-turns.js on 500-round
replay still finds 46 real skips + 64 double-acts.

turn.js changes:
- computeTurnOrderAfterAddition: insert by initiative (not append end)
- nextTurn wrap: no re-sort, cycle pointer
- togglePause resume: no re-sort, order stable
- addParticipant: patches turnOrderIds when started
- applyHpChange: death no longer flips isActive or touches turnOrderIds
  (FEAT-1 dead-not-skipped)

Tests:
- shared/tests/turn.skip.test.js (NEW): deterministic skip invariants
  pure 100 rounds + 540 rounds w/ mutations, both green
- shared/tests/turn.dead-skip.test.js: 4 green (FEAT-1)
- turn.characterization.test.js: 3 sites updated to new behavior
- turn.combat.test.js: boundary count fixed (wrap-turn attributed to
  new round), debug dump removed

scripts/analyze-turns.js (NEW): deterministic replay-stdout parser.
Reconstructs rounds, reports real skips + double-acts. Exit 1 on issue.
Catches bugs unit tests miss (46 skips/64 double-acts in 500 rounds).

TODO: FEAT-1 marked done, FEAT-2 added (upgrade app logs parseable).
This commit is contained in:
david raistrick
2026-07-01 11:42:43 -04:00
parent c6d3b7e1a6
commit 0473eacc1d
6 changed files with 423 additions and 45 deletions
+21 -11
View File
@@ -5,17 +5,27 @@ REWORK_PLAN.md.
## Feature backlog
### FEAT-1: Dead participants stay in turn order
- From user (Saturday game). Moved out of REWORK_PLAN (not milestone).
- Dead (HP=0) participants must NOT be skipped.
- Current: dead → `isActive=false` → removed from turn order → skipped.
- Desired: dead occupy initiative slot, turn still comes up. PCs get
death-save turn.
- Affects: `shared/turn.js` `nextTurn` (filters `isActive`), `applyHpChange`
(sets isActive=false on death), `computeTurnOrderAfterRemoval`.
- Characterization tests (`src/tests/Combat.characterization.test.js`) lock
CURRENT behavior — UPDATE to desired when implementing.
- RED test locked (desired state): `shared/tests/turn.dead-skip.test.js`.
### FEAT-1: Dead participants stay in turn order — DONE
- Fixed: `applyHpChange` no longer flips `isActive` or touches `turnOrderIds`
on death/revive. Dead stay in rotation, `nextTurn` visits them, PCs get
death-save turn. `isActive` = DM toggle only.
- Tests: `shared/tests/turn.dead-skip.test.js` (4 green). Char tests updated
to new behavior.
### FEAT-2: upgrade app internal logs to be parseable
- Goal: combat logs in Firestore store enough structured state to run
skip/rotation analysis on ANY historic round — not just replay stdout.
- Current logs: `{timestamp, message, encounterName, undo}`. Parser must
guess roster from message strings. Brittle.
- Upgrade: add structured fields at turn-state mutation log sites in
App.js (startEncounter, toggleActive, addParticipant, removeParticipant,
applyHpChange death/revive, togglePause, nextTurn):
```
turnSnapshot: { round, currentTurnParticipantId, turnOrderIds, activeIds }
```
- Then `scripts/analyze-turns.js` ingests app logs directly (adapter fetch).
Works on real game sessions, any round, deterministic.
- Parser scaffold NOW ingests replay stdout only (stopgap until FEAT-2).
## Confirmed bugs (tests written, NOT fixed)