e2eWindowsRuntimeHostPreflight.test.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { readFileSync } from "node:fs";
  2. import { describe, expect, it } from "vitest";
  3. // Bug 根因:Windows 上 Agent CLI 只能经过 zcode-runtime-host.exe 启动,而 E2E 只跑
  4. // build:no-runtime-assets,CI 上没有该 exe,全部 case 报 runtime host missing / slash 目录为空。
  5. describe("E2E Windows runtime host preflight", () => {
  6. it("prepareDesktopAppBuild 在复用或重建桌面产物前确保 runtime host 就绪", () => {
  7. const source = readFileSync(new URL("../wdio.conf.ts", import.meta.url), "utf8").replace(
  8. /\r\n/g,
  9. "\n",
  10. );
  11. const start = source.indexOf("\nfunction prepareDesktopAppBuild() {");
  12. const end = source.indexOf("\n}\n", start);
  13. expect(start).toBeGreaterThan(-1);
  14. const body = source.slice(start, end);
  15. const packagedIndex = body.indexOf("E2E_PACKAGED_APP_BINARY_PATH");
  16. const ensureIndex = body.indexOf("ensureWindowsRuntimeHost();");
  17. const skipBuildIndex = body.indexOf("shouldReuseDesktopE2EBuild(");
  18. expect(packagedIndex).toBeGreaterThan(-1);
  19. expect(ensureIndex).toBeGreaterThan(packagedIndex);
  20. expect(skipBuildIndex).toBeGreaterThan(ensureIndex);
  21. expect(source).toMatch(
  22. /function ensureWindowsRuntimeHost\(\) \{[\s\S]*?scripts\/build-windows-runtime-host\.mjs[\s\S]*?"--if-windows"[\s\S]*?"--ensure"/,
  23. );
  24. });
  25. it("预装入口 shim 也在复用构建前准备,构建失败不能进入 case", () => {
  26. const source = readFileSync(new URL("../wdio.conf.ts", import.meta.url), "utf8");
  27. const start = source.indexOf("\nfunction prepareDesktopAppBuild() {");
  28. const body = source.slice(start, source.indexOf("\n}\n", start));
  29. const ensureIndex = body.indexOf("ensureWindowsPreinstalledEntryShim();");
  30. expect(ensureIndex).toBeGreaterThan(body.indexOf("E2E_PACKAGED_APP_BINARY_PATH"));
  31. expect(body.indexOf("shouldReuseDesktopE2EBuild(")).toBeGreaterThan(ensureIndex);
  32. const helperStart = source.indexOf("function ensureWindowsPreinstalledEntryShim() {");
  33. const helper = source.slice(helperStart, source.indexOf("\n}\n", helperStart));
  34. expect(helper).toContain('"--ensure"');
  35. expect(helper).toContain('"--check"');
  36. expect(helper).toContain('"--stage-dir"');
  37. expect(helper).toContain("timeout:");
  38. expect(helper).toContain('killSignal: "SIGKILL"');
  39. expect(helper).toContain("E2E_RUN_CACHE_DIR");
  40. });
  41. it("Main 优先读取随运行目录隔离的 shim,而不是 cwd 的共享缓存", () => {
  42. const source = readFileSync(
  43. new URL("../src/main/desktopRuntimeEnv.ts", import.meta.url),
  44. "utf8",
  45. );
  46. const start = source.indexOf("export function resolvePreinstalledEntryShimPath()");
  47. const body = source.slice(
  48. source.indexOf("const candidates = [", start),
  49. source.indexOf("\n}\n", start),
  50. );
  51. expect(body.indexOf("process.resourcesPath")).toBeLessThan(body.indexOf("import.meta.dirname"));
  52. expect(body.indexOf("import.meta.dirname")).toBeLessThan(body.indexOf("process.cwd()"));
  53. });
  54. });