feishu-topic-runtime.test.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import type { IZCodeTaskService } from "@zcode/services";
  2. import { setRendererViewport, clearRendererViewport } from "#e2e/helpers/renderer-viewport";
  3. import { restartWithSeededOpenAIProviders } from "#e2e/helpers/custom-openai-provider";
  4. import {
  5. selectUpstreamProviderModelById,
  6. waitForUpstreamModelSelected,
  7. } from "#e2e/helpers/upstream-provider";
  8. import { startConversationModelProviderReplayServer } from "#e2e/helpers/model-provider-replay";
  9. import { clearAppData } from "#e2e/helpers/desktop-app";
  10. import { getTaskStoreSnapshot } from "#e2e/helpers/conversation-session-store";
  11. import {
  12. prepareV4ConversationE2E,
  13. sendV4PromptAndWaitAccepted,
  14. waitForV4TimelineContaining,
  15. waitForV4Pane,
  16. getV4PaneSnapshot,
  17. waitForV4QueueCount,
  18. clickV4Stop,
  19. } from "#e2e/helpers/v4-conversation";
  20. // 待用户手动执行。真实 Host/CLI 与 DOM,材料为合成输入;不代表原生飞书验收。
  21. describe("BOT-E2E-TP-01 topic start-now and original messages", () => {
  22. let replay: Awaited<ReturnType<typeof startConversationModelProviderReplayServer>>;
  23. before(async () => {
  24. replay = await startConversationModelProviderReplayServer("feishu-group-runtime");
  25. });
  26. after(async () => {
  27. if ((await getV4PaneSnapshot()).canStop) await clickV4Stop();
  28. await clearRendererViewport();
  29. await browser.electron.restoreAllMocks();
  30. await clearAppData();
  31. await replay?.stop();
  32. });
  33. it("starts the topic batch without queue and renders each original message", async () => {
  34. await prepareV4ConversationE2E({ skipProvider: true });
  35. const [provider] = await restartWithSeededOpenAIProviders([
  36. {
  37. modelId: "deepseek-v4-flash",
  38. providerId: "e2e-group-runtime",
  39. providerName: "Group Runtime E2E",
  40. },
  41. ]);
  42. if (!provider) throw new Error("Group runtime replay provider missing");
  43. await prepareV4ConversationE2E({ skipProvider: true });
  44. await selectUpstreamProviderModelById("deepseek-v4-flash", {
  45. includePlainModelFallback: false,
  46. providerId: provider.id,
  47. providerName: provider.name,
  48. });
  49. await waitForUpstreamModelSelected("deepseek-v4-flash", {
  50. includePlainModelFallback: false,
  51. providerId: provider.id,
  52. });
  53. // 冷启动接收曾耗时 36 秒;先等待真实 user row,避免把模型响应预算花在 Host 初始化上。
  54. await sendV4PromptAndWaitAccepted(
  55. "E2E_GROUP_RUNTIME_SLOW 慢慢回答",
  56. "E2E_GROUP_RUNTIME_SLOW",
  57. "initial desktop input was not accepted",
  58. 90000,
  59. );
  60. await waitForV4TimelineContaining("V4_QUEUE_STREAMING", 45000);
  61. await waitForV4Pane(
  62. (s) => s.canStop && !!s.sessionId && s.sessionId !== "draft",
  63. "initial turn is not running",
  64. 45000,
  65. );
  66. const pane = await getV4PaneSnapshot();
  67. const task = await getTaskStoreSnapshot(pane.sessionId!);
  68. const workspacePath = task.workspaceKey!;
  69. const botId = "feishu-runtime-e2e";
  70. const chatId = "oc_runtime_e2e";
  71. const threadId = "omt_runtime_e2e";
  72. // startNow 必须在权威停止之后提交;Bot 协调器的停止竞争由服务层测试覆盖。
  73. await clickV4Stop();
  74. await waitForV4Pane((state) => !state.canStop, "previous run did not stop", 30000);
  75. const ack = await browser.execute(
  76. async (params) => {
  77. const actions = (
  78. window as unknown as {
  79. __testActions: {
  80. submitBotGroupInput: NonNullable<IZCodeTaskService["submitBotGroupInput"]>;
  81. };
  82. }
  83. ).__testActions;
  84. return actions.submitBotGroupInput(params);
  85. },
  86. {
  87. workspacePath,
  88. taskId: pane.sessionId!,
  89. commandId: "e2e-topic-material-input",
  90. content: "E2E_GROUP_RUNTIME_SLOW E2E_TOPIC_MATERIALS",
  91. conversationQuotes: [{ text: "E2E_TOPIC_ROOT_ORIGINAL", senderName: "Root author" }],
  92. attachments: [
  93. {
  94. kind: "file",
  95. sourceKind: "topic-history",
  96. messageCount: 1,
  97. filename: "topic-history-e2e.txt",
  98. mimeType: "text/plain",
  99. sizeBytes: Buffer.byteLength(
  100. "Sender: E2E 群成员 | open_id: ou_member\nE2E_HISTORY_ORIGINAL\nOriginal second line",
  101. ),
  102. textContent:
  103. "Sender: E2E 群成员 | open_id: ou_member\nE2E_HISTORY_ORIGINAL\nOriginal second line",
  104. },
  105. ],
  106. source: {
  107. provider: "feishu",
  108. botId,
  109. chatId,
  110. threadId,
  111. senderId: "ou_member",
  112. senderName: "E2E 群成员",
  113. messageId: "om_material_second",
  114. messages: [
  115. {
  116. messageId: "om_material_first",
  117. senderId: "ou_first",
  118. senderName: "First author",
  119. text: "E2E_TOPIC_FIRST",
  120. attachmentIndexes: [],
  121. conversationQuotes: [{ text: "E2E_TOPIC_ROOT_ORIGINAL", senderName: "Root author" }],
  122. },
  123. {
  124. messageId: "om_material_second",
  125. senderId: "ou_member",
  126. senderName: "Second author",
  127. text: "E2E_TOPIC_SECOND",
  128. attachmentIndexes: [],
  129. },
  130. ],
  131. authorizationId: "e2e-authorization",
  132. },
  133. } satisfies Parameters<NonNullable<IZCodeTaskService["submitBotGroupInput"]>>[0],
  134. );
  135. expect(ack.result).toMatchObject({ type: "inputAccepted", delivery: "startNow" });
  136. await waitForV4QueueCount(0, 30000);
  137. const first = await $('[data-topic-message-id="om_material_first"]');
  138. const second = await $('[data-topic-message-id="om_material_second"]');
  139. await first.waitForDisplayed({ timeout: 30000 });
  140. await second.waitForDisplayed({ timeout: 30000 });
  141. expect(await first.getText()).toContain("E2E_TOPIC_FIRST");
  142. expect(await first.getText()).toContain("First author");
  143. expect(await second.getText()).toContain("E2E_TOPIC_SECOND");
  144. expect(await second.getText()).toContain("Second author");
  145. expect(await first.$("[data-v4-user-input-quotes]").isExisting()).toBe(true);
  146. expect(await second.$("[data-v4-user-input-quotes]").isExisting()).toBe(false);
  147. expect(await second.$("[data-v4-user-input-attachment-pill]").isExisting()).toBe(false);
  148. // 隔离应用继承系统语言;附件类型相同,aria-label 会按 locale 翻译。
  149. const historyFile = await $(
  150. '[data-v4-user-input-attachment-pill][aria-label="Open text attachment"], [data-v4-user-input-attachment-pill][aria-label="打开文本附件"]',
  151. );
  152. await historyFile.waitForDisplayed({ timeout: 30000 });
  153. expect(await historyFile.getText()).toMatch(/Topic history|话题历史/u);
  154. for (const width of [1280, 430]) {
  155. // 布局验证需要实际 renderer 高度;macOS 会把原生窗口限制在屏幕可用范围内。
  156. await setRendererViewport(width, 900);
  157. await historyFile.click();
  158. const preview = await $("[data-text-attachment-preview]");
  159. await preview.waitForDisplayed({ timeout: 15000 });
  160. expect(await preview.getText()).toContain("E2E_HISTORY_ORIGINAL");
  161. expect(await preview.getText()).toContain("ou_member");
  162. expect(await preview.getText()).toContain("Original second line");
  163. await browser.keys("Escape");
  164. await preview.waitForDisplayed({ reverse: true, timeout: 5000 });
  165. }
  166. await clearRendererViewport();
  167. await clickV4Stop();
  168. await waitForV4Pane((state) => !state.canStop, "topic task did not stop", 30000);
  169. });
  170. });