plugin-ui-session-ready.test.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import assert from "node:assert/strict";
  2. import { execFile } from "node:child_process";
  3. import { mkdir, mkdtemp, readFile, writeFile } from "node:fs/promises";
  4. import { join, resolve } from "node:path";
  5. import { promisify } from "node:util";
  6. const exec = promisify(execFile);
  7. describe("PLM-UI-SESSION-READY plugin cold recovery", () => {
  8. it("waits for session readiness and opens once without reload", async () => {
  9. const repo = resolve(process.cwd(), "../..");
  10. const artifacts =
  11. process.env.ZCODE_E2E_ARTIFACT_DIR ?? join(repo, "packages/desktop/.e2e-artifacts");
  12. await mkdir(artifacts, { recursive: true });
  13. const output = await mkdtemp(join(artifacts, "plugin-ui-session-ready-"));
  14. let stdout = "";
  15. let stderr = "";
  16. try {
  17. // 同一套真实 Electron / Agent / MCP 断言;正式集合不另写一份近似实现。
  18. // WDIO onPrepare 已构建并校验当前 Agent;重复构建会耗尽外层用例预算,遮住实际断言。
  19. ({ stdout, stderr } = await exec(
  20. process.execPath,
  21. [
  22. join(repo, "packages/desktop/scripts/mcp-apps-host-e2e.mjs"),
  23. "--session-ready-only",
  24. "--reuse-agent-build",
  25. "--output-dir",
  26. output,
  27. ],
  28. { cwd: repo, timeout: 100_000, maxBuffer: 8 * 1024 * 1024 },
  29. ));
  30. } catch (error) {
  31. const failure = error as Error & { stdout?: string; stderr?: string };
  32. stdout = failure.stdout ?? "";
  33. stderr = failure.stderr ?? "";
  34. throw error;
  35. } finally {
  36. await writeFile(join(output, "runner.log"), stdout + stderr);
  37. }
  38. // 构建成功或零收集都不能算回归通过,必须读取本例完成后的结果。
  39. const result = JSON.parse(await readFile(join(output, "session-ready-results.json"), "utf8"));
  40. assert.equal(result.caseId, "PLM-UI-SESSION-READY");
  41. assert.equal(result.checks.length, 1);
  42. assert.equal(
  43. result.checks[0].name,
  44. "cold session restore and App opening share readiness without reload",
  45. );
  46. });
  47. });