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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { clearAppData } from "#e2e/helpers/desktop-app";
  2. import { waitForUpstreamNetworkCapture } from "#e2e/helpers/upstream-capture";
  3. import {
  4. E2E_REPLY_TOKEN,
  5. clickV4Stop,
  6. getV4QueueAutoDrain,
  7. getV4QueueItems,
  8. prepareV4ConversationE2E,
  9. sendV4Prompt,
  10. setV4ComposerText,
  11. waitForV4PausedQueueSendDialog,
  12. waitForV4ConversationState,
  13. waitForV4AssistantMessageContaining,
  14. waitForV4ComposerText,
  15. } from "#e2e/helpers/v4-conversation";
  16. import {
  17. clickFirstQueueSendNow,
  18. waitForQueueContaining,
  19. waitForQueueCount,
  20. } from "#e2e/helpers/conversation-session-queue";
  21. import {
  22. countUpstreamRequestsContaining,
  23. expectNoUpstreamRequestForTextWithin,
  24. } from "#e2e/helpers/conversation-session-network";
  25. describe("会话区 Stop 与 Held Queue E2E", () => {
  26. after(async () => {
  27. await browser.electron.restoreAllMocks();
  28. await clearAppData();
  29. });
  30. it("stop 后应保留 queue 且默认不自动消费,立即发送才触发下一轮", async function () {
  31. this.timeout(150000);
  32. await prepareV4ConversationE2E();
  33. const runId = Date.now();
  34. const firstPrompt = `E2E_SLOW_STREAM E2E_STOP_HELD_RUNNING_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  35. await sendV4Prompt(firstPrompt);
  36. await waitForV4ComposerText("", "首轮发送后输入框没有清空");
  37. await waitForV4ConversationState(
  38. (snapshot) => snapshot.state === "streaming",
  39. "首轮发送后 chat-view 没有进入 streaming",
  40. 30000,
  41. );
  42. // running 投影早于首个模型 delta;先等真实回答,避免把首发取消当作流中断。
  43. await waitForV4AssistantMessageContaining("deep");
  44. const queuedPrompt = `E2E_STOP_HELD_QUEUE_FIRST_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  45. await sendV4Prompt(queuedPrompt);
  46. await waitForQueueContaining(`E2E_STOP_HELD_QUEUE_FIRST_${runId}`);
  47. await waitForQueueCount(1);
  48. const secondQueuedPrompt = `E2E_STOP_HELD_QUEUE_SECOND_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  49. await sendV4Prompt(secondQueuedPrompt);
  50. await waitForQueueContaining(`E2E_STOP_HELD_QUEUE_SECOND_${runId}`);
  51. await waitForQueueCount(2);
  52. const thirdQueuedPrompt = `E2E_STOP_HELD_QUEUE_THIRD_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  53. await sendV4Prompt(thirdQueuedPrompt);
  54. await waitForQueueContaining(`E2E_STOP_HELD_QUEUE_THIRD_${runId}`);
  55. await waitForQueueCount(3);
  56. // V4 的 Stop 控件和队列/目标投影是当前状态来源;旧 runtimeStatus 已不再写入。
  57. await clickV4Stop();
  58. await waitForV4ConversationState(
  59. (snapshot) => snapshot.state !== "streaming" && snapshot.queueCount === 3,
  60. // 修复原因:stop ACK 早于 task terminal 投影时,后续队列断言会撞上
  61. // 仍在收尾的 runtime,误判成 held queue 被自动消费或丢失。
  62. "stop 后没有退出 streaming 并保留 3 条 queue",
  63. 30000,
  64. );
  65. await expectNoUpstreamRequestForTextWithin(`E2E_STOP_HELD_QUEUE_FIRST_${runId}`, 900);
  66. const appendedPrompt = `E2E_STOP_HELD_QUEUE_APPEND_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  67. const appendedRequestsBefore = await countUpstreamRequestsContaining(
  68. `E2E_STOP_HELD_QUEUE_APPEND_${runId}`,
  69. );
  70. await sendV4Prompt(appendedPrompt);
  71. // B06:暂停队列下普通发送先确认;取消必须保留草稿和原队列。
  72. await waitForV4PausedQueueSendDialog();
  73. await browser.keys("Escape");
  74. await waitForV4ComposerText(appendedPrompt, "取消确认后草稿丢失");
  75. await waitForQueueCount(3);
  76. await expectNoUpstreamRequestForTextWithin(`E2E_STOP_HELD_QUEUE_APPEND_${runId}`, 900);
  77. expect(await countUpstreamRequestsContaining(`E2E_STOP_HELD_QUEUE_APPEND_${runId}`)).toBe(
  78. appendedRequestsBefore,
  79. );
  80. await setV4ComposerText("");
  81. const sentNowItem = await clickFirstQueueSendNow();
  82. expect(sentNowItem.content).toContain(`E2E_STOP_HELD_QUEUE_FIRST_${runId}`);
  83. // 修复原因:仅观察请求出现和出队会把 fixture 缺失的 500 当成成功;
  84. // B08 必须证明显式发送成功收口,并且没有恢复其余暂停项的自动消费。
  85. const sentRequest = await waitForUpstreamNetworkCapture(`E2E_STOP_HELD_QUEUE_FIRST_${runId}`);
  86. expect(sentRequest.statusCode).toBe(200);
  87. await waitForV4AssistantMessageContaining(E2E_REPLY_TOKEN);
  88. await waitForV4ConversationState(
  89. (snapshot) => snapshot.state === "idle" && snapshot.queueCount === 2,
  90. "立即发送没有完成,或意外消费了其余暂停项",
  91. );
  92. expect(await getV4QueueAutoDrain()).toBe(false);
  93. const remainingItems = await getV4QueueItems();
  94. expect(remainingItems.map((item) => item.text)).toEqual([
  95. expect.stringContaining(`E2E_STOP_HELD_QUEUE_SECOND_${runId}`),
  96. expect.stringContaining(`E2E_STOP_HELD_QUEUE_THIRD_${runId}`),
  97. ]);
  98. expect(await countUpstreamRequestsContaining(`E2E_STOP_HELD_QUEUE_SECOND_${runId}`)).toBe(0);
  99. expect(await countUpstreamRequestsContaining(`E2E_STOP_HELD_QUEUE_THIRD_${runId}`)).toBe(0);
  100. });
  101. });