conversation-session-preinstalled-tools-worker-start-failure.test.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { pinE2ELocale } from "#e2e/helpers/desktop-app";
  2. import { prepareV4ConversationE2E } from "#e2e/helpers/v4-conversation";
  3. const START_FAILURE_TEXT = "预装工具未能启动。请重启 ZCode 后再试";
  4. async function openDialog() {
  5. await $('[data-testid="workspace-help-menu-trigger"]').click();
  6. await $('[data-testid="workspace-help-menu-preinstalled-tools"]').click();
  7. await $('[data-testid="preinstalled-tools-dialog"]').waitForDisplayed();
  8. }
  9. async function expectStartFailure() {
  10. const alert = $('[data-testid="preinstalled-tools-load-failed"]');
  11. await alert.waitForDisplayed({
  12. timeout: 30000,
  13. timeoutMsg: "预装进程启动失败后,对话框仍停在读取状态",
  14. });
  15. expect(await alert.getText()).toContain(START_FAILURE_TEXT);
  16. const dialogText = await $('[data-testid="preinstalled-tools-dialog"]').getText();
  17. expect(dialogText).not.toContain("正在读取…");
  18. expect(await $$('[data-testid="preinstalled-tools-card"]').length).toBe(0);
  19. expect(await $('[data-testid="preinstalled-tools-auto-install"]').isEnabled()).toBe(false);
  20. }
  21. describe("预装进程初始化前退出(待审核)", () => {
  22. it("PT-30/31: 对话框结束读取并提示重启,Main 不重拉进程", async function () {
  23. this.timeout(120000);
  24. await prepareV4ConversationE2E();
  25. // 宿主可能使用英文,环境变量不能保证 macOS 界面语言;固定语言后再核对中文文案。
  26. await pinE2ELocale("zh-CN");
  27. const { exitBeforeInit } = await browser.electron.execute(() => ({
  28. exitBeforeInit: process.env.ZCODE_E2E_PREINSTALLED_TOOLS_EXIT_BEFORE_INIT ?? null,
  29. }));
  30. expect(exitBeforeInit).toBe("1");
  31. await openDialog();
  32. await expectStartFailure();
  33. // 查询只会在 Main 处理完子进程退出后才以错误结束;此时不应存在被重拉的预装进程。
  34. const workerPids = await browser.electron.execute((electron) =>
  35. electron.app
  36. .getAppMetrics()
  37. .filter((metric) => metric.name === "zcode-preinstalled-tools")
  38. .map((metric) => metric.pid),
  39. );
  40. expect(workerPids).toEqual([]);
  41. await browser.saveScreenshot(
  42. `${process.env.ZCODE_E2E_ARTIFACT_DIR}/lop-worker-start-failure.png`,
  43. );
  44. // 关闭再打开:新的读取同样以错误结束,不能退回持续加载。
  45. await browser.keys("Escape");
  46. await $('[data-testid="preinstalled-tools-dialog"]').waitForDisplayed({ reverse: true });
  47. await openDialog();
  48. await expectStartFailure();
  49. });
  50. });