release/86 #2

Merged
dahyeon merged 108 commits from release/86 into main 2026-07-15 08:56:05 +00:00
4 changed files with 47 additions and 5 deletions
Showing only changes of commit 78a2c7cf0d - Show all commits

No files matched your search

@@ -86,6 +86,32 @@ describe('generateSeriesGraph', () => {
expect(series).not.toHaveProperty('loserAdvancesTo');
}
});
it('rejects a first-to rule that can exhaust every GameSlot without a winner', () => {
try {
generateSeriesGraph({
competitionId: 'competition-unfinishable-first-to',
teams: Array.from({ length: 4 }, (_, index) => ({
teamId: `team-${index + 1}`,
displayOrder: index + 1,
seedNumber: index + 1,
})),
format: {
type: 'double-elimination',
resetFinalEnabled: false,
rules: {
upper: firstTo(2, 2),
lower: firstTo(1, 1),
grandFinal: firstTo(1, 1),
resetFinal: firstTo(1, 1),
},
},
});
throw new Error('Expected INVALID_FIRST_TO_RULE');
} catch (error) {
expect(error).toMatchObject({ code: 'INVALID_FIRST_TO_RULE' });
}
});
});
function firstTo(winsRequired: number, maxGames: number) {
@@ -561,7 +561,7 @@ function assertFirstToRule(rule: FirstToSeriesRule): void {
!Number.isInteger(rule.winsRequired) ||
rule.winsRequired < 1 ||
!Number.isInteger(rule.maxGames) ||
rule.maxGames < rule.winsRequired
rule.maxGames < rule.winsRequired * 2 - 1
) {
throw graphError(
'INVALID_FIRST_TO_RULE',
@@ -243,6 +243,24 @@ describe('projectSeries', () => {
}),
).toMatchObject({ status: 'inactive' });
});
it('rejects an unfinishable persisted first-to definition', () => {
const definition = seriesDefinition({
id: 'series-unfinishable',
stage: 'upper',
rule: { type: 'first-to', winsRequired: 2, maxGames: 2 },
});
expectInvariant(
() =>
projectSeries({
definition,
participants: ['team-8', 'team-3'],
facts: [],
}),
'SERIES_DEFINITION_INVALID',
);
});
});
function seriesDefinition(params: {
@@ -324,7 +324,7 @@ function validateDefinition(definition: SeriesDefinitionLike): void {
assertCompetitionInvariant(
Number.isInteger(definition.rule.winsRequired) &&
definition.rule.winsRequired > 0 &&
definition.rule.winsRequired <= definition.rule.maxGames,
definition.rule.maxGames >= definition.rule.winsRequired * 2 - 1,
'SERIES_DEFINITION_INVALID',
`Series ${definition.id} has an invalid first-to threshold`,
);
@@ -543,9 +543,7 @@ function assertNoSeriesActivity(
if (fact.seriesId === seriesId) activeAdjudications.add(fact.id);
break;
case 'adjudication-reversed':
if (
adjudicationSeriesById.get(fact.adjudicationFactId) === seriesId
) {
if (adjudicationSeriesById.get(fact.adjudicationFactId) === seriesId) {
assertCompetitionInvariant(
activeAdjudications.delete(fact.adjudicationFactId),
'FACT_ALREADY_REVERSED',