artifacts.spec.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { expect, test } from "@playwright/test"
  2. test("project artifact library aggregates ended runs and previews files", async ({ page }) => {
  3. await page.goto("/e2e/paas/index.html?completed&files")
  4. await page.getByLabel("API Key", { exact: true }).fill("artifacts")
  5. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  6. await page
  7. .getByRole("button", { name: /已有研究/ })
  8. .first()
  9. .click()
  10. await page.locator(".paas-sidebar").getByRole("button", { name: "成果", exact: true }).click()
  11. await expect(page.getByRole("heading", { name: "成果", exact: true })).toBeVisible()
  12. const group = page.getByRole("region", { name: "已有研究 的成果" })
  13. await expect(group).toBeVisible()
  14. await expect(group.getByText("研究计划.pdf", { exact: true })).toBeVisible()
  15. await expect(group.getByText("研究计划.md", { exact: true })).toBeVisible()
  16. await expect(group.getByText("config.yml", { exact: true })).toHaveCount(0)
  17. await expect(page.getByText("7 个文件", { exact: true })).toBeVisible()
  18. // Different artifact IDs with equal names must remain individually accessible.
  19. await expect(group.getByText("manifest.json", { exact: true })).toHaveCount(2)
  20. await page.getByRole("button", { name: "预览 研究计划.md", exact: true }).click()
  21. const preview = page.getByLabel("右侧预览", { exact: true })
  22. await expect(preview).toBeVisible()
  23. await expect(preview.getByText("可预览的研究计划", { exact: true })).toBeVisible()
  24. await page.getByRole("button", { name: "保存 研究计划.md", exact: true }).click()
  25. await expect(page.getByText("已保存 研究计划.md", { exact: true })).toBeVisible()
  26. })
  27. test("artifact library filters by type and search", async ({ page }) => {
  28. await page.goto("/e2e/paas/index.html?completed&files")
  29. await page.getByLabel("API Key", { exact: true }).fill("artifacts-filter")
  30. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  31. await page
  32. .getByRole("button", { name: /已有研究/ })
  33. .first()
  34. .click()
  35. await page.locator(".paas-sidebar").getByRole("button", { name: "成果", exact: true }).click()
  36. const library = page.locator(".paas-artifact-page")
  37. await page.getByRole("button", { name: "数据 · 3", exact: true }).click()
  38. await expect(library.getByText("config.yml", { exact: true })).toHaveCount(0)
  39. await expect(library.getByText("研究计划.md", { exact: true })).toHaveCount(0)
  40. await page.getByRole("button", { name: "代码 · 1", exact: true }).click()
  41. await expect(library.getByText("analysis.py", { exact: true })).toBeVisible()
  42. await expect(library.getByText("config.yml", { exact: true })).toHaveCount(0)
  43. await page.getByRole("button", { name: "全部 · 7", exact: true }).click()
  44. await page.getByLabel("搜索成果", { exact: true }).fill("不存在")
  45. await expect(library.getByText("没有匹配的成果", { exact: true })).toBeVisible()
  46. await page.getByRole("button", { name: "清除筛选", exact: true }).click()
  47. await expect(library.getByText("研究计划.md", { exact: true })).toBeVisible()
  48. })
  49. test("artifact library switches between session and folder views", async ({ page }) => {
  50. await page.goto("/e2e/paas/index.html?completed&files")
  51. await page.getByLabel("API Key", { exact: true }).fill("artifacts-views")
  52. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  53. await page
  54. .getByRole("button", { name: /已有研究/ })
  55. .first()
  56. .click()
  57. await page.locator(".paas-sidebar").getByRole("button", { name: "成果", exact: true }).click()
  58. const group = page.getByRole("region", { name: "已有研究 的成果" })
  59. await expect(group.getByText("已完成", { exact: true })).toBeVisible()
  60. await page.getByRole("button", { name: "按目录", exact: true }).click()
  61. const tree = page.locator(".paas-artifact-tree")
  62. await expect(tree.getByText("根目录 · 2 个文件", { exact: true })).toBeVisible()
  63. await expect(tree.getByText("final", { exact: true })).toBeVisible()
  64. await expect(tree.getByText("work", { exact: true })).toBeVisible()
  65. await expect(tree.getByText("研究计划.md", { exact: true })).toBeVisible()
  66. await page.getByRole("button", { name: "按会话", exact: true }).click()
  67. await group.getByRole("button", { name: "打开会话", exact: true }).click()
  68. await expect(page.locator(".paas-topbar-page")).toHaveText("会话")
  69. })
  70. test("artifact library is scoped to the active project", async ({ page }) => {
  71. await page.goto("/e2e/paas/index.html?completed")
  72. await page.getByLabel("API Key", { exact: true }).fill("artifacts-scope")
  73. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  74. await page
  75. .getByRole("button", { name: /已有研究/ })
  76. .first()
  77. .click()
  78. await page.getByRole("button", { name: "新建项目", exact: true }).click()
  79. await page.getByLabel("项目名称", { exact: true }).fill("第二个项目")
  80. await page.getByRole("button", { name: "创建项目", exact: true }).click()
  81. await expect(page.getByLabel("切换项目", { exact: true })).toContainText("第二个项目")
  82. await page.locator(".paas-sidebar").getByRole("button", { name: "成果", exact: true }).click()
  83. await expect(page.getByText("还没有可归档的成果", { exact: true })).toBeVisible()
  84. await expect(page.getByText("研究计划.md", { exact: true })).toHaveCount(0)
  85. })
  86. declare global {
  87. interface Window {
  88. artifactUX: { failFiles: boolean; holdFiles: boolean; held: boolean; release(): void }
  89. }
  90. }
  91. test("partial artifact discovery remains visible, reports incompleteness and retries when reopened", async ({
  92. page,
  93. }) => {
  94. await page.goto("/e2e/paas/index.html?completed&files")
  95. await page.getByLabel("API Key", { exact: true }).fill("artifacts-partial")
  96. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  97. await page
  98. .getByRole("button", { name: /已有研究/ })
  99. .first()
  100. .click()
  101. await page.evaluate(() => {
  102. window.artifactUX.failFiles = true
  103. })
  104. await page.locator(".paas-sidebar").getByRole("button", { name: "成果", exact: true }).click()
  105. await expect(
  106. page.getByText("部分任务的成果暂未同步,已展示其余内容;可稍后刷新重试。", { exact: true }),
  107. ).toBeVisible()
  108. await expect(page.locator(".paas-artifact-page").getByText("研究计划成果.pdf", { exact: true })).toBeVisible()
  109. await page.locator(".paas-sidebar").getByRole("button", { name: "会话", exact: true }).click()
  110. await page.evaluate(() => {
  111. window.artifactUX.failFiles = false
  112. })
  113. await page.locator(".paas-sidebar").getByRole("button", { name: "成果", exact: true }).click()
  114. await expect(page.locator(".paas-artifact-page").getByText("研究计划.md", { exact: true })).toBeVisible()
  115. await expect(page.getByText("部分任务的成果暂未同步,已展示其余内容;可稍后刷新重试。", { exact: true })).toHaveCount(
  116. 0,
  117. )
  118. })
  119. test("late artifact results cannot populate a different project", async ({ page }) => {
  120. await page.goto("/e2e/paas/index.html?completed&files")
  121. await page.getByLabel("API Key", { exact: true }).fill("artifacts-late")
  122. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  123. await page
  124. .getByRole("button", { name: /已有研究/ })
  125. .first()
  126. .click()
  127. await page.evaluate(() => {
  128. window.artifactUX.holdFiles = true
  129. })
  130. await page.locator(".paas-sidebar").getByRole("button", { name: "成果", exact: true }).click()
  131. await expect.poll(() => page.evaluate(() => window.artifactUX.held)).toBe(true)
  132. await page.getByRole("button", { name: "新建项目", exact: true }).click()
  133. await page.getByLabel("项目名称", { exact: true }).fill("独立项目")
  134. await page.getByRole("button", { name: "创建项目", exact: true }).click()
  135. await page.evaluate(() => {
  136. window.artifactUX.holdFiles = false
  137. window.artifactUX.release()
  138. })
  139. await page.locator(".paas-sidebar").getByRole("button", { name: "成果", exact: true }).click()
  140. await expect(page.getByText("还没有可归档的成果", { exact: true })).toBeVisible()
  141. await expect(page.locator(".paas-artifact-page .paas-artifact-row")).toHaveCount(0)
  142. })