project-workflow.spec.ts 9.8 KB

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