conversation-session-queue-operations.test.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { clearAppData } from "#e2e/helpers/desktop-app";
  2. import {
  3. E2E_REPLY_TOKEN,
  4. clickV4Stop,
  5. getV4ComposerText,
  6. setV4ComposerText,
  7. dragV4QueueItemOnto,
  8. prepareV4ConversationE2E,
  9. sendV4Prompt,
  10. waitForV4ConversationState,
  11. waitForV4ComposerText,
  12. } from "#e2e/helpers/v4-conversation";
  13. import {
  14. clickQueueRemove,
  15. getQueueItems,
  16. waitForQueueCount,
  17. waitForQueueOrderContaining,
  18. } from "#e2e/helpers/conversation-session-queue";
  19. import { countUpstreamRequestsContaining } from "#e2e/helpers/conversation-session-network";
  20. import {
  21. getV4QueueItemEditLock,
  22. openV4QueueItemEditInComposer,
  23. waitForV4ComposerEditClosed,
  24. waitForV4QueueItemEditLock,
  25. } from "#e2e/helpers/v4-composer-edit";
  26. describe("会话区 Held Queue 操作 E2E", () => {
  27. after(async () => {
  28. await browser.electron.restoreAllMocks();
  29. await clearAppData();
  30. });
  31. it("held queue 编辑原位冻结,重排和删除其他项保留编辑内容,提交原地替换且不触发模型请求", async function () {
  32. this.timeout(180000);
  33. await prepareV4ConversationE2E();
  34. const runId = Date.now();
  35. const runningPrompt = `E2E_SLOW_STREAM E2E_QUEUE_OPS_RUNNING_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  36. await sendV4Prompt(runningPrompt);
  37. await waitForV4ComposerText("", "held queue 操作首轮发送后输入框没有清空");
  38. await waitForV4ConversationState(
  39. (snapshot) => snapshot.state === "streaming",
  40. "held queue 操作首轮没有进入 streaming",
  41. 30000,
  42. );
  43. const firstQueuedPrompt = `E2E_QUEUE_OPS_FIRST_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  44. const secondQueuedPrompt = `E2E_QUEUE_OPS_SECOND_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  45. const thirdQueuedPrompt = `E2E_QUEUE_OPS_THIRD_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  46. await sendV4Prompt(firstQueuedPrompt);
  47. await waitForQueueCount(1);
  48. await sendV4Prompt(secondQueuedPrompt);
  49. await waitForQueueCount(2);
  50. await sendV4Prompt(thirdQueuedPrompt);
  51. let queue = await waitForQueueCount(3);
  52. expect(queue.map((item) => item.content)).toEqual([
  53. firstQueuedPrompt,
  54. secondQueuedPrompt,
  55. thirdQueuedPrompt,
  56. ]);
  57. await clickV4Stop();
  58. await waitForV4ConversationState(
  59. (snapshot) => snapshot.state !== "streaming" && snapshot.queueCount === 3,
  60. "held queue 操作 stop 后没有保留 3 条队列",
  61. 30000,
  62. );
  63. queue = await getQueueItems();
  64. const firstId = queue[0]?.id;
  65. const secondId = queue[1]?.id;
  66. const thirdId = queue[2]?.id;
  67. if (!firstId || !secondId || !thirdId) {
  68. throw new Error(`队列项 id 缺失: ${JSON.stringify(queue)}`);
  69. }
  70. const editedSecondPrompt = `E2E_QUEUE_OPS_SECOND_EDITED_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  71. const editedRequestsBefore = await countUpstreamRequestsContaining(
  72. `E2E_QUEUE_OPS_SECOND_EDITED_${runId}`,
  73. );
  74. // 编辑时队列项原位冻结(docs/ui/composer-edit-mode.md),composer 载入原文。
  75. await openV4QueueItemEditInComposer(secondId);
  76. await waitForV4ComposerText(secondQueuedPrompt, "编辑态没有载入原文");
  77. queue = await waitForQueueCount(3);
  78. expect(queue.map((item) => item.id)).toEqual([firstId, secondId, thirdId]);
  79. // 编辑态在 lock ACK 后进入;editLock 随后经投影到达,需等待而不是读一次。
  80. await waitForV4QueueItemEditLock(secondId, (state) => state.locked, "编辑项没有显示编辑锁");
  81. await setV4ComposerText(editedSecondPrompt);
  82. expect(await countUpstreamRequestsContaining(`E2E_QUEUE_OPS_SECOND_EDITED_${runId}`)).toBe(
  83. editedRequestsBefore,
  84. );
  85. // 冻结项之外的项仍可重排;编辑内容不受影响。
  86. await dragV4QueueItemOnto(thirdId, firstId);
  87. queue = await waitForQueueOrderContaining(
  88. [`E2E_QUEUE_OPS_THIRD_${runId}`, `E2E_QUEUE_OPS_FIRST_${runId}`],
  89. "重排队列项后没有只改变 queue 顺序",
  90. );
  91. expect(queue.map((item) => item.id)).toEqual([thirdId, firstId, secondId]);
  92. expect(await getV4ComposerText()).toBe(editedSecondPrompt);
  93. const removedRequestsBefore = await countUpstreamRequestsContaining(
  94. `E2E_QUEUE_OPS_FIRST_${runId}`,
  95. );
  96. await clickQueueRemove(firstId);
  97. queue = await waitForQueueCount(2);
  98. expect(queue.map((item) => item.id)).toEqual([thirdId, secondId]);
  99. expect(queue.map((item) => item.content).join("\n")).not.toContain(
  100. `E2E_QUEUE_OPS_FIRST_${runId}`,
  101. );
  102. expect(await getV4ComposerText()).toBe(editedSecondPrompt);
  103. expect(await countUpstreamRequestsContaining(`E2E_QUEUE_OPS_FIRST_${runId}`)).toBe(
  104. removedRequestsBefore,
  105. );
  106. // 提交编辑:原地替换 second,ID 与位置不变;held queue 下不触发消费。
  107. await sendV4Prompt(editedSecondPrompt);
  108. await waitForV4ComposerEditClosed("held queue 编辑提交后没有退出编辑态", 30000);
  109. queue = await waitForQueueOrderContaining(
  110. [`E2E_QUEUE_OPS_THIRD_${runId}`, `E2E_QUEUE_OPS_SECOND_EDITED_${runId}`],
  111. "编辑提交后队列项没有原地替换",
  112. );
  113. expect(queue.map((item) => item.id)).toEqual([thirdId, secondId]);
  114. expect((await getV4QueueItemEditLock(secondId)).locked).toBe(false);
  115. await waitForV4ComposerText("", "编辑提交后没有恢复原草稿(空)");
  116. expect(await countUpstreamRequestsContaining(`E2E_QUEUE_OPS_SECOND_EDITED_${runId}`)).toBe(
  117. editedRequestsBefore,
  118. );
  119. });
  120. });