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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { clearAppData } from "../../../helpers/desktop-app.js";
  2. import {
  3. E2E_REPLY_TOKEN,
  4. clickChatStop,
  5. clickQueueEdit,
  6. clickQueueEditSave,
  7. clickQueueRemove,
  8. countUpstreamRequestsContaining,
  9. dragQueueItemOnto,
  10. getComposerText,
  11. getQueueItems,
  12. prepareConversationE2E,
  13. sendPrompt,
  14. setQueueEditInputText,
  15. waitForChatState,
  16. waitForComposerText,
  17. waitForQueueCount,
  18. waitForQueueOrderContaining,
  19. } from "../../../helpers/conversation-session.js";
  20. describe("会话区 Held Queue 操作 E2E", () => {
  21. after(async () => {
  22. await browser.electron.restoreAllMocks();
  23. await clearAppData();
  24. });
  25. it("held queue 中编辑、重排、删除都只影响 queue 本身且不触发模型请求", async function () {
  26. this.timeout(180000);
  27. await prepareConversationE2E();
  28. const runId = Date.now();
  29. const runningPrompt =
  30. `E2E_SLOW_STREAM E2E_QUEUE_OPS_RUNNING_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  31. await sendPrompt(runningPrompt);
  32. await waitForComposerText("", "held queue 操作首轮发送后输入框没有清空");
  33. await waitForChatState(
  34. (snapshot) => snapshot.state === "streaming",
  35. "held queue 操作首轮没有进入 streaming",
  36. 30000,
  37. );
  38. const firstQueuedPrompt =
  39. `E2E_QUEUE_OPS_FIRST_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  40. const secondQueuedPrompt =
  41. `E2E_QUEUE_OPS_SECOND_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  42. const thirdQueuedPrompt =
  43. `E2E_QUEUE_OPS_THIRD_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  44. await sendPrompt(firstQueuedPrompt);
  45. await waitForQueueCount(1);
  46. await sendPrompt(secondQueuedPrompt);
  47. await waitForQueueCount(2);
  48. await sendPrompt(thirdQueuedPrompt);
  49. let queue = await waitForQueueCount(3);
  50. expect(queue.map((item) => item.content)).toEqual([
  51. firstQueuedPrompt,
  52. secondQueuedPrompt,
  53. thirdQueuedPrompt,
  54. ]);
  55. await clickChatStop();
  56. await waitForChatState(
  57. (snapshot) => snapshot.state !== "streaming" && snapshot.queueCount === 3,
  58. "held queue 操作 stop 后没有保留 3 条队列",
  59. 30000,
  60. );
  61. queue = await getQueueItems();
  62. const firstId = queue[0]?.id;
  63. const secondId = queue[1]?.id;
  64. const thirdId = queue[2]?.id;
  65. if (!firstId || !secondId || !thirdId) {
  66. throw new Error(`队列项 id 缺失: ${JSON.stringify(queue)}`);
  67. }
  68. const editedSecondPrompt =
  69. `E2E_QUEUE_OPS_SECOND_EDITED_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  70. const editedRequestsBefore = await countUpstreamRequestsContaining(
  71. `E2E_QUEUE_OPS_SECOND_EDITED_${runId}`,
  72. );
  73. await clickQueueEdit(secondId);
  74. await setQueueEditInputText(secondId, editedSecondPrompt);
  75. await clickQueueEditSave(secondId);
  76. queue = await waitForQueueOrderContaining(
  77. [
  78. `E2E_QUEUE_OPS_FIRST_${runId}`,
  79. `E2E_QUEUE_OPS_SECOND_EDITED_${runId}`,
  80. `E2E_QUEUE_OPS_THIRD_${runId}`,
  81. ],
  82. "编辑队列项后没有保持原顺序并更新内容",
  83. );
  84. expect(queue[1]?.id).toBe(secondId);
  85. expect(await getComposerText()).toBe("");
  86. expect(
  87. await countUpstreamRequestsContaining(`E2E_QUEUE_OPS_SECOND_EDITED_${runId}`),
  88. ).toBe(editedRequestsBefore);
  89. await dragQueueItemOnto(thirdId, firstId);
  90. queue = await waitForQueueOrderContaining(
  91. [
  92. `E2E_QUEUE_OPS_THIRD_${runId}`,
  93. `E2E_QUEUE_OPS_FIRST_${runId}`,
  94. `E2E_QUEUE_OPS_SECOND_EDITED_${runId}`,
  95. ],
  96. "重排队列项后没有只改变 queue 顺序",
  97. );
  98. expect(queue.map((item) => item.id)).toEqual([thirdId, firstId, secondId]);
  99. expect(await getComposerText()).toBe("");
  100. const removedRequestsBefore = await countUpstreamRequestsContaining(
  101. `E2E_QUEUE_OPS_FIRST_${runId}`,
  102. );
  103. await clickQueueRemove(firstId);
  104. queue = await waitForQueueCount(2);
  105. expect(queue.map((item) => item.id)).toEqual([thirdId, secondId]);
  106. expect(queue.map((item) => item.content).join("\n")).not.toContain(
  107. `E2E_QUEUE_OPS_FIRST_${runId}`,
  108. );
  109. expect(await getComposerText()).toBe("");
  110. expect(
  111. await countUpstreamRequestsContaining(`E2E_QUEUE_OPS_FIRST_${runId}`),
  112. ).toBe(removedRequestsBefore);
  113. });
  114. });