fix: normalize missing legacy match game mode

This commit is contained in:
dahyeon committed 2026-07-13 03:13:28 +00:00
1 parent 683d602d63
commit ee96f8d48b
3 files changed
+66

No files matched your search

@@ -39,6 +39,61 @@ describe('migrateCompetitionDomain', () => {
expect(db.createdIndexes).toHaveLength(0); expect(db.createdIndexes).toHaveLength(0);
}); });
it.each([
['absent', (match: AnyDoc) => delete match.gameMode],
['null', (match: AnyDoc) => (match.gameMode = null)],
])(
'restores the historical pair default when raw Mongo Match gameMode is %s',
async (_label, omitGameMode) => {
const match = readyMatch();
omitGameMode(match);
const before = canonical(match);
const db = new MemoryMigrationDb({
match: [match],
riotMatch: [riotArchive()],
tournamentCode: [usedTournamentCode(match)],
});
const result = await migrateCompetitionDomain(db);
expect(result.summary).toMatchObject({
scanned: 1,
ready: 1,
quarantined: 0,
failed: 0,
});
expect(result.matches[0]).toMatchObject({
status: 'ready',
factCount: 1,
assignmentCount: 1,
});
expect(canonical(db.docs('match')[0])).toBe(before);
expect(db.writeCount).toBe(0);
},
);
it('keeps an explicitly unknown raw Mongo Match gameMode quarantined', async () => {
const match = readyMatch();
match.gameMode = 'future-mode';
const db = new MemoryMigrationDb({ match: [match] });
const result = await migrateCompetitionDomain(db);
expect(result.summary).toMatchObject({
scanned: 1,
ready: 0,
quarantined: 1,
failed: 0,
});
expect(result.matches[0]).toMatchObject({
status: 'quarantined',
reasons: [
expect.objectContaining({ code: 'UNSUPPORTED_LEGACY_GAME_MODE' }),
],
});
expect(db.writeCount).toBe(0);
});
it('applies one Match atomically and converges on an already-applied replay', async () => { it('applies one Match atomically and converges on an already-applied replay', async () => {
const match = readyMatch(); const match = readyMatch();
const originalResult = canonical(match.result); const originalResult = canonical(match.result);
@@ -759,6 +759,10 @@ async function hydrateLegacyMatch(
return { return {
...match, ...match,
// Native collection reads bypass the MatchSchema default. Historical
// documents without a persisted gameMode still executed as pair mode via
// the runtime fallback.
gameMode: match.gameMode ?? 'pair',
...(hydratedResult ? { result: hydratedResult } : {}), ...(hydratedResult ? { result: hydratedResult } : {}),
tournamentCodes, tournamentCodes,
riotMatchArchiveIds: [...archivedIds].sort(), riotMatchArchiveIds: [...archivedIds].sort(),
+7
View File
@@ -269,6 +269,10 @@ Migration builds new collections without dual canonical writes.
- Ambiguous mappings, evidence conflicts, or already-played invalid descendants are - Ambiguous mappings, evidence conflicts, or already-played invalid descendants are
quarantined. quarantined.
- Legacy `bracket` format becomes `paired-series` with a warning. - Legacy `bracket` format becomes `paired-series` with a warning.
- Native Mongo migration reads do not receive Mongoose defaults. The hydration
boundary restores the historical Match default only when `gameMode` is absent or
`null`, mapping it to `pair`; an explicitly stored unknown mode remains
quarantined instead of being guessed.
- Dry-run is the default and emits machine-readable and human-readable reports. - Dry-run is the default and emits machine-readable and human-readable reports.
- Apply is resumable, idempotent, transactionally scoped per Match, and verifies fact - Apply is resumable, idempotent, transactionally scoped per Match, and verifies fact
replay equality after every write. replay equality after every write.
@@ -361,6 +365,9 @@ its `teamId` in the same object.
- Double-elimination seeds are persisted before the finalized team-build timestamp is - Double-elimination seeds are persisted before the finalized team-build timestamp is
exposed, and an expired reserved code can be provisioned again automatically. exposed, and an expired reserved code can be provisioned again automatically.
- Migration dry-run reports zero unclassified documents before apply. - Migration dry-run reports zero unclassified documents before apply.
- Historical Matches without a persisted `gameMode` plan as `paired-series`, while
an explicitly invalid legacy mode is still reported as
`UNSUPPORTED_LEGACY_GAME_MODE`.
- Competition unique/partial indexes are verified before the first apply write, and - Competition unique/partial indexes are verified before the first apply write, and
repeated limited apply runs advance without rescanning the first page. repeated limited apply runs advance without rescanning the first page.
- API tests and API/web production builds pass. - API tests and API/web production builds pass.