polish.spec.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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("polish-test")
  5. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  6. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled()
  7. }
  8. test("optional resource probes never block research and model invocation is explicit", async ({ page }) => {
  9. await connect(page)
  10. await expect(page.getByRole("button", { name: "定时任务", exact: true })).toHaveCount(0)
  11. await page.getByRole("button", { name: "平台设置", exact: true }).click()
  12. await page.getByRole("tab", { name: "资源检查", exact: true }).click()
  13. await page.getByRole("button", { name: "检查资源", exact: true }).click()
  14. await page.getByRole("button", { name: "测试模型连接", exact: true }).click()
  15. await page.getByRole("button", { name: "直接开始任务", exact: true }).click()
  16. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled()
  17. const calls = await page.evaluate(() => window.paasTestCalls)
  18. expect(calls.filter((c) => c.action === "verify").map((c) => c.checkModel)).toEqual([false, true])
  19. expect(calls.filter((c) => c.action === "execute")).toHaveLength(0)
  20. })
  21. test("continuation keeps a compact reference across reload and submits the original report once", async ({ page }) => {
  22. await connect(page)
  23. await page.getByRole("textbox", { name: "消息", exact: true }).fill("研究初稿")
  24. await page.getByRole("button", { name: "发送消息", exact: true }).click()
  25. await expect(page.getByRole("button", { name: "暂停", exact: true })).toBeVisible()
  26. await page.evaluate(() =>
  27. window.paasUX.update("ux_1", { status: "completed", output: "# 原始方案\n证据甲,不可丢失。" }),
  28. )
  29. await page.getByRole("button", { name: "刷新状态", exact: true }).click()
  30. await page.getByRole("textbox", { name: "消息", exact: true }).fill("补充对照设计")
  31. await page.getByRole("button", { name: "基于此方案继续", exact: true }).click()
  32. await page.getByRole("button", { name: "基于此方案继续", exact: true }).click()
  33. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toHaveValue("补充对照设计")
  34. await expect(page.getByLabel("已引用研究报告")).toHaveCount(1)
  35. await page.reload()
  36. await page.getByLabel("API Key", { exact: true }).fill("polish-test")
  37. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  38. await expect(page.getByLabel("已引用研究报告")).toContainText("证据甲")
  39. await page.getByRole("button", { name: "发送消息", exact: true }).click()
  40. const calls = await page.evaluate(() => window.paasTestCalls.filter((c) => c.action === "execute"))
  41. expect(calls).toHaveLength(1)
  42. expect(String(calls[0].input).match(/证据甲/g)).toHaveLength(1)
  43. expect(calls[0].input).toContain("补充对照设计")
  44. await expect(page.getByLabel("已引用研究报告")).toHaveCount(0)
  45. })
  46. test("report reader compares versions and passes the selected export format", async ({ page }, info) => {
  47. await connect(page)
  48. await page.evaluate(() => {
  49. window.paasUX.add({
  50. run_id: "v1",
  51. agent_id: "research",
  52. thread_id: "report",
  53. input: "版本一",
  54. output: "# 方案\n\n旧条件",
  55. status: "completed",
  56. })
  57. window.paasUX.add({
  58. run_id: "v2",
  59. agent_id: "research",
  60. thread_id: "report",
  61. input: "版本二",
  62. output: "# 方案\n\n新条件",
  63. status: "completed",
  64. })
  65. })
  66. await page.getByRole("button", { name: "平台任务", exact: true }).click()
  67. await page.getByLabel("项目范围", { exact: true }).selectOption("all")
  68. await page.getByRole("button", { name: "刷新任务", exact: true }).click()
  69. await page.getByRole("row").filter({ hasText: "版本二" }).getByRole("button", { name: "打开任务" }).click()
  70. await page.getByRole("button", { name: "阅读与对比", exact: true }).last().click()
  71. const dialog = page.getByRole("dialog")
  72. await dialog.getByRole("button", { name: "对比此前报告", exact: true }).click()
  73. await expect(dialog.locator('[data-change="added"]')).toContainText("新条件")
  74. await expect(dialog.locator('[data-change="removed"]')).toContainText("旧条件")
  75. await dialog.getByRole("button", { name: "导出 Word", exact: true }).click()
  76. expect(
  77. await page.evaluate(() => window.paasTestCalls.filter((c) => c.action === "export-report").at(-1)?.format),
  78. ).toBe("docx")
  79. await page.screenshot({ path: info.outputPath("report-reader.png"), fullPage: true })
  80. })
  81. test("research progress displays reported usage and outstanding work without inventing completion", async ({
  82. page,
  83. }, info) => {
  84. await connect(page)
  85. await page.getByRole("textbox", { name: "消息", exact: true }).fill("过程验收")
  86. await page.getByRole("button", { name: "发送消息", exact: true }).click()
  87. await expect(page.getByRole("button", { name: "暂停", exact: true })).toBeVisible()
  88. await page.evaluate(() =>
  89. window.paasUX.update("ux_1", {
  90. stage_name: "方案审阅",
  91. usage: { total_tokens: 42000, usage_complete: false },
  92. research: {
  93. science: {
  94. main_flow: { rounds_completed: 2 },
  95. next_step: "补充实验条件",
  96. outcome: { sections: [{ title: "已有产物与待办", lines: ["待办:核对适用范围"] }] },
  97. },
  98. },
  99. }),
  100. )
  101. await page.getByRole("button", { name: "刷新状态", exact: true }).click()
  102. await expect(page.getByLabel("研究进展")).toContainText("42,000")
  103. await expect(page.getByLabel("研究进展")).toContainText("方案审阅")
  104. await expect(page.getByLabel("研究进展")).toContainText("用量仍在汇总")
  105. await page.getByLabel("研究进展").scrollIntoViewIfNeeded()
  106. await page.screenshot({ path: info.outputPath("research-progress.png"), fullPage: true })
  107. })