project-workflow.spec.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import { expect, test } from "@playwright/test"
  2. test("automatic route selects data analysis and hides internal roles", async ({ page }) => {
  3. await page.goto("/e2e/paas/index.html?agent-groups")
  4. await page.getByLabel("API Key", { exact: true }).fill("automatic-route")
  5. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  6. await page.getByRole("textbox", { name: "消息", exact: true }).fill("合并 CSV 并画趋势图")
  7. const route = page.locator(".paas-agent-route > summary")
  8. await expect(route).toContainText("自动 · data67")
  9. await route.click()
  10. const select = page.getByLabel("选择执行角色", { exact: true })
  11. const options = await select.locator("option").allTextContents()
  12. expect(options).toContain("data67")
  13. expect(options).not.toContain("本体证据补全员")
  14. })
  15. test("agent directory separates direct roles from internal subagents", async ({ page }) => {
  16. await page.goto("/e2e/paas/index.html?agent-groups")
  17. await page.getByLabel("API Key", { exact: true }).fill("agent-groups")
  18. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  19. await page.getByRole("button", { name: "智能体", exact: true }).click()
  20. await expect(page.getByRole("heading", { name: "默认入口", exact: true })).toBeVisible()
  21. await expect(page.getByRole("heading", { name: "专业任务", exact: true })).toBeVisible()
  22. await expect(page.getByRole("heading", { name: "研究流水线", exact: true })).toBeVisible()
  23. const internal = page.locator(".paas-agent-internal")
  24. await expect(internal.getByRole("heading", { name: "本体证据补全员", exact: true })).toBeHidden()
  25. await internal.getByText("流程内部能力 · 1", { exact: true }).click()
  26. await expect(internal.getByRole("heading", { name: "本体证据补全员", exact: true })).toBeVisible()
  27. await expect(internal.getByRole("button", { name: "与 本体证据补全员 对话", exact: true })).toHaveCount(0)
  28. })
  29. test("workspace assistant requires and forwards the project folder", async ({ page }) => {
  30. await page.goto("/e2e/paas/index.html?workspace")
  31. await page.getByLabel("API Key", { exact: true }).fill("workspace-context")
  32. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  33. await page.locator(".paas-agent-route > summary").click()
  34. await page.getByLabel("选择执行角色", { exact: true }).selectOption({ label: "工作区助手" })
  35. await page.getByRole("textbox", { name: "消息", exact: true }).fill("整理这个文件夹")
  36. await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter")
  37. await expect(page.getByText("需要绑定项目工作文件夹", { exact: true })).toBeVisible()
  38. expect(
  39. await page.evaluate(
  40. () =>
  41. (window as unknown as { paasTestCalls: { action: string }[] }).paasTestCalls.filter(
  42. (call) => call.action === "execute",
  43. ).length,
  44. ),
  45. ).toBe(0)
  46. await page.getByRole("button", { name: "新建项目", exact: true }).click()
  47. await page.getByLabel("项目名称", { exact: true }).fill("工作区研究")
  48. await page.getByRole("button", { name: "创建项目", exact: true }).click()
  49. await page.getByRole("button", { name: "绑定文件夹", exact: true }).click()
  50. await page.locator(".paas-agent-route > summary").click()
  51. await page.getByLabel("选择执行角色", { exact: true }).selectOption({ label: "工作区助手" })
  52. await page.getByRole("textbox", { name: "消息", exact: true }).fill("整理这个文件夹并改 README")
  53. await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter")
  54. await expect
  55. .poll(() =>
  56. page.evaluate(
  57. () =>
  58. (window as unknown as { paasTestCalls: { action: string; workDir?: string }[] }).paasTestCalls.find(
  59. (call) => call.action === "execute",
  60. )?.workDir,
  61. ),
  62. )
  63. .toBe("D:/Research/optics")
  64. })
  65. test("projects isolate chat history and keep a bound workspace after reload", async ({ page }) => {
  66. await page.goto("/e2e/paas/index.html")
  67. await page.getByLabel("API Key", { exact: true }).fill("project-test")
  68. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  69. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled()
  70. await page.getByRole("button", { name: "新建项目", exact: true }).click()
  71. await page.getByLabel("项目名称", { exact: true }).fill("光学综述")
  72. await page.getByRole("button", { name: "创建项目", exact: true }).click()
  73. await expect(page.getByLabel("切换项目", { exact: true })).toContainText("光学综述")
  74. await page.getByRole("button", { name: "绑定文件夹", exact: true }).click()
  75. await expect(page.locator(".paas-composer-context").getByText("D:/Research/optics", { exact: true })).toBeVisible()
  76. await page.getByRole("textbox", { name: "消息", exact: true }).fill("光学综述草稿")
  77. await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter")
  78. await expect(page.getByRole("button", { name: /已有研究/ })).toHaveCount(0)
  79. await page.reload()
  80. await page.getByLabel("API Key", { exact: true }).fill("project-test")
  81. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  82. await expect(page.getByLabel("切换项目", { exact: true })).toContainText("光学综述")
  83. await expect(page.locator(".paas-composer-context").getByText("D:/Research/optics", { exact: true })).toBeVisible()
  84. })
  85. test("project creation supports focus, Chinese composition and cancellation", async ({ page }) => {
  86. await page.goto("/e2e/paas/index.html")
  87. await page.getByLabel("API Key", { exact: true }).fill("project-keyboard")
  88. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  89. const toggle = page.getByRole("button", { name: "新建项目", exact: true })
  90. await toggle.click()
  91. const name = page.getByLabel("项目名称", { exact: true })
  92. await expect(name).toBeFocused()
  93. await name.fill("材料研究")
  94. const cancelled = await name.evaluate(
  95. (input) =>
  96. !input.dispatchEvent(
  97. new KeyboardEvent("keydown", {
  98. key: "Enter",
  99. isComposing: true,
  100. bubbles: true,
  101. cancelable: true,
  102. }),
  103. ),
  104. )
  105. expect(cancelled).toBe(true)
  106. await expect(name).toBeVisible()
  107. await name.press("Escape")
  108. await expect(name).toHaveCount(0)
  109. await expect(toggle).toBeFocused()
  110. await expect(page.getByLabel("切换项目").locator("option", { hasText: "材料研究" })).toHaveCount(0)
  111. })
  112. test("role overrides can return to automatic matching without losing the draft", async ({ page }) => {
  113. await page.goto("/e2e/paas/index.html?agent-groups")
  114. await page.getByLabel("API Key", { exact: true }).fill("role-reset")
  115. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  116. const input = page.getByRole("textbox", { name: "消息", exact: true })
  117. await input.fill("合并 CSV 并画趋势图")
  118. const summary = page.locator(".paas-agent-route > summary")
  119. const menu = page.locator(".paas-agent-route")
  120. await summary.click()
  121. await page.getByLabel("选择执行角色").selectOption({ label: "工作区助手" })
  122. await expect(summary).toContainText("指定")
  123. await summary.click()
  124. await expect(menu).toContainText("已按你的选择指定角色")
  125. await page.getByLabel("选择执行角色").selectOption("")
  126. await expect(summary).toContainText("自动 · data67")
  127. await expect(input).toHaveValue("合并 CSV 并画趋势图")
  128. await summary.click()
  129. await page.keyboard.press("Escape")
  130. await expect(menu).not.toHaveAttribute("open", "")
  131. await expect(summary).toBeFocused()
  132. await summary.click()
  133. await input.click()
  134. await expect(menu).not.toHaveAttribute("open", "")
  135. })
  136. test("project folder errors are recoverable without changing the saved folders", async ({ page }) => {
  137. await page.goto("/e2e/paas/index.html?ux")
  138. await page.getByLabel("API Key", { exact: true }).fill("folder-retry")
  139. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  140. await page.getByRole("button", { name: "项目设置", exact: true }).click()
  141. await page.evaluate(() => Object.assign(Reflect.get(window, "paasUX"), { directoryError: "picker failed" }))
  142. await page.getByRole("button", { name: "添加工作文件夹", exact: true }).click()
  143. await expect(page.getByRole("alert")).toContainText("未能打开文件夹选择器")
  144. await expect(page.locator(".paas-project-folder-card")).toHaveCount(0)
  145. await page.evaluate(() => Object.assign(Reflect.get(window, "paasUX"), { directoryError: "" }))
  146. await page.getByRole("button", { name: "添加工作文件夹", exact: true }).click()
  147. await expect(page.locator(".paas-project-folder-card")).toContainText("D:/Research/optics")
  148. await page.getByRole("button", { name: "完成", exact: true }).click()
  149. await expect(page.locator(".paas-composer-context")).toContainText("D:/Research/optics")
  150. })
  151. for (const width of [360, 520]) {
  152. test(`role chooser stays within a ${width}px window`, async ({ page }) => {
  153. await page.setViewportSize({ width, height: 740 })
  154. await page.emulateMedia({ colorScheme: "dark" })
  155. await page.goto("/e2e/paas/index.html?agent-groups")
  156. await page.getByLabel("API Key", { exact: true }).fill(`narrow-${width}`)
  157. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  158. await page.locator(".paas-agent-route > summary").click()
  159. const panel = page.locator(".paas-agent-route-panel")
  160. await expect(panel).toBeVisible()
  161. const bounds = await panel.boundingBox()
  162. expect(bounds!.x).toBeGreaterThanOrEqual(0)
  163. expect(bounds!.x + bounds!.width).toBeLessThanOrEqual(width)
  164. await expect(page.getByLabel("选择执行角色")).toBeVisible()
  165. expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(width)
  166. })
  167. }