windows-e2e-shards.test.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. import { readFileSync } from "node:fs";
  2. import { EventEmitter } from "node:events";
  3. import { join, resolve } from "node:path";
  4. import { describe, expect, it, vi } from "vitest";
  5. import {
  6. createWindowsE2EShardPlan,
  7. executeWindowsE2EShardPlan,
  8. listDefaultFormalE2ESpecs,
  9. partitionE2ESpecsByWeight,
  10. resolveWindowsE2EShardTotal,
  11. } from "../scripts/run-windows-e2e-shards.mjs";
  12. const repoRoot = resolve("C:/repo");
  13. const desktopDir = join(repoRoot, "packages/desktop");
  14. function createPlan(overrides: Record<string, unknown> = {}) {
  15. return createWindowsE2EShardPlan({
  16. args: [],
  17. desktopDir,
  18. env: { ZCODE_E2E_RUN_ID: "local-full", ZCODE_E2E_SHARD_TOTAL: "2" },
  19. platform: "win32",
  20. repoRoot,
  21. ...overrides,
  22. });
  23. }
  24. describe("Windows E2E shard runner", () => {
  25. it("derives disjoint paths from automatic run IDs while preserving an explicit run ID", () => {
  26. const timestamp = new Date("2026-07-11T00:30:00.123Z");
  27. vi.useFakeTimers();
  28. vi.setSystemTime(timestamp);
  29. try {
  30. const firstPlan = createPlan({
  31. // 修复原因:默认 full run 已改为单 shard;路径隔离断言必须显式进入并发分片场景。
  32. env: { ZCODE_E2E_SHARD_TOTAL: "2" },
  33. processId: 4242,
  34. runIdEntropy: "entropy-a",
  35. runIdTimestamp: timestamp,
  36. });
  37. const secondPlan = createPlan({
  38. env: { ZCODE_E2E_SHARD_TOTAL: "2" },
  39. processId: 4242,
  40. runIdEntropy: "entropy-b",
  41. runIdTimestamp: timestamp,
  42. });
  43. expect(firstPlan.runId).not.toBe(secondPlan.runId);
  44. for (const key of [
  45. "ZCODE_E2E_HOME_DIR",
  46. "ZCODE_E2E_ARTIFACT_DIR",
  47. "ZCODE_E2E_NETWORK_CAPTURE_DIR",
  48. ] as const) {
  49. const firstPaths = new Set(firstPlan.children.map((child) => child.env[key]));
  50. const secondPaths = new Set(secondPlan.children.map((child) => child.env[key]));
  51. expect([...firstPaths].filter((path) => secondPaths.has(path))).toEqual([]);
  52. }
  53. const explicitPlan = createPlan({
  54. env: { ZCODE_E2E_RUN_ID: "explicit-compatible-run" },
  55. processId: 4242,
  56. runIdEntropy: "ignored-entropy",
  57. runIdTimestamp: timestamp,
  58. });
  59. expect(explicitPlan.runId).toBe("explicit-compatible-run");
  60. } finally {
  61. vi.useRealTimers();
  62. }
  63. });
  64. it("plans a default full Windows run as a single shard", () => {
  65. const plan = createPlan({
  66. env: { ZCODE_E2E_RUN_ID: "default-single" },
  67. });
  68. expect(plan.shardTotal).toBe(1);
  69. expect(plan.children).toHaveLength(1);
  70. expect(plan.children[0]?.args.some((arg) => arg.startsWith("--shard"))).toBe(false);
  71. expect(plan.children[0]?.env.ZCODE_E2E_HOME_DIR).toBe(
  72. join(desktopDir, ".e2e-home-default-single"),
  73. );
  74. });
  75. it("lists the default formal specs without manual-review or live provider cases", () => {
  76. const specs = listDefaultFormalE2ESpecs(resolve(process.cwd(), "packages/desktop"));
  77. // Bug 根因:formal case 由目录动态发现,固定总数会让新增或删除合法 case 误伤 pre-push。
  78. // 用稳定的 smoke 包含关系确认发现结果非空,其余断言只校验默认集合的语义边界。
  79. expect(specs).toContain("./test/e2e/infrastructure/smoke/smoke.test.ts");
  80. expect(specs).not.toContain("./test/e2e/infrastructure/smoke/upstream-provider.test.ts");
  81. expect(specs.some((spec) => spec.includes("/manual-review/"))).toBe(false);
  82. expect(specs.some((spec) => spec.includes("conversation-session-ssh-remote"))).toBe(false);
  83. const sshSpecs = listDefaultFormalE2ESpecs(resolve(process.cwd(), "packages/desktop"), {
  84. ZCODE_E2E_SSH_HOST: "ssh.example.test",
  85. ZCODE_E2E_SSH_USERNAME: "root",
  86. ZCODE_E2E_SSH_PASSWORD: "secret-from-test-env",
  87. });
  88. // 只有 SSH 凭据、没有 harness 容器时,远程队列用例不能进入共享主机的分片。
  89. expect(sshSpecs.some((spec) => spec.includes("conversation-session-ssh-remote"))).toBe(false);
  90. expect(sshSpecs).not.toContain(
  91. "./test/e2e/conversation-session/remote/configuration/conversation-session-r3-model-switch.test.ts",
  92. );
  93. const harnessSpecs = listDefaultFormalE2ESpecs(resolve(process.cwd(), "packages/desktop"), {
  94. ZCODE_E2E_SSH_HOST: "ssh.example.test",
  95. ZCODE_E2E_SSH_USERNAME: "root",
  96. ZCODE_E2E_SSH_PASSWORD: "secret-from-test-env",
  97. ZCODE_E2E_SSH_CONTAINER: "zcode-r3-server-example",
  98. });
  99. expect(harnessSpecs).toContain(
  100. "./test/e2e/conversation-session/remote/connection/conversation-session-ssh-remote-connection-p0.test.ts",
  101. );
  102. expect(harnessSpecs).toContain(
  103. "./test/e2e/conversation-session/remote/configuration/conversation-session-r3-model-switch.test.ts",
  104. );
  105. });
  106. it("uses deterministic LPT weights and a fallback for new specs", () => {
  107. const buckets = partitionE2ESpecsByWeight(
  108. ["./a.test.ts", "./b.test.ts", "./c.test.ts", "./new.test.ts"],
  109. 2,
  110. {
  111. defaultWeightMs: 40,
  112. weights: {
  113. "./a.test.ts": 100,
  114. "./b.test.ts": 80,
  115. "./c.test.ts": 20,
  116. },
  117. },
  118. );
  119. expect(buckets).toEqual([
  120. { estimatedWeightMs: 120, specs: ["./a.test.ts", "./c.test.ts"] },
  121. { estimatedWeightMs: 120, specs: ["./b.test.ts", "./new.test.ts"] },
  122. ]);
  123. });
  124. it("passes weighted spec groups explicitly instead of native contiguous shards", () => {
  125. const weightedSpecBuckets = [
  126. { estimatedWeightMs: 100, specs: ["./test/e2e/infrastructure/smoke/smoke.test.ts"] },
  127. { estimatedWeightMs: 90, specs: ["./test/e2e/infrastructure/smoke/container-boot.test.ts"] },
  128. ];
  129. const plan = createPlan({ weightedSpecBuckets });
  130. expect(plan.distributionKind).toBe("historical-lpt");
  131. expect(plan.children.map((child) => child.env.ZCODE_E2E_SPEC)).toEqual([
  132. "./test/e2e/infrastructure/smoke/smoke.test.ts",
  133. "./test/e2e/infrastructure/smoke/container-boot.test.ts",
  134. ]);
  135. expect(
  136. plan.children.every((child) => child.args.every((arg) => !arg.startsWith("--shard"))),
  137. ).toBe(true);
  138. });
  139. it("plans two isolated shards for an explicit two-shard run", () => {
  140. const plan = createPlan();
  141. expect(plan.shardTotal).toBe(2);
  142. expect(plan.children).toHaveLength(2);
  143. expect(plan.children.map((child) => child.shardId)).toEqual(["1/2", "2/2"]);
  144. expect(plan.children.map((child) => child.args.at(-1))).toEqual(["--shard=1/2", "--shard=2/2"]);
  145. for (const key of [
  146. "ZCODE_E2E_HOME_DIR",
  147. "ZCODE_E2E_RUN_ID",
  148. "ZCODE_E2E_ARTIFACT_DIR",
  149. "ZCODE_E2E_NETWORK_CAPTURE_DIR",
  150. ] as const) {
  151. expect(new Set(plan.children.map((child) => child.env[key])).size).toBe(2);
  152. }
  153. for (const child of plan.children) {
  154. expect(child.env.ZCODE_E2E_SKIP_BUILD).toBe("1");
  155. expect(child.env.ZCODE_E2E_SKIP_AGENT_BUILD).toBe("1");
  156. expect(child.summaryPath).toBe(join(child.artifactDir, "summary.json"));
  157. }
  158. });
  159. it("keeps every default HOME disjoint across concurrent runner run IDs", () => {
  160. const firstPlan = createPlan({
  161. // 修复原因:覆盖 env 会同时移除 createPlan 默认的 shard 数,需保留显式分片前提。
  162. env: {
  163. ZCODE_E2E_RUN_ID: "concurrent-run-a",
  164. ZCODE_E2E_SHARD_TOTAL: "2",
  165. },
  166. });
  167. const secondPlan = createPlan({
  168. env: {
  169. ZCODE_E2E_RUN_ID: "concurrent-run-b",
  170. ZCODE_E2E_SHARD_TOTAL: "2",
  171. },
  172. });
  173. const firstHomes = new Set(firstPlan.children.map((child) => child.env.ZCODE_E2E_HOME_DIR));
  174. const secondHomes = new Set(secondPlan.children.map((child) => child.env.ZCODE_E2E_HOME_DIR));
  175. expect([...firstHomes].filter((home) => secondHomes.has(home))).toEqual([]);
  176. expect([...firstHomes].every((home) => home.includes("concurrent-run-a"))).toBe(true);
  177. expect([...secondHomes].every((home) => home.includes("concurrent-run-b"))).toBe(true);
  178. });
  179. it("preserves an explicit HOME for a single-child run", () => {
  180. const explicitHomeRoot = resolve("C:/e2e-homes/single");
  181. const plan = createPlan({
  182. env: {
  183. ZCODE_E2E_HOME_DIR: explicitHomeRoot,
  184. ZCODE_E2E_RUN_ID: "explicit-single-home-run",
  185. },
  186. });
  187. expect(plan.shardTotal).toBe(1);
  188. expect(plan.children[0]?.env.ZCODE_E2E_HOME_DIR).toBe(explicitHomeRoot);
  189. });
  190. it("adds run and shard identity below an explicit sharded HOME base", () => {
  191. const explicitHomeRoot = resolve("C:/e2e-homes");
  192. const plan = createPlan({
  193. env: {
  194. ZCODE_E2E_HOME_DIR: explicitHomeRoot,
  195. ZCODE_E2E_RUN_ID: "explicit-home-run",
  196. ZCODE_E2E_SHARD_TOTAL: "2",
  197. },
  198. });
  199. expect(plan.children.map((child) => child.env.ZCODE_E2E_HOME_DIR)).toEqual([
  200. join(explicitHomeRoot, "explicit-home-run", "shard-1-of-2"),
  201. join(explicitHomeRoot, "explicit-home-run", "shard-2-of-2"),
  202. ]);
  203. });
  204. it("builds desktop and agent once before starting both children concurrently", async () => {
  205. const plan = createPlan();
  206. expect(
  207. plan.buildSteps.find((step) => step.id === "build-agent")?.env.ZCODE_DESKTOP_AGENT_BUILD_MODE,
  208. ).toBe("turbo");
  209. const shim = plan.buildSteps[0];
  210. expect(shim?.id).toBe("prepare-windows-entry-shim");
  211. expect(shim?.args).toContain("--ensure");
  212. expect(shim?.timeoutMs).toBeGreaterThan(0);
  213. expect(shim?.killProcessTree).toBe(true);
  214. const events: string[] = [];
  215. const childResolvers: Array<(result: { exitCode: number }) => void> = [];
  216. const execution = executeWindowsE2EShardPlan(plan, {
  217. now: (() => {
  218. let value = 1_000;
  219. return () => (value += 50);
  220. })(),
  221. summaryExists: () => true,
  222. spawnStep: vi.fn(async (step) => {
  223. events.push(`start:${step.id}`);
  224. if (step.kind === "build") {
  225. events.push(`finish:${step.id}`);
  226. return { exitCode: 0 };
  227. }
  228. return await new Promise<{ exitCode: number }>((resolveChild) => {
  229. childResolvers.push(resolveChild);
  230. });
  231. }),
  232. writeManifest: vi.fn(),
  233. printManifest: vi.fn(),
  234. });
  235. await vi.waitFor(() => expect(childResolvers).toHaveLength(2));
  236. expect(events).toEqual([
  237. "start:prepare-windows-entry-shim",
  238. "finish:prepare-windows-entry-shim",
  239. "start:build-desktop",
  240. "finish:build-desktop",
  241. "start:build-agent",
  242. "finish:build-agent",
  243. "start:shard-1-of-2",
  244. "start:shard-2-of-2",
  245. ]);
  246. childResolvers[1]?.({ exitCode: 0 });
  247. childResolvers[0]?.({ exitCode: 0 });
  248. const manifest = await execution;
  249. expect(manifest.wallDurationMs).toBe(50);
  250. expect(manifest.children.map((child) => child.exitCode)).toEqual([0, 0]);
  251. });
  252. it("prepares the shim before a single Windows child but leaves other platforms alone", () => {
  253. const windows = createPlan({ env: { ZCODE_E2E_RUN_ID: "single" } });
  254. expect(windows.buildSteps.map((step) => step.id)).toEqual(["prepare-windows-entry-shim"]);
  255. const mac = createPlan({ platform: "darwin", env: { ZCODE_E2E_RUN_ID: "single" } });
  256. expect(mac.buildSteps).toEqual([]);
  257. });
  258. it.each([
  259. {
  260. label: "targeted CLI",
  261. args: ["--spec=./test/e2e/infrastructure/smoke/container-boot.test.ts", "--shards=10"],
  262. env: { ZCODE_E2E_SHARD_TOTAL: "4" },
  263. },
  264. {
  265. label: "targeted env",
  266. args: ["--shards=10"],
  267. env: {
  268. ZCODE_E2E_SPEC: "./test/e2e/infrastructure/smoke/container-boot.test.ts",
  269. ZCODE_E2E_SHARD_TOTAL: "4",
  270. },
  271. },
  272. {
  273. label: "capture",
  274. args: ["--shards=10"],
  275. env: { E2E_PROVIDER_HTTP_MODE: "capture", ZCODE_E2E_SHARD_TOTAL: "4" },
  276. },
  277. {
  278. label: "manual review",
  279. args: ["--shards=10"],
  280. env: { ZCODE_E2E_MANUAL_REVIEW: "1", ZCODE_E2E_SHARD_TOTAL: "4" },
  281. },
  282. ])("keeps $label runs single despite explicit shard overrides", ({ args, env }) => {
  283. const plan = createPlan({ args, env });
  284. expect(plan.shardTotal).toBe(1);
  285. expect(plan.children).toHaveLength(1);
  286. });
  287. it("keeps non-Windows runs single by default", () => {
  288. expect(resolveWindowsE2EShardTotal({ args: [], env: {}, platform: "darwin" })).toBe(1);
  289. });
  290. it("validates explicit overrides and strips the runner-only option", () => {
  291. const plan = createPlan({
  292. args: ["--logLevel=warn", "--shards=3", "--mochaOpts.timeout=9000"],
  293. env: { ZCODE_E2E_SHARD_TOTAL: "4", ZCODE_E2E_RUN_ID: "override" },
  294. });
  295. expect(plan.shardTotal).toBe(3);
  296. expect(plan.wdioArgs).toEqual(["--logLevel=warn", "--mochaOpts.timeout=9000"]);
  297. expect(plan.children.map((child) => child.args.at(-1))).toEqual([
  298. "--shard=1/3",
  299. "--shard=2/3",
  300. "--shard=3/3",
  301. ]);
  302. expect(() =>
  303. resolveWindowsE2EShardTotal({ args: ["--shards=0"], env: {}, platform: "win32" }),
  304. ).toThrow("positive integer");
  305. expect(() =>
  306. resolveWindowsE2EShardTotal({
  307. args: [],
  308. env: { ZCODE_E2E_SHARD_TOTAL: "two" },
  309. platform: "win32",
  310. }),
  311. ).toThrow("positive integer");
  312. });
  313. it("does not reshard a native WDIO shard from any override", () => {
  314. expect(
  315. resolveWindowsE2EShardTotal({
  316. args: ["--shard=1/2"],
  317. env: { ZCODE_E2E_SHARD_TOTAL: "4" },
  318. platform: "win32",
  319. }),
  320. ).toBe(1);
  321. expect(
  322. resolveWindowsE2EShardTotal({
  323. args: ["--shard=1/2", "--shards=3"],
  324. env: { ZCODE_E2E_SHARD_TOTAL: "4" },
  325. platform: "win32",
  326. }),
  327. ).toBe(1);
  328. });
  329. it("waits for every child, writes one manifest, and fails when any shard fails", async () => {
  330. const plan = createPlan();
  331. const completed: string[] = [];
  332. const writeManifest = vi.fn();
  333. const printManifest = vi.fn();
  334. let caught: unknown;
  335. try {
  336. await executeWindowsE2EShardPlan(plan, {
  337. now: () => 2_000,
  338. summaryExists: () => true,
  339. spawnStep: async (step) => {
  340. if (step.kind === "build") return { exitCode: 0 };
  341. completed.push(step.id);
  342. return { exitCode: step.shardIndex === 1 ? 7 : 0 };
  343. },
  344. writeManifest,
  345. printManifest,
  346. });
  347. } catch (error) {
  348. caught = error;
  349. }
  350. expect(completed).toEqual(["shard-1-of-2", "shard-2-of-2"]);
  351. expect(writeManifest).toHaveBeenCalledOnce();
  352. expect(printManifest).toHaveBeenCalledOnce();
  353. expect(caught).toMatchObject({
  354. message: expect.stringContaining("shard 1/2 exited with code 7"),
  355. manifest: {
  356. runId: "local-full",
  357. shardTotal: 2,
  358. wallDurationMs: 0,
  359. children: [
  360. {
  361. shardId: "1/2",
  362. exitCode: 7,
  363. artifactDir: plan.children[0]?.artifactDir,
  364. summaryPath: plan.children[0]?.summaryPath,
  365. },
  366. {
  367. shardId: "2/2",
  368. exitCode: 0,
  369. artifactDir: plan.children[1]?.artifactDir,
  370. summaryPath: plan.children[1]?.summaryPath,
  371. },
  372. ],
  373. },
  374. });
  375. });
  376. it("rejects a zero-exit shard that produced no summary", async () => {
  377. const plan = createPlan();
  378. await expect(
  379. executeWindowsE2EShardPlan(plan, {
  380. now: () => 2_000,
  381. spawnStep: async () => ({ exitCode: 0 }),
  382. summaryExists: () => false,
  383. writeManifest: vi.fn(),
  384. printManifest: vi.fn(),
  385. }),
  386. ).rejects.toMatchObject({
  387. message: expect.stringContaining("missing shard summary"),
  388. manifest: {
  389. children: expect.arrayContaining([
  390. expect.objectContaining({ exitCode: 1, error: expect.stringContaining("summary.json") }),
  391. ]),
  392. },
  393. });
  394. });
  395. it("records a rejected shard start, waits for the delayed shard, and writes one manifest", async () => {
  396. const plan = createPlan();
  397. const writeManifest = vi.fn();
  398. const printManifest = vi.fn();
  399. let finishDelayedShard: (() => void) | undefined;
  400. const execution = executeWindowsE2EShardPlan(plan, {
  401. now: () => 2_000,
  402. summaryExists: () => true,
  403. spawnStep: (step) => {
  404. if (step.kind === "build") return Promise.resolve({ exitCode: 0 });
  405. if (step.shardIndex === 1) return Promise.reject(new Error("spawn pnpm EAGAIN"));
  406. return new Promise<{ exitCode: number }>((resolveChild) => {
  407. finishDelayedShard = () => resolveChild({ exitCode: 0 });
  408. });
  409. },
  410. writeManifest,
  411. printManifest,
  412. });
  413. await vi.waitFor(() => expect(finishDelayedShard).toBeTypeOf("function"));
  414. await Promise.resolve();
  415. expect(writeManifest).not.toHaveBeenCalled();
  416. finishDelayedShard?.();
  417. await expect(execution).rejects.toMatchObject({
  418. message: expect.stringContaining("shard 1/2 failed to start: spawn pnpm EAGAIN"),
  419. manifest: {
  420. children: [
  421. expect.objectContaining({
  422. shardId: "1/2",
  423. exitCode: 1,
  424. error: "spawn pnpm EAGAIN",
  425. }),
  426. expect.objectContaining({ shardId: "2/2", exitCode: 0 }),
  427. ],
  428. },
  429. });
  430. expect(writeManifest).toHaveBeenCalledOnce();
  431. expect(printManifest).toHaveBeenCalledOnce();
  432. });
  433. it("terminates another cancellable shard after an unrecoverable start error", async () => {
  434. const plan = createPlan();
  435. let finishSecondShard: ((result: { exitCode: number; signal?: string }) => void) | undefined;
  436. const terminateSecondShard = vi.fn(() => {
  437. finishSecondShard?.({ exitCode: 1, signal: "SIGTERM" });
  438. });
  439. const execution = executeWindowsE2EShardPlan(plan, {
  440. now: () => 2_000,
  441. summaryExists: () => true,
  442. spawnStep: (step) => {
  443. if (step.kind === "build") return Promise.resolve({ exitCode: 0 });
  444. if (step.shardIndex === 1) return Promise.reject(new Error("spawn pnpm ENOMEM"));
  445. return {
  446. result: new Promise<{ exitCode: number; signal?: string }>((resolveChild) => {
  447. finishSecondShard = resolveChild;
  448. }),
  449. terminate: terminateSecondShard,
  450. };
  451. },
  452. writeManifest: vi.fn(),
  453. printManifest: vi.fn(),
  454. });
  455. await expect(execution).rejects.toMatchObject({
  456. manifest: {
  457. children: [
  458. expect.objectContaining({ error: "spawn pnpm ENOMEM" }),
  459. expect.objectContaining({ signal: "SIGTERM" }),
  460. ],
  461. },
  462. });
  463. expect(terminateSecondShard).toHaveBeenCalledOnce();
  464. });
  465. it("terminates active shards on a parent signal and reports the interrupted run", async () => {
  466. const plan = createPlan();
  467. const signalSource = new EventEmitter();
  468. const childResolvers = new Map<
  469. number,
  470. (result: { exitCode: number; signal?: string }) => void
  471. >();
  472. const terminates: Array<ReturnType<typeof vi.fn>> = [];
  473. const execution = executeWindowsE2EShardPlan(plan, {
  474. now: () => 2_000,
  475. summaryExists: () => true,
  476. signalSource,
  477. spawnStep: (step) => {
  478. if (step.kind === "build") return Promise.resolve({ exitCode: 0 });
  479. const terminate = vi.fn(() => {
  480. childResolvers.get(step.shardIndex)?.({ exitCode: 1, signal: "SIGTERM" });
  481. });
  482. terminates.push(terminate);
  483. return {
  484. result: new Promise<{ exitCode: number; signal?: string }>((resolveChild) => {
  485. childResolvers.set(step.shardIndex, resolveChild);
  486. }),
  487. terminate,
  488. };
  489. },
  490. writeManifest: vi.fn(),
  491. printManifest: vi.fn(),
  492. });
  493. await vi.waitFor(() => expect(childResolvers.size).toBe(2));
  494. signalSource.emit("SIGTERM");
  495. await expect(execution).rejects.toMatchObject({
  496. message: expect.stringContaining("parent received SIGTERM"),
  497. manifest: expect.objectContaining({ interruptedBySignal: "SIGTERM" }),
  498. });
  499. expect(terminates).toHaveLength(2);
  500. expect(terminates.every((terminate) => terminate.mock.calls.length === 1)).toBe(true);
  501. expect(signalSource.listenerCount("SIGINT")).toBe(0);
  502. expect(signalSource.listenerCount("SIGTERM")).toBe(0);
  503. });
  504. it("separates the single-shard default from the fixed 10-shard performance entry", () => {
  505. const desktopPackage = JSON.parse(
  506. readFileSync(resolve(process.cwd(), "packages/desktop/package.json"), "utf-8"),
  507. ) as { scripts: Record<string, string> };
  508. const rootPackage = JSON.parse(
  509. readFileSync(resolve(process.cwd(), "package.json"), "utf-8"),
  510. ) as { scripts: Record<string, string> };
  511. expect(desktopPackage.scripts["pretest:e2e"]).toBe(
  512. "pnpm --filter @zcode/e2e-report build:node",
  513. );
  514. expect(desktopPackage.scripts["test:e2e"]).toBe("node scripts/run-windows-e2e-shards.mjs");
  515. expect(rootPackage.scripts["test:e2e"]).toBe("pnpm --filter @zcode/desktop test:e2e");
  516. expect(desktopPackage.scripts["test:e2e:windows:sharded"]).toBe("pnpm test:e2e -- --shards=10");
  517. expect(rootPackage.scripts["test:e2e:windows:sharded"]).toBe(
  518. "pnpm --filter @zcode/desktop test:e2e:windows:sharded",
  519. );
  520. });
  521. });