round2.spec.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import { expect, test, type Page } from "@playwright/test"
  2. async function connect(page: Page) {
  3. await page.goto("/e2e/paas/index.html?ux")
  4. await page.getByLabel("API Key", { exact: true }).fill("round2-test")
  5. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  6. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled()
  7. }
  8. test("settings survive navigation, stay unapplied until saved, and can be discarded", async ({ page }) => {
  9. await connect(page)
  10. await page.getByRole("button", { name: "研究设置", exact: true }).click()
  11. const rounds = page.getByLabel("最多研究轮次", { exact: true })
  12. await expect(rounds).toHaveValue("4")
  13. await rounds.fill("8")
  14. await page.getByRole("button", { name: "返回工作台" }).click()
  15. await page.getByRole("button", { name: "研究设置", exact: true }).click()
  16. await expect(rounds).toHaveValue("8")
  17. await expect(page.getByText(/已恢复未保存的修改/)).toBeVisible()
  18. expect(await page.evaluate(() => window.paasTestCalls.filter((c) => c.action === "update-agent"))).toHaveLength(0)
  19. await page.getByRole("button", { name: "放弃草稿并读取最新配置" }).click()
  20. await expect(rounds).toHaveValue("4")
  21. await rounds.fill("7")
  22. await page.getByRole("button", { name: /保存修改/ }).click()
  23. await page.getByRole("button", { name: "研究设置", exact: true }).click()
  24. await expect(rounds).toHaveValue("7")
  25. await expect(page.getByText(/已恢复未保存的修改/)).toHaveCount(0)
  26. })
  27. test("settings from an older version are retained but cannot silently overwrite newer settings", async ({ page }) => {
  28. await connect(page)
  29. await page.getByRole("button", { name: "研究设置", exact: true }).click()
  30. await page.getByLabel("最多研究轮次", { exact: true }).fill("8")
  31. await page.getByRole("button", { name: "返回工作台" }).click()
  32. await page.evaluate(() => {
  33. window.paasUX.configVersion = "version-2"
  34. })
  35. await page.getByRole("button", { name: "研究设置", exact: true }).click()
  36. await expect(page.getByLabel("最多研究轮次", { exact: true })).toHaveValue("8")
  37. await expect(page.getByText(/平台配置已更新,已保留你的草稿/)).toBeVisible()
  38. await page.getByRole("button", { name: /保存修改/ }).click()
  39. await expect(page.getByText(/配置版本已更新/)).toBeVisible()
  40. })
  41. test("report renders inline math without rewriting currency and code", async ({ page }, info) => {
  42. await connect(page)
  43. await page.evaluate(() =>
  44. window.paasUX.add({
  45. run_id: "math",
  46. agent_id: "research",
  47. thread_id: "math",
  48. input: "公式验收",
  49. status: "completed",
  50. output:
  51. "# 数学报告\n\n判断 $\\delta > 0$,区间 \\(x \\in [0,1]\\)。\n\n$$x^2 + y^2 = 1$$\n\n预算 $5 和 $10。\n\n`$raw$`\n\n```text\n$literal$\n```",
  52. }),
  53. )
  54. await page.getByRole("button", { name: "平台任务", exact: true }).click()
  55. await page.getByLabel("项目范围", { exact: true }).selectOption("all")
  56. await page.getByRole("button", { name: "刷新任务", exact: true }).click()
  57. await page.getByRole("row").filter({ hasText: "公式验收" }).getByRole("button", { name: "打开任务" }).click()
  58. await page.getByRole("button", { name: "阅读与对比", exact: true }).click()
  59. const dialog = page.getByRole("dialog")
  60. await expect(dialog.locator(".katex")).toHaveCount(3)
  61. await expect(dialog).toContainText("预算 $5 和 $10")
  62. await expect(dialog.locator("code").filter({ hasText: "$raw$" })).toBeVisible()
  63. await expect(dialog).toContainText("$literal$")
  64. await page.screenshot({ path: info.outputPath("math-report.png"), fullPage: true })
  65. })
  66. test("long tool activity loads recent entries first and retains access to older entries", async ({ page }) => {
  67. await connect(page)
  68. await page.getByRole("textbox", { name: "消息", exact: true }).fill("长任务")
  69. await page.getByRole("button", { name: "发送消息", exact: true }).click()
  70. await expect(page.getByRole("button", { name: "暂停", exact: true })).toBeVisible()
  71. await page.evaluate(() => {
  72. const executionID = String(window.paasTestCalls.find((c) => c.action === "execute")?.executionID)
  73. for (let i = 0; i < 123; i++)
  74. window.paasUX.progress({ executionID, type: "tool_result", tool: "lookup", content: `活动记录 ${i + 1}` })
  75. })
  76. const activity = page.locator(".paas-activity").first()
  77. await expect(activity.locator("li")).toHaveCount(0)
  78. await activity.locator("summary").first().click()
  79. await expect(activity.locator("li")).toHaveCount(50)
  80. await expect(activity).toContainText("活动记录 123")
  81. await activity.getByRole("button", { name: /加载更早活动/ }).click()
  82. await expect(activity.locator("li")).toHaveCount(80)
  83. await expect(activity).toContainText("活动记录 44")
  84. await expect(activity.getByRole("button", { name: /加载更早活动/ })).toHaveCount(0)
  85. })
  86. test("remote workspaces explain downloading files instead of offering a broken local open", async ({ page }) => {
  87. await page.goto("/e2e/paas/index.html?ux")
  88. await page.getByLabel("平台地址", { exact: true }).fill("https://remote.example")
  89. await page.getByLabel("API Key", { exact: true }).fill("round2-test")
  90. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  91. await page.locator(".paas-more-actions > summary").click()
  92. await expect(page.getByRole("button", { name: "在开发区打开工作区", exact: true })).toBeDisabled()
  93. await expect(page.getByText(/远程目录不能直接在本机打开/)).toBeVisible()
  94. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled()
  95. })
  96. test("a failed settings reload does not erase the retained draft", async ({ page }) => {
  97. await connect(page)
  98. await page.getByRole("button", { name: "研究设置", exact: true }).click()
  99. await page.getByLabel("最多研究轮次", { exact: true }).fill("9")
  100. await page.getByRole("button", { name: "返回工作台" }).click()
  101. await page.evaluate(() => {
  102. window.paasUX.configError = true
  103. })
  104. await page.getByRole("button", { name: "研究设置", exact: true }).click()
  105. await expect(page.getByText("配置服务暂时不可用")).toBeVisible()
  106. await page.getByRole("button", { name: "返回工作台" }).click()
  107. await page.evaluate(() => {
  108. window.paasUX.configError = false
  109. })
  110. await page.getByRole("button", { name: "研究设置", exact: true }).click()
  111. await expect(page.getByLabel("最多研究轮次", { exact: true })).toHaveValue("9")
  112. })