tests: round-rotation audit, dup-id fail, replay rewrite

- turn.round-rotation.test.js: 7 tests, full round visits each active
  participant once (pure nextTurn clean). Green.
- turn.characterization.test.js: RED 'addParticipant rejects duplicate id'.
  Validates current behavior allows dup ids (self-inflicted in audit via
  loop spin-while-paused re-adding same id; unreachable in app via
  crypto.randomUUID, but documents gap).
- audit-rotation.js: pure turn.js simulation of replay op sequence.
  Detects rotation violations (skip/dupe per round). Pause disabled = 0
  violations across 100 rounds. Pause enabled = 56-77 violations starting
  round 20. Pinpoints addParticipant+pause interaction.
- repro-pause-bug.js: minimal repro scripts.
- replay-combat.js: rewritten for real rounds (full initiative cycles),
  visible damage each turn, all conditions, toggleActive, remove,
  reinforce, edit, pause/resume, reorder, endEncounter. HP bumped for
  100-round sustain + revive dead each round.

No feature code changed.
This commit is contained in:
david raistrick
2026-06-29 15:49:39 -04:00
parent 7866dec83b
commit 13490fe3de
5 changed files with 643 additions and 60 deletions
+10
View File
@@ -337,4 +337,14 @@ describe('addParticipant', () => {
const { patch } = addParticipant(enc([p('a', 10)]), np);
expect(patch.participants.map(x => x.id)).toEqual(['a', 'z']);
});
test('rejects duplicate id (skip-bug root cause)', () => {
// Two participants with same id → togglePause resume rebuilds order with
// dup id twice → nextTurn gets stuck repeating that id forever.
// Audit found this in 100-round replay (addParticipant fired while paused
// because nextTurn threw, loop spun, same totalTurns %10 → re-added).
const existing = p('x', 5);
const dup = makeParticipant({ id: 'x', name: 'x2', type: 'monster', initiative: 10, maxHp: 100, currentHp: 100 });
expect(() => addParticipant(enc([p('a', 10), existing]), dup)).toThrow();
});
});