conversation-session-v4-stop-queue.test.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // catalog B02/B04(stopKeepsQueueAndDisablesAutoDrain)+ B06(暂停队列发送确认)
  2. // + B08(sendQueuedPromptNow)+ B14/B15(暂停队列继续)验收。
  3. // 证据层 L3:running 中入队 → stop → queue 原样保留并显示暂停提示;正常发送按钮
  4. // 打开 modal 后执行 keep/clear;idle 继续按 FIFO 到空;running 继续只武装、不抢占。
  5. // 语料来源:manual-review/pending 的 stop-held-queue(B02-B04)/ interrupted-actions 语义移植。
  6. import { clearAppData } from "#e2e/helpers/desktop-app";
  7. import {
  8. clickV4PausedQueueResume,
  9. clickV4QueueItemSendNow,
  10. clickV4Stop,
  11. getV4QueueItems,
  12. hasV4PausedQueueBanner,
  13. hasV4PausedQueueSendDialog,
  14. prepareV4ConversationE2E,
  15. sendV4PausedQueueClear,
  16. sendV4PausedQueueKeep,
  17. sendV4Prompt,
  18. waitForV4PausedQueueBanner,
  19. waitForV4Pane,
  20. waitForV4QueueCount,
  21. waitForV4TimelineContaining,
  22. } from "#e2e/helpers/v4-conversation";
  23. /** 建立「running 慢流 + 入队 N 条 → stop」的 held 前置状态。 */
  24. async function setupHeldQueue(queueTexts: string[]) {
  25. await prepareV4ConversationE2E();
  26. await sendV4Prompt("E2E_V4_HELD_SLOW 慢慢回答这个问题");
  27. await waitForV4TimelineContaining("V4_HELD_STREAMING", 45000);
  28. await waitForV4Pane(
  29. (s) => s.canStop && s.sessionId !== "draft" && s.sessionId !== null,
  30. "首轮没有进入 running(canStop)",
  31. 45000,
  32. );
  33. for (let i = 0; i < queueTexts.length; i++) {
  34. await sendV4Prompt(queueTexts[i]!);
  35. await waitForV4QueueCount(i + 1, 30000);
  36. }
  37. await clickV4Stop();
  38. await waitForV4Pane((s) => !s.canStop, "stop 后没有退出 running(canStop 仍在)", 30000);
  39. }
  40. describe("v4 catalog B 组:stop 后暂停队列、发送确认与继续消费", () => {
  41. after(async () => {
  42. await browser.electron.restoreAllMocks();
  43. await clearAppData();
  44. });
  45. it("B02/B04:stop 后 queue 原样保留、autoDrain=false,并显示暂停提示", async () => {
  46. await setupHeldQueue(["E2E_V4_HELD_Q1 排队的第一条", "E2E_V4_HELD_Q2 排队的第二条"]);
  47. // queue=2 原样保留(不被 stop 丢弃)
  48. const items = await getV4QueueItems();
  49. expect(items).toHaveLength(2);
  50. expect(items[0]!.text).toContain("E2E_V4_HELD_Q1");
  51. expect(items[1]!.text).toContain("E2E_V4_HELD_Q2");
  52. // 不自动消费:等 3s 后 queue 仍为 2,且 Q1 回复未出现
  53. await browser.pause(3000);
  54. const after = await getV4QueueItems();
  55. expect(after).toHaveLength(2);
  56. const snapshot = await waitForV4Pane(() => true, "读取快照失败", 5000);
  57. expect(snapshot.timelineText).not.toContain("V4_HELD_Q1_REPLY");
  58. await waitForV4PausedQueueBanner(15000);
  59. expect(await hasV4PausedQueueSendDialog()).toBe(false);
  60. });
  61. it("B06:正常发送按钮打开 modal;keep 保留队列发送,clear 清空队列发送", async () => {
  62. await setupHeldQueue(["E2E_V4_HELD_Q1 排队的第一条"]);
  63. await waitForV4PausedQueueBanner(15000);
  64. // keep:正常发送按钮先打开 modal;确认后新文本立即发送,queue 原样保留。
  65. await sendV4PausedQueueKeep("E2E_V4_HELD_KEEP 保留队列直接问");
  66. await waitForV4TimelineContaining("V4_HELD_KEEP_REPLY", 45000);
  67. await waitForV4Pane((s) => !s.canStop, "keep 发送后没有回到 idle", 30000);
  68. expect(await getV4QueueItems()).toHaveLength(1);
  69. // 回到 idle 后仍为暂停队列,提示条继续存在。
  70. await waitForV4PausedQueueBanner(15000);
  71. // clear:再次从正常发送按钮进入 modal,清空旧 queue 后发送新文本。
  72. await sendV4PausedQueueClear("E2E_V4_HELD_CLEAR 清空队列再问");
  73. await waitForV4TimelineContaining("V4_HELD_CLEAR_REPLY", 45000);
  74. await waitForV4QueueCount(0, 15000);
  75. await waitForV4Pane((s) => !s.canStop, "clear 发送后没有回到 idle", 30000);
  76. // queue 清空后暂停提示与确认 modal 都退出。
  77. await browser.waitUntil(
  78. async () => !(await hasV4PausedQueueBanner()) && !(await hasV4PausedQueueSendDialog()),
  79. { timeout: 15000, timeoutMsg: "queue 清空后暂停提示或确认 modal 仍然存在" },
  80. );
  81. // 被清空的 Q1 不应被消费
  82. const snapshot = await waitForV4Pane(() => true, "读取快照失败", 5000);
  83. expect(snapshot.timelineText).not.toContain("V4_HELD_Q1_REPLY");
  84. });
  85. it("B14:idle 暂停队列点继续后按 Q1/Q2 FIFO 自动消费到空", async () => {
  86. await setupHeldQueue(["E2E_V4_HELD_Q1 排队的第一条", "E2E_V4_HELD_Q2 排队的第二条"]);
  87. await waitForV4PausedQueueBanner(15000);
  88. await clickV4PausedQueueResume();
  89. await waitForV4TimelineContaining("V4_HELD_Q1_REPLY", 45000);
  90. await waitForV4TimelineContaining("V4_HELD_Q2_REPLY", 45000);
  91. await waitForV4QueueCount(0, 15000);
  92. await waitForV4Pane((s) => !s.canStop, "继续消费后没有回到 idle", 30000);
  93. const snapshot = await waitForV4Pane(() => true, "读取 FIFO 终态失败", 5000);
  94. expect(snapshot.timelineText.indexOf("V4_HELD_Q1_REPLY")).toBeGreaterThanOrEqual(0);
  95. expect(snapshot.timelineText.indexOf("V4_HELD_Q2_REPLY")).toBeGreaterThan(
  96. snapshot.timelineText.indexOf("V4_HELD_Q1_REPLY"),
  97. );
  98. expect(await hasV4PausedQueueBanner()).toBe(false);
  99. });
  100. it("B15:running 中点继续只武装,当前流收口后才消费暂停队首", async () => {
  101. await setupHeldQueue(["E2E_V4_HELD_Q1 排队的第一条"]);
  102. await sendV4PausedQueueKeep("E2E_V4_HELD_KEEP 保留队列并保持慢流");
  103. await waitForV4TimelineContaining("V4_HELD_KEEP_STREAMING", 30000);
  104. await waitForV4Pane((s) => s.canStop, "keep-and-send 没有进入 running", 15000);
  105. await clickV4PausedQueueResume();
  106. await browser.waitUntil(async () => !(await hasV4PausedQueueBanner()), {
  107. timeout: 15000,
  108. timeoutMsg: "点继续后暂停提示没有退出",
  109. });
  110. await browser.pause(500);
  111. expect(await getV4QueueItems()).toHaveLength(1);
  112. const armedSnapshot = await waitForV4Pane(
  113. (s) => s.canStop,
  114. "点继续后当前 running 被意外抢占",
  115. 5000,
  116. );
  117. expect(armedSnapshot.timelineText).not.toContain("V4_HELD_Q1_REPLY");
  118. await waitForV4TimelineContaining("V4_HELD_KEEP_REPLY", 45000);
  119. await waitForV4TimelineContaining("V4_HELD_Q1_REPLY", 45000);
  120. await waitForV4QueueCount(0, 15000);
  121. await waitForV4Pane((s) => !s.canStop, "armed drain 后没有回到 idle", 30000);
  122. const finalSnapshot = await waitForV4Pane(() => true, "读取 armed drain 终态失败", 5000);
  123. expect(finalSnapshot.timelineText.indexOf("V4_HELD_Q1_REPLY")).toBeGreaterThan(
  124. finalSnapshot.timelineText.indexOf("V4_HELD_KEEP_REPLY"),
  125. );
  126. });
  127. it("B08:held 队列项「立即发送」→ 该项出队并以新 turn 消费", async () => {
  128. await setupHeldQueue(["E2E_V4_HELD_Q1 排队的第一条"]);
  129. const items = await getV4QueueItems();
  130. expect(items).toHaveLength(1);
  131. const clicked = await clickV4QueueItemSendNow(items[0]!.queueItemId);
  132. expect(clicked).toBe(true);
  133. // 该项被消费:queue 清空 + 回复出现(不残留、不重复)
  134. await waitForV4TimelineContaining("V4_HELD_Q1_REPLY", 45000);
  135. await waitForV4QueueCount(0, 15000);
  136. await waitForV4Pane((s) => !s.canStop, "send-now 后没有回到 idle", 30000);
  137. expect(await getV4QueueItems()).toHaveLength(0);
  138. });
  139. });