conversation-session-queue-edit-freeze.test.ts 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // B09h/B09i/B09k/B09o/B09p 排队消息冻结编辑(docs/ui/composer-edit-mode.md)。
  2. // 证据层 L3:
  3. // 1) 编辑期间该项在 CLI 冻结(queueItem.editLock 进入投影);自动续跑到冻结项暂停,后面的项等待;
  4. // 2) 冻结项不能删除、立即发送,其他项不受影响;
  5. // 3) 工具栏载入队列项配置,修改后随 editQueueItem 原地写回,消费时按新配置执行;提交后工具栏保留新模型;
  6. // 其他排队项配置不同时提示是否一并应用,选应用后它们也按新配置消费;
  7. // 4) 发起端刷新后发现自己的锁但本地无编辑态,立即释放,不使用超时。
  8. import { DEFAULT_WORKSPACE, clearAppData, waitForWorkspaceApp } from "#e2e/helpers/desktop-app";
  9. import { releaseControlledReplay } from "#e2e/helpers/controlled-replay";
  10. import {
  11. expectNoUpstreamRequestForTextWithin,
  12. getUpstreamRequestEvidence,
  13. waitForUpstreamRequest,
  14. } from "#e2e/helpers/conversation-session-network";
  15. import {
  16. ensureUpstreamModelForE2E,
  17. selectUpstreamModelById,
  18. UPSTREAM_PROVIDER_ID,
  19. UPSTREAM_SECONDARY_MODEL,
  20. } from "#e2e/helpers/upstream-provider";
  21. import {
  22. confirmV4ComposerEditApplyQueue,
  23. getV4ComposerEditState,
  24. getV4QueueItemEditLock,
  25. openV4QueueItemEditInComposer,
  26. waitForV4ComposerEditApplyQueueDialog,
  27. waitForV4ComposerEditClosed,
  28. waitForV4QueueItemEditLock,
  29. } from "#e2e/helpers/v4-composer-edit";
  30. import {
  31. clickV4QueueItemDelete,
  32. clickV4QueueItemSendNow,
  33. clickV4Send,
  34. clickV4Stop,
  35. getV4ComposerText,
  36. getV4ModelConfig,
  37. getV4PaneSnapshot,
  38. getV4QueueItems,
  39. prepareV4ConversationE2E,
  40. selectV4TaskById,
  41. sendV4Prompt,
  42. setV4ComposerText,
  43. startNewV4Draft,
  44. waitForV4ComposerText,
  45. waitForV4Pane,
  46. waitForV4QueueCount,
  47. waitForV4TimelineContaining,
  48. } from "#e2e/helpers/v4-conversation";
  49. const DRAFT_TEXT = "E2E_QEF_DRAFT 保留的原草稿";
  50. describe("B09 排队消息冻结编辑", () => {
  51. afterEach(async () => {
  52. const pane = await getV4PaneSnapshot();
  53. if (!pane.canStop) return;
  54. await clickV4Stop();
  55. await waitForV4Pane((next) => !next.canStop, "冻结编辑 case 收尾 stop 没有完成", 30000);
  56. });
  57. after(async () => {
  58. await browser.electron.restoreAllMocks();
  59. await clearAppData();
  60. });
  61. it("B09h/B09i/B09o/B09p:续跑在冻结项前暂停 → 冻结项操作被禁用 → 改配置提交后按新配置原地消费 → 应用到后面的排队项", async () => {
  62. await prepareV4ConversationE2E();
  63. await ensureUpstreamModelForE2E(UPSTREAM_SECONDARY_MODEL);
  64. await startNewV4Draft();
  65. await sendV4Prompt("E2E_QEF_SLOW_G 慢慢回答");
  66. await waitForV4TimelineContaining("QEF_G_STREAMING", 45000);
  67. await waitForV4Pane((s) => s.canStop, "B09h 首轮没有进入 running", 45000);
  68. await sendV4Prompt("E2E_QEF_A 第一条");
  69. await waitForV4QueueCount(1, 30000);
  70. await sendV4Prompt("E2E_QEF_C 冻结的一条");
  71. await waitForV4QueueCount(2, 30000);
  72. await sendV4Prompt("E2E_QEF_D 冻结项之后的一条");
  73. await waitForV4QueueCount(3, 30000);
  74. const [itemA, itemC, itemD] = await getV4QueueItems();
  75. if (!itemA || !itemC || !itemD) throw new Error("B09h 队列项不完整");
  76. // 新草稿的模型在首发后才完成初始化;入队时记录的是此刻工具栏的默认模型。
  77. const configBefore = await getV4ModelConfig();
  78. expect(configBefore.model).not.toBe(UPSTREAM_SECONDARY_MODEL);
  79. await setV4ComposerText(DRAFT_TEXT);
  80. await openV4QueueItemEditInComposer(itemC.queueItemId);
  81. await waitForV4ComposerText("E2E_QEF_C 冻结的一条", "编辑态没有载入冻结项原文");
  82. // B09o:工具栏载入队列项记录的配置(入队时为默认模型)。
  83. expect((await getV4ModelConfig()).model).toBe(configBefore.model);
  84. // B09i:冻结项的编辑、删除、立即发送都不可用;其他项不受影响。
  85. const locked = await waitForV4QueueItemEditLock(
  86. itemC.queueItemId,
  87. (state) => state.locked && state.owner === "self",
  88. "冻结项没有显示本端编辑锁",
  89. );
  90. expect(locked).toMatchObject({ editAction: false, deleteAction: false, sendNowAction: false });
  91. // 即使入口仍渲染为 disabled,点击也不能删除或提升冻结项。
  92. await clickV4QueueItemDelete(itemC.queueItemId);
  93. await clickV4QueueItemSendNow(itemC.queueItemId);
  94. expect((await getV4QueueItems()).map((item) => item.queueItemId)).toEqual([
  95. itemA.queueItemId,
  96. itemC.queueItemId,
  97. itemD.queueItemId,
  98. ]);
  99. const other = await getV4QueueItemEditLock(itemD.queueItemId);
  100. expect(other).toMatchObject({ locked: false, deleteAction: true, sendNowAction: true });
  101. // B09h:A 正常消费;到冻结项 C 时暂停,D 保持等待。
  102. await releaseControlledReplay("qef-slow-g");
  103. await waitForV4TimelineContaining("QEF_A_REPLY", 45000);
  104. await waitForV4Pane((s) => !s.canStop, "A 消费后没有停在冻结项前", 45000);
  105. await expectNoUpstreamRequestForTextWithin("E2E_QEF_D", 1500);
  106. expect((await getV4QueueItems()).map((item) => item.queueItemId)).toEqual([
  107. itemC.queueItemId,
  108. itemD.queueItemId,
  109. ]);
  110. expect(await getV4ComposerEditState()).toMatchObject({ kind: "queueItem", state: "editing" });
  111. // B09o:修改模型与正文后提交,editQueueItem 原地写回,解锁后 C 按新配置消费,随后 D。
  112. await selectUpstreamModelById(UPSTREAM_SECONDARY_MODEL, {
  113. includePlainModelFallback: false,
  114. providerId: UPSTREAM_PROVIDER_ID,
  115. });
  116. await setV4ComposerText("E2E_QEF_C_EDITED 改过的冻结项");
  117. await clickV4Send();
  118. await waitForV4ComposerEditClosed("editQueueItem 成功后没有退出编辑态", 30000);
  119. await waitForV4ComposerText(DRAFT_TEXT, "editQueueItem 成功后没有恢复原草稿", 15000);
  120. // B09o:正文恢复原草稿,工具栏保留提交的新模型,下一条消息不悄悄回到旧模型。
  121. expect((await getV4ModelConfig()).model).toBe(UPSTREAM_SECONDARY_MODEL);
  122. // B09p:D 仍按旧模型排队 → 发起端提示是否一并应用;文案写出新模型,不写条数。
  123. const applyDialogText = await waitForV4ComposerEditApplyQueueDialog();
  124. expect(applyDialogText).toContain(UPSTREAM_SECONDARY_MODEL);
  125. expect(applyDialogText).not.toMatch(/\d+\s*条/u);
  126. await confirmV4ComposerEditApplyQueue();
  127. await waitForUpstreamRequest(
  128. { lastUserMessageIncludes: ["E2E_QEF_C_EDITED"] },
  129. "解锁后冻结项没有按新内容消费",
  130. 45000,
  131. );
  132. const [consumedC] = await getUpstreamRequestEvidence({
  133. lastUserMessageIncludes: ["E2E_QEF_C_EDITED"],
  134. });
  135. expect(consumedC?.requestJson).toMatchObject({ model: UPSTREAM_SECONDARY_MODEL });
  136. // C 是慢流:确认应用时 D 仍在排队;释放后 D 按应用的新模型消费。
  137. await releaseControlledReplay("qef-c");
  138. await waitForV4TimelineContaining("QEF_C_REPLY", 45000);
  139. await waitForUpstreamRequest(
  140. { lastUserMessageIncludes: ["E2E_QEF_D"] },
  141. "应用到排队消息后 D 没有被消费",
  142. 45000,
  143. );
  144. const [consumedD] = await getUpstreamRequestEvidence({
  145. lastUserMessageIncludes: ["E2E_QEF_D"],
  146. });
  147. expect(consumedD?.requestJson).toMatchObject({ model: UPSTREAM_SECONDARY_MODEL });
  148. await waitForV4TimelineContaining("QEF_D_REPLY", 45000);
  149. const finalSnapshot = await waitForV4Pane(
  150. (s) => !s.canStop && s.timelineText.includes("QEF_D_REPLY"),
  151. "解锁后队列没有按顺序消费完",
  152. 45000,
  153. );
  154. expect(finalSnapshot.timelineText).not.toContain("E2E_QEF_C 冻结的一条");
  155. expect(finalSnapshot.timelineText.indexOf("QEF_C_REPLY")).toBeLessThan(
  156. finalSnapshot.timelineText.indexOf("QEF_D_REPLY"),
  157. );
  158. expect(await getV4QueueItems()).toHaveLength(0);
  159. });
  160. it("B09k:发起端刷新后自动释放自己的锁,composer 只恢复原草稿,队列继续消费", async () => {
  161. await prepareV4ConversationE2E();
  162. await startNewV4Draft();
  163. await sendV4Prompt("E2E_QEF_SLOW_J 慢慢回答");
  164. await waitForV4TimelineContaining("QEF_J_STREAMING", 45000);
  165. const running = await waitForV4Pane(
  166. (s) => s.canStop && s.sessionId !== null && s.sessionId !== "draft",
  167. "B09k 首轮没有进入 running",
  168. 45000,
  169. );
  170. const sessionId = running.sessionId!;
  171. await sendV4Prompt("E2E_QEF_J 刷新时冻结的一条");
  172. await waitForV4QueueCount(1, 30000);
  173. const [itemJ] = await getV4QueueItems();
  174. if (!itemJ) throw new Error("B09k 队列项不存在");
  175. await setV4ComposerText(DRAFT_TEXT);
  176. await openV4QueueItemEditInComposer(itemJ.queueItemId);
  177. await setV4ComposerText("E2E_QEF_J 编辑中的内容");
  178. await browser.execute(() => window.location.reload());
  179. await waitForWorkspaceApp(DEFAULT_WORKSPACE, 30000);
  180. await selectV4TaskById(sessionId);
  181. await waitForV4Pane((s) => s.sessionId === sessionId, "刷新后没有恢复 session", 30000);
  182. await waitForV4QueueItemEditLock(
  183. itemJ.queueItemId,
  184. (state) => state.exists && !state.locked,
  185. "刷新后发起端没有释放自己的锁",
  186. );
  187. expect(await getV4ComposerEditState()).toBeNull();
  188. await browser.waitUntil(async () => (await getV4ComposerText()) === DRAFT_TEXT, {
  189. timeout: 15000,
  190. timeoutMsg: "刷新后没有恢复进入编辑态前的原草稿",
  191. });
  192. expect((await getV4QueueItems())[0]?.text).toContain("刷新时冻结的一条");
  193. await releaseControlledReplay("qef-slow-j");
  194. await waitForV4TimelineContaining("QEF_J_REPLY", 45000);
  195. await waitForV4QueueCount(0, 30000);
  196. });
  197. });