Skip to content

Commit d3ae2b1

Browse files
committed
Merge remote-tracking branch 'origin/main' into HEAD
2 parents 7462532 + f141408 commit d3ae2b1

7 files changed

Lines changed: 172 additions & 232 deletions

File tree

scripts/lib/vitest-local-scheduling.d.mts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export type VitestHostInfo = {
22
cpuCount?: number;
33
loadAverage1m?: number;
44
totalMemoryBytes?: number;
5+
freeMemoryBytes?: number;
56
};
67

78
export type LocalVitestScheduling = {
@@ -25,10 +26,6 @@ export function resolveLocalVitestScheduling(
2526
system?: VitestHostInfo,
2627
pool?: "forks" | "threads",
2728
): LocalVitestScheduling;
28-
export function shouldUseLargeLocalFullSuiteProfile(
29-
env?: Record<string, string | undefined>,
30-
system?: VitestHostInfo,
31-
): boolean;
3229
export function resolveLocalFullSuiteProfile(
3330
env?: Record<string, string | undefined>,
3431
system?: VitestHostInfo,

scripts/lib/vitest-local-scheduling.mjs

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
import os from "node:os";
55

6-
const DEFAULT_LOCAL_FULL_SUITE_PARALLELISM = 4;
7-
const LARGE_LOCAL_FULL_SUITE_PARALLELISM = 10;
8-
const DEFAULT_LOCAL_FULL_SUITE_VITEST_WORKERS = 1;
9-
const LARGE_LOCAL_FULL_SUITE_VITEST_WORKERS = 2;
6+
const MAX_LOCAL_FULL_SUITE_PARALLELISM = 10;
107

118
const clamp = (value, min, max) => Math.max(min, Math.min(max, value));
129

@@ -189,42 +186,12 @@ export function resolveLocalVitestScheduling(
189186
};
190187
}
191188

192-
export function shouldUseLargeLocalFullSuiteProfile(
193-
env = process.env,
194-
system = detectVitestHostInfo(),
195-
) {
196-
if (isCiLikeEnv(env)) {
197-
return false;
198-
}
199-
const scheduling = resolveLocalVitestScheduling(env, system, "threads");
200-
return scheduling.maxWorkers >= 5 && !scheduling.throttledBySystem;
201-
}
202-
203189
export function resolveLocalFullSuiteProfile(env = process.env, system = detectVitestHostInfo()) {
204-
if (!isSystemThrottleDisabled(env)) {
205-
const memoryPressureLimit = resolveMemoryPressureWorkerLimit(system);
206-
if (memoryPressureLimit === 1) {
207-
return {
208-
shardParallelism: 1,
209-
vitestMaxWorkers: 1,
210-
};
211-
}
212-
if (memoryPressureLimit === 2) {
213-
return {
214-
shardParallelism: 2,
215-
vitestMaxWorkers: 1,
216-
};
217-
}
218-
}
219-
220-
if (shouldUseLargeLocalFullSuiteProfile(env, system)) {
221-
return {
222-
shardParallelism: LARGE_LOCAL_FULL_SUITE_PARALLELISM,
223-
vitestMaxWorkers: LARGE_LOCAL_FULL_SUITE_VITEST_WORKERS,
224-
};
225-
}
190+
const scheduling = resolveLocalVitestScheduling(env, system, "threads");
226191
return {
227-
shardParallelism: DEFAULT_LOCAL_FULL_SUITE_PARALLELISM,
228-
vitestMaxWorkers: DEFAULT_LOCAL_FULL_SUITE_VITEST_WORKERS,
192+
// Each shard is a separate Vitest process with its own module graph. Spend the
193+
// host worker budget once across shards instead of multiplying it inside them.
194+
shardParallelism: Math.min(scheduling.maxWorkers, MAX_LOCAL_FULL_SUITE_PARALLELISM),
195+
vitestMaxWorkers: 1,
229196
};
230197
}

scripts/test-projects.mjs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ async function main() {
313313
);
314314
}
315315
if (concurrency > 1) {
316-
const localFullSuiteProfile = resolveLocalFullSuiteProfile(baseEnv);
317316
const shardTimings = readShardTimings(process.cwd(), baseEnv);
318317
const parallelSpecs = applyDefaultParallelVitestWorkerBudget(
319318
applyParallelVitestCachePaths(orderFullSuiteSpecsForParallelRun(runSpecs, shardTimings), {
@@ -322,16 +321,6 @@ async function main() {
322321
}),
323322
baseEnv,
324323
);
325-
if (
326-
!isCiLikeEnv(baseEnv) &&
327-
!baseEnv.OPENCLAW_TEST_PROJECTS_PARALLEL &&
328-
!baseEnv.OPENCLAW_VITEST_MAX_WORKERS &&
329-
!baseEnv.OPENCLAW_TEST_WORKERS &&
330-
localFullSuiteProfile.shardParallelism === 10 &&
331-
localFullSuiteProfile.vitestMaxWorkers === 2
332-
) {
333-
console.error("[test] using host-aware local full-suite profile: shards=10 workers=2");
334-
}
335324
console.error(
336325
`[test] running ${parallelSpecs.length} Vitest shards with parallelism ${concurrency}`,
337326
);

src/scripts/test-projects.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ const {
104104
cpuCount?: number;
105105
loadAverage1m?: number;
106106
totalMemoryBytes?: number;
107+
freeMemoryBytes?: number;
107108
},
108109
) => number;
109110
};
@@ -583,7 +584,7 @@ describe("test-projects args", () => {
583584
).toBe(3);
584585
});
585586

586-
it("uses a bounded local default for full-suite project parallelism", () => {
587+
it("uses the global host worker budget for full-suite project parallelism", () => {
587588
expect(
588589
resolveParallelFullSuiteConcurrency(
589590
58,
@@ -596,7 +597,7 @@ describe("test-projects args", () => {
596597
totalMemoryBytes: 16 * 1024 ** 3,
597598
},
598599
),
599-
).toBe(4);
600+
).toBe(2);
600601
});
601602

602603
it("gives parallel Vitest shards separate filesystem module caches", () => {

0 commit comments

Comments
 (0)