| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import { clearAppData } from "#e2e/helpers/desktop-app";
- import {
- E2E_REPLY_TOKEN,
- assertVisibleV4UserMessagesNotContaining,
- clickV4Stop,
- editFirstV4UserQuery,
- getV4Messages,
- prepareV4ConversationE2E,
- sendV4Prompt,
- startNewV4Draft,
- waitForV4AssistantMessageContaining,
- waitForV4Pane,
- waitForV4UserMessageContaining,
- } from "#e2e/helpers/v4-conversation";
- import { waitForUpstreamRequestContaining } from "#e2e/helpers/conversation-session-network";
- import { waitForQueueContaining, waitForQueueCount } from "#e2e/helpers/conversation-session-queue";
- const PARTIAL = "E2E_INTERRUPTED_PARTIAL";
- describe("会话区 Interrupted Actions E2E", () => {
- after(async () => {
- await browser.electron.restoreAllMocks();
- await clearAppData();
- });
- it("interrupted 后允许 edit;空队列和 held queue 下 stopped assistant partial 均不可 fork", async function () {
- this.timeout(180000);
- await prepareV4ConversationE2E();
- // 原因:旧 Stop/Edit/Fork selector 已退役,且快速完成分支会直接跳过核心断言。
- // 回放在真实 partial 后保持连接;必须点击 V4 Stop,不能用自然完成替代 interrupted。
- const source = "E2E_INTERRUPTED_EDIT_SOURCE";
- await startPartial(source);
- await clickV4Stop();
- await waitForV4Pane((pane) => !pane.canStop, "Stop 没有收口当前轮");
- await assertPartialCannotFork();
- const edited = "E2E_INTERRUPTED_EDIT_RERUN";
- expect((await getV4Messages("user")).at(-1)?.text).toContain(source);
- await editFirstV4UserQuery(edited);
- await waitForUpstreamRequestContaining(edited);
- await waitForV4UserMessageContaining(edited);
- await assertVisibleV4UserMessagesNotContaining(source);
- await waitForV4AssistantMessageContaining(E2E_REPLY_TOKEN);
- await waitForV4Pane((pane) => !pane.canStop, "编辑重跑没有完成");
- for (const held of [false, true]) {
- await startNewV4Draft();
- await startPartial(held ? "E2E_INTERRUPTED_NO_FORK_HELD" : "E2E_INTERRUPTED_NO_FORK_EMPTY");
- let queuedId: string | undefined;
- if (held) {
- await sendV4Prompt("E2E_INTERRUPTED_NO_FORK_HELD_QUEUE");
- await waitForQueueContaining("E2E_INTERRUPTED_NO_FORK_HELD_QUEUE");
- queuedId = (await waitForQueueCount(1))[0]?.id;
- expect(queuedId).toBeTruthy();
- }
- await clickV4Stop();
- await waitForV4Pane((pane) => !pane.canStop, "停止 partial 后没有收口");
- await assertPartialCannotFork();
- const queue = await waitForQueueCount(held ? 1 : 0);
- if (held) {
- expect(queue[0]?.id).toBe(queuedId);
- expect(queue[0]?.content).toContain("E2E_INTERRUPTED_NO_FORK_HELD_QUEUE");
- }
- }
- });
- });
- async function startPartial(marker: string) {
- await sendV4Prompt(
- `E2E_SLOW_STREAM ${marker}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`,
- );
- await waitForV4UserMessageContaining(marker);
- await waitForV4AssistantMessageContaining(PARTIAL);
- await waitForV4Pane((pane) => pane.canStop, "受控 partial 没有保持运行窗口");
- }
- async function assertPartialCannotFork() {
- const partial = (await getV4Messages("assistant")).find((message) =>
- message.text.includes(PARTIAL),
- );
- expect(partial?.id).toBeTruthy();
- const enabled = await browser.execute((rowId) => {
- const row = document.querySelector<HTMLElement>(`[data-row-id="${rowId}"]`);
- if (!row) throw new Error("partial 行不存在,不能证明禁止 fork");
- return Array.from(row.querySelectorAll<HTMLButtonElement>('[data-testid^="v4-fork-"]')).some(
- (button) => !button.disabled && button.getAttribute("aria-disabled") !== "true",
- );
- }, partial!.id);
- expect(enabled).toBe(false);
- }
|