From 5aef49a421bf6ccefc5f55dbf1b032c77dba49a8 Mon Sep 17 00:00:00 2001 From: ShuaixinHuang <1836656514@qq.com> Date: Wed, 25 Nov 2026 00:48:01 +0800 Subject: [PATCH] fix(ci): keep equal-duration shard allocation from leaving jobs empty (#14257) Co-authored-by: ShuaixinHuang --- tests/boundary/filesystem/ciTestSequencer.test.ts | 10 ++++++++++ tests/ciTestSequencer.ts | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/boundary/filesystem/ciTestSequencer.test.ts b/tests/boundary/filesystem/ciTestSequencer.test.ts index 452bfae0e4..502e0c04b1 100644 --- a/tests/boundary/filesystem/ciTestSequencer.test.ts +++ b/tests/boundary/filesystem/ciTestSequencer.test.ts @@ -235,3 +235,13 @@ describe("duration shard allocation", () => { ).toBe(300); }); }); + +it("uses both shards when equal files fit into spare workers in one shard", () => { + const items = ["a", "b"].map((key) => ({ + item: key, + key, + duration: 20, + laneWidth: 2, + })); + expect(allocateByDuration(items, 2)).toEqual([["a"], ["b"]]); +}); diff --git a/tests/ciTestSequencer.ts b/tests/ciTestSequencer.ts index ec80212b67..945762f6a1 100644 --- a/tests/ciTestSequencer.ts +++ b/tests/ciTestSequencer.ts @@ -181,7 +181,10 @@ export function allocateByDuration( for (const candidate of shards.slice(1)) { const phases = place(candidate.phases, entry, duration); const wall = wallOf(phases); - if (wall < chosenWall) { + if ( + wall < chosenWall || + (wall === chosenWall && candidate.items.length < chosen.items.length) + ) { chosen = candidate; chosenPhases = phases; chosenWall = wall;