inbox.spec.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import { expect, test } from "@playwright/test"
  2. test("completed research appears in inbox until opened", async ({ page }) => {
  3. await page.goto("/e2e/paas/index.html?completed")
  4. await page.getByLabel("API Key", { exact: true }).fill("inbox-test")
  5. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  6. await page
  7. .getByRole("button", { name: /已有研究/ })
  8. .first()
  9. .click()
  10. const inbox = page.getByRole("button", { name: /^通知:/ })
  11. await expect(inbox).toBeVisible()
  12. await page.getByRole("button", { name: "平台任务", exact: true }).click()
  13. await expect(page.getByRole("heading", { name: "平台任务", exact: true })).toBeVisible()
  14. await expect(page.getByRole("heading", { name: "研究计划", exact: true })).not.toBeVisible()
  15. await inbox.click()
  16. await page
  17. .getByRole("dialog", { name: "任务通知" })
  18. .getByRole("button", { name: /已有研究/ })
  19. .click()
  20. await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toBeVisible()
  21. await expect(page.getByRole("button", { name: /^通知:/ })).toHaveCount(0)
  22. })
  23. test("inbox panel closes on Escape inside it and on an outside pointer click", async ({ page }) => {
  24. await page.goto("/e2e/paas/index.html?completed")
  25. await page.getByLabel("API Key", { exact: true }).fill("inbox-escape")
  26. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  27. await page
  28. .getByRole("button", { name: /已有研究/ })
  29. .first()
  30. .click()
  31. const inbox = page.getByRole("button", { name: /^通知:/ })
  32. const panel = page.getByRole("dialog", { name: "任务通知" })
  33. await inbox.click()
  34. await expect(panel).toBeVisible()
  35. await page.getByRole("textbox", { name: "消息", exact: true }).focus()
  36. await page.keyboard.press("Escape")
  37. await expect(panel).toBeVisible()
  38. await inbox.focus()
  39. await page.keyboard.press("Escape")
  40. await expect(panel).toHaveCount(0)
  41. await expect(inbox).toBeFocused()
  42. await inbox.click()
  43. await expect(panel).toBeVisible()
  44. await page.locator(".paas-conversation").click({ position: { x: 8, y: 8 } })
  45. await expect(panel).toHaveCount(0)
  46. })
  47. test("non-active completed chat is recovered from the task index after reload", async ({ page }) => {
  48. const connect = async (apiKey: string) => {
  49. await page.getByLabel("API Key", { exact: true }).fill(apiKey)
  50. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  51. await page.getByRole("textbox", { name: "消息", exact: true }).waitFor()
  52. }
  53. await page.goto("/e2e/paas/index.html?completed")
  54. await connect("inbox-recover")
  55. await page
  56. .getByRole("button", { name: /已有研究/ })
  57. .first()
  58. .click()
  59. await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toBeVisible()
  60. await expect(page.getByRole("button", { name: /^通知:/ })).toBeVisible()
  61. // Switch to another chat with a saved draft so the completed chat is persisted but not active.
  62. await page.locator(".paas-chat-header-actions").getByRole("button", { name: "新会话", exact: true }).click()
  63. await expect(page.locator(".paas-topbar-chat-title")).toHaveText("新会话")
  64. await page.getByRole("textbox", { name: "消息", exact: true }).fill("让完成会话保持非活动")
  65. await page.reload()
  66. await connect("inbox-recover")
  67. // The completed history is never opened here; its cache loads without messages.
  68. await expect(page.locator(".paas-topbar-chat-title")).toHaveText("新会话")
  69. await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toHaveCount(0)
  70. await page.locator(".paas-sidebar").getByRole("button", { name: "平台任务", exact: true }).click()
  71. await expect(page.locator(".paas-task-title")).toHaveText("分析材料")
  72. const inbox = page.getByRole("button", { name: /^通知:/ })
  73. await expect(inbox).toBeVisible()
  74. await inbox.click()
  75. await expect(page.getByRole("dialog", { name: "任务通知" }).getByRole("button", { name: /已有研究/ })).toBeVisible()
  76. })
  77. test("opening an approval keeps it listed in inbox", async ({ page }) => {
  78. await page.goto("/e2e/paas/index.html")
  79. await page.getByLabel("API Key", { exact: true }).fill("inbox-approval")
  80. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  81. await page
  82. .getByRole("button", { name: /已有研究/ })
  83. .first()
  84. .click()
  85. await page.getByRole("button", { name: /^通知:/ }).click()
  86. const panel = page.getByRole("dialog", { name: "任务通知" })
  87. await panel.getByRole("button", { name: /已有研究/ }).click()
  88. await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toBeVisible()
  89. await expect(page.getByRole("dialog", { name: "任务通知" })).toHaveCount(0)
  90. await expect(page.getByRole("button", { name: /^通知:/ })).toBeVisible()
  91. })
  92. test("completed unread stays read after a reload", async ({ page }) => {
  93. await page.goto("/e2e/paas/index.html?completed")
  94. await page.getByLabel("API Key", { exact: true }).fill("inbox-reload")
  95. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  96. await page
  97. .getByRole("button", { name: /已有研究/ })
  98. .first()
  99. .click()
  100. const inbox = page.getByRole("button", { name: /^通知:/ })
  101. await expect(inbox).toBeVisible()
  102. await inbox.click()
  103. await page
  104. .getByRole("dialog", { name: "任务通知" })
  105. .getByRole("button", { name: /已有研究/ })
  106. .click()
  107. await expect(page.getByRole("button", { name: /^通知:/ })).toHaveCount(0)
  108. await page.reload()
  109. await page.getByLabel("API Key", { exact: true }).fill("inbox-reload")
  110. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  111. await page
  112. .getByRole("button", { name: /已有研究/ })
  113. .first()
  114. .click()
  115. await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toBeVisible()
  116. await expect(page.getByRole("button", { name: /^通知:/ })).toHaveCount(0)
  117. })
  118. for (const width of [360, 520]) {
  119. test(`inbox stays within a ${width}px window and restores focus when closed`, async ({ page }) => {
  120. await page.goto("/e2e/paas/index.html?completed")
  121. await page.getByLabel("API Key", { exact: true }).fill(`inbox-width-${width}`)
  122. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  123. await page
  124. .getByRole("button", { name: /已有研究/ })
  125. .first()
  126. .click()
  127. await page.setViewportSize({ width, height: 650 })
  128. const toggle = page.getByRole("button", { name: /^通知:/ })
  129. await toggle.click()
  130. const panel = page.getByRole("dialog", { name: "任务通知" })
  131. const bounds = await panel.boundingBox()
  132. expect(bounds!.x).toBeGreaterThanOrEqual(0)
  133. expect(bounds!.x + bounds!.width).toBeLessThanOrEqual(width)
  134. expect(bounds!.y + bounds!.height).toBeLessThanOrEqual(650)
  135. await page.getByRole("button", { name: "关闭任务通知", exact: true }).click()
  136. await expect(panel).toHaveCount(0)
  137. await expect(toggle).toBeFocused()
  138. })
  139. }
  140. test("unloaded inbox results stay unread after a failed fetch, then open the exact run on retry", async ({ page }) => {
  141. await page.goto("/e2e/paas/index.html?ux")
  142. await page.getByLabel("API Key", { exact: true }).fill("inbox-load")
  143. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  144. await page.getByRole("textbox", { name: "消息", exact: true }).fill("最初的研究")
  145. await page.getByRole("button", { name: "发送消息", exact: true }).click()
  146. await expect(page.getByRole("button", { name: "暂停", exact: true })).toBeVisible()
  147. await page.evaluate(() => {
  148. window.paasUX.update("ux_1", { status: "completed", output: "第一轮研究结果" })
  149. })
  150. await page.getByRole("button", { name: "刷新状态", exact: true }).click()
  151. await expect(page.getByText("第一轮研究结果", { exact: true }).first()).toBeVisible()
  152. await page.getByRole("textbox", { name: "消息", exact: true }).fill("保留的草稿")
  153. await page.evaluate(() => {
  154. window.paasUX.add({
  155. run_id: "external_result",
  156. agent_id: "research",
  157. thread_id: "thread_ux_1",
  158. status: "completed",
  159. input: "另一轮研究",
  160. output: "# 新增研究成果\n\n完成证据核验。",
  161. updated_at: "2026-11-30T12:00:00Z",
  162. })
  163. Object.assign(window.paasUX, { threadError: "模拟会话读取失败" })
  164. })
  165. await page.getByRole("button", { name: "平台任务", exact: true }).click()
  166. const toggle = page.getByRole("button", { name: /^通知:/ })
  167. await expect(toggle).toBeVisible()
  168. await toggle.click()
  169. await page
  170. .getByRole("dialog", { name: "任务通知" })
  171. .getByRole("button", { name: /另一轮研究/ })
  172. .click()
  173. await expect(page.getByRole("alert")).toBeVisible()
  174. await page.getByText("查看错误详情", { exact: true }).click()
  175. await expect(page.getByText("模拟会话读取失败", { exact: true })).toBeVisible()
  176. await expect(toggle).toBeVisible()
  177. await page.evaluate(() => Object.assign(window.paasUX, { threadError: "" }))
  178. await toggle.click()
  179. await page
  180. .getByRole("dialog", { name: "任务通知" })
  181. .getByRole("button", { name: /另一轮研究/ })
  182. .click()
  183. const target = page.locator('.paas-chat-message[data-run-id="external_result"]')
  184. await expect(target).toBeFocused()
  185. await expect(target).toContainText("新增研究成果")
  186. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toHaveValue("保留的草稿")
  187. await expect(page.getByRole("button", { name: /^通知:/ })).toBeVisible()
  188. })