conversation-session-v4-queue.test.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // M4 门禁:queue 单项管理 + B09 撤回到 composer。
  2. // 证据层 L3:running turn 期间 sendText 入队 → QueuePanel → deleteQueueItem 权威移除 →
  3. // 发起端恢复 text + AttachmentRef[];重发产生新 queueItemId。非空草稿在 UI admission
  4. // 边界阻止命令,queue 与草稿都不变。
  5. import { clearAppData } from "../helpers/desktop-app.js";
  6. import { waitForToastContaining } from "../helpers/conversation-session-toast.js";
  7. import {
  8. clickV4Stop,
  9. clickV4QueueItemDelete,
  10. dragV4QueueItemOnto,
  11. clickV4QueueItemEdit,
  12. getV4ComposerAttachments,
  13. getV4ComposerText,
  14. getV4PaneSnapshot,
  15. getV4QueueItems,
  16. isV4ComposerFocused,
  17. prepareV4ConversationE2E,
  18. pasteV4ComposerImageAttachment,
  19. sendV4Prompt,
  20. setV4ComposerText,
  21. waitForV4Pane,
  22. waitForV4QueueCount,
  23. waitForV4TimelineContaining,
  24. } from "../helpers/v4-conversation.js";
  25. describe("v4 M4/B09 门禁:queue 单项管理与撤回编辑", () => {
  26. afterEach(async () => {
  27. const snapshot = await getV4PaneSnapshot();
  28. if (!snapshot.canStop) return;
  29. // 修复原因:controlled stream 会跨 case 存活 45 秒;不主动 stop 会让上一条
  30. // active runtime 与下一条 draft 并行,并在结尾 drain 残留 queue,污染模型/fixture。
  31. await clickV4Stop();
  32. await waitForV4Pane((next) => !next.canStop, "queue operation case 收尾 stop 没有完成", 30000);
  33. });
  34. after(async () => {
  35. await browser.electron.restoreAllMocks();
  36. await clearAppData();
  37. });
  38. it("running 中入队一条 → QueuePanel 显示 → 删除 → 队列清空", async () => {
  39. await prepareV4ConversationE2E();
  40. // 首轮:可控慢流,保持 running
  41. await sendV4Prompt("E2E_V4_QUEUE_SLOW 慢慢回答");
  42. await waitForV4TimelineContaining("V4_QUEUE_STREAMING", 45000);
  43. await waitForV4Pane(
  44. (s) => s.canStop && s.sessionId !== "draft" && s.sessionId !== null,
  45. "首轮没有进入 running(canStop)",
  46. 45000,
  47. );
  48. // running 中发第二条 → 入队
  49. await sendV4Prompt("E2E_V4_QUEUE_ITEM 排队的问题");
  50. await waitForV4QueueCount(1, 30000);
  51. const before = await getV4QueueItems();
  52. expect(before).toHaveLength(1);
  53. expect(before[0]!.text).toContain("E2E_V4_QUEUE_ITEM");
  54. // 删除该队列项 → 队列清空
  55. const clicked = await clickV4QueueItemDelete(before[0]!.queueItemId);
  56. expect(clicked).toBe(true);
  57. await waitForV4QueueCount(0, 30000);
  58. expect(await getV4QueueItems()).toHaveLength(0);
  59. });
  60. it("running 中带图片入队 → 撤回到 composer → 修改重发产生新 queueItemId", async () => {
  61. await prepareV4ConversationE2E();
  62. await sendV4Prompt("E2E_V4_QUEUE_SLOW 慢慢回答");
  63. await waitForV4TimelineContaining("V4_QUEUE_STREAMING", 45000);
  64. await waitForV4Pane(
  65. (s) => s.canStop && s.sessionId !== "draft" && s.sessionId !== null,
  66. "首轮没有进入 running(canStop)",
  67. 45000,
  68. );
  69. await pasteV4ComposerImageAttachment("e2e-queue-edit.png");
  70. await sendV4Prompt("E2E_V4_QUEUE_ITEM 排队原文");
  71. await waitForV4QueueCount(1, 30000);
  72. const before = await getV4QueueItems();
  73. expect(before[0]!.text).toContain("排队原文");
  74. const queueItemId = before[0]!.queueItemId;
  75. // 修复原因:ACK 回来前的双击若发出两个 delete,会重复恢复同一份附件草稿。
  76. // 同一事件循环连点两次,验证 renderer-local operation lock 在 React 重渲染前也生效。
  77. const clicked = await clickV4QueueItemEdit(queueItemId, 2);
  78. expect(clicked).toBe(true);
  79. await waitForV4QueueCount(0, 30000);
  80. await browser.waitUntil(
  81. async () => {
  82. const text = await getV4ComposerText();
  83. const attachments = await getV4ComposerAttachments();
  84. return (
  85. text === "E2E_V4_QUEUE_ITEM 排队原文" &&
  86. attachments.length === 1 &&
  87. // Bug 原因:从 queue 恢复的媒体 ref 不重建本地 object URL,缩略图可能只显示
  88. // image fallback icon;用 innerText 验证 filename 会误判已恢复且 ready 的附件。
  89. attachments[0]?.uploadStatus === "ready"
  90. );
  91. },
  92. { timeout: 30000, timeoutMsg: "队列项移除后没有完整恢复 composer 文本与附件" },
  93. );
  94. expect(await isV4ComposerFocused()).toBe(true);
  95. expect(await getV4ComposerAttachments()).toHaveLength(1);
  96. await sendV4Prompt("E2E_V4_QUEUE_ITEM 编辑后重新提交");
  97. await waitForV4QueueCount(1, 30000);
  98. const after = await getV4QueueItems();
  99. expect(after).toHaveLength(1);
  100. expect(after[0]?.queueItemId).not.toBe(queueItemId);
  101. expect(after[0]?.text).toContain("编辑后重新提交");
  102. });
  103. it("composer 已有草稿时编辑 queue 不撤回且提示先处理草稿", async () => {
  104. await prepareV4ConversationE2E();
  105. await sendV4Prompt("E2E_V4_QUEUE_SLOW 慢慢回答");
  106. await waitForV4TimelineContaining("V4_QUEUE_STREAMING", 45000);
  107. await waitForV4Pane(
  108. (s) => s.canStop && s.sessionId !== "draft" && s.sessionId !== null,
  109. "首轮没有进入 running(canStop)",
  110. 45000,
  111. );
  112. await sendV4Prompt("E2E_V4_QUEUE_ITEM 不应被撤回");
  113. await waitForV4QueueCount(1, 30000);
  114. const before = await getV4QueueItems();
  115. await setV4ComposerText("保留现有草稿");
  116. expect(await clickV4QueueItemEdit(before[0]!.queueItemId)).toBe(true);
  117. await waitForToastContaining(
  118. [
  119. "Send or clear the current draft before editing a queued message.",
  120. "请先发送或清空当前草稿,再编辑队列消息。",
  121. ],
  122. // Bug 根因:E2E 会继承 workspace locale,旧断言只接受英文,中文环境下把
  123. // 已正确出现的冲突提示误报为缺失。行为契约必须同时覆盖两种受支持语言。
  124. "非空草稿没有出现撤回阻止提示",
  125. );
  126. expect(await getV4ComposerText()).toBe("保留现有草稿");
  127. const after = await getV4QueueItems();
  128. expect(after).toHaveLength(1);
  129. expect(after[0]?.queueItemId).toBe(before[0]?.queueItemId);
  130. expect(after[0]?.text).toContain("不应被撤回");
  131. });
  132. it("running 中入队两条 → 拖拽第二条到第一条 → 顺序互换(reorderQueueItem)", async () => {
  133. await prepareV4ConversationE2E();
  134. await sendV4Prompt("E2E_V4_QUEUE_SLOW 慢慢回答");
  135. await waitForV4TimelineContaining("V4_QUEUE_STREAMING", 45000);
  136. await waitForV4Pane(
  137. (s) => s.canStop && s.sessionId !== "draft" && s.sessionId !== null,
  138. "首轮没有进入 running(canStop)",
  139. 45000,
  140. );
  141. // running 中依次入队两条
  142. await sendV4Prompt("E2E_V4_QUEUE_ITEM 第一条问题");
  143. await waitForV4QueueCount(1, 30000);
  144. await sendV4Prompt("E2E_V4_QUEUE_ITEM 第二条问题");
  145. await waitForV4QueueCount(2, 30000);
  146. const before = await getV4QueueItems();
  147. expect(before).toHaveLength(2);
  148. expect(before[0]!.text).toContain("第一条问题");
  149. expect(before[1]!.text).toContain("第二条问题");
  150. const secondId = before[1]!.queueItemId;
  151. // 拖拽只发 reorderQueueItem;顺序更新必须来自 CLI projection 回流。
  152. await dragV4QueueItemOnto(secondId, before[0]!.queueItemId);
  153. await browser.waitUntil(
  154. async () => {
  155. const items = await getV4QueueItems();
  156. return items.length === 2 && items[0]!.queueItemId === secondId;
  157. },
  158. { timeout: 30000, timeoutMsg: "第二条没有拖拽到队首" },
  159. );
  160. const after = await getV4QueueItems();
  161. expect(after).toHaveLength(2);
  162. expect(after[0]!.queueItemId).toBe(secondId);
  163. expect(after[0]!.text).toContain("第二条问题");
  164. expect(after[1]!.text).toContain("第一条问题");
  165. });
  166. });