import { expect, test, type Page } from "@playwright/test" async function connect(page: Page) { await page.goto("/e2e/paas/index.html?ux") await page.getByLabel("API Key", { exact: true }).fill("round2-test") await page.getByRole("button", { name: "连接平台", exact: true }).click() await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled() } test("settings survive navigation, stay unapplied until saved, and can be discarded", async ({ page }) => { await connect(page) await page.getByRole("button", { name: "研究设置", exact: true }).click() const rounds = page.getByLabel("最多研究轮次", { exact: true }) await expect(rounds).toHaveValue("4") await rounds.fill("8") await page.getByRole("button", { name: "返回工作台" }).click() await page.getByRole("button", { name: "研究设置", exact: true }).click() await expect(rounds).toHaveValue("8") await expect(page.getByText(/已恢复未保存的修改/)).toBeVisible() expect(await page.evaluate(() => window.paasTestCalls.filter((c) => c.action === "update-agent"))).toHaveLength(0) await page.getByRole("button", { name: "放弃草稿并读取最新配置" }).click() await expect(rounds).toHaveValue("4") await rounds.fill("7") await page.getByRole("button", { name: /保存修改/ }).click() await page.getByRole("button", { name: "研究设置", exact: true }).click() await expect(rounds).toHaveValue("7") await expect(page.getByText(/已恢复未保存的修改/)).toHaveCount(0) }) test("settings from an older version are retained but cannot silently overwrite newer settings", async ({ page }) => { await connect(page) await page.getByRole("button", { name: "研究设置", exact: true }).click() await page.getByLabel("最多研究轮次", { exact: true }).fill("8") await page.getByRole("button", { name: "返回工作台" }).click() await page.evaluate(() => { window.paasUX.configVersion = "version-2" }) await page.getByRole("button", { name: "研究设置", exact: true }).click() await expect(page.getByLabel("最多研究轮次", { exact: true })).toHaveValue("8") await expect(page.getByText(/平台配置已更新,已保留你的草稿/)).toBeVisible() await page.getByRole("button", { name: /保存修改/ }).click() await expect(page.getByText(/配置版本已更新/)).toBeVisible() }) test("report renders inline math without rewriting currency and code", async ({ page }, info) => { await connect(page) await page.evaluate(() => window.paasUX.add({ run_id: "math", agent_id: "research", thread_id: "math", input: "公式验收", status: "completed", output: "# 数学报告\n\n判断 $\\delta > 0$,区间 \\(x \\in [0,1]\\)。\n\n$$x^2 + y^2 = 1$$\n\n预算 $5 和 $10。\n\n`$raw$`\n\n```text\n$literal$\n```", }), ) await page.getByRole("button", { name: "平台任务", exact: true }).click() await page.getByLabel("项目范围", { exact: true }).selectOption("all") await page.getByRole("button", { name: "刷新任务", exact: true }).click() await page.getByRole("row").filter({ hasText: "公式验收" }).getByRole("button", { name: "打开任务" }).click() await page.getByRole("button", { name: "阅读与对比", exact: true }).click() const dialog = page.getByRole("dialog") await expect(dialog.locator(".katex")).toHaveCount(3) await expect(dialog).toContainText("预算 $5 和 $10") await expect(dialog.locator("code").filter({ hasText: "$raw$" })).toBeVisible() await expect(dialog).toContainText("$literal$") await page.screenshot({ path: info.outputPath("math-report.png"), fullPage: true }) }) test("long tool activity loads recent entries first and retains access to older entries", async ({ page }) => { await connect(page) await page.getByRole("textbox", { name: "消息", exact: true }).fill("长任务") await page.getByRole("button", { name: "发送消息", exact: true }).click() await expect(page.getByRole("button", { name: "暂停", exact: true })).toBeVisible() await page.evaluate(() => { const executionID = String(window.paasTestCalls.find((c) => c.action === "execute")?.executionID) for (let i = 0; i < 123; i++) window.paasUX.progress({ executionID, type: "tool_result", tool: "lookup", content: `活动记录 ${i + 1}` }) }) const activity = page.locator(".paas-activity").first() await expect(activity.locator("li")).toHaveCount(0) await activity.locator("summary").first().click() await expect(activity.locator("li")).toHaveCount(50) await expect(activity).toContainText("活动记录 123") await activity.getByRole("button", { name: /加载更早活动/ }).click() await expect(activity.locator("li")).toHaveCount(80) await expect(activity).toContainText("活动记录 44") await expect(activity.getByRole("button", { name: /加载更早活动/ })).toHaveCount(0) }) test("remote workspaces explain downloading files instead of offering a broken local open", async ({ page }) => { await page.goto("/e2e/paas/index.html?ux") await page.getByLabel("平台地址", { exact: true }).fill("https://remote.example") await page.getByLabel("API Key", { exact: true }).fill("round2-test") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.locator(".paas-more-actions > summary").click() await expect(page.getByRole("button", { name: "在开发区打开工作区", exact: true })).toBeDisabled() await expect(page.getByText(/远程目录不能直接在本机打开/)).toBeVisible() await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled() }) test("a failed settings reload does not erase the retained draft", async ({ page }) => { await connect(page) await page.getByRole("button", { name: "研究设置", exact: true }).click() await page.getByLabel("最多研究轮次", { exact: true }).fill("9") await page.getByRole("button", { name: "返回工作台" }).click() await page.evaluate(() => { window.paasUX.configError = true }) await page.getByRole("button", { name: "研究设置", exact: true }).click() await expect(page.getByText("配置服务暂时不可用")).toBeVisible() await page.getByRole("button", { name: "返回工作台" }).click() await page.evaluate(() => { window.paasUX.configError = false }) await page.getByRole("button", { name: "研究设置", exact: true }).click() await expect(page.getByLabel("最多研究轮次", { exact: true })).toHaveValue("9") })