From 0e7cc1ca53b9b78561a3ca9eb6c6be4a1df57dbb Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 16 May 2026 08:47:05 +0800 Subject: [PATCH] fix(test): avoid walking gateway suite targets --- scripts/test-projects.test-support.mjs | 17 ++++++++++++++++- test/scripts/test-projects.test.ts | 12 ++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/scripts/test-projects.test-support.mjs b/scripts/test-projects.test-support.mjs index 89b9ab80715..15b9c4ffaea 100644 --- a/scripts/test-projects.test-support.mjs +++ b/scripts/test-projects.test-support.mjs @@ -589,6 +589,21 @@ function listRepoFilesRecursive(root, cwd) { }); } +function listGatewayFilesFromGit(cwd) { + const result = spawnSync("git", ["ls-files", "--", "src/gateway"], { + cwd, + encoding: "utf8", + stdio: ["ignore", "pipe", "ignore"], + }); + if (result.status !== 0) { + return null; + } + return result.stdout + .split("\n") + .map((line) => normalizePathPattern(line.trim())) + .filter((line) => line.length > 0); +} + function isGatewayServerFullSuiteTarget(relative) { if ( GATEWAY_SERVER_EXCLUDED_TEST_TARGETS.has(relative) || @@ -609,7 +624,7 @@ function resolveGatewayServerFullSuiteTargets(cwd) { if (!fs.existsSync(gatewayDir)) { return []; } - return listRepoFilesRecursive(gatewayDir, cwd) + return (listGatewayFilesFromGit(cwd) ?? listRepoFilesRecursive(gatewayDir, cwd)) .filter(isGatewayServerFullSuiteTarget) .toSorted((a, b) => a.localeCompare(b)); } diff --git a/test/scripts/test-projects.test.ts b/test/scripts/test-projects.test.ts index c6ba2e1410a..02b55a20635 100644 --- a/test/scripts/test-projects.test.ts +++ b/test/scripts/test-projects.test.ts @@ -1172,9 +1172,20 @@ describe("scripts/test-projects full-suite sharding", () => { const gatewayServerConfig = "test/vitest/vitest.gateway-server.config.ts"; process.env.OPENCLAW_TEST_PROJECTS_LEAF_SHARDS = "1"; let plans: ReturnType; + const readdirSync = vi.spyOn(fs, "readdirSync"); + const before = readdirSync.mock.calls.length; + let gatewayTreeReads: unknown[][] = []; try { plans = buildFullSuiteVitestRunPlans([], process.cwd()); + gatewayTreeReads = readdirSync.mock.calls + .slice(before) + .filter(([target]) => + typeof target === "string" + ? normalizeRepoPath(target).includes("src/gateway") + : false, + ); } finally { + readdirSync.mockRestore(); if (previous === undefined) { delete process.env.OPENCLAW_TEST_PROJECTS_LEAF_SHARDS; } else { @@ -1182,6 +1193,7 @@ describe("scripts/test-projects full-suite sharding", () => { } } + expect(gatewayTreeReads).toEqual([]); expect(plans.map((plan) => plan.config)).toEqual([ "test/vitest/vitest.unit-fast.config.ts", "test/vitest/vitest.unit-src.config.ts",