ux.spec.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import { expect, test, type Page } from "@playwright/test"
  2. async function connect(page: Page, key = "ux-account") {
  3. await page.getByLabel("平台地址", { exact: true }).fill("https://research.example")
  4. await page.getByLabel("API Key", { exact: true }).fill(key)
  5. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  6. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled()
  7. }
  8. async function run(page: Page, input: string) {
  9. await page.getByRole("textbox", { name: "消息", exact: true }).fill(input)
  10. await page.getByRole("button", { name: "发送消息", exact: true }).click()
  11. await expect(page.getByRole("button", { name: "暂停", exact: true })).toBeVisible()
  12. }
  13. test("parallel chats preserve next-round drafts, materials and active chat across reload and isolate accounts", async ({
  14. page,
  15. }) => {
  16. await page.goto("/e2e/paas/index.html?ux")
  17. await connect(page)
  18. await run(page, "第一项后台研究")
  19. const input = page.getByRole("textbox", { name: "消息", exact: true })
  20. await input.fill("第一项下一轮草稿")
  21. await expect(page.getByRole("button", { name: "发送消息", exact: true })).toBeDisabled()
  22. await page.locator(".paas-topbar-chat-actions").getByRole("button", { name: "新会话", exact: true }).click()
  23. await run(page, "第二项后台研究")
  24. await input.fill("第二项下一轮草稿")
  25. await page.getByRole("button", { name: /第一项后台研究/ }).click()
  26. await expect(input).toHaveValue("第一项下一轮草稿")
  27. await page.reload()
  28. await connect(page)
  29. await expect(input).toHaveValue("第一项下一轮草稿")
  30. // Reopening never repeats either execution; unresolved background jobs remain read-only until confirmed.
  31. expect(
  32. await page.evaluate(
  33. () =>
  34. (window as unknown as { paasTestCalls: { action: string }[] }).paasTestCalls.filter(
  35. (c) => c.action === "execute",
  36. ).length,
  37. ),
  38. ).toBe(0)
  39. await page.getByRole("button", { name: "平台设置", exact: true }).click()
  40. await page.getByRole("button", { name: "断开并忘记连接", exact: true }).click()
  41. await connect(page, "other-account")
  42. await expect(input).toHaveValue("")
  43. await expect(page.getByText("第一项后台研究", { exact: true })).toHaveCount(0)
  44. })
  45. test("partial upload failure keeps successful materials and retries only the failed file; drop works", async ({
  46. page,
  47. }) => {
  48. await page.goto("/e2e/paas/index.html?ux")
  49. await connect(page)
  50. await page.getByRole("button", { name: "添加文件", exact: true }).click()
  51. await expect(page.getByRole("button", { name: "移除成功.txt", exact: true })).toBeVisible()
  52. await page.getByRole("button", { name: "重试 重试.txt", exact: true }).click()
  53. await expect(page.getByRole("button", { name: "移除重试.txt", exact: true })).toBeVisible()
  54. expect(await page.evaluate(() => (window as unknown as { paasUX: { uploads: number } }).paasUX.uploads)).toBe(3)
  55. const transfer = await page.evaluateHandle(() => {
  56. const data = new DataTransfer()
  57. data.items.add(new File(["research"], "拖放.txt", { type: "text/plain" }))
  58. return data
  59. })
  60. await page.locator(".paas-composer").dispatchEvent("drop", { dataTransfer: transfer })
  61. await expect(page.getByRole("button", { name: "移除拖放.txt", exact: true })).toBeVisible()
  62. await page.getByRole("textbox", { name: "消息", exact: true }).fill("保留材料的草稿")
  63. await page.reload()
  64. await connect(page)
  65. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toHaveValue("保留材料的草稿")
  66. await expect(page.getByRole("button", { name: "移除成功.txt", exact: true })).toBeVisible()
  67. await expect(page.getByRole("button", { name: "移除重试.txt", exact: true })).toBeVisible()
  68. await expect(page.getByRole("button", { name: "移除拖放.txt", exact: true })).toBeVisible()
  69. })
  70. test("unknown submission is recoverable without an automatic duplicate; task index opens the existing run", async ({
  71. page,
  72. }) => {
  73. await page.goto("/e2e/paas/index.html?ux")
  74. await connect(page)
  75. await page.getByRole("textbox", { name: "消息", exact: true }).fill("模拟网络中断")
  76. await page.getByRole("button", { name: "发送消息", exact: true }).click()
  77. await page.getByRole("button", { name: "恢复原输入与材料", exact: true }).click()
  78. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toHaveValue("模拟网络中断")
  79. await expect(page.getByRole("button", { name: "发送消息", exact: true })).toBeDisabled()
  80. await page.locator(".paas-topbar-chat-actions").getByRole("button", { name: "新会话", exact: true }).click()
  81. await run(page, "任务中心可打开的研究")
  82. await page.getByRole("button", { name: "平台任务", exact: true }).click()
  83. await page.getByRole("button", { name: "刷新任务", exact: true }).click()
  84. await expect(page.getByRole("table")).toContainText("任务中心可打开的研究")
  85. await page.getByRole("button", { name: "打开任务", exact: true }).click()
  86. await expect(page.getByRole("button", { name: "暂停", exact: true })).toBeVisible()
  87. expect(
  88. await page.evaluate(
  89. () =>
  90. (window as unknown as { paasTestCalls: { action: string }[] }).paasTestCalls.filter(
  91. (c) => c.action === "execute",
  92. ).length,
  93. ),
  94. ).toBe(2)
  95. })
  96. test("reports render tables and math; background updates do not pull the reader down", async ({ page }) => {
  97. const errors: string[] = []
  98. page.on("pageerror", (error) => errors.push(error.message))
  99. await page.goto("/e2e/paas/index.html?ux")
  100. await connect(page)
  101. await run(page, "阅读长报告")
  102. await page.evaluate(() => {
  103. const control = (window as unknown as { paasUX: { update(id: string, value: Record<string, unknown>): void } })
  104. .paasUX
  105. control.update("ux_1", {
  106. output:
  107. "# 研究报告\n\n| 指标 | 结果 |\n|---|---|\n| 样本 | 42 |\n\n$$E=mc^2$$\n\n" +
  108. Array.from({ length: 35 }, (_, i) => `第 ${i + 1} 节研究分析。\n\n`).join(""),
  109. })
  110. })
  111. await expect(page.locator(".paas-report table")).toBeVisible({ timeout: 10000 })
  112. await expect(page.locator(".paas-report .katex")).toBeVisible()
  113. const log = page.getByRole("log", { name: "会话消息" })
  114. await log.evaluate((el) => {
  115. el.scrollTop = 0
  116. el.dispatchEvent(new Event("scroll"))
  117. })
  118. await page.evaluate(() => {
  119. const control = (
  120. window as unknown as {
  121. paasUX: { update(id: string, value: Record<string, unknown>): void; run(id: string): { output: string } }
  122. }
  123. ).paasUX
  124. control.update("ux_1", { output: control.run("ux_1").output + "\n\n新的研究进展。" })
  125. })
  126. await expect(page.getByRole("button", { name: "有新进展 · 回到底部", exact: true })).toBeVisible({ timeout: 10000 })
  127. expect(await log.evaluate((el) => el.scrollTop)).toBeLessThan(80)
  128. await page.getByRole("button", { name: "有新进展 · 回到底部", exact: true }).click()
  129. await expect(page.getByRole("button", { name: "有新进展 · 回到底部", exact: true })).toHaveCount(0)
  130. expect(errors).toEqual([])
  131. await page.screenshot({ path: "/tmp/lambda-desktop-ux-report.png", fullPage: true })
  132. })
  133. test("background task approval produces a navigable notice and readable confirmation", async ({ page }) => {
  134. await page.goto("/e2e/paas/index.html?ux")
  135. await connect(page)
  136. await run(page, "需要确认的后台研究")
  137. await page.getByRole("button", { name: "平台任务", exact: true }).click()
  138. await page.getByRole("button", { name: "刷新任务", exact: true }).click()
  139. await expect(page.getByRole("table")).toContainText("运行中")
  140. await page.evaluate(() => {
  141. const control = (window as unknown as { paasUX: { update(id: string, value: Record<string, unknown>): void } })
  142. .paasUX
  143. control.update("ux_1", {
  144. status: "running",
  145. pending_approval: {
  146. approval_id: "approve_ux",
  147. stage_name: "实验方案审阅",
  148. prompt: "请核对实验设置后继续。",
  149. artifacts: [{ name: "实验方案.md" }],
  150. },
  151. })
  152. })
  153. await expect(page.getByLabel("任务通知", { exact: true })).toContainText("等待人工确认", { timeout: 15000 })
  154. await page
  155. .getByLabel("任务通知", { exact: true })
  156. .getByRole("button", { name: /等待人工确认/ })
  157. .click()
  158. await expect(page.getByText("当前阶段:实验方案审阅", { exact: true })).toBeVisible()
  159. await expect(page.getByText("待确认成果:实验方案.md", { exact: true })).toBeVisible()
  160. await expect(page.getByRole("button", { name: "同意并继续", exact: true })).toBeVisible()
  161. await expect(page.getByRole("button", { name: "发送消息", exact: true })).toBeDisabled()
  162. })