| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- import { expect, test, type Page } from "@playwright/test"
- async function connect(page: Page, key = "ux-account") {
- await page.getByLabel("平台地址", { exact: true }).fill("https://research.example")
- await page.getByLabel("API Key", { exact: true }).fill(key)
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled()
- }
- async function run(page: Page, input: string) {
- await page.getByRole("textbox", { name: "消息", exact: true }).fill(input)
- await page.getByRole("button", { name: "发送消息", exact: true }).click()
- await expect(page.getByRole("button", { name: "暂停", exact: true })).toBeVisible()
- }
- test("parallel chats preserve next-round drafts, materials and active chat across reload and isolate accounts", async ({
- page,
- }) => {
- await page.goto("/e2e/paas/index.html?ux")
- await connect(page)
- await run(page, "第一项后台研究")
- const input = page.getByRole("textbox", { name: "消息", exact: true })
- await input.fill("第一项下一轮草稿")
- await expect(page.getByRole("button", { name: "发送消息", exact: true })).toBeDisabled()
- await page.locator(".paas-topbar-chat-actions").getByRole("button", { name: "新会话", exact: true }).click()
- await run(page, "第二项后台研究")
- await input.fill("第二项下一轮草稿")
- await page.getByRole("button", { name: /第一项后台研究/ }).click()
- await expect(input).toHaveValue("第一项下一轮草稿")
- await page.reload()
- await connect(page)
- await expect(input).toHaveValue("第一项下一轮草稿")
- // Reopening never repeats either execution; unresolved background jobs remain read-only until confirmed.
- expect(
- await page.evaluate(
- () =>
- (window as unknown as { paasTestCalls: { action: string }[] }).paasTestCalls.filter(
- (c) => c.action === "execute",
- ).length,
- ),
- ).toBe(0)
- await page.getByRole("button", { name: "平台设置", exact: true }).click()
- await page.getByRole("button", { name: "断开并忘记连接", exact: true }).click()
- await connect(page, "other-account")
- await expect(input).toHaveValue("")
- await expect(page.getByText("第一项后台研究", { exact: true })).toHaveCount(0)
- })
- test("partial upload failure keeps successful materials and retries only the failed file; drop works", async ({
- page,
- }) => {
- await page.goto("/e2e/paas/index.html?ux")
- await connect(page)
- await page.getByRole("button", { name: "添加文件", exact: true }).click()
- await expect(page.getByRole("button", { name: "移除成功.txt", exact: true })).toBeVisible()
- await page.getByRole("button", { name: "重试 重试.txt", exact: true }).click()
- await expect(page.getByRole("button", { name: "移除重试.txt", exact: true })).toBeVisible()
- expect(await page.evaluate(() => (window as unknown as { paasUX: { uploads: number } }).paasUX.uploads)).toBe(3)
- const transfer = await page.evaluateHandle(() => {
- const data = new DataTransfer()
- data.items.add(new File(["research"], "拖放.txt", { type: "text/plain" }))
- return data
- })
- await page.locator(".paas-composer").dispatchEvent("drop", { dataTransfer: transfer })
- await expect(page.getByRole("button", { name: "移除拖放.txt", exact: true })).toBeVisible()
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("保留材料的草稿")
- await page.reload()
- await connect(page)
- await expect(page.getByRole("textbox", { name: "消息", exact: true })).toHaveValue("保留材料的草稿")
- await expect(page.getByRole("button", { name: "移除成功.txt", exact: true })).toBeVisible()
- await expect(page.getByRole("button", { name: "移除重试.txt", exact: true })).toBeVisible()
- await expect(page.getByRole("button", { name: "移除拖放.txt", exact: true })).toBeVisible()
- })
- test("unknown submission is recoverable without an automatic duplicate; task index opens the existing run", async ({
- page,
- }) => {
- await page.goto("/e2e/paas/index.html?ux")
- await connect(page)
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("模拟网络中断")
- await page.getByRole("button", { name: "发送消息", exact: true }).click()
- await page.getByRole("button", { name: "恢复原输入与材料", exact: true }).click()
- await expect(page.getByRole("textbox", { name: "消息", exact: true })).toHaveValue("模拟网络中断")
- await expect(page.getByRole("button", { name: "发送消息", exact: true })).toBeDisabled()
- await page.locator(".paas-topbar-chat-actions").getByRole("button", { name: "新会话", exact: true }).click()
- await run(page, "任务中心可打开的研究")
- await page.getByRole("button", { name: "平台任务", exact: true }).click()
- await page.getByRole("button", { name: "刷新任务", exact: true }).click()
- await expect(page.getByRole("table")).toContainText("任务中心可打开的研究")
- await page.getByRole("button", { name: "打开任务", exact: true }).click()
- await expect(page.getByRole("button", { name: "暂停", exact: true })).toBeVisible()
- expect(
- await page.evaluate(
- () =>
- (window as unknown as { paasTestCalls: { action: string }[] }).paasTestCalls.filter(
- (c) => c.action === "execute",
- ).length,
- ),
- ).toBe(2)
- })
- test("reports render tables and math; background updates do not pull the reader down", async ({ page }) => {
- const errors: string[] = []
- page.on("pageerror", (error) => errors.push(error.message))
- await page.goto("/e2e/paas/index.html?ux")
- await connect(page)
- await run(page, "阅读长报告")
- await page.evaluate(() => {
- const control = (window as unknown as { paasUX: { update(id: string, value: Record<string, unknown>): void } })
- .paasUX
- control.update("ux_1", {
- output:
- "# 研究报告\n\n| 指标 | 结果 |\n|---|---|\n| 样本 | 42 |\n\n$$E=mc^2$$\n\n" +
- Array.from({ length: 35 }, (_, i) => `第 ${i + 1} 节研究分析。\n\n`).join(""),
- })
- })
- await expect(page.locator(".paas-report table")).toBeVisible({ timeout: 10000 })
- await expect(page.locator(".paas-report .katex")).toBeVisible()
- const log = page.getByRole("log", { name: "会话消息" })
- await log.evaluate((el) => {
- el.scrollTop = 0
- el.dispatchEvent(new Event("scroll"))
- })
- await page.evaluate(() => {
- const control = (
- window as unknown as {
- paasUX: { update(id: string, value: Record<string, unknown>): void; run(id: string): { output: string } }
- }
- ).paasUX
- control.update("ux_1", { output: control.run("ux_1").output + "\n\n新的研究进展。" })
- })
- await expect(page.getByRole("button", { name: "有新进展 · 回到底部", exact: true })).toBeVisible({ timeout: 10000 })
- expect(await log.evaluate((el) => el.scrollTop)).toBeLessThan(80)
- await page.getByRole("button", { name: "有新进展 · 回到底部", exact: true }).click()
- await expect(page.getByRole("button", { name: "有新进展 · 回到底部", exact: true })).toHaveCount(0)
- expect(errors).toEqual([])
- await page.screenshot({ path: "/tmp/lambda-desktop-ux-report.png", fullPage: true })
- })
- test("background task approval produces a navigable notice and readable confirmation", async ({ page }) => {
- await page.goto("/e2e/paas/index.html?ux")
- await connect(page)
- await run(page, "需要确认的后台研究")
- await page.getByRole("button", { name: "平台任务", exact: true }).click()
- await page.getByRole("button", { name: "刷新任务", exact: true }).click()
- await expect(page.getByRole("table")).toContainText("运行中")
- await page.evaluate(() => {
- const control = (window as unknown as { paasUX: { update(id: string, value: Record<string, unknown>): void } })
- .paasUX
- control.update("ux_1", {
- status: "running",
- pending_approval: {
- approval_id: "approve_ux",
- stage_name: "实验方案审阅",
- prompt: "请核对实验设置后继续。",
- artifacts: [{ name: "实验方案.md" }],
- },
- })
- })
- await expect(page.getByLabel("即时任务通知", { exact: true })).toContainText("等待人工确认", { timeout: 15000 })
- await page
- .getByLabel("即时任务通知", { exact: true })
- .getByRole("button", { name: /等待人工确认/ })
- .click()
- await expect(page.getByText("当前阶段:实验方案审阅", { exact: true })).toBeVisible()
- await expect(page.getByText("待确认成果:实验方案.md", { exact: true })).toBeVisible()
- await expect(page.getByRole("button", { name: "同意并继续", exact: true })).toBeVisible()
- await expect(page.getByRole("button", { name: "发送消息", exact: true })).toBeDisabled()
- })
|