conversation-session-running-queue.test.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { clearAppData } from "#e2e/helpers/desktop-app";
  2. import {
  3. E2E_REPLY_TOKEN,
  4. assertVisibleV4UserMessagesNotContaining,
  5. prepareV4ConversationE2E,
  6. sendV4Prompt,
  7. setV4ComposerText,
  8. clickV4Send,
  9. clickV4Stop,
  10. waitForV4ConversationState,
  11. waitForV4ComposerText,
  12. waitForV4UserMessageContaining,
  13. } from "#e2e/helpers/v4-conversation";
  14. import {
  15. countUpstreamRequestsContaining,
  16. expectNoUpstreamRequestForTextWithin,
  17. } from "#e2e/helpers/conversation-session-network";
  18. import {
  19. getQueueItems,
  20. waitForQueueContaining,
  21. waitForQueueCount,
  22. } from "#e2e/helpers/conversation-session-queue";
  23. describe("会话区 Running Queue E2E", () => {
  24. after(async () => {
  25. await browser.electron.restoreAllMocks();
  26. await clearAppData();
  27. });
  28. it("running 中 text、compact、goal 按提交顺序入队,不启动并行请求", async function () {
  29. this.timeout(150000);
  30. await prepareV4ConversationE2E();
  31. const runId = Date.now();
  32. const firstPrompt = `E2E_SLOW_STREAM E2E_RUNNING_QUEUE_FIRST_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  33. await sendV4Prompt(firstPrompt);
  34. await waitForV4ComposerText("", "首轮发送后输入框没有清空");
  35. await waitForV4UserMessageContaining(firstPrompt);
  36. await waitForV4ConversationState(
  37. (snapshot) => snapshot.state === "streaming",
  38. "首轮发送后 chat-view 没有进入 streaming",
  39. 30000,
  40. );
  41. const secondPrompt = `E2E_RUNNING_QUEUE_SECOND_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  42. await sendV4Prompt(secondPrompt);
  43. await waitForV4ComposerText("", "running 中第二条发送后输入框没有清空");
  44. await waitForQueueContaining(`E2E_RUNNING_QUEUE_SECOND_${runId}`);
  45. let queue = await waitForQueueCount(1);
  46. expect(queue[0]?.kind).toBe("text");
  47. const thirdPrompt = `E2E_RUNNING_QUEUE_THIRD_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  48. await sendV4Prompt(thirdPrompt);
  49. await waitForQueueContaining(`E2E_RUNNING_QUEUE_THIRD_${runId}`);
  50. queue = await waitForQueueCount(2);
  51. expect(queue.map((item) => item.content).join("\n")).toContain(
  52. `E2E_RUNNING_QUEUE_SECOND_${runId}`,
  53. );
  54. expect(queue.map((item) => item.content).join("\n")).toContain(
  55. `E2E_RUNNING_QUEUE_THIRD_${runId}`,
  56. );
  57. const fourthPrompt = `E2E_RUNNING_QUEUE_FOURTH_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  58. await sendV4Prompt(fourthPrompt);
  59. await waitForQueueContaining(`E2E_RUNNING_QUEUE_FOURTH_${runId}`);
  60. queue = await waitForQueueCount(3);
  61. expect(queue.map((item) => item.content).join("\n")).toContain(
  62. `E2E_RUNNING_QUEUE_FOURTH_${runId}`,
  63. );
  64. expect(queue.map((item) => item.kind)).toEqual(["text", "text", "text"]);
  65. const fifthPrompt = `E2E_RUNNING_QUEUE_FIFTH_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  66. await sendV4Prompt(fifthPrompt);
  67. await waitForQueueContaining(`E2E_RUNNING_QUEUE_FIFTH_${runId}`);
  68. queue = await waitForQueueCount(4);
  69. expect(queue.map((item) => item.content).join("\n")).toContain(
  70. `E2E_RUNNING_QUEUE_FIFTH_${runId}`,
  71. );
  72. expect(queue.map((item) => item.kind)).toEqual(["text", "text", "text", "text"]);
  73. const compactRequestsBefore = await countUpstreamRequestsContaining(
  74. "CRITICAL: Respond with TEXT ONLY",
  75. );
  76. await setV4ComposerText("/compact");
  77. await clickV4Send();
  78. await expectNoUpstreamRequestForTextWithin("CRITICAL: Respond with TEXT ONLY", 500);
  79. expect(await countUpstreamRequestsContaining("CRITICAL: Respond with TEXT ONLY")).toBe(
  80. compactRequestsBefore,
  81. );
  82. // 原因:M04/M05 当前合同是 compact 维护项入 FIFO,旧用例仍要求拒绝。
  83. queue = await waitForQueueCount(5);
  84. expect(queue.map((item) => item.kind)).toEqual(["text", "text", "text", "text", "compact"]);
  85. await assertVisibleV4UserMessagesNotContaining("/compact");
  86. const goalPrompt = `/goal E2E_RUNNING_QUEUE_GOAL_${runId}`;
  87. await sendV4Prompt(goalPrompt);
  88. await browser.waitUntil(
  89. async () => {
  90. queue = await getQueueItems();
  91. const queueContent = queue.map((item) => item.content).join("\n");
  92. return (
  93. queueContent.includes(`E2E_RUNNING_QUEUE_SECOND_${runId}`) &&
  94. queueContent.includes(`E2E_RUNNING_QUEUE_THIRD_${runId}`) &&
  95. queueContent.includes(`E2E_RUNNING_QUEUE_FOURTH_${runId}`) &&
  96. queueContent.includes(`E2E_RUNNING_QUEUE_FIFTH_${runId}`) &&
  97. queueContent.includes(`E2E_RUNNING_QUEUE_GOAL_${runId}`)
  98. );
  99. },
  100. {
  101. timeout: 30000,
  102. timeoutMsg: "队列没有同时保留 running 中发送的普通消息和 /goal",
  103. },
  104. );
  105. const goalItem = queue.find((item) => item.content.includes(`E2E_RUNNING_QUEUE_GOAL_${runId}`));
  106. expect(goalItem?.kind).toBe("goal");
  107. expect(queue.map((item) => item.kind)).toEqual([
  108. "text",
  109. "text",
  110. "text",
  111. "text",
  112. "compact",
  113. "goal",
  114. ]);
  115. await browser.waitUntil(
  116. async () => (await countUpstreamRequestsContaining(`E2E_RUNNING_QUEUE_FIRST_${runId}`)) >= 1,
  117. {
  118. timeout: 10000,
  119. timeoutMsg: "没有捕获到首轮 running 请求",
  120. },
  121. );
  122. await clickV4Stop();
  123. await waitForQueueCount(6);
  124. });
  125. });