Skip to content

Commit d4ee874

Browse files
authored
fix(ci): preserve scoped extension test plans (#123534)
Preserve externally scoped Telegram and Matrix test plans instead of expanding each CI shard back into the full extension suite. Keep broad runs bounded and retain external include ownership through directory run specs. Co-authored-by: Ayaan Zaidi <[email protected]>
1 parent 8391ac5 commit d4ee874

2 files changed

Lines changed: 78 additions & 14 deletions

File tree

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -969,12 +969,17 @@ function createBroadToolingScriptPlans(params: VitestRunPlan & { cwd: string })
969969
: null;
970970
}
971971

972-
function createBoundedExtensionPlans(plan: VitestRunPlan) {
972+
function createBoundedExtensionPlans(plan: VitestRunPlan, env?: NodeJS.ProcessEnv) {
973973
const { config, forwardedArgs, watchMode } = plan;
974974
const roots = EXTENSION_TEST_PROCESS_ROOTS.get(config);
975975
if (watchMode || !roots) {
976976
return [plan];
977977
}
978+
// A CI include file already owns the test scope. Expanding its config here
979+
// or emitting local patterns would replace that shard in the run spec.
980+
if (env?.[INCLUDE_FILE_ENV_KEY]?.trim()) {
981+
return [{ ...plan, includePatterns: null }];
982+
}
978983
const chunks = createExtensionTestProcessTargetChunks(config, roots, forwardedArgs);
979984
if (chunks.length <= 1) {
980985
return [plan];
@@ -3609,12 +3614,15 @@ export function buildVitestRunPlans(
36093614
);
36103615
}
36113616
return explicitConfigTargets.flatMap((config) =>
3612-
createBoundedExtensionPlans({
3613-
config,
3614-
forwardedArgs: nonTargetArgs,
3615-
includePatterns: null,
3616-
watchMode,
3617-
}),
3617+
createBoundedExtensionPlans(
3618+
{
3619+
config,
3620+
forwardedArgs: nonTargetArgs,
3621+
includePatterns: null,
3622+
watchMode,
3623+
},
3624+
options.env,
3625+
),
36183626
);
36193627
}
36203628

@@ -3726,7 +3734,7 @@ export function buildVitestRunPlans(
37263734
includePatterns: null,
37273735
watchMode,
37283736
};
3729-
plans.push(...createBoundedExtensionPlans(plan));
3737+
plans.push(...createBoundedExtensionPlans(plan, options.env));
37303738
}
37313739
continue;
37323740
}
@@ -3778,12 +3786,15 @@ export function buildVitestRunPlans(
37783786
});
37793787
const boundedExtensionPlans =
37803788
boundedExtensionRoots.length > 0 && boundedRootsCoverGroupedTargets
3781-
? createBoundedExtensionPlans({
3782-
config,
3783-
forwardedArgs: forwardedPlanArgs,
3784-
includePatterns,
3785-
watchMode,
3786-
})
3789+
? createBoundedExtensionPlans(
3790+
{
3791+
config,
3792+
forwardedArgs: forwardedPlanArgs,
3793+
includePatterns,
3794+
watchMode,
3795+
},
3796+
options.env,
3797+
)
37873798
: null;
37883799
if (boundedExtensionPlans) {
37893800
plans.push(...boundedExtensionPlans);

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,59 @@ describe("scripts/test-projects changed-target routing", () => {
21462146
);
21472147
});
21482148

2149+
it.each([
2150+
{
2151+
channel: "Telegram",
2152+
config: "test/vitest/vitest.extension-telegram.config.ts",
2153+
},
2154+
{ channel: "Matrix", config: "test/vitest/vitest.extension-matrix.config.ts" },
2155+
])("preserves an externally scoped $channel config target", ({ config }) => {
2156+
expect(
2157+
buildVitestRunPlans([config], process.cwd(), () => [], {
2158+
env: { OPENCLAW_VITEST_INCLUDE_FILE: "ci-shard.json" },
2159+
}),
2160+
).toEqual([
2161+
{
2162+
config,
2163+
forwardedArgs: [],
2164+
includePatterns: null,
2165+
watchMode: false,
2166+
},
2167+
]);
2168+
});
2169+
2170+
it.each([
2171+
{
2172+
channel: "Telegram",
2173+
config: "test/vitest/vitest.extension-telegram.config.ts",
2174+
directory: "extensions/telegram",
2175+
},
2176+
{
2177+
channel: "Matrix",
2178+
config: "test/vitest/vitest.extension-matrix.config.ts",
2179+
directory: "extensions/matrix",
2180+
},
2181+
])("preserves an externally scoped $channel directory run spec", ({ config, directory }) => {
2182+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-external-test-scope-"));
2183+
try {
2184+
const includeFile = path.join(tempDir, "ci-shard.json");
2185+
fs.writeFileSync(includeFile, JSON.stringify([`${directory}/src/example.test.ts`]));
2186+
const [spec] = createVitestRunSpecs([directory], {
2187+
baseEnv: { OPENCLAW_VITEST_INCLUDE_FILE: includeFile },
2188+
tempDir,
2189+
});
2190+
2191+
expect(spec).toMatchObject({
2192+
config,
2193+
env: { OPENCLAW_VITEST_INCLUDE_FILE: includeFile },
2194+
includeFilePath: null,
2195+
includePatterns: null,
2196+
});
2197+
} finally {
2198+
fs.rmSync(tempDir, { force: true, recursive: true });
2199+
}
2200+
});
2201+
21492202
it("bounds an explicit Matrix directory target across process lifetimes", () => {
21502203
const plans = buildVitestRunPlans(["extensions/matrix"], process.cwd());
21512204

0 commit comments

Comments
 (0)