conversation-session-stop-held-queue.test.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { clearAppData } from "../../../helpers/desktop-app.js";
  2. import { waitForUpstreamNetworkCapture } from "../../../helpers/upstream-capture.js";
  3. import {
  4. E2E_REPLY_TOKEN,
  5. clickChatStop,
  6. clickFirstQueueSendNow,
  7. countUpstreamRequestsContaining,
  8. expectNoUpstreamRequestForTextWithin,
  9. getChatRootSnapshot,
  10. prepareConversationE2E,
  11. sendPrompt,
  12. waitForChatState,
  13. waitForComposerText,
  14. waitForQueueContaining,
  15. waitForQueueCount,
  16. } from "../../../helpers/conversation-session.js";
  17. describe("会话区 Stop 与 Held Queue E2E", () => {
  18. after(async () => {
  19. await browser.electron.restoreAllMocks();
  20. await clearAppData();
  21. });
  22. it("stop 后应保留 queue 且默认不自动消费,立即发送才触发下一轮", async function () {
  23. this.timeout(150000);
  24. await prepareConversationE2E();
  25. const runId = Date.now();
  26. const firstPrompt =
  27. `E2E_SLOW_STREAM E2E_STOP_HELD_RUNNING_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  28. await sendPrompt(firstPrompt);
  29. await waitForComposerText("", "首轮发送后输入框没有清空");
  30. await waitForChatState(
  31. (snapshot) => snapshot.state === "streaming",
  32. "首轮发送后 chat-view 没有进入 streaming",
  33. 30000,
  34. );
  35. const queuedPrompt =
  36. `E2E_STOP_HELD_QUEUE_FIRST_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  37. await sendPrompt(queuedPrompt);
  38. await waitForQueueContaining(`E2E_STOP_HELD_QUEUE_FIRST_${runId}`);
  39. await waitForQueueCount(1);
  40. const secondQueuedPrompt =
  41. `E2E_STOP_HELD_QUEUE_SECOND_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  42. await sendPrompt(secondQueuedPrompt);
  43. await waitForQueueContaining(`E2E_STOP_HELD_QUEUE_SECOND_${runId}`);
  44. await waitForQueueCount(2);
  45. const thirdQueuedPrompt =
  46. `E2E_STOP_HELD_QUEUE_THIRD_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  47. await sendPrompt(thirdQueuedPrompt);
  48. await waitForQueueContaining(`E2E_STOP_HELD_QUEUE_THIRD_${runId}`);
  49. await waitForQueueCount(3);
  50. await clickChatStop();
  51. await waitForChatState(
  52. (snapshot) =>
  53. snapshot.state !== "streaming" &&
  54. snapshot.runtimeStatus === "completed" &&
  55. snapshot.activeInputId === null &&
  56. snapshot.queueCount === 3,
  57. // 修复原因:stop ACK 早于 task terminal 投影时,后续队列断言会撞上
  58. // 仍在收尾的 runtime,误判成 held queue 被自动消费或丢失。
  59. "stop 后没有退出 streaming 并保留 3 条 queue",
  60. 30000,
  61. );
  62. await expectNoUpstreamRequestForTextWithin(
  63. `E2E_STOP_HELD_QUEUE_FIRST_${runId}`,
  64. 900,
  65. );
  66. const appendedPrompt =
  67. `E2E_STOP_HELD_QUEUE_APPEND_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  68. const appendedRequestsBefore =
  69. await countUpstreamRequestsContaining(`E2E_STOP_HELD_QUEUE_APPEND_${runId}`);
  70. await sendPrompt(appendedPrompt);
  71. await waitForQueueContaining(`E2E_STOP_HELD_QUEUE_APPEND_${runId}`);
  72. await waitForQueueCount(4);
  73. await expectNoUpstreamRequestForTextWithin(
  74. `E2E_STOP_HELD_QUEUE_APPEND_${runId}`,
  75. 900,
  76. );
  77. expect(
  78. await countUpstreamRequestsContaining(`E2E_STOP_HELD_QUEUE_APPEND_${runId}`),
  79. ).toBe(appendedRequestsBefore);
  80. const sentNowItem = await clickFirstQueueSendNow();
  81. expect(sentNowItem.content).toContain(`E2E_STOP_HELD_QUEUE_FIRST_${runId}`);
  82. await waitForUpstreamNetworkCapture(`E2E_STOP_HELD_QUEUE_FIRST_${runId}`);
  83. const finalSnapshot = await getChatRootSnapshot();
  84. expect(finalSnapshot.queueCount).toBeLessThanOrEqual(3);
  85. });
  86. });