From 4a67e4b976882dba879e67107d72de4ea53e23c6 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Wed, 3 Jun 2026 11:04:59 +0200 Subject: [PATCH] fix(test): avoid empty script changed runs --- scripts/test-projects.test-support.mjs | 15 +++++++++++++-- test/scripts/test-projects.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/scripts/test-projects.test-support.mjs b/scripts/test-projects.test-support.mjs index 648a445b55fb..35d109a735ad 100644 --- a/scripts/test-projects.test-support.mjs +++ b/scripts/test-projects.test-support.mjs @@ -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) { diff --git a/test/scripts/test-projects.test.ts b/test/scripts/test-projects.test.ts index bab718432705..909b1ea45591 100644 --- a/test/scripts/test-projects.test.ts +++ b/test/scripts/test-projects.test.ts @@ -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",