import { expect, test } from "@playwright/test" test("automatic route selects data analysis and hides internal roles", async ({ page }) => { await page.goto("/e2e/paas/index.html?agent-groups") await page.getByLabel("API Key", { exact: true }).fill("automatic-route") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.getByRole("textbox", { name: "消息", exact: true }).fill("合并 CSV 并画趋势图") const route = page.getByRole("button", { name: "选择执行角色", exact: true }) await expect(route).toContainText("自动 · data67") await route.click() await expect(page.getByRole("option", { name: /data67/ })).toBeVisible() await expect(page.getByRole("option", { name: /本体证据补全员/ })).toHaveCount(0) }) test("agent directory separates direct roles from internal subagents", async ({ page }) => { await page.goto("/e2e/paas/index.html?agent-groups") await page.getByLabel("API Key", { exact: true }).fill("agent-groups") 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.getByRole("heading", { name: "专业任务", exact: true })).toBeVisible() await expect(page.getByRole("heading", { name: "研究流水线", exact: true })).toBeVisible() const internal = page.locator(".paas-agent-internal") await expect(internal.getByRole("heading", { name: "本体证据补全员", exact: true })).toBeHidden() await internal.getByText("流程内部能力 · 1", { exact: true }).click() await expect(internal.getByRole("heading", { name: "本体证据补全员", exact: true })).toBeVisible() await expect(internal.getByRole("button", { name: "与 本体证据补全员 对话", exact: true })).toHaveCount(0) }) test("workspace assistant requires and forwards the project folder", async ({ page }) => { await page.goto("/e2e/paas/index.html?workspace") await page.getByLabel("API Key", { exact: true }).fill("workspace-context") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.getByRole("button", { name: "选择执行角色", exact: true }).click() await page.getByRole("option", { name: /^工作区助手/ }).click() await page.getByRole("textbox", { name: "消息", exact: true }).fill("整理这个文件夹") await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter") await expect(page.getByText("需要绑定项目工作文件夹", { exact: true })).toBeVisible() expect( await page.evaluate( () => (window as unknown as { paasTestCalls: { action: string }[] }).paasTestCalls.filter( (call) => call.action === "execute", ).length, ), ).toBe(0) await page.getByRole("button", { name: "新建项目", exact: true }).click() await page.getByLabel("项目名称", { exact: true }).fill("工作区研究") 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.getByRole("option", { name: /^工作区助手/ }).click() await page.getByRole("textbox", { name: "消息", exact: true }).fill("整理这个文件夹并改 README") await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter") await expect .poll(() => page.evaluate( () => (window as unknown as { paasTestCalls: { action: string; workDir?: string }[] }).paasTestCalls.find( (call) => call.action === "execute", )?.workDir, ), ) .toBe("D:/Research/optics") }) test("projects isolate chat history and keep a bound workspace after reload", async ({ page }) => { await page.goto("/e2e/paas/index.html") await page.getByLabel("API Key", { exact: true }).fill("project-test") await page.getByRole("button", { name: "连接平台", exact: true }).click() await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled() await page.getByRole("button", { name: "新建项目", exact: true }).click() await page.getByLabel("项目名称", { exact: true }).fill("光学综述") await page.getByRole("button", { name: "创建项目", exact: true }).click() await expect(page.getByLabel("切换项目", { exact: true })).toContainText("光学综述") await page.getByRole("button", { name: "绑定文件夹", exact: true }).click() await expect(page.locator(".paas-composer-context").getByText("D:/Research/optics", { exact: true })).toBeVisible() await page.getByRole("textbox", { name: "消息", exact: true }).fill("光学综述草稿") await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter") await expect(page.getByRole("button", { name: /已有研究/ })).toHaveCount(0) await page.reload() await page.getByLabel("API Key", { exact: true }).fill("project-test") await page.getByRole("button", { name: "连接平台", exact: true }).click() await expect(page.getByLabel("切换项目", { exact: true })).toContainText("光学综述") await expect(page.locator(".paas-composer-context").getByText("D:/Research/optics", { exact: true })).toBeVisible() }) test("project creation supports focus, Chinese composition and cancellation", async ({ page }) => { await page.goto("/e2e/paas/index.html") await page.getByLabel("API Key", { exact: true }).fill("project-keyboard") await page.getByRole("button", { name: "连接平台", exact: true }).click() const toggle = page.getByRole("button", { name: "新建项目", exact: true }) await toggle.click() const name = page.getByLabel("项目名称", { exact: true }) await expect(name).toBeFocused() await name.fill("材料研究") const cancelled = await name.evaluate( (input) => !input.dispatchEvent( new KeyboardEvent("keydown", { key: "Enter", isComposing: true, bubbles: true, cancelable: true, }), ), ) expect(cancelled).toBe(true) await expect(name).toBeVisible() await name.press("Escape") await expect(name).toHaveCount(0) await expect(toggle).toBeFocused() await expect(page.getByLabel("切换项目").locator("option", { hasText: "材料研究" })).toHaveCount(0) }) test("role overrides can return to automatic matching without losing the draft", async ({ page }) => { await page.goto("/e2e/paas/index.html?agent-groups") await page.getByLabel("API Key", { exact: true }).fill("role-reset") await page.getByRole("button", { name: "连接平台", exact: true }).click() const input = page.getByRole("textbox", { name: "消息", exact: true }) await input.fill("合并 CSV 并画趋势图") const summary = page.getByRole("button", { name: "选择执行角色", exact: true }) const menu = page.getByRole("dialog", { name: "选择执行角色", exact: true }) await summary.click() await page.getByRole("option", { name: /^工作区助手/ }).click() await expect(summary).toContainText("指定") await summary.click() await expect(page.getByRole("option", { name: /^工作区助手/ })).toHaveAttribute("aria-selected", "true") await page.getByRole("option", { name: /^自动匹配/ }).click() await expect(summary).toContainText("自动 · data67") await expect(input).toHaveValue("合并 CSV 并画趋势图") await summary.click() await page.keyboard.press("Escape") await expect(menu).toHaveCount(0) await expect(summary).toBeFocused() await summary.click() await page.keyboard.press("Escape") await expect(menu).toHaveCount(0) }) test("project folder errors are recoverable without changing the saved folders", async ({ page }) => { await page.goto("/e2e/paas/index.html?ux") await page.getByLabel("API Key", { exact: true }).fill("folder-retry") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.getByRole("button", { name: "项目设置", exact: true }).click() await page.evaluate(() => Object.assign(Reflect.get(window, "paasUX"), { directoryError: "picker failed" })) await page.getByRole("button", { name: "添加工作文件夹", exact: true }).click() await expect(page.getByRole("alert")).toContainText("未能打开文件夹选择器") await expect(page.locator(".paas-project-folder-card")).toHaveCount(0) await page.evaluate(() => Object.assign(Reflect.get(window, "paasUX"), { directoryError: "" })) await page.getByRole("button", { name: "添加工作文件夹", exact: true }).click() await expect(page.locator(".paas-project-folder-card")).toContainText("D:/Research/optics") await page.getByRole("button", { name: "完成", exact: true }).click() await expect(page.locator(".paas-composer-context")).toContainText("D:/Research/optics") }) for (const width of [360, 520]) { test(`role chooser stays within a ${width}px window`, async ({ page }) => { await page.setViewportSize({ width, height: 740 }) await page.emulateMedia({ colorScheme: "dark" }) await page.goto("/e2e/paas/index.html?agent-groups") await page.getByLabel("API Key", { exact: true }).fill(`narrow-${width}`) await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.getByRole("button", { name: "选择执行角色", exact: true }).click() const panel = page.getByRole("dialog", { name: "选择执行角色", exact: true }) await expect(panel).toBeVisible() const bounds = await panel.boundingBox() expect(bounds!.x).toBeGreaterThanOrEqual(0) expect(bounds!.x + bounds!.width).toBeLessThanOrEqual(width) await expect(page.getByRole("listbox", { name: "执行角色" })).toBeVisible() expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(width) }) }