conversation-session-interrupted-actions.test.ts 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { clearAppData } from "#e2e/helpers/desktop-app";
  2. import {
  3. E2E_REPLY_TOKEN,
  4. assertVisibleV4UserMessagesNotContaining,
  5. clickV4Stop,
  6. editFirstV4UserQuery,
  7. getV4Messages,
  8. prepareV4ConversationE2E,
  9. sendV4Prompt,
  10. startNewV4Draft,
  11. waitForV4AssistantMessageContaining,
  12. waitForV4Pane,
  13. waitForV4UserMessageContaining,
  14. } from "#e2e/helpers/v4-conversation";
  15. import { waitForUpstreamRequestContaining } from "#e2e/helpers/conversation-session-network";
  16. import { waitForQueueContaining, waitForQueueCount } from "#e2e/helpers/conversation-session-queue";
  17. const PARTIAL = "E2E_INTERRUPTED_PARTIAL";
  18. describe("会话区 Interrupted Actions E2E", () => {
  19. after(async () => {
  20. await browser.electron.restoreAllMocks();
  21. await clearAppData();
  22. });
  23. it("interrupted 后允许 edit;空队列和 held queue 下 stopped assistant partial 均不可 fork", async function () {
  24. this.timeout(180000);
  25. await prepareV4ConversationE2E();
  26. // 原因:旧 Stop/Edit/Fork selector 已退役,且快速完成分支会直接跳过核心断言。
  27. // 回放在真实 partial 后保持连接;必须点击 V4 Stop,不能用自然完成替代 interrupted。
  28. const source = "E2E_INTERRUPTED_EDIT_SOURCE";
  29. await startPartial(source);
  30. await clickV4Stop();
  31. await waitForV4Pane((pane) => !pane.canStop, "Stop 没有收口当前轮");
  32. await assertPartialCannotFork();
  33. const edited = "E2E_INTERRUPTED_EDIT_RERUN";
  34. expect((await getV4Messages("user")).at(-1)?.text).toContain(source);
  35. await editFirstV4UserQuery(edited);
  36. await waitForUpstreamRequestContaining(edited);
  37. await waitForV4UserMessageContaining(edited);
  38. await assertVisibleV4UserMessagesNotContaining(source);
  39. await waitForV4AssistantMessageContaining(E2E_REPLY_TOKEN);
  40. await waitForV4Pane((pane) => !pane.canStop, "编辑重跑没有完成");
  41. for (const held of [false, true]) {
  42. await startNewV4Draft();
  43. await startPartial(held ? "E2E_INTERRUPTED_NO_FORK_HELD" : "E2E_INTERRUPTED_NO_FORK_EMPTY");
  44. let queuedId: string | undefined;
  45. if (held) {
  46. await sendV4Prompt("E2E_INTERRUPTED_NO_FORK_HELD_QUEUE");
  47. await waitForQueueContaining("E2E_INTERRUPTED_NO_FORK_HELD_QUEUE");
  48. queuedId = (await waitForQueueCount(1))[0]?.id;
  49. expect(queuedId).toBeTruthy();
  50. }
  51. await clickV4Stop();
  52. await waitForV4Pane((pane) => !pane.canStop, "停止 partial 后没有收口");
  53. await assertPartialCannotFork();
  54. const queue = await waitForQueueCount(held ? 1 : 0);
  55. if (held) {
  56. expect(queue[0]?.id).toBe(queuedId);
  57. expect(queue[0]?.content).toContain("E2E_INTERRUPTED_NO_FORK_HELD_QUEUE");
  58. }
  59. }
  60. });
  61. });
  62. async function startPartial(marker: string) {
  63. await sendV4Prompt(
  64. `E2E_SLOW_STREAM ${marker}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`,
  65. );
  66. await waitForV4UserMessageContaining(marker);
  67. await waitForV4AssistantMessageContaining(PARTIAL);
  68. await waitForV4Pane((pane) => pane.canStop, "受控 partial 没有保持运行窗口");
  69. }
  70. async function assertPartialCannotFork() {
  71. const partial = (await getV4Messages("assistant")).find((message) =>
  72. message.text.includes(PARTIAL),
  73. );
  74. expect(partial?.id).toBeTruthy();
  75. const enabled = await browser.execute((rowId) => {
  76. const row = document.querySelector<HTMLElement>(`[data-row-id="${rowId}"]`);
  77. if (!row) throw new Error("partial 行不存在,不能证明禁止 fork");
  78. return Array.from(row.querySelectorAll<HTMLButtonElement>('[data-testid^="v4-fork-"]')).some(
  79. (button) => !button.disabled && button.getAttribute("aria-disabled") !== "true",
  80. );
  81. }, partial!.id);
  82. expect(enabled).toBe(false);
  83. }