Fix TOO_MANY_PLACEMENTS check when using different teams per group for different round robins

This commit is contained in:
Kalle 2026-03-21 13:07:16 +02:00
parent 52d41cfcc1
commit 42fbf60a3e
2 changed files with 27 additions and 11 deletions

View File

@ -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([
{

View File

@ -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;
}
}