fix(test): avoid empty script changed runs

This commit is contained in:
Vincent Koc
2026-06-03 11:04:59 +02:00
parent 41ee6b1dd6
commit 4a67e4b976
2 changed files with 36 additions and 2 deletions

View File

@@ -1647,8 +1647,11 @@ function resolveToolingChangedTestTargets(changedPaths, cwd = process.cwd()) {
return [...new Set(targets)];
}
const TOOLING_SCRIPT_PATH_PATTERN =
/^scripts\/(.+)\.(?:mjs|cjs|js|mts|cts|ts|sh|py|ps1)$/u;
function resolveConventionalToolingTestTargets(changedPath, cwd = process.cwd()) {
const match = /^scripts\/(.+)\.(?:mjs|ts|js|sh|py)$/u.exec(changedPath);
const match = TOOLING_SCRIPT_PATH_PATTERN.exec(changedPath);
if (!match) {
return null;
}
@@ -1667,6 +1670,10 @@ function resolveConventionalToolingTestTargets(changedPath, cwd = process.cwd())
return targets.length > 0 ? targets : null;
}
function isToolingScriptPath(changedPath) {
return TOOLING_SCRIPT_PATH_PATTERN.test(changedPath);
}
function resolveParallelsToolingTestTargets(changedPath) {
if (!/^scripts\/e2e\/parallels\/[^/]+\.ts$/u.test(changedPath)) {
return null;
@@ -1697,7 +1704,11 @@ function resolveToolingTestTargets(changedPath, cwd = process.cwd()) {
if (explicitTargets && conventionalTargets) {
return uniqueOrdered([...explicitTargets, ...conventionalTargets]);
}
return explicitTargets ?? conventionalTargets;
return (
explicitTargets ??
conventionalTargets ??
(isToolingScriptPath(changedPath) ? [TOOLING_VITEST_CONFIG] : null)
);
}
function shouldUseBroadChangedTargets(env = process.env) {

View File

@@ -267,6 +267,29 @@ describe("scripts/test-projects changed-target routing", () => {
});
});
it("routes unmatched script changes to the tooling suite instead of skipping tests", () => {
const targets = [
"scripts/check-no-raw-http2-imports.mjs",
"scripts/e2e/lib/clawhub-fixture-server.cjs",
"scripts/install.ps1",
];
expect(resolveChangedTestTargetPlan(targets)).toEqual({
mode: "targets",
targets: ["test/vitest/vitest.tooling.config.ts"],
});
expect(buildVitestRunPlans(["--changed", "origin/main"], process.cwd(), () => targets)).toEqual(
[
{
config: "test/vitest/vitest.tooling.config.ts",
forwardedArgs: [],
includePatterns: null,
watchMode: false,
},
],
);
});
it("routes Z.AI fallback repro script changes through its regression test", () => {
expect(resolveChangedTestTargetPlan(["scripts/zai-fallback-repro.ts"])).toEqual({
mode: "targets",