Skip to content

Commit d437a4a

Browse files
authored
fix(test): route extension roots through bounded planner (#124553)
* fix(test): route extension roots through bounded planner * test: cover bounded Codex fallback shards
1 parent c1622d0 commit d437a4a

6 files changed

Lines changed: 123 additions & 23 deletions

File tree

‎scripts/lib/extension-test-plan.mts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,17 @@ const EXTENSION_TEST_COST_MULTIPLIERS: Record<string, number> = {
8989
// overstates its real wall-clock cost during CI shard planning.
9090
"test/vitest/vitest.extensions.config.ts": 1.1,
9191
};
92+
const CODEX_EXTENSION_TEST_PROCESS_FILE_LIMIT = 40;
9293
const MATRIX_EXTENSION_TEST_PROCESS_FILE_LIMIT = 40;
9394
const TELEGRAM_EXTENSION_TEST_PROCESS_FILE_LIMIT = 1;
9495
const TELEGRAM_EXTENSION_TEST_JOB_FILE_LIMIT = 10;
9596
const EXTENSION_TEST_PROCESS_FILE_LIMITS = new Map<string, number>([
97+
[
98+
"test/vitest/vitest.extension-codex.config.ts",
99+
// This non-isolated fileParallelism:false lane accumulates every mocked module graph.
100+
// At ~166 files, one worker exhausted its heap during teardown (#124413).
101+
CODEX_EXTENSION_TEST_PROCESS_FILE_LIMIT,
102+
],
96103
// The non-isolated Matrix suite intentionally shares module state within a process.
97104
// Bound its lifetime so Vite's transformed module graph cannot grow across the whole suite.
98105
["test/vitest/vitest.extension-matrix.config.ts", MATRIX_EXTENSION_TEST_PROCESS_FILE_LIMIT],

‎scripts/run-vitest.mts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { toolingIsolatedTestFiles } from "../test/vitest/vitest.tooling-isolated
1313
import { isUiTestTarget } from "../test/vitest/vitest.ui-paths.mjs";
1414
import { boundaryTestFiles } from "../test/vitest/vitest.unit-paths.mjs";
1515
import { parsePermissiveBooleanToken } from "./lib/arg-utils.mts";
16+
import { resolveExtensionTestConfig } from "./lib/extension-test-plan.mts";
1617
import { runWithFailedTrailer, writeFailedTrailer } from "./lib/failed-trailer.mts";
1718
import { createGatewayServerTestTargetChunks } from "./lib/gateway-server-test-plan.mts";
1819
import { signalExitCode } from "./lib/managed-child-process.mts";
@@ -699,6 +700,22 @@ function isOwnedAgentDirectoryTarget(arg: string, cwd: string, fsImpl: VitestPat
699700
);
700701
}
701702

703+
function isOwnedExtensionRootTarget(arg: string, cwd: string, fsImpl: VitestPathFs): boolean {
704+
const relative = toRepoRelativeArg(arg, cwd).replace(/\/+$/u, "");
705+
const [root, extensionId, ...remainder] = relative.split("/");
706+
if (
707+
root !== "extensions" ||
708+
!extensionId ||
709+
remainder.length > 0 ||
710+
!isExplicitDirectoryTargetArg(arg, cwd, fsImpl)
711+
) {
712+
return false;
713+
}
714+
// Extension roots delegate so the bounded planner owns process lifetime (#124413).
715+
// Raw Vitest would run the workspace config as one process.
716+
return resolveExtensionTestConfig(relative).length > 0;
717+
}
718+
702719
function isExplicitProjectRouterTargetArg(
703720
arg: string,
704721
cwd = process.cwd(),
@@ -715,7 +732,9 @@ function isExplicitProjectRouterTargetArg(
715732
}
716733
const filePath = path.isAbsolute(arg) ? arg : path.resolve(cwd, arg);
717734
return fsImpl.existsSync(filePath)
718-
? isDelegableBroadProjectRouterTarget(arg, cwd) || isOwnedAgentDirectoryTarget(arg, cwd, fsImpl)
735+
? isDelegableBroadProjectRouterTarget(arg, cwd) ||
736+
isOwnedAgentDirectoryTarget(arg, cwd, fsImpl) ||
737+
isOwnedExtensionRootTarget(arg, cwd, fsImpl)
719738
: path.extname(arg) === "" &&
720739
/^(?:src|test|extensions|ui|packages|apps)\//u.test(toRepoRelativeArg(arg, cwd));
721740
}

‎scripts/test-projects.test-support.mts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ import { isAcpxExtensionRoot } from "../test/vitest/vitest.extension-acpx-paths.
3131
import { isActiveMemoryExtensionRoot } from "../test/vitest/vitest.extension-active-memory-paths.mjs";
3232
import { isBrowserExtensionRoot } from "../test/vitest/vitest.extension-browser-paths.mjs";
3333
import { resolveSplitChannelExtensionShard } from "../test/vitest/vitest.extension-channel-split-paths.mjs";
34-
import { isCodexExtensionRoot } from "../test/vitest/vitest.extension-codex-paths.mjs";
34+
import {
35+
codexExtensionTestRoots,
36+
isCodexExtensionRoot,
37+
} from "../test/vitest/vitest.extension-codex-paths.mjs";
3538
import { isDiffsExtensionRoot } from "../test/vitest/vitest.extension-diffs-paths.mjs";
3639
import { isFeishuExtensionRoot } from "../test/vitest/vitest.extension-feishu-paths.mjs";
3740
import { isIrcExtensionRoot } from "../test/vitest/vitest.extension-irc-paths.mjs";
@@ -261,6 +264,7 @@ const UNIT_SECURITY_VITEST_CONFIG = "test/vitest/vitest.unit-security.config.ts"
261264
const UNIT_SRC_VITEST_CONFIG = "test/vitest/vitest.unit-src.config.ts";
262265
const UNIT_SUPPORT_VITEST_CONFIG = "test/vitest/vitest.unit-support.config.ts";
263266
const EXTENSION_TEST_PROCESS_ROOTS = new Map([
267+
[EXTENSION_CODEX_VITEST_CONFIG, codexExtensionTestRoots],
264268
[EXTENSION_MATRIX_VITEST_CONFIG, matrixExtensionTestRoots],
265269
[EXTENSION_TELEGRAM_VITEST_CONFIG, telegramExtensionTestRoots],
266270
]);

‎test/scripts/ci-changed-node-test-plan.test.ts‎

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,31 @@ import {
1010
hasQaSmokeAffectingChange,
1111
hasSqliteSessionLifecycleAffectingChange,
1212
} from "../../scripts/lib/ci-changed-node-test-plan.mts";
13+
import { listExtensionTestFilesForRoots } from "../../scripts/lib/extension-test-plan.mts";
1314
import { hasImportGraphImpactOnTargets } from "../../scripts/test-projects.test-support.mts";
1415
import { listGitTrackedFiles } from "../../src/test-utils/repo-files.js";
1516
import { isGatewayServerTestFile } from "../vitest/vitest.gateway-server-paths.mjs";
1617

18+
const CODEX_TEST_PROCESS_FILE_LIMIT = 40;
19+
20+
function expectBoundedCodexFallback(
21+
shards: ReturnType<typeof createChangedExtensionFallbackShards>,
22+
) {
23+
const targets = shards.flatMap((shard) => shard.includePatterns ?? []);
24+
25+
expect(shards.length).toBeGreaterThan(1);
26+
expect(
27+
shards.every(
28+
(shard) =>
29+
shard.configs[0] === "test/vitest/vitest.extension-codex.config.ts" &&
30+
(shard.includePatterns?.length ?? 0) > 0 &&
31+
(shard.includePatterns?.length ?? 0) <= CODEX_TEST_PROCESS_FILE_LIMIT,
32+
),
33+
).toBe(true);
34+
expect(targets).toEqual(listExtensionTestFilesForRoots(["extensions/codex"]));
35+
expect(new Set(targets).size).toBe(targets.length);
36+
}
37+
1738
describe("CI changed Node test plan", () => {
1839
it("routes Control UI style changes through source-scanning policy tests", () => {
1940
const shards = createChangedNodeTestShards(["ui/src/styles/chat/layout.css"]);
@@ -274,15 +295,7 @@ describe("CI changed Node test plan", () => {
274295
];
275296

276297
expect(createChangedNodeTestShards(changedPaths)).toBeNull();
277-
expect(createChangedExtensionFallbackShards(changedPaths)).toEqual([
278-
{
279-
checkName: "checks-node-changed-extensions-config",
280-
configs: ["test/vitest/vitest.extension-codex.config.ts"],
281-
requiresDist: false,
282-
runner: "blacksmith-8vcpu-ubuntu-2404",
283-
shardName: "changed-extensions-config",
284-
},
285-
]);
298+
expectBoundedCodexFallback(createChangedExtensionFallbackShards(changedPaths));
286299
});
287300

288301
it.each([
@@ -348,22 +361,14 @@ describe("CI changed Node test plan", () => {
348361
).toEqual([]);
349362
});
350363

351-
it("falls back to the affected extension config for deleted sources", () => {
364+
it("falls back to bounded Codex config shards for deleted sources", () => {
352365
const cwd = mkdtempSync(path.join(tmpdir(), "openclaw-ci-extension-fallback-"));
353366
try {
354-
expect(
367+
expectBoundedCodexFallback(
355368
createChangedExtensionFallbackShards(["extensions/codex/src/deleted-session-runtime.ts"], {
356369
cwd,
357370
}),
358-
).toEqual([
359-
{
360-
checkName: "checks-node-changed-extensions-config",
361-
configs: ["test/vitest/vitest.extension-codex.config.ts"],
362-
requiresDist: false,
363-
runner: "blacksmith-8vcpu-ubuntu-2404",
364-
shardName: "changed-extensions-config",
365-
},
366-
]);
371+
);
367372
expect(
368373
createChangedExtensionFallbackShards(
369374
["extensions/codex/src/deleted-session-runtime.test.ts"],

‎test/scripts/run-vitest.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,31 @@ describe("scripts/run-vitest", () => {
391391
expect(resolveTestProjectsDelegationArgs([prefix])).toEqual([prefix]);
392392
});
393393

394+
it("delegates an existing extension root to the project router", () => {
395+
const directory = "extensions/codex";
396+
397+
expect(resolveTestProjectsDelegationArgs([directory])).toEqual([directory]);
398+
expect(resolveTestProjectsDelegationArgs(["run", directory, "--reporter=verbose"])).toEqual([
399+
directory,
400+
"--",
401+
"--reporter=verbose",
402+
]);
403+
});
404+
405+
it("keeps extension subdirectories and direct-mode root runs on Vitest", () => {
406+
const directory = "extensions/codex";
407+
408+
expect(resolveTestProjectsDelegationArgs([`${directory}/src`])).toBeNull();
409+
expect(
410+
resolveTestProjectsDelegationArgs([
411+
"--config",
412+
"test/vitest/vitest.extension-codex.config.ts",
413+
directory,
414+
]),
415+
).toBeNull();
416+
expect(resolveTestProjectsDelegationArgs(["--watch", directory])).toBeNull();
417+
});
418+
394419
it("delegates owned agent directories with separate Vitest option values", () => {
395420
const directory = "src/agents/embedded-agent-runner/run";
396421

‎test/scripts/test-projects.test.ts‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ import {
4040
} from "../vitest/vitest.contracts-shared.ts";
4141

4242
const normalizeRepoPath = toRepoPath;
43+
const CODEX_TEST_PROCESS_FILE_LIMIT = 40;
4344
const MATRIX_TEST_PROCESS_FILE_LIMIT = 40;
4445
const TELEGRAM_TEST_PROCESS_FILE_LIMIT = 1;
4546

47+
function expectedCodexTestProcessCount() {
48+
const testFileCount = listExtensionTestFilesForRoots(["extensions/codex"]).length;
49+
return Math.max(1, Math.ceil(testFileCount / CODEX_TEST_PROCESS_FILE_LIMIT));
50+
}
51+
4652
function expectedMatrixTestProcessCount() {
4753
const testFileCount = listExtensionTestFilesForRoots(["extensions/matrix"]).length;
4854
return Math.max(1, Math.ceil(testFileCount / MATRIX_TEST_PROCESS_FILE_LIMIT));
@@ -54,9 +60,11 @@ function expectedTelegramTestProcessCount() {
5460
}
5561

5662
function listExpectedFullExtensionRunPlans() {
63+
const codexConfig = "test/vitest/vitest.extension-codex.config.ts";
5764
const matrixConfig = "test/vitest/vitest.extension-matrix.config.ts";
5865
const telegramConfig = "test/vitest/vitest.extension-telegram.config.ts";
5966
const boundedPlansByConfig = new Map([
67+
[codexConfig, buildVitestRunPlans(["extensions/codex"], process.cwd())],
6068
[matrixConfig, buildVitestRunPlans(["extensions/matrix"], process.cwd())],
6169
[telegramConfig, buildVitestRunPlans(["extensions/telegram"], process.cwd())],
6270
]);
@@ -2105,12 +2113,13 @@ describe("scripts/test-projects changed-target routing", () => {
21052113
});
21062114

21072115
it("routes the top-level extensions target to every extension shard", () => {
2116+
const codexConfig = "test/vitest/vitest.extension-codex.config.ts";
21082117
const matrixConfig = "test/vitest/vitest.extension-matrix.config.ts";
21092118
const telegramConfig = "test/vitest/vitest.extension-telegram.config.ts";
21102119
const plans = buildVitestRunPlans(["extensions"], process.cwd());
21112120
const matrixPlans = plans.filter((plan) => plan.config === matrixConfig);
21122121
const telegramPlans = plans.filter((plan) => plan.config === telegramConfig);
2113-
const boundedConfigs = new Set([matrixConfig, telegramConfig]);
2122+
const boundedConfigs = new Set([codexConfig, matrixConfig, telegramConfig]);
21142123

21152124
expect(plans.filter((plan) => !boundedConfigs.has(plan.config))).toEqual(
21162125
listFullExtensionVitestProjectConfigs()
@@ -2253,6 +2262,37 @@ describe("scripts/test-projects changed-target routing", () => {
22532262
);
22542263
});
22552264

2265+
it("bounds an explicit Codex directory target across process lifetimes", () => {
2266+
const config = "test/vitest/vitest.extension-codex.config.ts";
2267+
const plans = buildVitestRunPlans(["extensions/codex"], process.cwd());
2268+
2269+
expect(plans.length).toBeGreaterThan(1);
2270+
expect(plans).toHaveLength(expectedCodexTestProcessCount());
2271+
expect(plans.every((plan) => plan.config === config)).toBe(true);
2272+
expect(
2273+
plans.every((plan) => (plan.includePatterns?.length ?? 0) <= CODEX_TEST_PROCESS_FILE_LIMIT),
2274+
).toBe(true);
2275+
expect(plans.flatMap((plan) => plan.includePatterns ?? [])).toEqual(
2276+
listExtensionTestFilesForRoots(["extensions/codex"]),
2277+
);
2278+
});
2279+
2280+
it("keeps an explicit Codex file target in one process", () => {
2281+
const testFile = listExtensionTestFilesForRoots(["extensions/codex"])[0];
2282+
if (!testFile) {
2283+
throw new Error("expected a Codex test fixture");
2284+
}
2285+
2286+
expect(buildVitestRunPlans([testFile], process.cwd())).toEqual([
2287+
{
2288+
config: "test/vitest/vitest.extension-codex.config.ts",
2289+
forwardedArgs: [],
2290+
includePatterns: [testFile],
2291+
watchMode: false,
2292+
},
2293+
]);
2294+
});
2295+
22562296
it("keeps grouped Matrix targets covered when bounding the directory", () => {
22572297
const testFile = listExtensionTestFilesForRoots(["extensions/matrix"])[0];
22582298
if (!testFile) {

0 commit comments

Comments
 (0)