Merge branch 'dev' into feat/custom-events-spans
Some checks failed
DB migration compat / Check if migrations changed (push) Has been cancelled
DB migration compat / Back-compat — Current branch migrations with ${{ needs.check-migrations-changed.outputs.base_branch }} branch code (push) Has been cancelled
DB migration compat / Forward-compat — Current branch code with ${{ needs.check-migrations-changed.outputs.base_branch }} branch migrations (push) Has been cancelled
DB migration compat / No migration changes (skipped) (push) Has been cancelled

This commit is contained in:
Mantra 2026-07-03 16:57:31 -07:00 committed by GitHub
commit 35a41082e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -466,7 +466,13 @@ export function parseBackfillResumeOptions(args: string[]): BackfillResumeOption
const continueOnError = args.includes("--continue-on-error");
const batchSizeArg = readArg("batch-size");
// Accept both `--batch-size=500` and the space form `--batch-size 500`. The
// space form arrives as two separate argv tokens, so `readArg` (which only
// matches the `name=` prefix) would miss it and we'd silently fall back to the
// default — a nasty footgun. Read the following token in that case, and fail
// loudly if `--batch-size` is present but has no usable value.
const bareBatchSizeIndex = args.indexOf("--batch-size");
const batchSizeArg = readArg("batch-size") ?? (bareBatchSizeIndex === -1 ? undefined : args[bareBatchSizeIndex + 1]);
let batchSize: number | undefined = undefined;
if (batchSizeArg !== undefined) {
const parsed = Number(batchSizeArg);
@ -474,6 +480,8 @@ export function parseBackfillResumeOptions(args: string[]): BackfillResumeOption
throw new Error(`--batch-size must be a positive integer (got "${batchSizeArg}")`);
}
batchSize = parsed;
} else if (bareBatchSizeIndex !== -1) {
throw new Error("--batch-size requires a value, e.g. --batch-size=500 or --batch-size 500");
}
// Common options that apply regardless of whether a resume cursor was passed.
const base: BackfillResumeOptions = { continueOnError, ...(batchSize !== undefined ? { batchSize } : {}) };
@ -648,6 +656,22 @@ import.meta.vitest?.describe("parseBackfillResumeOptions", (test) => {
.toEqual({ continueOnError: false, batchSize: 1000 });
});
test("parses the space form --batch-size 100 (two argv tokens)", ({ expect }) => {
expect(parseBackfillResumeOptions(["--batch-size", "100"]))
.toEqual({ continueOnError: false, batchSize: 100 });
// ...including after the command token, as it arrives via the CLI.
expect(parseBackfillResumeOptions(["backfill-bulldozer-from-prisma", "--batch-size", "100"]))
.toEqual({ continueOnError: false, batchSize: 100 });
});
test("throws (never silently defaults) when --batch-size has no value", ({ expect }) => {
expect(() => parseBackfillResumeOptions(["--batch-size"]))
.toThrow("--batch-size requires a value");
// A following flag is not a value → still a positive-integer failure, loud.
expect(() => parseBackfillResumeOptions(["--batch-size", "--continue-on-error"]))
.toThrow("--batch-size must be a positive integer");
});
test("parses --batch-size alongside resume flags", ({ expect }) => {
expect(parseBackfillResumeOptions(["--resume-table=Subscription", "--resume-cursor=ten-1,sub-9", "--batch-size=250"]))
.toEqual({