conversation-session-prewarming-queue.test.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { clearAppData } from "../../../helpers/desktop-app.js";
  2. import {
  3. E2E_REPLY_TOKEN,
  4. assertVisibleUserMessagesNotContaining,
  5. clickChatStop,
  6. expectNoUpstreamRequestForTextWithin,
  7. prepareConversationE2E,
  8. sendPrompt,
  9. waitForChatState,
  10. waitForComposerText,
  11. waitForUpstreamRequestContaining,
  12. waitForQueueContaining,
  13. waitForQueueCount,
  14. waitForUserMessageContaining,
  15. } from "../../../helpers/conversation-session.js";
  16. describe("会话区 Prewarming Queue E2E", () => {
  17. after(async () => {
  18. await browser.electron.restoreAllMocks();
  19. await clearAppData();
  20. });
  21. it("A02: prewarming 中继续发普通文本应进入 queue 且不打断首轮", async function () {
  22. this.timeout(90000);
  23. await prepareConversationE2E();
  24. const runId = Date.now();
  25. const firstMarker = `E2E_PREWARMING_FIRST_${runId}`;
  26. const queuedMarker = `E2E_PREWARMING_QUEUED_${runId}`;
  27. const firstPrompt =
  28. `E2E_PREWARMING_DELAY ${firstMarker}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  29. const queuedPrompt =
  30. `${queuedMarker}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  31. await sendPrompt(firstPrompt);
  32. await waitForComposerText("", "prewarming 首轮发送后输入框没有清空");
  33. await waitForUserMessageContaining(firstPrompt);
  34. await waitForUpstreamRequestContaining(firstMarker);
  35. const prewarmingSnapshot = await waitForChatState(
  36. (snapshot) =>
  37. Boolean(snapshot.sessionId || snapshot.taskId) &&
  38. snapshot.queueCount === 0 &&
  39. (snapshot.state === "submitting" || snapshot.state === "streaming"),
  40. "首轮发送后没有进入 prewarming/running 窗口",
  41. 10000,
  42. );
  43. expect(prewarmingSnapshot.queueCount).toBe(0);
  44. await sendPrompt(queuedPrompt);
  45. await waitForComposerText("", "prewarming 中第二条发送后输入框没有清空");
  46. await waitForQueueContaining(queuedMarker);
  47. const queue = await waitForQueueCount(1);
  48. expect(queue[0]?.kind).toBe("text");
  49. expect(queue[0]?.content).toContain(queuedMarker);
  50. await assertVisibleUserMessagesNotContaining(queuedPrompt);
  51. await expectNoUpstreamRequestForTextWithin(queuedMarker, 750);
  52. await clickChatStop();
  53. await waitForChatState(
  54. (snapshot) =>
  55. snapshot.state !== "submitting" &&
  56. snapshot.state !== "streaming" &&
  57. snapshot.queueCount === 1,
  58. "停止 prewarming 首轮后没有保留 queued prompt",
  59. 30000,
  60. );
  61. });
  62. });