diff --git a/frontend/tests/e2e/thread-routing.spec.ts b/frontend/tests/e2e/thread-routing.spec.ts index 1e1b0408..13b18f9f 100644 --- a/frontend/tests/e2e/thread-routing.spec.ts +++ b/frontend/tests/e2e/thread-routing.spec.ts @@ -1,15 +1,22 @@ import { expect, test } from "@playwright/test"; +import { v4 as uuid } from "uuid"; import { THREAD_FOR_WELCOME, newChatEntry, openChat, reuseThreadChatEntry, + sendMessage, skipIfMissingThread, waitForAnyMessages, waitForMessageListReady, } from "./support/chat-helpers"; +test.use({ + screenshot: "on", + video: "on", +}); + test.describe("线程路由(无 isnew)", () => { test("/new 始终走欢迎态,发送后进入具体 thread 路由", async ({ page }, testInfo) => { skipIfMissingThread(testInfo, THREAD_FOR_WELCOME, "FRONTEND_E2E_THREAD_ID"); @@ -29,4 +36,46 @@ test.describe("线程路由(无 isnew)", () => { await expect(page).toHaveURL(new RegExp(`/workspace/chats/${THREAD_FOR_WELCOME!}`)); await expect(page.locator(".is-user, .is-assistant").first()).toBeVisible(); }); + + test("/new 使用 uuid thread_id 发送后触发 stream(cod=0) 并进入 thread 路由", async ({ + page, + }) => { + const threadId = uuid(); + const text = `e2e-${threadId.slice(0, 8)}`; + + await openChat(page, newChatEntry(threadId)); + await expect(page.getByTestId("welcome-suggestions")).toBeVisible(); + + const streamRequestPromise = page.waitForRequest( + (request) => { + const url = request.url(); + if (!url.includes("/stream")) return false; + if (!url.includes(threadId)) return false; + try { + const parsed = new URL(url); + return parsed.searchParams.get("cancel_on_disconnect") === "0"; + } catch { + return url.includes("cancel_on_disconnect=0"); + } + }, + { timeout: 30_000 }, + ); + + await sendMessage(page, text); + await expect(page.locator(".is-user").filter({ hasText: text })).toHaveCount(1); + await expect + .poll( + async () => await page.locator(".is-assistant").count(), + { timeout: 30_000 }, + ) + .toBeGreaterThan(0); + + const streamRequest = await streamRequestPromise; + expect(streamRequest.url()).toContain("cancel_on_disconnect=0"); + + await expect(page).toHaveURL( + new RegExp(`/workspace/chats/${threadId}\\?is_chatting=true`), + { timeout: 30_000 }, + ); + }); });