import { expect, test } from "@playwright/test" test("independent workbench connects, uploads, confirms and saves without a developer server", async ({ page }) => { const errors: string[] = [] page.on("pageerror", (error) => errors.push(error.message)) await page.goto("/e2e/paas/index.html") await expect(page.getByText("连接工作平台", { exact: true })).toBeVisible() await page.getByLabel("平台地址", { exact: true }).fill("https://research.example") await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() await expect(page.locator(".paas-topbar-chat-title")).toBeVisible() await expect(page.getByText("任务后台执行 · 会话与草稿自动保存", { exact: true })).toHaveCount(0) await page.getByRole("button", { name: "智能体", exact: true }).click() await page.getByRole("button", { name: "与 科研助手 对话", exact: true }).click() await page.getByRole("button", { name: "添加文件", exact: true }).click() await expect(page.getByRole("button", { name: "移除材料.pdf", exact: true })).toBeVisible() await page.getByRole("textbox", { name: "消息", exact: true }).fill("分析材料并制定研究计划") await expect(page.getByText("草稿已保留", { exact: true })).toHaveCount(0) await expect(page.locator(".paas-chat-caption")).toHaveCount(0) await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter") await expect(page.getByRole("button", { name: "同意并继续", exact: true })).toBeVisible() await expect(page.locator(".paas-result-live")).toBeVisible() await expect(page.locator(".paas-notifications")).toHaveCount(0) await expect(page.getByText("是否执行验证?", { exact: true })).toBeVisible() await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toBeVisible() await expect(page.getByRole("cell", { name: "证据清单", exact: true })).toBeVisible() await expect(page.getByRole("link", { name: "查看平台任务", exact: true })).toHaveAttribute("target", "_blank") await expect(page.getByText("工具活动 · 2 条", { exact: true })).toBeVisible() await page.getByText("工具活动 · 2 条", { exact: true }).click() await expect(page.getByText("调用工具 · file_search", { exact: true })).toBeVisible() await expect(page.getByText("找到 2 份材料", { exact: true })).toBeVisible() await page.locator("details.paas-activity").getByText("技术信息", { exact: true }).click() await expect(page.locator(".paas-activity-raw pre")).toContainText('"type": "tool_call"') await expect(page.getByRole("button", { name: "停止任务", exact: true })).toBeVisible() await page.getByRole("button", { name: "同意并继续", exact: true }).click() await expect(page.getByRole("button", { name: "同意并继续", exact: true })).toHaveCount(0) await page.locator(".paas-result-panel > summary").click() await expect(page.getByRole("heading", { name: "成果 · 1", exact: true })).toBeVisible() await expect(page.getByLabel("任务进度与成果").getByText("研究计划成果.pdf", { exact: true })).toBeVisible() await expect(page.getByText("没有可保存的工作文件。", { exact: true })).toHaveCount(0) await page.getByRole("button", { name: "保存成果", exact: true }).click() await expect(page.getByText("文件已保存。", { exact: true })).toBeVisible() await page.locator(".paas-work-directory > summary").click() await page.getByRole("button", { name: /^(查看|刷新)工作文件$/ }).click() await page.getByRole("button", { name: "保存文件", exact: true }).first().click() await expect(page.getByText("文件已保存。", { exact: true })).toBeVisible() await expect(page.getByText("没有可保存的工作文件。", { exact: true })).toHaveCount(0) const calls = await page.evaluate( () => (window as unknown as { paasTestCalls: Record[] }).paasTestCalls, ) expect(calls.find((value) => value.action === "execute")?.files).toEqual([{ file_id: "file_1", name: "材料.pdf" }]) expect(calls.filter((value) => value.action === "execute")).toHaveLength(1) expect(calls.find((value) => value.action === "confirm")).toMatchObject({ approvalID: "approval_1", approved: true }) const downloads = calls.filter((value) => value.action === "download") expect(downloads).toHaveLength(2) expect(downloads[0]).toMatchObject({ artifactID: "artifact_1", name: "研究计划成果.pdf" }) expect(downloads[1]).toMatchObject({ path: "final/研究计划.pdf" }) await expect(page.getByText("等待人工确认 · run_1", { exact: true })).toHaveCount(0) expect(errors).toEqual([]) await page.screenshot({ path: "/tmp/lambda-desktop-workbench.png", fullPage: true }) }) test("pause, resume and stop use the existing task without resubmission", async ({ page }) => { await page.goto("/e2e/paas/index.html") await page.getByLabel("平台地址", { exact: true }).fill("https://research.example") await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() await expect(page.locator(".paas-topbar-chat-title")).toBeVisible() await expect(page.getByText("任务后台执行 · 会话与草稿自动保存", { exact: true })).toHaveCount(0) await page.getByRole("button", { name: "智能体", exact: true }).click() await page.getByRole("button", { name: "与 科研助手 对话", exact: true }).click() await page.getByRole("textbox", { name: "消息", exact: true }).fill("持续研究") await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter") await page.getByRole("button", { name: "暂停", exact: true }).click() await expect(page.getByRole("button", { name: "停止任务", exact: true })).toBeVisible() await page.getByRole("button", { name: "继续执行", exact: true }).click() await page.getByRole("button", { name: "停止任务", exact: true }).click() await expect(page.getByRole("button", { name: "停止任务", exact: true })).toHaveCount(0) const calls = await page.evaluate( () => (window as unknown as { paasTestCalls: Record[] }).paasTestCalls, ) expect(calls.filter((value) => value.action === "execute")).toHaveLength(1) expect(calls.find((value) => value.action === "resume")).toMatchObject({ checkpointID: "checkpoint_1" }) expect(calls.filter((value) => value.action === "run").length).toBeLessThan(12) }) test("narrow navigation opens as a drawer and switches pages without leaving history behind", async ({ page }) => { await page.setViewportSize({ width: 600, height: 800 }) await page.goto("/e2e/paas/index.html") await page.getByLabel("平台地址", { exact: true }).fill("https://research.example") await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.getByRole("button", { name: "打开导航", exact: true }).click() await expect(page.getByRole("textbox", { name: "搜索会话标题", exact: true })).toBeVisible() await expect(page.locator(".paas-new-session")).toBeFocused() await expect(page.locator('.paas-sidebar nav button[aria-label="工作台"]')).toHaveCount(0) await expect(page.locator('.paas-sidebar nav button[aria-label="资源检查"]')).toHaveCount(0) await expect(page.locator('.paas-sidebar nav button[aria-label="平台连接"]')).toHaveCount(0) await expect(page.locator('.paas-sidebar nav button[aria-label="平台设置"]')).toHaveCount(1) await page.locator('.paas-sidebar nav button[aria-label="智能体"]').click() await expect(page.getByRole("heading", { name: "智能体", exact: true })).toBeVisible() await expect(page.getByRole("button", { name: "打开导航", exact: true })).toBeVisible() await page.getByRole("button", { name: "打开导航", exact: true }).click() await expect(page.getByRole("textbox", { name: "搜索会话标题", exact: true })).toBeVisible() await page.keyboard.press("Escape") await expect(page.getByRole("textbox", { name: "搜索会话标题", exact: true })).toBeHidden() await expect(page.getByRole("button", { name: "打开导航", exact: true })).toBeFocused() }) test("header actions stay aligned when the more menu opens", async ({ page }) => { await page.goto("/e2e/paas/index.html") await page.getByLabel("平台地址", { exact: true }).fill("https://research.example") await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() await expect(page.getByRole("button", { name: "刷新历史会话", exact: true })).toBeVisible() await expect(page.locator(".paas-chat-header-actions")).toHaveCSS("display", "flex") const settings = page.locator(".paas-chat-header-actions").getByRole("button", { name: "研究设置", exact: true }) const create = page.locator(".paas-chat-header-actions").getByRole("button", { name: "新会话", exact: true }) const more = page.locator(".paas-more-actions > summary") const box = async (locator: typeof settings) => { const value = await locator.boundingBox() return ( value && { x: Math.round(value.x), y: Math.round(value.y), width: Math.round(value.width), height: Math.round(value.height), } ) } const before = { settings: await box(settings), create: await box(create), more: await box(more) } expect(new Set([before.settings?.y, before.create?.y, before.more?.y]).size).toBe(1) expect(before.more!.x).toBeGreaterThan(before.create!.x) await more.click() expect(await box(settings)).toEqual(before.settings) expect(await box(create)).toEqual(before.create) expect(await box(more)).toEqual(before.more) expect(await page.getByText("刷新历史会话", { exact: true }).count()).toBe(0) await page.keyboard.press("Escape") await expect(page.getByRole("button", { name: "重命名会话", exact: true })).toHaveCount(0) await more.click() await page.getByRole("textbox", { name: "消息", exact: true }).click() await expect(page.getByRole("button", { name: "重命名会话", exact: true })).toHaveCount(0) }) test("wide layout keeps messages and composer on one reading axis", async ({ page }) => { await page.setViewportSize({ width: 1707, height: 1019 }) await page.goto("/e2e/paas/index.html") await page.getByLabel("平台地址", { exact: true }).fill("https://research.example") await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.getByRole("textbox", { name: "消息", exact: true }).waitFor() const box = async (selector: string) => { const value = await page.locator(selector).boundingBox() return ( value && { x: Math.round(value.x), width: Math.round(value.width), } ) } const content = await box(".paas-chat-messages > div") const composer = await box(".paas-composer") expect(composer).toEqual(content) expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBe(1707) await page.getByRole("textbox", { name: "消息", exact: true }).fill("分析材料并制定研究计划") await page.getByRole("button", { name: "发送消息", exact: true }).click() await page.getByRole("button", { name: "同意并继续", exact: true }).waitFor() const live = await box(".paas-result-live") expect(live).toBeDefined() expect(Math.round(live!.x + live!.width / 2)).toBe(Math.round(content!.x + content!.width / 2)) expect(live!.width).toBeLessThanOrEqual(content!.width) expect(live).toEqual(await box(".paas-chat-messages > div")) }) test("history hides unused agents, collapses groups and starts a new session from any page", async ({ page }) => { await page.goto("/e2e/paas/index.html?groups") await page.getByLabel("平台地址", { exact: true }).fill("https://research.example") await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() const sidebar = page.locator(".paas-sidebar") await expect(sidebar.locator(".paas-session-group")).toHaveCount(1) await expect(sidebar.getByText("未使用智能体", { exact: true })).toHaveCount(0) const group = sidebar.locator(".paas-session-group").first() await expect(group).toHaveAttribute("data-active", "true") const toggle = group.locator(".paas-session-toggle") await expect(toggle).toHaveAttribute("aria-expanded", "true") await toggle.click() await expect(group.locator(".paas-session-items")).toHaveCount(0) await toggle.click() await expect(group.locator(".paas-session-items")).toBeVisible() await sidebar.getByRole("button", { name: "平台任务", exact: true }).click() await page.getByLabel("项目范围", { exact: true }).selectOption("all") await expect(page.getByRole("heading", { name: "平台任务", exact: true })).toBeVisible() await expect(page.getByRole("columnheader", { name: "时间", exact: true })).toBeVisible() await page.locator(".paas-new-session").click() await expect(page.locator(".paas-topbar-page")).toHaveText("会话") await expect(page.locator(".paas-topbar-chat-title")).toHaveText("新会话") }) test("agent directory filters locally and keeps distinct illustrations", async ({ page }) => { await page.goto("/e2e/paas/index.html?groups") await page.getByLabel("平台地址", { exact: true }).fill("https://research.example") await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.locator('.paas-sidebar nav button[aria-label="智能体"]').click() const cards = page.locator(".paas-agent-card") await expect(cards).toHaveCount(2) await page.getByLabel("搜索智能体", { exact: true }).fill("未使用") await expect(cards).toHaveCount(1) await expect(cards.locator("h2")).toHaveText("未使用智能体") await expect(cards.locator(".paas-agent-illustration")).toHaveAttribute("data-kind", "agent") await page.getByLabel("搜索智能体", { exact: true }).fill("") await expect(cards).toHaveCount(2) }) test("settings tabs support arrow keys and expose the active tab panel", async ({ page }) => { await page.goto("/e2e/paas/index.html") await page.getByLabel("平台地址", { exact: true }).fill("https://research.example") await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.locator('.paas-sidebar nav button[aria-label="平台设置"]').click() const connection = page.getByRole("tab", { name: "平台连接", exact: true }) const resources = page.getByRole("tab", { name: "资源检查", exact: true }) await connection.focus() await page.keyboard.press("ArrowRight") await expect(resources).toHaveAttribute("aria-selected", "true") await expect(resources).toBeFocused() await expect(page.getByRole("tabpanel", { name: "资源检查", exact: true })).toBeVisible() await page.keyboard.press("ArrowLeft") await expect(connection).toHaveAttribute("aria-selected", "true") }) test("empty new sessions stay out of history and persistence", async ({ page }) => { await page.goto("/e2e/paas/index.html") const connect = async () => { await page.getByLabel("平台地址", { exact: true }).fill("https://research.example") await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.getByRole("textbox", { name: "消息", exact: true }).waitFor() } await connect() const sidebar = page.locator(".paas-sidebar") await page.locator(".paas-new-session").click() await page.locator(".paas-new-session").click() await expect(sidebar.locator(".paas-session-items").getByRole("button", { name: "新会话", exact: true })).toHaveCount( 0, ) await expect(page.locator(".paas-topbar-chat-title")).toHaveText("新会话") await page.getByRole("textbox", { name: "消息", exact: true }).fill("未发送草稿") await expect(sidebar.locator(".paas-session-items").getByRole("button", { name: "新会话", exact: true })).toHaveCount( 0, ) await page.reload() await connect() await expect(sidebar.locator(".paas-session-items").getByRole("button", { name: "新会话", exact: true })).toHaveCount( 0, ) await expect(page.getByRole("textbox", { name: "消息", exact: true })).toHaveValue("未发送草稿") await page.getByRole("textbox", { name: "消息", exact: true }).fill("真实研究") await page.getByRole("button", { name: "发送消息", exact: true }).click() await expect(sidebar.getByRole("button", { name: /真实研究/ })).toBeVisible() }) test("the page-bar conversation title can be renamed and saved", async ({ page }) => { await page.goto("/e2e/paas/index.html") await page.getByLabel("平台地址", { exact: true }).fill("https://research.example") await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.getByRole("textbox", { name: "消息", exact: true }).fill("可改标题的研究") await page.getByRole("button", { name: "发送消息", exact: true }).click() await page.getByRole("button", { name: "同意并继续", exact: true }).waitFor() const title = page.locator(".paas-topbar-chat-title") await title.click() const input = page.getByRole("textbox", { name: "会话名称", exact: true }) await input.fill("自定义研究标题") await input.press("Enter") await expect(title).toHaveText("自定义研究标题") }) test("left navigation resizes, collapses into an icon rail and persists", async ({ page }) => { await page.setViewportSize({ width: 1440, height: 900 }) await page.goto("/e2e/paas/index.html") await page.getByLabel("平台地址", { exact: true }).fill("https://research.example") await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.locator(".paas-topbar-chat-title").waitFor() const workspace = page.locator(".paas-workspace") const sidebar = page.locator(".paas-sidebar") const splitter = page.locator(".paas-splitter-nav") await expect(sidebar).toHaveCSS("width", "240px") const first = await splitter.boundingBox() await page.mouse.move(first!.x + 3, first!.y + 200) await page.mouse.down() await page.mouse.move(first!.x - 77, first!.y + 200, { steps: 6 }) await page.mouse.up() await expect(workspace).toHaveClass(/paas-nav-rail/) await expect(sidebar).toHaveCSS("width", "56px") await expect(page.getByRole("button", { name: "会话", exact: true })).toBeVisible() await page.getByRole("button", { name: "展开导航", exact: true }).click() await expect(sidebar).toHaveCSS("width", "240px") const second = await splitter.boundingBox() await page.mouse.move(second!.x + 3, second!.y + 200) await page.mouse.down() await page.mouse.move(second!.x + 43, second!.y + 200, { steps: 4 }) await page.mouse.up() await expect(sidebar).toHaveCSS("width", "280px") await page.reload() await expect(page.locator(".paas-sidebar")).toHaveCSS("width", "280px") }) test("topbar actions are icon-only with accessible names and titles", async ({ page }) => { await page.goto("/e2e/paas/index.html") await page.getByLabel("平台地址", { exact: true }).fill("https://research.example") await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.locator(".paas-topbar-chat-title").waitFor() const actions = page.locator(".paas-chat-header-actions") const settings = actions.getByRole("button", { name: "研究设置", exact: true }) const create = actions.getByRole("button", { name: "新会话", exact: true }) const workspace = actions.getByRole("button", { name: "在开发区打开工作区", exact: true }) await expect(settings).toHaveAttribute("title", "研究设置") await expect(create).toHaveAttribute("title", "新会话") await expect(workspace).toHaveAttribute("aria-label", "在开发区打开工作区") await expect(settings).not.toContainText("研究设置") await expect(create).not.toContainText("新会话") await expect(workspace).not.toContainText("在开发区打开工作区") const summary = page.locator(".paas-more-actions > summary") await expect(summary).toHaveAttribute("aria-label", "更多操作") await expect(summary).not.toContainText("更多操作") await summary.click() await expect(page.getByRole("button", { name: "重命名会话", exact: true })).toBeVisible() }) test("generated file cards open the right preview, resize and close at the lower bound", async ({ page }) => { await page.setViewportSize({ width: 1440, height: 900 }) await page.goto("/e2e/paas/index.html") await page.getByLabel("平台地址", { exact: true }).fill("https://research.example") await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.locator(".paas-topbar-chat-title").waitFor() const toggle = page.getByRole("button", { name: "预览", exact: true }) await toggle.click() await expect(page.locator(".paas-preview-empty")).toBeVisible() await page.getByRole("button", { name: "关闭预览", exact: true }).click() await page .getByRole("button", { name: /已有研究/ }) .first() .click() const card = page.getByRole("button", { name: "预览 研究计划.md", exact: true }) await card.waitFor() await card.click() const preview = page.locator(".paas-preview") await expect(preview).toBeVisible() await expect(preview.locator(".paas-preview-meta")).toContainText("研究计划.md") await expect(preview.getByRole("heading", { name: "可预览的研究计划", exact: true })).toBeVisible() await expect(preview.getByRole("button", { name: "保存文件", exact: true })).toBeVisible() await expect(card).toHaveClass(/is-selected/) await expect(toggle).toHaveAttribute("aria-pressed", "true") await page.getByRole("button", { name: "预览 研究计划.pdf", exact: true }).click() await expect(preview.locator(".paas-preview-meta")).toContainText("研究计划.pdf") await card.click() await expect(preview.getByRole("heading", { name: "可预览的研究计划", exact: true })).toBeVisible() expect( await page.evaluate( () => window.paasTestCalls.filter( (call) => call.action === "preview-file" && (call as Record).name === "研究计划.md", ).length, ), ).toBe(2) const splitter = page.locator(".paas-splitter-preview") const first = await splitter.boundingBox() await page.mouse.move(first!.x + 3, first!.y + 200) await page.mouse.down() await page.mouse.move(first!.x - 77, first!.y + 200, { steps: 5 }) await page.mouse.up() await expect(preview).toHaveCSS("width", "520px") const second = await splitter.boundingBox() await page.mouse.move(second!.x + 3, second!.y + 200) await page.mouse.down() await page.mouse.move(second!.x + 343, second!.y + 200, { steps: 6 }) await page.mouse.up() await expect(preview).toHaveCount(0) await expect(toggle).toHaveAttribute("aria-pressed", "false") await toggle.click() await expect(page.locator(".paas-preview")).toHaveCSS("width", "520px") await page.keyboard.press("Escape") await expect(page.locator(".paas-preview")).toHaveCount(0) }) test("managed deployment locks the platform address and model fields", async ({ page }) => { await page.goto("/e2e/paas/index.html?managed&ux") const address = page.locator('input[type="url"]') await expect(address).toHaveValue("https://team.example") await expect(address).toHaveAttribute("readonly", "") await expect(page.getByRole("button", { name: "一键连接本机", exact: true })).toHaveCount(0) await page.getByLabel("API Key", { exact: true }).fill("test-only") await page.getByRole("button", { name: "连接平台", exact: true }).click() await expect(page.locator(".paas-topbar-chat-title")).toBeVisible() await page.getByRole("button", { name: "智能体", exact: true }).click() await page.getByRole("button", { name: "编辑 科研助手", exact: true }).click() await expect(page.getByRole("heading", { name: "编辑智能体", exact: true })).toBeVisible() await expect(page.getByText("模型由平台统一提供,不能在客户端修改。", { exact: true })).toBeVisible() await expect(page.getByText("模型提供商", { exact: true })).toHaveCount(0) await expect(page.getByText("高级配置(JSON)", { exact: true })).toHaveCount(0) })