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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { clearAppData } from "../../../helpers/desktop-app.js";
  2. import {
  3. E2E_REPLY_TOKEN,
  4. assertVisibleUserMessagesNotContaining,
  5. countUpstreamRequestsContaining,
  6. expectNoUpstreamRequestForTextWithin,
  7. getQueueItems,
  8. prepareConversationE2E,
  9. sendPrompt,
  10. typeChatPrompt,
  11. clickChatSend,
  12. clickChatStop,
  13. waitForChatState,
  14. waitForComposerText,
  15. waitForQueueContaining,
  16. waitForQueueCount,
  17. waitForUserMessageContaining,
  18. } from "../../../helpers/conversation-session.js";
  19. describe("会话区 Running Queue E2E", () => {
  20. after(async () => {
  21. await browser.electron.restoreAllMocks();
  22. await clearAppData();
  23. });
  24. it("running 中普通输入和 /goal 应入队,/compact 应被拒绝且没有副作用", async function () {
  25. this.timeout(150000);
  26. await prepareConversationE2E();
  27. const runId = Date.now();
  28. const firstPrompt =
  29. `E2E_SLOW_STREAM E2E_RUNNING_QUEUE_FIRST_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  30. await sendPrompt(firstPrompt);
  31. await waitForComposerText("", "首轮发送后输入框没有清空");
  32. await waitForUserMessageContaining(firstPrompt);
  33. await waitForChatState(
  34. (snapshot) => snapshot.state === "streaming",
  35. "首轮发送后 chat-view 没有进入 streaming",
  36. 30000,
  37. );
  38. const secondPrompt =
  39. `E2E_RUNNING_QUEUE_SECOND_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  40. await sendPrompt(secondPrompt);
  41. await waitForComposerText("", "running 中第二条发送后输入框没有清空");
  42. await waitForQueueContaining(`E2E_RUNNING_QUEUE_SECOND_${runId}`);
  43. let queue = await waitForQueueCount(1);
  44. expect(queue[0]?.kind).toBe("text");
  45. const thirdPrompt =
  46. `E2E_RUNNING_QUEUE_THIRD_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  47. await sendPrompt(thirdPrompt);
  48. await waitForQueueContaining(`E2E_RUNNING_QUEUE_THIRD_${runId}`);
  49. queue = await waitForQueueCount(2);
  50. expect(queue.map((item) => item.content).join("\n")).toContain(
  51. `E2E_RUNNING_QUEUE_SECOND_${runId}`,
  52. );
  53. expect(queue.map((item) => item.content).join("\n")).toContain(
  54. `E2E_RUNNING_QUEUE_THIRD_${runId}`,
  55. );
  56. const fourthPrompt =
  57. `E2E_RUNNING_QUEUE_FOURTH_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  58. await sendPrompt(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 =
  66. `E2E_RUNNING_QUEUE_FIFTH_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  67. await sendPrompt(fifthPrompt);
  68. await waitForQueueContaining(`E2E_RUNNING_QUEUE_FIFTH_${runId}`);
  69. queue = await waitForQueueCount(4);
  70. expect(queue.map((item) => item.content).join("\n")).toContain(
  71. `E2E_RUNNING_QUEUE_FIFTH_${runId}`,
  72. );
  73. expect(queue.map((item) => item.kind)).toEqual(["text", "text", "text", "text"]);
  74. const compactRequestsBefore = await countUpstreamRequestsContaining(
  75. "CRITICAL: Respond with TEXT ONLY",
  76. );
  77. await typeChatPrompt("/compact");
  78. await clickChatSend();
  79. await expectNoUpstreamRequestForTextWithin(
  80. "CRITICAL: Respond with TEXT ONLY",
  81. 500,
  82. );
  83. expect(
  84. await countUpstreamRequestsContaining("CRITICAL: Respond with TEXT ONLY"),
  85. ).toBe(compactRequestsBefore);
  86. expect(await getQueueItems()).toHaveLength(4);
  87. await assertVisibleUserMessagesNotContaining("/compact");
  88. const goalPrompt = `/goal E2E_RUNNING_QUEUE_GOAL_${runId}`;
  89. await sendPrompt(goalPrompt);
  90. await browser.waitUntil(
  91. async () => {
  92. queue = await getQueueItems();
  93. const queueContent = queue.map((item) => item.content).join("\n");
  94. return (
  95. queueContent.includes(`E2E_RUNNING_QUEUE_SECOND_${runId}`) &&
  96. queueContent.includes(`E2E_RUNNING_QUEUE_THIRD_${runId}`) &&
  97. queueContent.includes(`E2E_RUNNING_QUEUE_FOURTH_${runId}`) &&
  98. queueContent.includes(`E2E_RUNNING_QUEUE_FIFTH_${runId}`) &&
  99. queueContent.includes(`E2E_RUNNING_QUEUE_GOAL_${runId}`)
  100. );
  101. },
  102. {
  103. timeout: 30000,
  104. timeoutMsg: "队列没有同时保留 running 中发送的普通消息和 /goal",
  105. },
  106. );
  107. const goalItem = queue.find((item) =>
  108. item.content.includes(`E2E_RUNNING_QUEUE_GOAL_${runId}`),
  109. );
  110. expect(goalItem?.kind).toBe("goal");
  111. await browser.waitUntil(
  112. async () =>
  113. (await countUpstreamRequestsContaining(
  114. `E2E_RUNNING_QUEUE_FIRST_${runId}`,
  115. )) >= 1,
  116. {
  117. timeout: 10000,
  118. timeoutMsg: "没有捕获到首轮 running 请求",
  119. },
  120. );
  121. await clickChatStop();
  122. });
  123. });