fix: preserve legacy competition slot identity
This commit is contained in:
1 parent
c2f89f9cb2
commit
a307780752
2 files changed
+686
-53
No files matched your search
@@ -139,6 +139,249 @@ describe('planCompetitionMigration', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('preserves a persisted non-canonical round-robin schedule', () => {
|
||||
const schedule = [
|
||||
[1, 1, 1, 2],
|
||||
[2, 1, 3, 4],
|
||||
[3, 1, 5, 6],
|
||||
[4, 1, 7, 8],
|
||||
[5, 2, 1, 3],
|
||||
[6, 2, 2, 4],
|
||||
[7, 2, 5, 7],
|
||||
[8, 2, 6, 8],
|
||||
[9, 3, 1, 4],
|
||||
[10, 3, 2, 3],
|
||||
[11, 3, 5, 8],
|
||||
[12, 3, 6, 7],
|
||||
] as const;
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-persisted-round-robin-schedule',
|
||||
gameMode: 'round-robin',
|
||||
gameCount: 1,
|
||||
roundRobinMaxRounds: 3,
|
||||
teams: Array.from({ length: 8 }, (_, index) =>
|
||||
legacyTeam(index + 1, `${index + 1}팀`),
|
||||
),
|
||||
gameSchedule: schedule.map(
|
||||
([gameNumber, roundNumber, teamAIndex, teamBIndex]) => ({
|
||||
gameNumber,
|
||||
roundNumber,
|
||||
teamAIndex,
|
||||
teamBIndex,
|
||||
}),
|
||||
),
|
||||
result: {
|
||||
games: schedule.map(([gameNumber, , teamAIndex, teamBIndex]) =>
|
||||
legacyGame({
|
||||
gameNumber,
|
||||
riotMatchId: `KR_PERSISTED_RR_${gameNumber}`,
|
||||
blueTeamIndex: teamAIndex,
|
||||
redTeamIndex: teamBIndex,
|
||||
winnerTeamIndex: teamAIndex,
|
||||
riotArchivePresent: true,
|
||||
}),
|
||||
),
|
||||
seriesResults: [],
|
||||
},
|
||||
});
|
||||
|
||||
const plan = requireReady(planCompetitionMigration(legacy));
|
||||
|
||||
expect(plan.competition.format).toMatchObject({
|
||||
type: 'round-robin',
|
||||
pairings: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
roundNumber: 3,
|
||||
matchNumber: 4,
|
||||
teamAId: plan.competition.teams[5].teamId,
|
||||
teamBId: plan.competition.teams[6].teamId,
|
||||
}),
|
||||
]),
|
||||
});
|
||||
expect(
|
||||
plan.facts.filter(({ type }) => type === 'game-accepted'),
|
||||
).toHaveLength(12);
|
||||
});
|
||||
|
||||
it('maps a result-less reserved TournamentCode by its global game number', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-future-reserved-code',
|
||||
gameCount: 2,
|
||||
teams: [
|
||||
legacyTeam(1, 'One'),
|
||||
legacyTeam(2, 'Two'),
|
||||
legacyTeam(3, 'Three'),
|
||||
legacyTeam(4, 'Four'),
|
||||
],
|
||||
gameSchedule: undefined,
|
||||
result: { games: [], seriesResults: [] },
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'future-code-for-global-game-3',
|
||||
state: 'reserved',
|
||||
gameNumber: 3,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = requireReady(planCompetitionMigration(legacy));
|
||||
const expectedSeries = plan.competition.seriesGraph.find(
|
||||
(series) => series.code === 'PAIR_M2',
|
||||
);
|
||||
|
||||
expect(expectedSeries).toBeDefined();
|
||||
expect(plan.assignments).toContainEqual(
|
||||
expect.objectContaining({
|
||||
tournamentCodeId: 'future-code-for-global-game-3',
|
||||
seriesId: expectedSeries!.id,
|
||||
gameSlotId: expectedSeries!.gameSlots[0].id,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('maps persisted WB_FINAL global game numbers to distinct stable slots', () => {
|
||||
const legacy = loadDataTxtFixture();
|
||||
legacy.result = { games: [], seriesResults: [] };
|
||||
legacy.doubleElimination!.bracketMatches = dataTxtUpperBracketTopology();
|
||||
legacy.tournamentCodes = [19, 20, 21].map((gameNumber, index) => ({
|
||||
_id: `wb-final-code-${index + 1}`,
|
||||
state: 'reserved' as const,
|
||||
bracketMatchId: 'WB_FINAL',
|
||||
gameNumber,
|
||||
}));
|
||||
|
||||
const plan = requireReady(planCompetitionMigration(legacy));
|
||||
const wbFinal = plan.competition.seriesGraph.find(
|
||||
(series) => series.code === 'WB_FINAL',
|
||||
);
|
||||
|
||||
expect(wbFinal).toBeDefined();
|
||||
expect(wbFinal!.gameSlots).toHaveLength(3);
|
||||
expect(plan.assignments).toHaveLength(3);
|
||||
for (const [index, slot] of wbFinal!.gameSlots.entries()) {
|
||||
expect(plan.assignments).toContainEqual(
|
||||
expect.objectContaining({
|
||||
tournamentCodeId: `wb-final-code-${index + 1}`,
|
||||
seriesId: wbFinal!.id,
|
||||
gameSlotId: slot.id,
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('quarantines a TournamentCode whose bracket identity conflicts with its global game number', () => {
|
||||
const legacy = loadDataTxtFixture();
|
||||
legacy.result = { games: [], seriesResults: [] };
|
||||
legacy.doubleElimination!.bracketMatches = dataTxtUpperBracketTopology();
|
||||
legacy.tournamentCodes = [
|
||||
{
|
||||
_id: 'conflicting-wb-final-code',
|
||||
state: 'reserved',
|
||||
bracketMatchId: 'WB_FINAL',
|
||||
gameNumber: 1,
|
||||
},
|
||||
];
|
||||
|
||||
const plan = planCompetitionMigration(legacy);
|
||||
|
||||
expect(plan).toMatchObject({
|
||||
status: 'quarantined',
|
||||
reasons: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: 'TOURNAMENT_CODE_ASSIGNMENT_CONFLICT',
|
||||
}),
|
||||
]),
|
||||
});
|
||||
});
|
||||
|
||||
it('quarantines conflicting Riot evidence and global game number', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-conflicting-code-evidence',
|
||||
gameCount: 2,
|
||||
gameSchedule: undefined,
|
||||
result: {
|
||||
games: [
|
||||
legacyGame({
|
||||
gameNumber: 1,
|
||||
riotMatchId: 'KR_CONFLICTING_CODE_EVIDENCE',
|
||||
blueTeamIndex: 1,
|
||||
redTeamIndex: 2,
|
||||
winnerTeamIndex: 1,
|
||||
riotArchivePresent: true,
|
||||
}),
|
||||
],
|
||||
seriesResults: [],
|
||||
},
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'code-with-conflicting-evidence',
|
||||
state: 'used',
|
||||
gameNumber: 2,
|
||||
riotMatchId: 'KR_CONFLICTING_CODE_EVIDENCE',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(planCompetitionMigration(legacy)).toMatchObject({
|
||||
status: 'quarantined',
|
||||
reasons: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: 'TOURNAMENT_CODE_ASSIGNMENT_CONFLICT',
|
||||
}),
|
||||
]),
|
||||
});
|
||||
});
|
||||
|
||||
it('quarantines a TournamentCode game number outside the Competition topology', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-out-of-range-code',
|
||||
gameSchedule: undefined,
|
||||
result: { games: [], seriesResults: [] },
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'out-of-range-code',
|
||||
state: 'reserved',
|
||||
gameNumber: 99,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(planCompetitionMigration(legacy)).toMatchObject({
|
||||
status: 'quarantined',
|
||||
reasons: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: 'TOURNAMENT_CODE_ASSIGNMENT_MAPPING_NOT_FOUND',
|
||||
}),
|
||||
]),
|
||||
});
|
||||
});
|
||||
|
||||
it('does not guess the first slot of a multi-slot Series without exact slot evidence', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-multi-slot-code-without-evidence',
|
||||
gameCount: 3,
|
||||
result: { games: [], seriesResults: [] },
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'code-with-series-only',
|
||||
state: 'reserved',
|
||||
bracketMatchId: 'PAIR_M1',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = planCompetitionMigration(legacy);
|
||||
|
||||
expect(plan).toMatchObject({
|
||||
status: 'quarantined',
|
||||
reasons: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: 'TOURNAMENT_CODE_ASSIGNMENT_MAPPING_NOT_FOUND',
|
||||
}),
|
||||
]),
|
||||
});
|
||||
});
|
||||
|
||||
it('repairs the data.txt WB_R2_M2 positional bug from accepted game evidence', () => {
|
||||
const legacy = loadDataTxtFixture();
|
||||
|
||||
@@ -301,3 +544,21 @@ function loadDataTxtFixture(): LegacyMatchInput {
|
||||
updatedAt: '2026-07-12T17:17:00.000Z',
|
||||
};
|
||||
}
|
||||
|
||||
function dataTxtUpperBracketTopology() {
|
||||
return [
|
||||
'WB_R1_M1',
|
||||
'WB_R1_M2',
|
||||
'WB_R1_M3',
|
||||
'WB_R1_M4',
|
||||
'WB_R2_M1',
|
||||
'WB_R2_M2',
|
||||
'WB_FINAL',
|
||||
].map((bracketMatchId, index) => ({
|
||||
bracketMatchId,
|
||||
gameNumber: index + 1,
|
||||
gameCount: 3,
|
||||
requiredWins: 2,
|
||||
bracketSide: 'winner' as const,
|
||||
}));
|
||||
}
|
||||
Reference in new issue
Block a user