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

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