conversation-session-bot-channel-worker.test.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { createBotWorkerIntegration } from "#e2e/helpers/bot-worker-integration";
  2. import { startConversationModelProviderReplayServer } from "#e2e/helpers/model-provider-replay";
  3. import {
  4. createRecordingFeishuFetch,
  5. type RecordedRequest,
  6. } from "#e2e/bots/helpers/bots-service-harness";
  7. import { generateTraceId, type BotInboundMessage } from "@zcode/shared";
  8. // 默认工具注册与发送接线暂停;保留原用例及 fixture,待插件入口接入后恢复。
  9. describe.skip("BOT-E2E-MN-02/FN-01 actual channel reply tool chain", () => {
  10. it("sends a trusted mention then resolves a new typed name from desktop input", async function () {
  11. this.timeout(180000);
  12. const replay = await startConversationModelProviderReplayServer(
  13. "conversation-session-bot-channel-worker",
  14. );
  15. const requests: RecordedRequest[] = [];
  16. const originalFetch = globalThis.fetch;
  17. const record = createRecordingFeishuFetch(requests);
  18. globalThis.fetch = async (input, init) => {
  19. if (!String(input).startsWith("https://open.feishu.cn/"))
  20. throw new Error("Unexpected non-fixture request");
  21. if (String(input).includes("/members?"))
  22. return Response.json({
  23. code: 0,
  24. data: {
  25. items: [{ member_id: "ou_directory", name: "目录目标" }],
  26. has_more: false,
  27. },
  28. });
  29. if (String(input).includes("/im/v1/chats/"))
  30. return Response.json({ code: 0, data: { name: "Isolated group" } });
  31. return record(input, init);
  32. };
  33. let cleanup: Awaited<ReturnType<typeof createBotWorkerIntegration>> | undefined;
  34. const input: BotInboundMessage = {
  35. botId: "bot-worker",
  36. text: "E2E_BOT_CHANNEL_FIRST 请提醒 @目标",
  37. actor: {
  38. botId: "bot-worker",
  39. provider: "feishu",
  40. chatType: "group",
  41. chatId: "oc_worker",
  42. providerUserId: "ou_e2e_user",
  43. providerMessageId: "om_first",
  44. },
  45. contentParts: [
  46. { type: "text", text: "E2E_BOT_CHANNEL_FIRST 请提醒 " },
  47. {
  48. type: "channelMention",
  49. refId: "om_first:m1",
  50. name: "目标",
  51. targetId: "ou_target",
  52. channel: "feishu",
  53. idType: "open_id",
  54. entityType: "user",
  55. },
  56. ],
  57. };
  58. try {
  59. const host = (cleanup = await createBotWorkerIntegration(
  60. replay.baseUrl,
  61. "E2E_CHANNEL_DONE_first",
  62. ));
  63. await host.bot.service.handleInboundMessage({
  64. ...input,
  65. text: "/enable",
  66. contentParts: undefined,
  67. });
  68. await host.bot.service.handleInboundMessage(input);
  69. const key = JSON.stringify(["bot-worker", "oc_worker"]);
  70. let taskId = "";
  71. await browser.waitUntil(
  72. async () => {
  73. taskId = host.bot.readState().bots[key]?.activeTaskId ?? "";
  74. return !!taskId && host.reverseReplies.length === 1;
  75. },
  76. { timeout: 60000, timeoutMsg: "真实 ReplyToChannel 未到达 Host(权限/协议/执行失败)" },
  77. );
  78. await browser.waitUntil(
  79. async () =>
  80. (await host.agent.readSession({ workspacePath: host.workspacePath, sessionId: taskId }))
  81. .session.status === "idle",
  82. { timeout: 30000 },
  83. );
  84. expect(
  85. Object.values(host.bot.readState().bots[key]!.group!.deliveries!)
  86. .filter((d) => d.contentParts)
  87. .map((d) => d.status),
  88. ).toEqual(["sent"]);
  89. expect(host.droppedTextEvents.length).toBeGreaterThan(0);
  90. await browser.waitUntil(
  91. async () =>
  92. Object.values(host.bot.readState().bots[key]!.group!.deliveries!).some(
  93. (d) => d.text === "E2E_CHANNEL_DONE_first" && d.status === "sent",
  94. ),
  95. { timeout: 15000 },
  96. );
  97. expect(
  98. Object.values(host.bot.readState().bots[key]!.group!.deliveries!).filter(
  99. (d) => d.text === "E2E_CHANNEL_DONE_first",
  100. ),
  101. ).toHaveLength(1);
  102. await host.task.sendPrompt({
  103. taskId,
  104. content: "E2E_BOT_CHANNEL_FOLLOWUP 请 @ 目录目标",
  105. traceId: generateTraceId("e2e-followup"),
  106. modelSelection: host.modelSelection,
  107. });
  108. await browser.waitUntil(
  109. async () =>
  110. host.reverseReplies.length === 2 &&
  111. (await host.agent.readSession({ workspacePath: host.workspacePath, sessionId: taskId }))
  112. .session.status === "idle",
  113. { timeout: 60000 },
  114. );
  115. const deliveries = Object.values(host.bot.readState().bots[key]!.group!.deliveries!).filter(
  116. (d) => d.contentParts,
  117. );
  118. expect(deliveries).toHaveLength(2);
  119. expect(deliveries.map((d) => d.status)).toEqual(["sent", "sent"]);
  120. expect(
  121. deliveries.map((d) => d.contentParts?.find((p) => p.type === "channelMention")?.targetId),
  122. ).toEqual(["ou_target", "ou_directory"]);
  123. const nativePosts = requests.filter(
  124. (r) =>
  125. r.method === "POST" &&
  126. (r.body?.includes("<at id=ou_target>") || r.body?.includes("<at id=ou_directory>")),
  127. );
  128. expect(nativePosts).toHaveLength(2);
  129. expect(nativePosts.every((r) => r.url.endsWith("/om_first/reply"))).toBe(true);
  130. expect(host.permissionRequests).toHaveLength(0);
  131. // 当前产品仍回传模型总结,本 case 不偷偷改变已暂停的重复回执语义。
  132. expect(host.reverseReplies[1]).not.toHaveProperty("authorizationId");
  133. } finally {
  134. await cleanup?.dispose();
  135. globalThis.fetch = originalFetch;
  136. await replay.stop();
  137. }
  138. });
  139. });