fix(test): avoid walking gateway suite targets

This commit is contained in:
Vincent Koc
2026-05-16 08:47:05 +08:00
parent efabae2f9b
commit 0e7cc1ca53
2 changed files with 28 additions and 1 deletions

View File

@@ -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));
}

View File

@@ -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<typeof buildFullSuiteVitestRunPlans>;
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",