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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { clearAppData } from "../helpers/desktop-app.js";
  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. clickQueueEdit,
  15. clickQueueRemove,
  16. getQueueItems,
  17. waitForQueueCount,
  18. waitForQueueOrderContaining,
  19. } from "#e2e/helpers/conversation-session-queue";
  20. import { countUpstreamRequestsContaining } from "#e2e/helpers/conversation-session-network";
  21. describe("会话区 Held Queue 操作 E2E", () => {
  22. after(async () => {
  23. await browser.electron.restoreAllMocks();
  24. await clearAppData();
  25. });
  26. it("held queue 撤回编辑恢复 Composer,重排和删除保留草稿且不触发模型请求", async function () {
  27. this.timeout(180000);
  28. await prepareV4ConversationE2E();
  29. const runId = Date.now();
  30. const runningPrompt = `E2E_SLOW_STREAM E2E_QUEUE_OPS_RUNNING_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  31. await sendV4Prompt(runningPrompt);
  32. await waitForV4ComposerText("", "held queue 操作首轮发送后输入框没有清空");
  33. await waitForV4ConversationState(
  34. (snapshot) => snapshot.state === "streaming",
  35. "held queue 操作首轮没有进入 streaming",
  36. 30000,
  37. );
  38. const firstQueuedPrompt = `E2E_QUEUE_OPS_FIRST_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  39. const secondQueuedPrompt = `E2E_QUEUE_OPS_SECOND_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  40. const thirdQueuedPrompt = `E2E_QUEUE_OPS_THIRD_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  41. await sendV4Prompt(firstQueuedPrompt);
  42. await waitForQueueCount(1);
  43. await sendV4Prompt(secondQueuedPrompt);
  44. await waitForQueueCount(2);
  45. await sendV4Prompt(thirdQueuedPrompt);
  46. let queue = await waitForQueueCount(3);
  47. expect(queue.map((item) => item.content)).toEqual([
  48. firstQueuedPrompt,
  49. secondQueuedPrompt,
  50. thirdQueuedPrompt,
  51. ]);
  52. await clickV4Stop();
  53. await waitForV4ConversationState(
  54. (snapshot) => snapshot.state !== "streaming" && snapshot.queueCount === 3,
  55. "held queue 操作 stop 后没有保留 3 条队列",
  56. 30000,
  57. );
  58. queue = await getQueueItems();
  59. const firstId = queue[0]?.id;
  60. const secondId = queue[1]?.id;
  61. const thirdId = queue[2]?.id;
  62. if (!firstId || !secondId || !thirdId) {
  63. throw new Error(`队列项 id 缺失: ${JSON.stringify(queue)}`);
  64. }
  65. const editedSecondPrompt = `E2E_QUEUE_OPS_SECOND_EDITED_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  66. const editedRequestsBefore = await countUpstreamRequestsContaining(
  67. `E2E_QUEUE_OPS_SECOND_EDITED_${runId}`,
  68. );
  69. // 原因:当前产品使用权威删除后撤回到 Composer,不再原地编辑 queue。
  70. await clickQueueEdit(secondId);
  71. await waitForV4ComposerText(secondQueuedPrompt, "撤回没有恢复原文");
  72. queue = await waitForQueueCount(2);
  73. expect(queue.map((item) => item.id)).toEqual([firstId, thirdId]);
  74. await setV4ComposerText(editedSecondPrompt);
  75. expect(await countUpstreamRequestsContaining(`E2E_QUEUE_OPS_SECOND_EDITED_${runId}`)).toBe(
  76. editedRequestsBefore,
  77. );
  78. await dragV4QueueItemOnto(thirdId, firstId);
  79. queue = await waitForQueueOrderContaining(
  80. [`E2E_QUEUE_OPS_THIRD_${runId}`, `E2E_QUEUE_OPS_FIRST_${runId}`],
  81. "重排队列项后没有只改变 queue 顺序",
  82. );
  83. expect(queue.map((item) => item.id)).toEqual([thirdId, firstId]);
  84. expect(await getV4ComposerText()).toBe(editedSecondPrompt);
  85. const removedRequestsBefore = await countUpstreamRequestsContaining(
  86. `E2E_QUEUE_OPS_FIRST_${runId}`,
  87. );
  88. await clickQueueRemove(firstId);
  89. queue = await waitForQueueCount(1);
  90. expect(queue.map((item) => item.id)).toEqual([thirdId]);
  91. expect(queue.map((item) => item.content).join("\n")).not.toContain(
  92. `E2E_QUEUE_OPS_FIRST_${runId}`,
  93. );
  94. expect(await getV4ComposerText()).toBe(editedSecondPrompt);
  95. expect(await countUpstreamRequestsContaining(`E2E_QUEUE_OPS_FIRST_${runId}`)).toBe(
  96. removedRequestsBefore,
  97. );
  98. });
  99. });