Rework backend #1

Merged
robert merged 86 commits from rework-backend into main 2026-07-01 19:29:34 -04:00
2 changed files with 4 additions and 3 deletions
Showing only changes of commit d35a730e12 - Show all commits
+1 -3
View File
@@ -338,9 +338,7 @@ describe('addParticipant', () => {
expect(patch.participants.map(x => x.id)).toEqual(['a', 'z']);
});
// SKIPPED: RED test documenting BUG-2 (addParticipant allows dup id).
// See TODO.md BUG-2. Re-enable (remove .skip) when fix lands.
test.skip('rejects duplicate id (skip-bug root cause)', () => {
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
+3
View File
@@ -270,6 +270,9 @@ function togglePause(encounter) {
// ADD_PARTICIPANT — appends participant. (Initiative rolled by caller via build*.)
function addParticipant(encounter, participant) {
if ((encounter.participants || []).some(p => p.id === participant.id)) {
throw new Error(`Participant with id "${participant.id}" already exists in encounter.`);
}
const updatedParticipants = [...(encounter.participants || []), participant];
return {
patch: { participants: updatedParticipants },