






























@@ -1,3 +1,4 @@
1+import { spawnSync } from "node:child_process";
12import { existsSync, readdirSync } from "node:fs";
23import { join, relative, resolve } from "node:path";
34import fg from "fast-glob";
@@ -34,6 +35,20 @@ const GATEWAY_SERVER_EXCLUDED_TESTS = new Set([
3435]);
35363637function listTestFiles(rootDir: string): string[] {
38+const result = spawnSync("git", ["ls-files", "--", rootDir], {
39+cwd: process.cwd(),
40+encoding: "utf8",
41+stdio: ["ignore", "pipe", "ignore"],
42+});
43+expect(result.status).toBe(0);
44+if (result.status === 0) {
45+return result.stdout
46+.split("\n")
47+.map((line) => line.trim().replaceAll("\\", "/"))
48+.filter((line) => line.endsWith(".test.ts"))
49+.toSorted((a, b) => a.localeCompare(b));
50+}
51+3752if (!existsSync(rootDir)) {
3853return [];
3954}
@@ -78,6 +93,54 @@ function isGatewayServerTestFile(file: string): boolean {
7893}
79948095describe("scripts/lib/ci-node-test-plan.mjs", () => {
96+it("creates split shards without walking test roots", () => {
97+const result = spawnSync(
98+process.execPath,
99+[
100+"--input-type=module",
101+"--eval",
102+`
103+ import fs from "node:fs";
104+ import { syncBuiltinESMExports } from "node:module";
105+ const counts = { existsSync: 0, readdirSync: 0 };
106+ const originalExistsSync = fs.existsSync;
107+ const originalReaddirSync = fs.readdirSync;
108+ fs.existsSync = (...args) => {
109+ counts.existsSync += 1;
110+ return originalExistsSync(...args);
111+ };
112+ fs.readdirSync = (...args) => {
113+ counts.readdirSync += 1;
114+ return originalReaddirSync(...args);
115+ };
116+ syncBuiltinESMExports();
117+ const { createNodeTestShards } = await import("./scripts/lib/ci-node-test-plan.mjs");
118+ const shards = createNodeTestShards();
119+ console.log(JSON.stringify({
120+ counts,
121+ includePatterns: shards.reduce((total, shard) => total + (shard.includePatterns?.length ?? 0), 0),
122+ shards: shards.length,
123+ }));
124+ `,
125+],
126+{
127+cwd: process.cwd(),
128+encoding: "utf8",
129+stdio: ["ignore", "pipe", "pipe"],
130+},
131+);
132+133+expect(result.status, result.stderr).toBe(0);
134+const payload = JSON.parse(result.stdout) as {
135+counts: { existsSync: number; readdirSync: number };
136+includePatterns: number;
137+shards: number;
138+};
139+expect(payload.shards).toBeGreaterThan(0);
140+expect(payload.includePatterns).toBeGreaterThan(0);
141+expect(payload.counts).toEqual({ existsSync: 0, readdirSync: 0 });
142+});
143+81144it("splits the slow core unit shards while keeping paired source/security coverage", () => {
82145const coreUnitShards = createNodeTestShards()
83146.filter((shard) => shard.shardName.startsWith("core-unit-"))
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。