fix: recover legacy tournament code transitions
This commit is contained in:
1 parent
489d040d8f
commit
ef47de7e4f
5 files changed
+775
-5
No files matched your search
+410
-4
@@ -683,28 +683,434 @@ describe('planCompetitionMigration', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('still quarantines an inverted timestamp from the current lifecycle', () => {
|
||||
it('normalizes a post-game reservation timestamp for an accepted used code', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-inverted-current-code-timeline',
|
||||
_id: 'match-post-game-used-code-reservation',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
updatedAt: '2026-07-03T00:06:00.000Z',
|
||||
result: {
|
||||
games: [
|
||||
legacyGame({
|
||||
gameNumber: 1,
|
||||
riotMatchId: 'KR_INVERTED_CURRENT_TIMELINE',
|
||||
riotMatchId: 'KR_POST_GAME_CODE_RESERVATION',
|
||||
riotArchivePresent: true,
|
||||
riotGameEndedAt: '2026-07-02T00:00:00.000Z',
|
||||
riotGameEndedAtSource: 'gameEndTimestamp',
|
||||
}),
|
||||
],
|
||||
seriesResults: [],
|
||||
},
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'used-code-inverted-current-timeline',
|
||||
_id: 'used-code-reserved-after-game',
|
||||
state: 'used',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-03T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:00:00.000Z',
|
||||
updatedAt: '2026-07-03T00:05:00.000Z',
|
||||
riotMatchId: 'KR_POST_GAME_CODE_RESERVATION',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = requireReady(planCompetitionMigration(legacy));
|
||||
|
||||
expect(plan.assignments[0]).toMatchObject({
|
||||
state: 'used',
|
||||
reservedAt: '2026-07-03T00:00:00.000Z',
|
||||
usedAt: '2026-07-03T00:05:00.000Z',
|
||||
});
|
||||
expect(plan.warnings).toContainEqual({
|
||||
code: 'LEGACY_USED_CODE_TRANSITION_TIME_NORMALIZED',
|
||||
message:
|
||||
'Legacy used TournamentCode usedAt represented Riot game time and was normalized to its persisted transition time.',
|
||||
details: {
|
||||
tournamentCodeId: 'used-code-reserved-after-game',
|
||||
originalReservedAt: '2026-07-03T00:00:00.000Z',
|
||||
originalUsedAt: '2026-07-02T00:00:00.000Z',
|
||||
sourceUpdatedAt: '2026-07-03T00:05:00.000Z',
|
||||
normalizedUsedAt: '2026-07-03T00:05:00.000Z',
|
||||
factRecordedAt: '2026-07-03T00:06:00.000Z',
|
||||
legacyOccurrenceSource: 'riot-archive-gameEndTimestamp',
|
||||
riotMatchId: 'KR_POST_GAME_CODE_RESERVATION',
|
||||
gameSlotId: plan.assignments[0].gameSlotId,
|
||||
strategy: 'use-persisted-transition-time',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('normalizes a chronological legacy Riot occurrence to the persisted used transition', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-chronological-legacy-used-occurrence',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
updatedAt: '2026-07-02T00:06:00.000Z',
|
||||
result: {
|
||||
games: [
|
||||
legacyGame({
|
||||
gameNumber: 1,
|
||||
riotMatchId: 'KR_CHRONOLOGICAL_LEGACY_USED_OCCURRENCE',
|
||||
riotArchivePresent: true,
|
||||
riotGameEndedAt: '2026-07-02T00:00:00.000Z',
|
||||
riotGameEndedAtSource: 'gameEndTimestamp',
|
||||
}),
|
||||
],
|
||||
seriesResults: [],
|
||||
},
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'chronological-legacy-used-occurrence',
|
||||
state: 'used',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-01T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:00:00.000Z',
|
||||
updatedAt: '2026-07-02T00:05:00.000Z',
|
||||
riotMatchId: 'KR_CHRONOLOGICAL_LEGACY_USED_OCCURRENCE',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = requireReady(planCompetitionMigration(legacy));
|
||||
|
||||
expect(plan.assignments[0]).toMatchObject({
|
||||
reservedAt: '2026-07-01T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:05:00.000Z',
|
||||
});
|
||||
expect(plan.warnings).toContainEqual(
|
||||
expect.objectContaining({
|
||||
code: 'LEGACY_USED_CODE_TRANSITION_TIME_NORMALIZED',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('recognizes the legacy Riot gameCreation fallback occurrence path', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-legacy-game-creation-used-occurrence',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
updatedAt: '2026-07-02T00:06:00.000Z',
|
||||
result: {
|
||||
games: [
|
||||
legacyGame({
|
||||
gameNumber: 1,
|
||||
riotMatchId: 'KR_LEGACY_GAME_CREATION_USED_OCCURRENCE',
|
||||
riotArchivePresent: true,
|
||||
riotGameEndedAt: '2026-07-02T00:00:00.000Z',
|
||||
riotGameEndedAtSource: 'gameCreation',
|
||||
}),
|
||||
],
|
||||
seriesResults: [],
|
||||
},
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'legacy-game-creation-used-occurrence',
|
||||
state: 'used',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-01T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:00:00.000Z',
|
||||
updatedAt: '2026-07-02T00:05:00.000Z',
|
||||
riotMatchId: 'KR_LEGACY_GAME_CREATION_USED_OCCURRENCE',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = requireReady(planCompetitionMigration(legacy));
|
||||
|
||||
expect(plan.assignments[0].usedAt).toBe('2026-07-02T00:05:00.000Z');
|
||||
const warning = plan.warnings.find(
|
||||
({ code }) => code === 'LEGACY_USED_CODE_TRANSITION_TIME_NORMALIZED',
|
||||
);
|
||||
expect(warning?.details).toMatchObject({
|
||||
legacyOccurrenceSource: 'riot-archive-gameCreation',
|
||||
});
|
||||
});
|
||||
|
||||
it('recognizes the legacy repair gameCreation plus duration occurrence path', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-repaired-legacy-used-occurrence',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
updatedAt: '2026-07-03T00:06:00.000Z',
|
||||
result: {
|
||||
games: [
|
||||
legacyGame({
|
||||
gameNumber: 1,
|
||||
riotMatchId: 'KR_REPAIRED_LEGACY_USED_OCCURRENCE',
|
||||
riotArchivePresent: true,
|
||||
gameCreation: '2026-07-02T00:00:00.000Z',
|
||||
gameDuration: 1800,
|
||||
riotGameEndedAt: '2026-07-02T00:30:17.000Z',
|
||||
riotGameEndedAtSource: 'gameEndTimestamp',
|
||||
}),
|
||||
],
|
||||
seriesResults: [],
|
||||
},
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'repaired-legacy-used-occurrence',
|
||||
state: 'used',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-01T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:30:00.000Z',
|
||||
updatedAt: '2026-07-03T00:05:00.000Z',
|
||||
riotMatchId: 'KR_REPAIRED_LEGACY_USED_OCCURRENCE',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = requireReady(planCompetitionMigration(legacy));
|
||||
|
||||
expect(plan.assignments[0]).toMatchObject({
|
||||
reservedAt: '2026-07-01T00:00:00.000Z',
|
||||
usedAt: '2026-07-03T00:05:00.000Z',
|
||||
});
|
||||
const warning = plan.warnings.find(
|
||||
({ code }) => code === 'LEGACY_USED_CODE_TRANSITION_TIME_NORMALIZED',
|
||||
);
|
||||
expect(warning?.details).toMatchObject({
|
||||
legacyOccurrenceSource: 'legacy-gameCreation-plus-duration',
|
||||
});
|
||||
});
|
||||
|
||||
it('does not normalize an inverted used-code lifecycle without Riot archive evidence', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-unverified-used-code-transition',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
updatedAt: '2026-07-03T00:06:00.000Z',
|
||||
result: {
|
||||
games: [
|
||||
legacyGame({
|
||||
gameNumber: 1,
|
||||
riotMatchId: 'KR_UNVERIFIED_USED_CODE_TRANSITION',
|
||||
riotArchivePresent: false,
|
||||
}),
|
||||
],
|
||||
seriesResults: [],
|
||||
},
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'unverified-used-code-transition',
|
||||
state: 'used',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-03T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:00:00.000Z',
|
||||
updatedAt: '2026-07-03T00:05:00.000Z',
|
||||
riotMatchId: 'KR_UNVERIFIED_USED_CODE_TRANSITION',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = planCompetitionMigration(legacy);
|
||||
|
||||
expectQuarantineReason(plan, 'INVALID_TOURNAMENT_CODE_TIMELINE');
|
||||
});
|
||||
|
||||
it('preserves a chronological usedAt that does not match a known occurrence encoding', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-current-used-transition-semantics',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
updatedAt: '2026-07-02T00:10:00.000Z',
|
||||
result: {
|
||||
games: [
|
||||
legacyGame({
|
||||
gameNumber: 1,
|
||||
riotMatchId: 'KR_CURRENT_USED_TRANSITION_SEMANTICS',
|
||||
riotArchivePresent: true,
|
||||
riotGameEndedAt: '2026-07-02T00:00:00.000Z',
|
||||
riotGameEndedAtSource: 'gameEndTimestamp',
|
||||
}),
|
||||
],
|
||||
seriesResults: [],
|
||||
},
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'current-used-transition-semantics',
|
||||
state: 'used',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-01T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:10:00.000Z',
|
||||
updatedAt: '2026-07-02T00:10:00.000Z',
|
||||
riotMatchId: 'KR_CURRENT_USED_TRANSITION_SEMANTICS',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = requireReady(planCompetitionMigration(legacy));
|
||||
|
||||
expect(plan.assignments[0].usedAt).toBe('2026-07-02T00:10:00.000Z');
|
||||
expect(
|
||||
plan.warnings.some(
|
||||
({ code }) => code === 'LEGACY_USED_CODE_TRANSITION_TIME_NORMALIZED',
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('quarantines an inverted used timeline with an out-of-range legacy duration without throwing', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-out-of-range-legacy-duration',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
updatedAt: '2026-07-03T00:06:00.000Z',
|
||||
result: {
|
||||
games: [
|
||||
legacyGame({
|
||||
gameNumber: 1,
|
||||
riotMatchId: 'KR_OUT_OF_RANGE_LEGACY_DURATION',
|
||||
riotArchivePresent: true,
|
||||
gameCreation: '2026-07-02T00:00:00.000Z',
|
||||
gameDuration: Number.MAX_VALUE,
|
||||
}),
|
||||
],
|
||||
seriesResults: [],
|
||||
},
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'out-of-range-legacy-duration',
|
||||
state: 'used',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-03T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:00:00.000Z',
|
||||
updatedAt: '2026-07-03T00:05:00.000Z',
|
||||
riotMatchId: 'KR_OUT_OF_RANGE_LEGACY_DURATION',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = planCompetitionMigration(legacy);
|
||||
|
||||
expectQuarantineReason(plan, 'INVALID_TOURNAMENT_CODE_TIMELINE');
|
||||
});
|
||||
|
||||
it('does not normalize an inverted used-code lifecycle with an invalid transition time', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-invalid-used-code-transition-time',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
updatedAt: '2026-07-03T00:06:00.000Z',
|
||||
result: {
|
||||
games: [
|
||||
legacyGame({
|
||||
gameNumber: 1,
|
||||
riotMatchId: 'KR_INVALID_USED_CODE_TRANSITION_TIME',
|
||||
riotArchivePresent: true,
|
||||
riotGameEndedAt: '2026-07-02T00:00:00.000Z',
|
||||
riotGameEndedAtSource: 'gameEndTimestamp',
|
||||
}),
|
||||
],
|
||||
seriesResults: [],
|
||||
},
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'invalid-used-code-transition-time',
|
||||
state: 'used',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-03T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:00:00.000Z',
|
||||
updatedAt: '2026-07-02T12:00:00.000Z',
|
||||
riotMatchId: 'KR_INVALID_USED_CODE_TRANSITION_TIME',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = planCompetitionMigration(legacy);
|
||||
|
||||
expectQuarantineReason(plan, 'INVALID_TOURNAMENT_CODE_TIMELINE');
|
||||
});
|
||||
|
||||
it.each<[string, string | undefined]>([
|
||||
['missing', undefined],
|
||||
['earlier than the Riot occurrence', '2026-07-01T12:00:00.000Z'],
|
||||
])(
|
||||
'quarantines a recognized legacy occurrence when persisted transition time is %s',
|
||||
(_label, updatedAt) => {
|
||||
const legacy = pairedMatch({
|
||||
_id: `match-invalid-persisted-transition-${_label}`,
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
updatedAt: '2026-07-03T00:06:00.000Z',
|
||||
result: {
|
||||
games: [
|
||||
legacyGame({
|
||||
gameNumber: 1,
|
||||
riotMatchId: 'KR_INVALID_PERSISTED_TRANSITION',
|
||||
riotArchivePresent: true,
|
||||
riotGameEndedAt: '2026-07-02T00:00:00.000Z',
|
||||
riotGameEndedAtSource: 'gameEndTimestamp',
|
||||
}),
|
||||
],
|
||||
seriesResults: [],
|
||||
},
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: `invalid-persisted-transition-${_label}`,
|
||||
state: 'used',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-01T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:00:00.000Z',
|
||||
...(updatedAt ? { updatedAt } : {}),
|
||||
riotMatchId: 'KR_INVALID_PERSISTED_TRANSITION',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = planCompetitionMigration(legacy);
|
||||
|
||||
expectQuarantineReason(plan, 'INVALID_TOURNAMENT_CODE_TIMELINE');
|
||||
},
|
||||
);
|
||||
|
||||
it('does not normalize a used-code transition recorded after the accepted fact', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-used-code-transition-after-fact',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
updatedAt: '2026-07-03T00:04:00.000Z',
|
||||
result: {
|
||||
games: [
|
||||
legacyGame({
|
||||
gameNumber: 1,
|
||||
riotMatchId: 'KR_USED_CODE_TRANSITION_AFTER_FACT',
|
||||
riotArchivePresent: true,
|
||||
riotGameEndedAt: '2026-07-02T00:00:00.000Z',
|
||||
riotGameEndedAtSource: 'gameEndTimestamp',
|
||||
}),
|
||||
],
|
||||
seriesResults: [],
|
||||
},
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'used-code-transition-after-fact',
|
||||
state: 'used',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-03T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:00:00.000Z',
|
||||
updatedAt: '2026-07-03T00:05:00.000Z',
|
||||
riotMatchId: 'KR_USED_CODE_TRANSITION_AFTER_FACT',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = planCompetitionMigration(legacy);
|
||||
|
||||
expectQuarantineReason(plan, 'INVALID_TOURNAMENT_CODE_TIMELINE');
|
||||
});
|
||||
|
||||
it('still quarantines an inverted released-code lifecycle', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-inverted-released-code-timeline',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
result: { games: [], seriesResults: [] },
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'released-code-inverted-current-timeline',
|
||||
state: 'released',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-03T00:00:00.000Z',
|
||||
releasedAt: '2026-07-02T00:00:00.000Z',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user