feishu-topic-runtime.test.ts 7.2 KB

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