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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { dismissOccupationOnboarding } from "../helpers/occupation-onboarding.js";
  2. import {
  3. prepareV4ConversationE2E,
  4. sendV4Prompt,
  5. switchV4Mode,
  6. waitForV4AssistantMessageContaining,
  7. waitForV4Pane,
  8. } from "../helpers/v4-conversation.js";
  9. import { waitForToolCallBlockByToolName } from "../helpers/conversation-session-tool.js";
  10. import { expandAssistantHistoriesWithContent } from "../helpers/conversation-session-tool-diagnostics.js";
  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. await $("[data-testid=conversation-share-confirm]").waitForClickable();
  41. await $("[data-testid=conversation-share-confirm]").click();
  42. await $("[data-testid=conversation-share-success-dock]").waitForDisplayed({ timeout: 90_000 });
  43. expect(await $("[data-testid=conversation-share-open-browser]").isEnabled()).toBe(true);
  44. await $("[data-testid=conversation-share-copy-link]").click();
  45. const link = await browser.execute(() => navigator.clipboard.readText());
  46. const url = new URL(link);
  47. const code = url.pathname.split("/").at(-1)!;
  48. const preview = (await fetch(`${url.origin}/api/v1/shares/${code}/preview`).then((response) =>
  49. response.json(),
  50. )) as { data: { rows: unknown[]; content_blocks?: Array<{ type: string }> } };
  51. expect(preview.data.rows.length).toBeGreaterThan(0);
  52. const fetchRow = preview.data.rows.find(
  53. (row) =>
  54. (row as { kind?: string; toolName?: string }).kind === "toolCall" &&
  55. (row as { toolName?: string }).toolName === "WebFetch",
  56. ) as { input?: { url?: string }; inputText: string };
  57. expect((fetchRow.input ?? JSON.parse(fetchRow.inputText)).url).toBe(
  58. "http://example.localhost/paper",
  59. );
  60. await browser.electron.execute((electron, shareCode) => {
  61. electron.app.emit(
  62. "open-url",
  63. { preventDefault() {} } as never,
  64. `zcode://share/import?code=${encodeURIComponent(shareCode)}`,
  65. );
  66. }, code);
  67. const imported = await $("[data-conversation-share-import-notice]");
  68. await imported.waitForDisplayed({ timeout: 90_000 });
  69. expect(await imported.getText()).toContain("http://example.localhost/paper");
  70. expect(await imported.getText()).toMatch(/Fetch|网页抓取/);
  71. });
  72. });