import { expect, test } from "@playwright/test" test("opening model setup starts at its heading instead of inheriting the previous page scroll", async ({ page }) => { await page.setViewportSize({ width: 1100, height: 700 }) await page.goto("/e2e/paas/index.html?setup&ux&unified") 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 page.locator(".paas-content").evaluate((element) => { element.scrollTop = 400 }) await expect.poll(() => page.locator(".paas-content").evaluate((element) => element.scrollTop)).toBeGreaterThan(0) await page.getByRole("button", { name: "检查与配置资源", exact: true }).click() await expect(page.getByRole("heading", { name: "模型与资源", exact: true })).toBeInViewport() await expect.poll(() => page.locator(".paas-content").evaluate((element) => element.scrollTop)).toBe(0) }) test("model controls stay readable throughout theme changes and while disabled", async ({ page }) => { await page.goto("/e2e/paas/index.html?setup&ux&unified") await page.getByRole("button", { name: "准备本机服务并连接", exact: true }).click() await page.getByRole("button", { name: "平台设置", exact: true }).click() await page.getByRole("button", { name: "检查与配置资源", exact: true }).click() const samples = await page.evaluate(async () => { const input = document.querySelector('.paas-model-setup input[aria-label="模型名称"]')! const select = document.querySelector(".paas-model-setup select")! const button = document.querySelector(".paas-setup-submit button")! const luminance = (color: string) => { const components = color .match(/[\d.]+/g)! .slice(0, 3) .map(Number) .map((value) => { const channel = value / 255 return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4 }) return components[0] * 0.2126 + components[1] * 0.7152 + components[2] * 0.0722 } const readings: { mode: string; control: string; contrast: number; background: string }[] = [] for (const mode of ["dark", "light", "dark"]) { document.documentElement.style.colorScheme = mode for (let frame = 0; frame < 12; frame++) { await new Promise(requestAnimationFrame) for (const element of [input, select, button]) { const style = getComputedStyle(element) const fore = luminance(style.color) const back = luminance(style.backgroundColor) readings.push({ mode, control: element.tagName, contrast: (Math.max(fore, back) + 0.05) / (Math.min(fore, back) + 0.05), background: style.backgroundColor, }) } } } input.disabled = true select.disabled = true for (const element of [input, select]) { const style = getComputedStyle(element) const fore = luminance(style.color) const back = luminance(style.backgroundColor) readings.push({ mode: "disabled", control: element.tagName, contrast: (Math.max(fore, back) + 0.05) / (Math.min(fore, back) + 0.05), background: style.backgroundColor, }) } return readings }) expect(samples.filter((sample) => sample.contrast < 4.5)).toEqual([]) }) test("first-use prepares local service, configures model and starts no task without sending", async ({ page }) => { await page.goto("/e2e/paas/index.html?setup&ux&unified") await page.getByRole("button", { name: "准备本机服务并连接", exact: true }).click() await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeVisible() await page.getByRole("button", { name: "平台设置", exact: true }).click() await page.getByRole("button", { name: "检查与配置资源", exact: true }).click() const region = page.getByRole("region", { name: "模型与应用配置" }) await region.getByLabel("模型服务", { exact: true }).selectOption("deepseek") await region.getByLabel("模型名称", { exact: true }).fill("deepseek-chat") await region.getByLabel("模型 API Key", { exact: true }).fill("synthetic-ui-key") await region.getByRole("checkbox", { name: "科研助手" }).check() await region.getByRole("button", { name: "保存模型配置", exact: true }).click() await expect(region.getByText(/模型已配置,后续新任务生效/)).toBeVisible() await expect(region.getByLabel("模型 API Key", { exact: true })).toHaveValue("") expect( await page.evaluate(() => window.paasTestCalls.some((call) => call.action === "execute" || call.action === "verify"), ), ).toBe(false) await expect(region.getByRole("button", { name: "保存模型配置", exact: true })).toBeEnabled() await region.locator(".paas-setup-submit").scrollIntoViewIfNeeded() const checkbox = await region.getByRole("checkbox", { name: /科研助手/ }).boundingBox() const label = await region.locator(".paas-setup-target-name").first().boundingBox() expect(Math.abs(checkbox!.y + checkbox!.height / 2 - label!.y - label!.height / 2)).toBeLessThan(2) expect(label!.x - checkbox!.x - checkbox!.width).toBeGreaterThanOrEqual(8) await page.screenshot({ path: "/private/tmp/lambda-model-alignment-light.png", fullPage: true }) await page.emulateMedia({ colorScheme: "dark" }) await page.setViewportSize({ width: 700, height: 900 }) await expect(region.getByLabel("模型名称", { exact: true })).toHaveCSS("background-color", "rgb(28, 30, 33)") expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true) await region.locator(".paas-setup-submit").scrollIntoViewIfNeeded() const narrowCheckbox = await region.getByRole("checkbox", { name: /科研助手/ }).boundingBox() const narrowLabel = await region.locator(".paas-setup-target-name").first().boundingBox() expect( Math.abs(narrowCheckbox!.y + narrowCheckbox!.height / 2 - narrowLabel!.y - narrowLabel!.height / 2), ).toBeLessThan(2) await page.screenshot({ path: "/private/tmp/lambda-model-alignment-dark.png", fullPage: true }) await region.getByRole("button", { name: "开始任务", exact: true }).click() await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeVisible() }) test("model batch shows partial success and retains only failed applications for retry", async ({ page }) => { await page.goto("/e2e/paas/index.html?setup&ux&groups") await page.getByRole("button", { name: "准备本机服务并连接", exact: true }).click() await page.getByRole("button", { name: "平台设置", exact: true }).click() await page.getByRole("button", { name: "检查与配置资源", exact: true }).click() const region = page.getByRole("region", { name: "模型与应用配置" }) await region.getByLabel("模型服务", { exact: true }).selectOption("deepseek") await region.getByLabel("模型名称", { exact: true }).fill("deepseek-chat") await region.getByLabel("模型 API Key", { exact: true }).fill("synthetic-ui-key") await region.getByRole("checkbox", { name: "科研助手", exact: true }).check() await region.getByRole("checkbox", { name: "未使用智能体", exact: true }).check() await region.getByRole("button", { name: "保存模型配置", exact: true }).click() await expect(region.getByText(/配置版本已变更/)).toBeVisible() await expect(region.getByRole("checkbox", { name: /科研助手/ })).not.toBeChecked() await expect(region.getByRole("checkbox", { name: "未使用智能体", exact: true })).toBeChecked() await region.getByRole("button", { name: "保存模型配置", exact: true }).click() await expect(region.getByText(/配置版本已变更/)).toBeVisible() expect(await page.evaluate(() => window.paasTestCalls.filter((call) => call.action === "save-provider").length)).toBe( 1, ) }) test("tool token is vaulted before inspection, never saved in the draft or agent config", async ({ page }) => { await page.goto("/e2e/paas/index.html?plugins&setup&unified&agent-groups") await page.getByRole("button", { name: "准备本机服务并连接", exact: true }).click() await page.getByRole("button", { name: "应用与插件", exact: true }).click() await page.getByRole("tab", { name: "工具扩展" }).click() await page.getByLabel("工具配置对象").selectOption("workspace") await page.getByRole("button", { name: "添加工具连接" }).click() await page.getByLabel("连接名称", { exact: true }).fill("文献检索") await page.getByLabel("服务地址", { exact: true }).fill("https://papers.example/mcp") await page.getByLabel("工具访问凭证(可选)", { exact: true }).fill("synthetic-plugin-key") await page.getByRole("button", { name: "读取工具", exact: true }).click() await expect(page.getByLabel("工具访问凭证(可选)", { exact: true })).toHaveValue("") expect(await page.evaluate(() => JSON.stringify(localStorage).includes("synthetic-plugin-key"))).toBe(false) await page.getByRole("button", { name: "保存连接", exact: true }).click() expect( await page.evaluate(() => JSON.stringify(window.paasTestCalls.filter((call) => call.action === "update-agent")).includes( "synthetic-plugin-key", ), ), ).toBe(false) await page.getByRole("button", { name: "编辑连接", exact: true }).click() await page.getByLabel("服务地址", { exact: true }).fill("https://another.example/mcp") await expect(page.getByRole("button", { name: "保存连接", exact: true })).toBeDisabled() await page.getByRole("button", { name: "读取工具", exact: true }).click() const inspection = await page.evaluate(() => window.paasTestCalls.filter((call) => call.action === "inspect-tool").at(-1), ) expect(inspection).toMatchObject({ bearerEnv: "" }) })