fix(auction): harden lifecycle and durable bid storage
Serialize lifecycle changes and make cancellation, deadlines, and match side effects recoverable and idempotent. Archive accepted bids durably, quarantine invalid payloads, and preserve compatibility with empty round IDs. Synchronize HTTP polling and socket state with scoped resync events. Add cancellation cleanup index migration and regression coverage. Validated with 744 API tests, 65 Redis integration tests, and 28 Mongo integration tests.
This commit is contained in:
1 parent
f2eec479d9
commit
f649490cd2
55 files changed
+5374
-522
No files matched your search
+39
@@ -0,0 +1,39 @@
|
||||
import type { mongo } from 'mongoose';
|
||||
import { AUCTION_CANCELLATION_CLEANUP_INDEX } from '../auction-cancellation-index';
|
||||
|
||||
/** Creates only this additive index; never drops or rebuilds other indexes. */
|
||||
export async function migrateAuctionCancellationIndex(
|
||||
db: mongo.Db,
|
||||
{ dryRun = true }: { dryRun?: boolean } = {},
|
||||
) {
|
||||
const { key, options } = AUCTION_CANCELLATION_CLEANUP_INDEX;
|
||||
const collection = db.collection('match');
|
||||
const indexes = await collection
|
||||
.listIndexes()
|
||||
.toArray()
|
||||
.catch((error: unknown) => {
|
||||
if (error instanceof Error && 'code' in error && error.code === 26)
|
||||
return [];
|
||||
throw error;
|
||||
});
|
||||
const existing = indexes.find((index) => index.name === options.name);
|
||||
if (
|
||||
existing &&
|
||||
(JSON.stringify(existing.key) !== JSON.stringify(key) ||
|
||||
JSON.stringify(existing.partialFilterExpression) !==
|
||||
JSON.stringify(options.partialFilterExpression) ||
|
||||
existing.unique === true ||
|
||||
existing.sparse === true ||
|
||||
existing.hidden === true)
|
||||
) {
|
||||
throw new Error(
|
||||
`Index ${options.name} already exists with a different definition.`,
|
||||
);
|
||||
}
|
||||
if (!dryRun) await collection.createIndex(key, options);
|
||||
return {
|
||||
dryRun,
|
||||
alreadyPresent: Boolean(existing),
|
||||
index: { key, ...options },
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user