diff --git a/app/features/tournament-bracket/core/Progression.test.ts b/app/features/tournament-bracket/core/Progression.test.ts index 5cc13a04a..02f913b8d 100644 --- a/app/features/tournament-bracket/core/Progression.test.ts +++ b/app/features/tournament-bracket/core/Progression.test.ts @@ -407,6 +407,26 @@ describe("validatedSources - other rules", () => { expect((error as any).bracketIdx).toEqual(1); }); + it("does not flag TOO_MANY_PLACEMENTS when larger round robin has valid high placements", () => { + const result = getValidatedBrackets([ + { + settings: { teamsPerGroup: 6 }, + type: "round_robin", + }, + { + settings: {}, + type: "single_elimination", + sources: [{ bracketId: "0", placements: "1,2,3,4,5,6" }], + }, + { + settings: { teamsPerGroup: 4 }, + type: "round_robin", + }, + ]); + + expect(Array.isArray(result)).toBe(true); + }); + it("handles DUPLICATE_BRACKET_NAME", () => { const error = getValidatedBrackets([ { diff --git a/app/features/tournament-bracket/core/Progression.ts b/app/features/tournament-bracket/core/Progression.ts index 2439352cd..60117da01 100644 --- a/app/features/tournament-bracket/core/Progression.ts +++ b/app/features/tournament-bracket/core/Progression.ts @@ -469,20 +469,16 @@ function tooManyPlacements(brackets: ParsedBracket[]) { const roundRobins = brackets.flatMap((bracket, bracketIdx) => bracket.type === "round_robin" ? [bracketIdx] : [], ); - // technically not correct but i guess not too common to have different round robins in the same bracket - const size = Math.min( - ...roundRobins.map( - (bracketIdx) => - brackets[bracketIdx].settings.teamsPerGroup ?? Number.POSITIVE_INFINITY, - ), - ); for (const [bracketIdx, bracket] of brackets.entries()) { for (const source of bracket.sources ?? []) { - if ( - roundRobins.includes(source.bracketIdx) && - source.placements.some((placement) => placement > size) - ) { + if (!roundRobins.includes(source.bracketIdx)) continue; + + const size = + brackets[source.bracketIdx].settings.teamsPerGroup ?? + TOURNAMENT.RR_DEFAULT_TEAM_COUNT_PER_GROUP; + + if (source.placements.some((placement) => placement > size)) { return bracketIdx; } }