conversation-session-share-tool-presentation.test.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { dismissOccupationOnboarding } from "#e2e/helpers/occupation-onboarding";
  2. import {
  3. prepareV4ConversationE2E,
  4. sendV4Prompt,
  5. switchV4Mode,
  6. waitForV4AssistantMessageContaining,
  7. waitForV4Pane,
  8. } from "#e2e/helpers/v4-conversation";
  9. import { waitForToolCallBlockByToolName } from "#e2e/helpers/conversation-session-tool";
  10. import { expandAssistantHistoriesWithContent } from "#e2e/helpers/conversation-session-tool-diagnostics";
  11. const MARKER = "E2E_SHARE_TOOL_PRESENTATION";
  12. describe("FETCH01 / SHARE-TOOLS01: shared readonly tool presentation", () => {
  13. it("keeps WebFetch separate from search and publishes tool content", async function () {
  14. this.timeout(240_000);
  15. await browser.waitUntil(
  16. async () =>
  17. (await $("[data-testid=onboarding-page]").isExisting()) ||
  18. (await $("[data-testid=task-settings-button]").isExisting()),
  19. { timeout: 30_000 },
  20. );
  21. if (await $("[data-testid=onboarding-page]").isExisting()) await dismissOccupationOnboarding();
  22. await prepareV4ConversationE2E();
  23. await switchV4Mode("yolo");
  24. await sendV4Prompt(
  25. `${MARKER}: Use WebFetch to read http://example.localhost/paper with an extraction prompt, then reply exactly SHARE_TOOLS_READY. Do not use WebSearch.`,
  26. );
  27. await waitForV4AssistantMessageContaining("SHARE_TOOLS_READY");
  28. await waitForV4Pane((snapshot) => !snapshot.canStop, "Fetch did not finish", 90_000);
  29. await expandAssistantHistoriesWithContent();
  30. const tool = await waitForToolCallBlockByToolName("WebFetch");
  31. expect(tool.text).toMatch(/Fetch|网页抓取/);
  32. expect(tool.text).toContain("http://example.localhost/paper");
  33. expect(tool.text).not.toContain("EXTRACTION_MUST_NOT_BE_VISIBLE");
  34. // 验证真实发布 UI 与本地 fake API;人工 review 前只保留 pending,不自行转正。
  35. await $("[data-testid=conversation-share-trigger]").click();
  36. // 分享设置已合为单个浮窗;范围默认已选,敏感信息确认仍必须由用户勾选。
  37. await $("[data-testid=conversation-share-popover]").waitForDisplayed();
  38. await $("[data-testid=conversation-share-disclosure-checkbox]").waitForClickable();
  39. await $("[data-testid=conversation-share-disclosure-checkbox]").click();
  40. // 修复原因:勾选确认后,waitForClickable 轮询的是勾选前取到的元素引用,5s 内一直判为
  41. // 不可点击;同一时刻重新查询到的按钮可见、可用且位于命中点顶层。每次轮询重新查询元素。
  42. await browser.waitUntil(() => $("[data-testid=conversation-share-confirm]").isClickable(), {
  43. timeout: 10_000,
  44. timeoutMsg: "分享确认按钮没有变为可点击",
  45. });
  46. await $("[data-testid=conversation-share-confirm]").click();
  47. await $("[data-testid=conversation-share-success-dock]").waitForDisplayed({ timeout: 90_000 });
  48. expect(await $("[data-testid=conversation-share-open-browser]").isEnabled()).toBe(true);
  49. await $("[data-testid=conversation-share-copy-link]").click();
  50. const link = await browser.execute(() => navigator.clipboard.readText());
  51. const url = new URL(link);
  52. const code = url.pathname.split("/").at(-1)!;
  53. const preview = (await fetch(`${url.origin}/api/v1/shares/${code}/preview`).then((response) =>
  54. response.json(),
  55. )) as { data: { rows: unknown[]; content_blocks?: Array<{ type: string }> } };
  56. expect(preview.data.rows.length).toBeGreaterThan(0);
  57. const fetchRow = preview.data.rows.find(
  58. (row) =>
  59. (row as { kind?: string; toolName?: string }).kind === "toolCall" &&
  60. (row as { toolName?: string }).toolName === "WebFetch",
  61. ) as { input?: { url?: string }; inputText: string };
  62. expect((fetchRow.input ?? JSON.parse(fetchRow.inputText)).url).toBe(
  63. "http://example.localhost/paper",
  64. );
  65. await browser.electron.execute((electron, shareCode) => {
  66. electron.app.emit(
  67. "open-url",
  68. { preventDefault() {} } as never,
  69. `zcode://share/import?code=${encodeURIComponent(shareCode)}`,
  70. );
  71. }, code);
  72. const imported = await $("[data-conversation-share-import-notice]");
  73. await imported.waitForDisplayed({ timeout: 90_000 });
  74. expect(await imported.getText()).toContain("http://example.localhost/paper");
  75. expect(await imported.getText()).toMatch(/Fetch|网页抓取/);
  76. });
  77. });