conversation-session-preinstalled-tools-startup.test.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
  2. import { join } from "node:path";
  3. import { getLatestUpstreamToolResultByToolCallId } from "#e2e/helpers/conversation-session-network";
  4. import { resolveE2EStorageRoot } from "#e2e/helpers/e2e-runtime-paths";
  5. import { reloadElectronSessionPreservingBrowserProfile } from "#e2e/helpers/e2e-electron-reload";
  6. import {
  7. getV4PaneSnapshot,
  8. prepareV4ConversationE2E,
  9. sendV4Prompt,
  10. switchV4Mode,
  11. waitForV4AssistantMessageContaining,
  12. } from "#e2e/helpers/v4-conversation";
  13. async function openDialog() {
  14. await $('[data-testid="workspace-help-menu-trigger"]').click();
  15. await $('[data-testid="workspace-help-menu-preinstalled-tools"]').click();
  16. await $('[data-testid="preinstalled-tools-dialog"]').waitForDisplayed();
  17. }
  18. async function waitStatus(status: string) {
  19. await browser.waitUntil(
  20. async () =>
  21. (await $(
  22. '[data-tool-id="libreoffice"] [data-testid="preinstalled-tools-status"]',
  23. ).getAttribute("data-status")) === status,
  24. { timeout: 30000 },
  25. );
  26. }
  27. const fixtureUrl = () => process.env.ZCODE_E2E_PREINSTALL_FIXTURE_URL!;
  28. describe("预装初始化失败恢复(待审核)", () => {
  29. it("LOP-STARTUP: 目录故障不阻塞聊天,手动修复后原会话继续", async function () {
  30. this.timeout(240000);
  31. await prepareV4ConversationE2E();
  32. const roots = join(resolveE2EStorageRoot(), "preinstalled-tools");
  33. const root = join(roots, (await readdir(roots))[0]!);
  34. const legacy = join(root, "installation.json");
  35. const oldRecord = join(
  36. root,
  37. "records",
  38. "old-resource",
  39. "25.0.0-darwin-arm64",
  40. "installation.json",
  41. );
  42. await reloadElectronSessionPreservingBrowserProfile(browser, {
  43. afterElectronProcessExit: async () => {
  44. await rm(join(root, "tools", "libreoffice", "staging"), { recursive: true, force: true });
  45. await writeFile(join(root, "tools", "libreoffice", "staging"), "filesystem-conflict");
  46. await mkdir(join(root, "records", "old-resource", "25.0.0-darwin-arm64"), {
  47. recursive: true,
  48. });
  49. await writeFile(oldRecord, "readable-old-target");
  50. await writeFile(legacy, "readable-legacy-target");
  51. },
  52. });
  53. await prepareV4ConversationE2E();
  54. await switchV4Mode("yolo");
  55. await openDialog();
  56. await waitStatus("failed");
  57. const pid = await browser.electron.execute(
  58. (electron) =>
  59. electron.app.getAppMetrics().find((metric) => metric.name === "zcode-preinstalled-tools")
  60. ?.pid,
  61. );
  62. expect(pid).toBeDefined();
  63. await browser.saveScreenshot(`${process.env.ZCODE_E2E_ARTIFACT_DIR}/lop-startup-failed.png`);
  64. await browser.keys("Escape");
  65. await sendV4Prompt("E2E_LOP_STARTUP_BEFORE: Read the preinstalled tools environment.");
  66. await waitForV4AssistantMessageContaining("E2E_LOP_STARTUP_BEFORE_DONE", 90000);
  67. const firstResult = await getLatestUpstreamToolResultByToolCallId("toolu_lop_startup_before");
  68. const first = JSON.parse(firstResult!.content) as {
  69. entryPath: string;
  70. exists: boolean;
  71. available: string;
  72. };
  73. expect(first.exists).toBe(false);
  74. expect(first.entryPath).toContain(join("bin", "zcode-soffice"));
  75. expect(await readFile(oldRecord, "utf8")).toBe("readable-old-target");
  76. expect(await readFile(legacy, "utf8")).toBe("readable-legacy-target");
  77. const sessionId = (await getV4PaneSnapshot()).sessionId;
  78. await rm(join(root, "tools", "libreoffice", "staging"));
  79. await openDialog();
  80. await $('[data-testid="preinstalled-tools-retry"]').click();
  81. await fetch(`${fixtureUrl()}/release`);
  82. await fetch(`${fixtureUrl()}/finish-check`);
  83. await waitStatus("ready");
  84. expect(
  85. await browser.electron.execute(
  86. (electron) =>
  87. electron.app.getAppMetrics().find((metric) => metric.name === "zcode-preinstalled-tools")
  88. ?.pid,
  89. ),
  90. ).toBe(pid);
  91. await browser.saveScreenshot(`${process.env.ZCODE_E2E_ARTIFACT_DIR}/lop-startup-ready.png`);
  92. await browser.keys("Escape");
  93. await sendV4Prompt("E2E_LOP_STARTUP_CONTINUE: Read the fixed tool entry after preparation.");
  94. await waitForV4AssistantMessageContaining("E2E_LOP_STARTUP_CONTINUE_DONE", 90000);
  95. expect((await getV4PaneSnapshot()).sessionId).toBe(sessionId);
  96. const result = await getLatestUpstreamToolResultByToolCallId("toolu_lop_startup_continue");
  97. const continued = JSON.parse(result!.content) as {
  98. entryPath: string;
  99. content: string;
  100. exists: boolean;
  101. available: string;
  102. };
  103. expect(continued.entryPath).toBe(first.entryPath);
  104. expect(continued.exists).toBe(true);
  105. expect(continued.available).toBe("1");
  106. expect(continued.content).toContain(
  107. `fixture-libreoffice-26.8.1-${process.platform}-${process.arch}`,
  108. );
  109. await browser.saveScreenshot(`${process.env.ZCODE_E2E_ARTIFACT_DIR}/lop-startup-continued.png`);
  110. });
  111. });