From 36a596aa9fed8916897e48c8103cdc72519d475f Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Tue, 2 Jun 2026 21:18:52 +0200 Subject: [PATCH] fix(ci): reject malformed targeted docker group size --- scripts/plan-targeted-docker-lane-groups.mjs | 14 ++------------ test/scripts/targeted-docker-lane-groups.test.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/scripts/plan-targeted-docker-lane-groups.mjs b/scripts/plan-targeted-docker-lane-groups.mjs index 74149807a3c3..32a3c11581b9 100644 --- a/scripts/plan-targeted-docker-lane-groups.mjs +++ b/scripts/plan-targeted-docker-lane-groups.mjs @@ -1,4 +1,5 @@ import { fileURLToPath } from "node:url"; +import { parsePositiveInt } from "./lib/numeric-options.mjs"; const BASELINE_SHARDED_LANES = new Set(["published-upgrade-survivor", "update-migration"]); @@ -13,17 +14,6 @@ function splitTokens(raw) { ]; } -function parsePositiveInt(raw, fallback, label) { - const parsed = Number.parseInt(String(raw ?? ""), 10); - if (!Number.isFinite(parsed)) { - return fallback; - } - if (parsed < 1) { - throw new Error(`${label} must be a positive integer. Got: ${JSON.stringify(raw)}`); - } - return parsed; -} - function sanitizeLabel(value) { return ( String(value) @@ -43,7 +33,7 @@ export function planTargetedDockerLaneGroups({ throw new Error("docker_lanes is required when planning targeted Docker lane groups."); } - const parsedGroupSize = parsePositiveInt(groupSize, 1, "groupSize"); + const parsedGroupSize = parsePositiveInt(groupSize, "groupSize"); const baselineSpecs = splitTokens(upgradeSurvivorBaselines); const groups = []; let pendingLanes = []; diff --git a/test/scripts/targeted-docker-lane-groups.test.ts b/test/scripts/targeted-docker-lane-groups.test.ts index 74911d194abd..f0b0cab3edb4 100644 --- a/test/scripts/targeted-docker-lane-groups.test.ts +++ b/test/scripts/targeted-docker-lane-groups.test.ts @@ -65,4 +65,19 @@ describe("scripts/plan-targeted-docker-lane-groups", () => { { docker_lanes: "published-upgrade-survivor", label: "published-upgrade-survivor" }, ]); }); + + it("rejects malformed group size values", () => { + expect(() => + planTargetedDockerLaneGroups({ + groupSize: "2x", + lanes: "doctor-switch update-channel-switch", + }), + ).toThrow("groupSize must be a positive integer"); + expect(() => + planTargetedDockerLaneGroups({ + groupSize: 0, + lanes: "doctor-switch update-channel-switch", + }), + ).toThrow("groupSize must be a positive integer"); + }); });