Prioritize explicit turn endings - #1298
Draft
janmarsino98 wants to merge 1 commit into
Draft
Conversation
devill
reviewed
Aug 1, 2026
devill
left a comment
Member
There was a problem hiding this comment.
Fixes #924's repro, but it also switches off turn.endIf.
Events.dispatch is never cleared, so isTurnEndPending() stays true after the queued endTurn
has been consumed — every later OnMove / UpdateStage / UpdateActivePlayers in that action
skips ShouldEndTurn, which gates endIf and not just maxMoves. No maxMoves here; passes on
main, Received: 2 on this branch:
const client = Client({
game: {
setup: () => ({}),
turn: {
onBegin: ({ ctx, events }) => {
if (ctx.turn === 2) events.setActivePlayers({ all: Stage.NULL });
},
endIf: ({ ctx }) => ctx.turn === 2,
},
moves: { A: ({ events }) => { events.endTurn(); } },
},
numPlayers: 3,
});
client.moves.A();
expect(client.getState().ctx.turn).toBe(3);Could you scope isTurnEndPending() to the entries update() hasn't reached yet, and add this
as a regression test?
Worth settling first: flow.ts:280 is the only _private use outside src/plugins/, and the
?? false fallback silently restores the old behaviour if that api is ever absent.
Moving it to draft, please reopen once comments are addressed.
devill
marked this pull request as draft
August 1, 2026 15:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #924
An explicit
endTurnorpassqueued by a move now takes precedence over the automaticmaxMoves/ legacymoveLimitturn end. This preserves arguments such asendTurn({ next: '2' })instead of advancing through the default play order.The automatic turn end previously ran before the queued event was flushed. By the time that event was processed, its captured turn no longer matched and its
nextargument was discarded.Tests:
pnpm run lintpnpm test: 43 suites passed, 903 tests passed, 1 todopnpm run test:coveragepnpm run tspnpm run build