workspace-chat.spec.ts 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019
  1. import { test, expect, type Page } from '@playwright/test'
  2. import { writeFile } from 'node:fs/promises'
  3. async function login(page: Page) {
  4. await page.goto('/conversations')
  5. await page.getByRole('textbox', { name: '账号', exact: true }).fill('fixture')
  6. await page.getByRole('textbox', { name: '密码', exact: true }).fill('fixture-pass')
  7. await page.getByRole('button', { name: '登录', exact: true }).click()
  8. await expect(page.getByRole('heading', { name: '还没有聊天' })).toBeVisible()
  9. }
  10. async function openCreate(page: Page, name: '新建 Bot' | '新建群聊') {
  11. await page.locator('.desktop-sidebar .sidebar-create-trigger').click()
  12. await page.getByRole('menuitem', { name, exact: true }).click()
  13. }
  14. async function createAgent(page: Page, name: string) {
  15. await openCreate(page, '新建 Bot')
  16. const dialog = page.getByRole('dialog')
  17. await dialog.getByRole('textbox', { name: '名称', exact: true }).fill(name)
  18. await dialog
  19. .getByRole('textbox', { name: '角色提示词与规则', exact: true })
  20. .fill(`你是${name},每次回复给出验收证据。`)
  21. await dialog.getByRole('button', { name: `使用颜色 ${name === '产品经理' ? '#ff6b00' : '#00b9ac'}`, exact: true }).click()
  22. await dialog.locator('.mascot-grid--shape button').filter({ hasText: name === '产品经理' ? '圆形' : '小三角' }).first().click()
  23. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  24. await expect(page.getByRole('heading', { name, exact: true })).toBeVisible()
  25. }
  26. for (const { surface, kind } of [
  27. { surface: 'Web', kind: 'direct' }, { surface: 'desktop bridge', kind: 'direct' },
  28. { surface: 'Web', kind: 'group' }, { surface: 'desktop bridge', kind: 'group' },
  29. ] as const) {
  30. test(`sending and queued Bot replies keep the ${kind} chat frame stable through ${surface}`, async ({ page }, testInfo) => {
  31. await page.setViewportSize({ width: surface === 'Web' ? 1280 : 1024, height: 800 })
  32. if (surface === 'desktop bridge') await page.addInitScript(() => {
  33. Object.assign(window, { yaoyaoDesktop: { deviceHost: async () => ({ deviceHost: 'local' }) } })
  34. })
  35. await login(page)
  36. const capabilities = await (await page.request.get('/api/realtime/capabilities')).json()
  37. const headers = { 'X-CSRF-Token': capabilities.csrfToken, Origin: new URL(page.url()).origin }
  38. const created = await page.request.post('/api/app/agents', { headers, data: { name: `发送布局验收 ${surface} ${kind}`, profile: 'default' } })
  39. expect(created.ok(), await created.text()).toBe(true)
  40. const agent = (await created.json()).agent
  41. const conversations = (await (await page.request.get('/api/app/conversations')).json()).conversations
  42. let conversation = conversations.find((c: any) => c.kind === 'direct' && c.memberIds[0] === agent.id)
  43. if (kind === 'group') {
  44. const peerResponse = await page.request.post('/api/app/agents', { headers, data: { name: `群聊布局成员 ${surface}`, profile: 'default' } })
  45. expect(peerResponse.ok(), await peerResponse.text()).toBe(true)
  46. const peer = (await peerResponse.json()).agent
  47. const groupResponse = await page.request.post('/api/app/conversations', { headers, data: {
  48. name: `发送布局群 ${surface}`, memberIds: [agent.id, peer.id], administratorId: agent.id, autoReplyIds: [agent.id],
  49. } })
  50. expect(groupResponse.ok(), await groupResponse.text()).toBe(true)
  51. conversation = (await groupResponse.json()).conversation
  52. }
  53. await page.goto(`/conversations/${conversation.id}`)
  54. const input = page.locator('.composer-textarea')
  55. await input.fill('[hold-workspace] 先执行第一条消息')
  56. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  57. await expect(page.getByTestId('chat-run-thinking-dots')).toBeVisible()
  58. await expect(page.locator('.message--assistant')).toBeVisible()
  59. await expect(input).toHaveValue('')
  60. await input.fill('排队执行第二条消息')
  61. const messageIds = await page.locator('[data-message-id]').evaluateAll(rows => rows.map(row => row.getAttribute('data-message-id')))
  62. await page.evaluate(() => {
  63. const selectors = ['.timeline-header', '.timeline', '.composer-area', '.composer-shell', '.composer-textarea', '.composer-tools', '.composer-actions']
  64. const nodes = selectors.map(selector => document.querySelector(selector)!)
  65. const previousMessages = [...document.querySelectorAll('[data-message-id]')]
  66. const samples: Array<{ connected: boolean; rects: number[][] }> = []
  67. let frame: number
  68. const record = () => {
  69. samples.push({ connected: [...nodes, ...previousMessages].every(node => node.isConnected), rects: nodes.map(node => {
  70. const box = node.getBoundingClientRect(); return [box.x, box.y, box.width, box.height]
  71. }) })
  72. frame = requestAnimationFrame(record)
  73. }
  74. record()
  75. Object.assign(window, { stopSendLayoutRecording: () => { cancelAnimationFrame(frame); return { selectors, samples } } })
  76. })
  77. let release!: () => void
  78. const gate = new Promise<void>(resolve => { release = resolve })
  79. const pattern = `**/api/app/conversations/${conversation.id}/messages`
  80. await page.route(pattern, async route => {
  81. expect(route.request().postDataJSON().deviceHost).toBe(surface === 'Web' ? null : 'local')
  82. await gate; await route.continue()
  83. })
  84. try {
  85. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  86. await expect(page.locator('.composer-sending')).toBeVisible()
  87. await page.evaluate(async () => { for (let count = 0; count < 3; count++) await new Promise(requestAnimationFrame) })
  88. release()
  89. await expect(page.getByText('正在等待可用机器人', { exact: true })).toBeVisible()
  90. await expect(input).toHaveValue('')
  91. await expect(page.locator('[data-message-id]')).toHaveCount(messageIds.length + 1)
  92. await page.screenshot({ path: testInfo.outputPath('send-layout-queued.png') })
  93. await page.request.post('http://127.0.0.1:19120/__release')
  94. await expect(page.locator('.message--assistant')).toHaveCount(2)
  95. await page.request.post('http://127.0.0.1:19120/__release')
  96. await expect(page.getByTestId('chat-run-thinking-dots')).toHaveCount(0)
  97. await input.fill('完成后再发送一条普通消息')
  98. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  99. await expect(page.locator('.message--user')).toHaveCount(3)
  100. await expect(page.locator('.message--assistant')).toHaveCount(3)
  101. await page.request.post('http://127.0.0.1:19120/__release')
  102. await expect(page.getByTestId('chat-run-thinking-dots')).toHaveCount(0)
  103. await expect(input).toHaveValue('')
  104. } finally {
  105. release(); await page.unroute(pattern)
  106. }
  107. const recording = await page.evaluate(() => (window as unknown as { stopSendLayoutRecording(): { selectors: string[]; samples: { connected: boolean; rects: number[][] }[] } }).stopSendLayoutRecording())
  108. const recordingPath = testInfo.outputPath('send-layout-frames.json')
  109. await writeFile(recordingPath, JSON.stringify(recording, null, 2))
  110. await testInfo.attach('send-layout-frames.json', { path: recordingPath, contentType: 'application/json' })
  111. expect(recording.samples.every(sample => sample.connected)).toBe(true)
  112. for (const [index, selector] of recording.selectors.entries()) {
  113. for (let coordinate = 0; coordinate < 4; coordinate++) {
  114. const values = recording.samples.map(sample => sample.rects[index]![coordinate]!)
  115. expect(Math.max(...values) - Math.min(...values), `${selector} coordinate ${coordinate} shifted`).toBeLessThanOrEqual(1)
  116. }
  117. }
  118. })
  119. }
  120. test('UTF-8 attachments stay inside the composer and retain their names after sending and reload', async ({ page }, testInfo) => {
  121. await login(page)
  122. const capabilities = await (await page.request.get('/api/realtime/capabilities')).json()
  123. const headers = { 'X-CSRF-Token': capabilities.csrfToken, Origin: new URL(page.url()).origin }
  124. const created = await page.request.post('/api/app/agents', { headers, data: { name: '附件验收', profile: 'default' } })
  125. expect(created.ok(), await created.text()).toBe(true)
  126. const agent = (await created.json()).agent
  127. const conversations = (await (await page.request.get('/api/app/conversations')).json()).conversations
  128. const conversation = conversations.find((c: any) => c.kind === 'direct' && c.memberIds[0] === agent.id)
  129. await page.goto(`/conversations/${conversation.id}`)
  130. const name = '人工智能合同综合质量评估系统V2.0-信息采集表-待确认.docx'
  131. const certificate = 'CertificateSigningRequest.certSigningRequest'
  132. await page.locator('.composer-file-input').setInputFiles([
  133. { name, mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', buffer: Buffer.from('附件内容保持不变') },
  134. { name: certificate, mimeType: 'application/octet-stream', buffer: Buffer.from('certificate') },
  135. { name: '图片.png', mimeType: 'image/png', buffer: Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=', 'base64') },
  136. ])
  137. await page.locator('.composer-textarea').fill('请按格式填写附件')
  138. for (const width of [1280, 655, 375]) {
  139. await page.setViewportSize({ width, height: 863 })
  140. const attachments = page.locator('.composer-shell > .composer-attachments')
  141. await expect(attachments.locator('.composer-attachment')).toHaveCount(3)
  142. await expect(attachments).toContainText(name)
  143. await expect(attachments.getByRole('img', { name: '图片.png' })).toBeVisible()
  144. const shell = (await page.locator('.composer-shell').boundingBox())!
  145. const tray = (await attachments.boundingBox())!
  146. const input = (await page.locator('.composer-textarea').boundingBox())!
  147. expect(tray.x).toBeGreaterThan(shell.x)
  148. expect(tray.y).toBeGreaterThan(shell.y)
  149. expect(tray.x + tray.width).toBeLessThan(shell.x + shell.width)
  150. expect(input.y - (tray.y + tray.height)).toBeGreaterThanOrEqual(0)
  151. expect(input.y - (tray.y + tray.height)).toBeLessThanOrEqual(12)
  152. expect(input.y + input.height).toBeLessThan(shell.y + shell.height)
  153. expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true)
  154. await page.screenshot({ path: testInfo.outputPath(`composer-attachments-${width}.png`) })
  155. }
  156. await page.getByRole('button', { name: '移除 图片.png', exact: true }).click()
  157. await page.getByRole('button', { name: `移除 ${certificate}`, exact: true }).click()
  158. await expect(page.locator('.composer-attachment')).toHaveCount(1)
  159. await expect(page.locator('.composer-textarea')).toHaveValue('请按格式填写附件')
  160. const uploaded = page.waitForResponse(response => response.url().endsWith('/api/app/uploads') && response.request().method() === 'POST')
  161. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  162. expect((await (await uploaded).json()).files[0].name).toBe(name)
  163. const file = page.locator('.message-file').filter({ hasText: name })
  164. await expect(file).toBeVisible()
  165. await expect(file).toHaveAccessibleName(new RegExp(`预览文件 ${name}`))
  166. await expect(page.locator('.composer-attachment')).toHaveCount(0)
  167. await page.reload()
  168. await expect(file).toBeVisible()
  169. await page.screenshot({ path: testInfo.outputPath('utf8-attachment-message.png') })
  170. })
  171. test('Bot unread dots sync across viewers and neither detail nor read requests delay navigation', async ({ page, context }, testInfo) => {
  172. await login(page)
  173. const capabilities = await (await page.request.get('/api/realtime/capabilities')).json()
  174. const headers = { 'X-CSRF-Token': capabilities.csrfToken, Origin: new URL(page.url()).origin }
  175. const create = async (name: string) => {
  176. const response = await page.request.post('/api/app/agents', { headers, data: { name, profile: 'default' } })
  177. expect(response.ok(), await response.text()).toBe(true)
  178. return (await response.json()).agent
  179. }
  180. const first = await create('红点测试甲'), second = await create('红点测试乙')
  181. const conversations = (await (await page.request.get('/api/app/conversations')).json()).conversations
  182. const direct = conversations.find((c: any) => c.kind === 'direct' && c.memberIds[0] === first.id)
  183. const other = conversations.find((c: any) => c.kind === 'direct' && c.memberIds[0] === second.id)
  184. const groupResponse = await page.request.post('/api/app/conversations', { headers, data: { name: '红点测试群', memberIds: [first.id, second.id], administratorId: first.id } })
  185. expect(groupResponse.ok(), await groupResponse.text()).toBe(true)
  186. const group = (await groupResponse.json()).conversation
  187. await page.goto(`/conversations/${other.id}`)
  188. const viewer = await context.newPage()
  189. await viewer.goto(`/conversations/${other.id}`)
  190. try {
  191. for (const target of [direct, group]) {
  192. const sent = await page.request.post(`/api/app/conversations/${target.id}/messages`, { headers, data: { requestId: crypto.randomUUID(), content: '给出测试结果' } })
  193. expect(sent.ok(), await sent.text()).toBe(true)
  194. const row = page.locator(`.desktop-sidebar [data-sidebar-id="${target.id}"]`)
  195. const viewerRow = viewer.locator(`.desktop-sidebar [data-sidebar-id="${target.id}"]`)
  196. await expect(row.getByRole('img', { name: '未读', exact: true })).toBeVisible()
  197. await expect(viewerRow.getByRole('img', { name: '未读', exact: true })).toBeVisible()
  198. await expect(row.locator('b')).toHaveCount(0)
  199. await page.screenshot({ path: testInfo.outputPath(`unread-${target.kind}-dot.png`) })
  200. let releaseDetail!: () => void, releaseRead!: () => void
  201. const detailGate = new Promise<void>(resolve => { releaseDetail = resolve })
  202. const readGate = new Promise<void>(resolve => { releaseRead = resolve })
  203. const detailPattern = new RegExp(`/api/app/conversations/${target.id}(?:\\?.*)?$`)
  204. const readPattern = new RegExp(`/api/app/conversations/${target.id}/read(?:\\?.*)?$`)
  205. await page.route(detailPattern, async route => { await detailGate; await route.continue() })
  206. await page.route(readPattern, async route => { await readGate; await route.continue() })
  207. try {
  208. // Warm transcripts are already in the snapshot; a detail request is optional.
  209. await row.click()
  210. await expect(page.getByRole('heading', { name: target.name, exact: true })).toBeVisible()
  211. releaseDetail()
  212. await expect(page.getByRole('textbox', { name: '输入消息,Enter 发送,Shift + Enter 换行' })).toBeEnabled()
  213. await expect(row.getByRole('img', { name: '未读', exact: true })).toHaveCount(0)
  214. releaseRead()
  215. await expect(viewerRow.getByRole('img', { name: '未读', exact: true })).toHaveCount(0)
  216. } finally {
  217. releaseDetail(); releaseRead()
  218. await page.unroute(detailPattern); await page.unroute(readPattern)
  219. }
  220. await page.locator(`.desktop-sidebar [data-sidebar-id="${other.id}"]`).click()
  221. }
  222. await expect(page.getByRole('textbox', { name: '输入消息,Enter 发送,Shift + Enter 换行' })).toBeEnabled()
  223. await page.screenshot({ path: testInfo.outputPath('unread-desktop.png') })
  224. const sent = await page.request.post(`/api/app/conversations/${group.id}/messages`, { headers, data: { requestId: crypto.randomUUID(), content: '再次确认结果' } })
  225. expect(sent.ok(), await sent.text()).toBe(true)
  226. await page.setViewportSize({ width: 375, height: 812 })
  227. await page.emulateMedia({ colorScheme: 'dark', reducedMotion: 'reduce' })
  228. await page.goto('/conversations')
  229. await expect(page.getByRole('option').filter({ hasText: group.name }).getByRole('img', { name: '未读', exact: true })).toBeVisible()
  230. await page.screenshot({ path: testInfo.outputPath('unread-mobile.png') })
  231. } finally {
  232. await viewer.close()
  233. // This suite shares its fixture account; remove only the records created above.
  234. const archived = await page.request.patch(`/api/app/conversations/${group.id}`, { headers, data: { archived: true } })
  235. expect(archived.ok(), await archived.text()).toBe(true)
  236. const removed = await page.request.delete(`/api/app/conversations/${group.id}`, { headers })
  237. expect(removed.ok(), await removed.text()).toBe(true)
  238. for (const agent of [first, second]) {
  239. const archived = await page.request.patch(`/api/app/agents/${agent.id}`, { headers, data: { archived: true } })
  240. expect(archived.ok(), await archived.text()).toBe(true)
  241. const removed = await page.request.delete(`/api/app/agents/${agent.id}`, { headers })
  242. expect(removed.ok(), await removed.text()).toBe(true)
  243. }
  244. }
  245. })
  246. test('an open Web chat list receives cross-client sessions and real title events without reload', async ({
  247. page,
  248. context,
  249. }) => {
  250. await login(page)
  251. const pageAChannelOpened = page.waitForResponse(response =>
  252. response.request().method() === 'POST'
  253. && response.url().endsWith('/api/realtime/channels'))
  254. await page.goto('/chat')
  255. await pageAChannelOpened
  256. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  257. const marker = `${Date.now()}-${Math.random().toString(16).slice(2)}`
  258. const initialTitle = `跨端新会话 ${marker}`
  259. const generatedTitle = `自动标题 ${marker}`
  260. const sentinel = `page-a-${marker}`
  261. await page.evaluate(value => {
  262. ;(window as Window & { __crossClientProjectionSentinel?: string })
  263. .__crossClientProjectionSentinel = value
  264. }, sentinel)
  265. const pageB = await context.newPage()
  266. const pageBChannelOpened = pageB.waitForResponse(response =>
  267. response.request().method() === 'POST'
  268. && response.url().endsWith('/api/realtime/channels'))
  269. await pageB.goto('/chat')
  270. await pageBChannelOpened
  271. await pageB.getByRole('button', { name: '新建聊天', exact: true }).click()
  272. const pageBComposer = pageB.getByRole('textbox', {
  273. name: '输入消息,Enter 发送,Shift + Enter 换行',
  274. })
  275. await pageBComposer.fill(`[cross-client-title:${initialTitle}] 创建跨端会话`)
  276. const pageBSend = pageB.getByRole('button', { name: '发送消息', exact: true })
  277. await expect(pageBSend).toBeEnabled()
  278. await pageBSend.click()
  279. await expect(pageB).toHaveURL(/\/chat\/(?!draft-)[^/?]+(?:\?.*)?$/)
  280. const sessionId = decodeURIComponent(new URL(pageB.url()).pathname.split('/').at(-1) || '')
  281. expect(sessionId).not.toMatch(/^draft-/)
  282. await expect(pageB.locator('.message--assistant')).toContainText('会话独立保存')
  283. const cwdCalls = await (await page.request.get('http://127.0.0.1:19120/__calls')).json()
  284. const created = cwdCalls.calls.filter((call: { method: string }) => call.method === 'session.create').at(-1)
  285. expect(created.params.cwd).toBe('/tmp/hermes-fixture/default')
  286. const aligned = cwdCalls.calls.filter((call: { method: string }) => call.method === 'session.cwd.set').at(-1)
  287. expect(aligned.params.cwd).toBe('/tmp/hermes-fixture/default')
  288. const sessionRow = page.locator(`.desktop-sidebar .sidebar-item[data-sidebar-id="${sessionId}"]`)
  289. await expect(sessionRow).toContainText(initialTitle)
  290. expect(await page.evaluate(() =>
  291. (window as Window & { __crossClientProjectionSentinel?: string })
  292. .__crossClientProjectionSentinel)).toBe(sentinel)
  293. await pageB.close()
  294. const titled = await page.request.post(
  295. `http://127.0.0.1:19120/__test/sessions/title?id=${encodeURIComponent(sessionId)}`
  296. + `&title=${encodeURIComponent(generatedTitle)}`,
  297. )
  298. expect(titled.ok(), await titled.text()).toBe(true)
  299. await expect(sessionRow).toContainText(generatedTitle)
  300. await expect(sessionRow).not.toContainText(initialTitle)
  301. expect(await page.evaluate(() =>
  302. (window as Window & { __crossClientProjectionSentinel?: string })
  303. .__crossClientProjectionSentinel)).toBe(sentinel)
  304. })
  305. test('an idle Web viewer follows an iOS-origin run and restores thinking after reload', async ({ page }, testInfo) => {
  306. await login(page)
  307. const capabilities = await (await page.request.get('/api/realtime/capabilities')).json()
  308. const headers = { 'X-CSRF-Token': capabilities.csrfToken, Origin: new URL(page.url()).origin }
  309. const opened = await page.request.post('/api/realtime/channels', { headers, data: { channel: 'chat', chatProtocol: 'ordinary-chat-transcript-v2' } })
  310. expect(opened.ok(), await opened.text()).toBe(true)
  311. const channel = (await opened.json()).id
  312. let sequence = 0
  313. async function command(method: string, params: Record<string, unknown>) {
  314. const response = await page.request.post(`/api/realtime/channels/${channel}/commands`, {
  315. headers: { ...headers, 'Idempotency-Key': `ios-live-${Date.now()}-${++sequence}` },
  316. data: { jsonrpc: '2.0', method, params },
  317. })
  318. expect(response.ok(), await response.text()).toBe(true)
  319. const receipt = await response.json()
  320. expect(receipt.state).toBe('confirmed')
  321. return receipt.response.result
  322. }
  323. const session = await command('session.create', { profile: 'default', source: 'ios' })
  324. const subscribed = page.waitForResponse(response => response.url().endsWith('/commands')
  325. && response.request().postDataJSON()?.method === 'session.resume')
  326. await page.goto(`/chat/${session.stored_session_id}?profile=default`)
  327. await subscribed
  328. await page.getByRole('button', { name: '设置', exact: true }).click()
  329. await page.getByRole('switch', { name: /显示思考/ }).click()
  330. await page.getByRole('button', { name: '设置', exact: true }).click()
  331. await command('prompt.submit', { session_id: session.session_id, text: '[cross-client-live] 检查文件' })
  332. const typing = page.getByTestId('chat-run-thinking-dots')
  333. await expect(typing).toBeVisible()
  334. await expect(typing.locator('.agent-avatar')).toBeVisible()
  335. await expect(typing.locator('.thinking-indicator__dot')).toHaveCount(3)
  336. await expect(typing).toContainText('秒')
  337. await page.getByText('思考与工具', { exact: true }).click()
  338. await expect(page.getByText('read_file', { exact: true })).toBeVisible()
  339. await expect(typing).toBeVisible()
  340. await page.screenshot({ path: testInfo.outputPath('ios-run-web-thinking-tools.png') })
  341. // This Web page has never submitted a prompt or written an in-flight marker.
  342. await page.evaluate(() => sessionStorage.clear())
  343. await page.reload()
  344. await expect(typing).toBeVisible()
  345. await page.request.post('http://127.0.0.1:19120/__release')
  346. await expect(page.locator('.message--assistant')).toContainText('会话独立保存')
  347. await expect(typing).toHaveCount(0)
  348. await page.screenshot({ path: testInfo.outputPath('ios-run-web-completed.png') })
  349. })
  350. test('created roles and editable teams share a durable chat list without plugin calls', async ({
  351. page,
  352. context,
  353. }, testInfo) => {
  354. const pluginCalls: string[] = []
  355. page.on('request', (r) => {
  356. if (r.url().includes('/plugins/yaoyao')) pluginCalls.push(r.url())
  357. })
  358. await page.setViewportSize({ width: 1638, height: 874 })
  359. await login(page)
  360. const rail = page.locator('.desktop-sidebar')
  361. await expect(rail.locator('.sidebar-feature-nav')).toHaveCount(0)
  362. await expect(rail.locator('.sidebar-primary-action')).toHaveCount(0)
  363. await expect(rail).toHaveCSS('width', '360px')
  364. await expect(rail.locator('.sidebar-context__heading')).toHaveCount(0)
  365. await expect(rail.locator('.bot-logo-trigger .brand-mark')).toBeVisible()
  366. await expect(rail.locator('.sidebar-footer')).toBeVisible()
  367. await expect(rail.locator('.sidebar-account-switcher__main')).toContainText('fixture')
  368. await expect(rail.locator('.sidebar-account-switcher__main .account-initial-avatar')).toHaveText('F')
  369. await rail.locator('.sidebar-account-switcher__main').click()
  370. await expect(page.getByRole('menu', { name: '账号菜单' }).getByRole('menuitem')).toHaveText(['我的设置', '关于', '检测更新', '帮助', '进入聊天模式'])
  371. await page.getByRole('menuitem', { name: '关于', exact: true }).click()
  372. const about = page.getByRole('dialog', { name: '关于夭夭 AI', exact: true })
  373. await expect(about).toBeVisible()
  374. await expect(about.locator('.about-version')).toHaveText(/^版本 \d+\.\d+\.\d+$/)
  375. await expect(page.getByRole('dialog', { name: '我的设置', exact: true })).toHaveCount(0)
  376. await page.screenshot({ path: testInfo.outputPath('independent-about.png') })
  377. await page.keyboard.press('Escape')
  378. await expect(about).toHaveCount(0)
  379. await rail.getByRole('button', { name: '工具', exact: true }).click()
  380. await page.getByRole('menuitem', { name: '已连接应用', exact: true }).click()
  381. const apps = page.getByRole('dialog', { name: '已连接应用', exact: true })
  382. await expect(apps).toBeVisible()
  383. await expect(apps.getByRole('tab', { name: 'MCP 服务', exact: true })).toBeVisible()
  384. await expect(page.locator('.settings-sidebar')).toHaveCount(0)
  385. await page.screenshot({ path: testInfo.outputPath('independent-apps.png') })
  386. await apps.getByRole('button', { name: '关闭已连接应用', exact: true }).click()
  387. await rail.getByRole('button', { name: '工具', exact: true }).click()
  388. await page.getByRole('menuitem', { name: '自动化', exact: true }).click()
  389. await expect(page).toHaveURL(/\/conversations\/automations(?:\?.*)?$/)
  390. await expect(page.getByRole('main', { name: '自动化工作区' })).toBeVisible()
  391. await expect(page.locator('.schedule-day')).toHaveCount(7)
  392. await page.getByRole('tab', { name: '运行日志', exact: true }).click()
  393. await page.screenshot({ path: testInfo.outputPath('independent-automations.png') })
  394. await page.getByRole('button', { name: '返回聊天', exact: true }).click()
  395. await expect(page).toHaveURL(/\/conversations$/)
  396. await rail.locator('.sidebar-account-switcher__main').click()
  397. await page.getByRole('menuitem', { name: '我的设置', exact: true }).click()
  398. const settings = page.getByRole('dialog', { name: '我的设置', exact: true })
  399. await settings.getByRole('button', {name:'账号资料',exact:true}).click()
  400. await expect(settings.locator('.account-avatar-card')).toContainText('fixture')
  401. await expect(settings.locator('.account-avatar-card .account-initial-avatar')).toHaveText('F')
  402. await settings.locator('.account-avatar-card input[type=file]').setInputFiles({name:'account.png',mimeType:'image/png',buffer:Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=','base64')})
  403. await expect(settings.locator('.account-avatar-card .account-initial-avatar img')).toBeVisible()
  404. expect((await (await page.request.get('/api/app/bootstrap')).json()).user.avatar).toMatch(/^data:image\/png;base64,/)
  405. await settings.getByRole('button', {name:'使用首字母',exact:true}).click()
  406. await expect(settings.locator('.account-avatar-card .account-initial-avatar')).toHaveText('F')
  407. await settings.getByRole('button', { name: '身份与头像', exact: true }).click()
  408. await settings.getByRole('button', { name: '造型:星星', exact: true }).click()
  409. await settings.getByRole('button', { name: '使用颜色 #1488ff', exact: true }).click()
  410. await settings.locator('.mascot-grid--expression button').filter({ hasText: '开心' }).click()
  411. await settings.getByRole('button', { name: '保存更改', exact: true }).click()
  412. await expect(settings.getByRole('button', { name: '保存更改', exact: true })).toBeDisabled()
  413. await settings.getByRole('button', { name: '关闭我的设置', exact: true }).click()
  414. await rail.locator('.sidebar-account-switcher__main').click()
  415. await page.getByRole('menuitem', {name:'我的设置',exact:true}).click()
  416. await settings.getByRole('button', { name: '身份与头像', exact: true }).click()
  417. await expect(settings.getByRole('button', { name: '造型:星星', exact: true })).toHaveAttribute('aria-pressed', 'true')
  418. await expect(settings.getByRole('button', { name: '使用颜色 #1488ff', exact: true })).toHaveAttribute('aria-pressed', 'true')
  419. await expect(settings.locator('.mascot-grid--expression button').filter({ hasText: '开心' })).toHaveAttribute('aria-pressed', 'true')
  420. await settings.getByRole('button', { name: '关闭我的设置', exact: true }).click()
  421. await expect(rail.getByRole('checkbox', { name: '显示已归档' })).toHaveCount(0)
  422. const plus = rail.getByRole('button', { name: '新建', exact: true })
  423. await expect(rail.locator('.sidebar-collapse')).toHaveCount(0)
  424. await plus.click()
  425. await expect(page.getByRole('menu', { name: '新建聊天' }).getByRole('menuitem')).toHaveText(['新建 Bot', '添加远程机器人', '新建群聊'])
  426. await page.keyboard.press('Escape')
  427. await rail.getByRole('button', { name: '搜索', exact: true }).click()
  428. await expect(page.getByRole('dialog', { name: '搜索聊天' })).toBeVisible()
  429. await page.keyboard.press('Escape')
  430. await page.goto('/chat')
  431. await expect(rail).toHaveCSS('width', '264px')
  432. await expect(rail.getByRole('button', { name: '聊天', exact: true })).toHaveCount(0)
  433. await rail.getByRole('button', { name: '设置与模式', exact: true }).click()
  434. const settingsMenu = page.getByRole('menu', { name: '账号菜单', exact: true })
  435. await expect(settingsMenu.getByRole('menuitem')).toHaveText(['我的设置', '关于', '检测更新', '帮助', '进入 Bot 模式'])
  436. await page.screenshot({ path: testInfo.outputPath('chat-settings-mode-menu.png') })
  437. await settingsMenu.getByRole('menuitem', { name: '我的设置', exact: true }).click()
  438. await expect(page.getByRole('dialog', { name: '我的设置', exact: true })).toBeVisible()
  439. await page.getByRole('button', { name: '关闭我的设置', exact: true }).click()
  440. await expect(rail.getByRole('button', { name: '设置与模式', exact: true })).toBeFocused()
  441. await rail.getByRole('button', { name: '设置与模式', exact: true }).click()
  442. await settingsMenu.getByRole('menuitem', { name: '进入 Bot 模式', exact: true }).click()
  443. await expect(page).toHaveURL(/\/conversations$/)
  444. await expect(rail).toHaveCSS('width', '360px')
  445. await page.addInitScript(() => { Object.defineProperty(crypto, 'randomUUID', { value: undefined, configurable: true }) })
  446. await page.reload()
  447. await createAgent(page, '产品经理')
  448. await page.getByRole('button', {name:'聊天设置',exact:true}).click()
  449. const avatarEditor = page.getByRole('dialog')
  450. await expect(avatarEditor.locator('.color-grid button')).toHaveCount(11)
  451. await expect(avatarEditor.locator('.mascot-grid--expression button')).toHaveCount(10)
  452. await avatarEditor.getByRole('button', {name:'造型:星星',exact:true}).click()
  453. await avatarEditor.locator('.mascot-grid--expression button').filter({hasText:'自豪'}).click()
  454. await avatarEditor.getByRole('button', {name:'使用颜色 #000000',exact:true}).click()
  455. await avatarEditor.getByRole('button', {name:'保存',exact:true}).click()
  456. const identities = await (await page.request.get('/api/app/agents')).json()
  457. const edited = identities.agents.find((a: {name:string}) => a.name === '产品经理')
  458. expect(JSON.parse(edited.avatar.slice('yaoyao-avatar:v2:'.length))).toMatchObject({version:2,bodyId:'star',expression:'proud',color:'#000000'})
  459. await page.reload()
  460. await page.getByRole('button', {name:'聊天设置',exact:true}).click()
  461. await expect(avatarEditor.getByRole('button', {name:'造型:星星',exact:true})).toHaveAttribute('aria-pressed','true')
  462. await avatarEditor.locator('input[type=file]').setInputFiles({name:'avatar.png',mimeType:'image/png',buffer:Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=','base64')})
  463. await expect(avatarEditor.getByText('图片裁剪',{exact:true})).toBeVisible()
  464. let photoBytes=''
  465. for(const [label,crop] of [['圆形','circle'],['方形','square'],['圆角方形','rounded']]){
  466. await avatarEditor.getByRole('button',{name:label,exact:true}).click()
  467. await avatarEditor.getByRole('button',{name:'保存',exact:true}).click()
  468. const payload=await (await page.request.get('/api/app/agents')).json()
  469. const avatar=JSON.parse(payload.agents.find((a:{name:string})=>a.name==='产品经理').avatar.slice('yaoyao-avatar:v2:'.length))
  470. expect(avatar).toMatchObject({avatarMode:'image',imageCrop:crop})
  471. if(photoBytes)expect(avatar.imageDataURL).toBe(photoBytes)
  472. else photoBytes=avatar.imageDataURL
  473. await page.getByRole('button',{name:'聊天设置',exact:true}).click()
  474. }
  475. await avatarEditor.getByRole('button',{name:'动态吉祥物',exact:true}).click()
  476. await avatarEditor.locator('.mascot-grid--shape button').filter({hasText:'圆形'}).first().click()
  477. await avatarEditor.getByRole('button', {name:'使用颜色 #ff6b00',exact:true}).click()
  478. await avatarEditor.locator('.mascot-grid--expression button').filter({hasText:'默认'}).click()
  479. await avatarEditor.getByRole('button', {name:'保存',exact:true}).click()
  480. await expect(avatarEditor).toBeHidden()
  481. const composerInput = page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行')
  482. const sendButton = page.getByRole('button', { name: '发送消息', exact: true })
  483. await expect(composerInput).toBeEnabled()
  484. await expect(rail.getByText('聊天', { exact: true })).toHaveCount(0)
  485. await expect(rail.getByText('聊天列表', { exact: true })).toHaveCount(0)
  486. await expect(rail.locator('.sidebar-item__row strong').first()).toHaveCSS('font-size', '15px')
  487. await expect(rail.locator('.sidebar-item__row--secondary').first()).toHaveCSS('font-size', '13px')
  488. await expect(rail.locator('.sidebar-item__row small').first()).toHaveCSS('font-size', '10px')
  489. await composerInput.fill('请说明角色职责')
  490. await expect(sendButton).toBeEnabled()
  491. await sendButton.click()
  492. await expect(page.locator('.message--assistant')).toContainText('我是产品经理')
  493. for (const colorScheme of ['light', 'dark'] as const) {
  494. await page.emulateMedia({ colorScheme })
  495. for (const selector of ['.message__avatar.agent-avatar', '.desktop-sidebar .sidebar-item__icon--avatar', '.desktop-sidebar .agent-avatar']) {
  496. await expect(page.locator(selector).first()).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
  497. await expect(page.locator(selector).first()).toHaveCSS('background-image', 'none')
  498. }
  499. }
  500. await page.emulateMedia({ colorScheme: 'light' })
  501. await expect(page.locator('.message--assistant a').first()).toHaveAttribute(
  502. 'href',
  503. /\/api\/app\/files\/.+\/download/,
  504. )
  505. await page.locator('.message--assistant a').first().click()
  506. const textPreview = page.getByRole('dialog', { name: '预览 workspace-report.txt', exact: true })
  507. await expect(textPreview).toBeVisible()
  508. await expect(textPreview).toContainText('Fixture report')
  509. await textPreview.getByRole('button', { name: '关闭预览' }).click()
  510. const managerRow = rail.getByRole('option').filter({ hasText: '产品经理' })
  511. await managerRow.click({ button: 'right' })
  512. await page.getByRole('menuitem', {name:'置顶聊天',exact:true}).click()
  513. await managerRow.click({ button: 'right' })
  514. await expect(page.getByRole('menuitem', {name:'取消置顶',exact:true})).toBeVisible()
  515. await page.getByRole('menuitem', {name:'取消置顶',exact:true}).press('Escape')
  516. const directURL = page.url()
  517. await createAgent(page, '开发工程师')
  518. await expect(page.locator('.message')).toHaveCount(0)
  519. await openCreate(page, '新建群聊')
  520. const dialog = page.getByRole('dialog')
  521. await dialog.getByRole('textbox', { name: '名称', exact: true }).fill('产品开发团队')
  522. await dialog.getByRole('checkbox', { name: '产品经理', exact: true }).check()
  523. await dialog.getByRole('checkbox', { name: '开发工程师', exact: true }).check()
  524. await dialog.getByText('高级协作设置', { exact: true }).click()
  525. await dialog.getByRole('combobox', { name: '协作方式', exact: true }).selectOption('host')
  526. await dialog
  527. .getByRole('combobox', { name: '负责人', exact: true })
  528. .selectOption({ label: '产品经理' })
  529. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  530. await expect(page.getByRole('heading', { name: '产品开发团队', exact: true })).toBeVisible()
  531. await expect(page.locator('.desktop-sidebar .sidebar-item')).toHaveCount(3)
  532. // Every cluster portrait must be the same portrait shown in that member's direct chat.
  533. const groupRow = page.locator('.desktop-sidebar .sidebar-item').filter({ hasText: '产品开发团队' })
  534. await expect(groupRow.locator('.team-avatar__member')).toHaveCount(2)
  535. for (const name of ['产品经理', '开发工程师']) {
  536. const portrait = `.agent-avatar[aria-label="${name} 的头像"]`
  537. const direct = page.locator('.desktop-sidebar .sidebar-item').filter({ hasText: name }).filter({ hasNot: page.locator('.team-avatar') }).locator(portrait)
  538. const member = groupRow.locator(portrait)
  539. await expect(member.locator('[data-part=outline] > :first-child')).toHaveAttribute('fill', await direct.locator('[data-part=outline] > :first-child').getAttribute('fill') || '')
  540. expect(await member.locator('[data-part=outline] > :first-child').evaluate(el => el.tagName))
  541. .toBe(await direct.locator('[data-part=outline] > :first-child').evaluate(el => el.tagName))
  542. }
  543. await expect(page.locator('.desktop-sidebar')).not.toContainText('话题')
  544. await expect(page.locator('.desktop-sidebar .sidebar-account-switcher__main')).not.toContainText(
  545. '通用助手',
  546. )
  547. await page.getByRole('button', { name: '聊天设置', exact: true }).click()
  548. await expect(dialog.getByRole('checkbox', { name: '产品经理', exact: true })).toBeDisabled()
  549. await expect(dialog.getByRole('checkbox', { name: '开发工程师', exact: true })).toBeEnabled()
  550. await dialog.getByRole('button', { name: '取消', exact: true }).click()
  551. await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('请@开发工程师给出实现结果')
  552. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  553. await expect(page.locator('.message--assistant')).toHaveCount(3)
  554. await expect(page.locator('.message--assistant').nth(1)).toContainText('我是开发工程师')
  555. await expect(page.locator('.run-status')).toHaveCount(0)
  556. const second = await context.newPage()
  557. await second.goto(page.url())
  558. await expect(second.locator('.message--assistant')).toHaveCount(3)
  559. await page.screenshot({ path: testInfo.outputPath('mixed-chats.png'), fullPage: true })
  560. const groupURL=page.url()
  561. await page.getByRole('button', { name: '聊天设置', exact: true }).click()
  562. await dialog.getByRole('checkbox', { name: '开发工程师', exact: true }).uncheck()
  563. await expect(dialog.getByRole('checkbox', { name: '产品经理', exact: true })).toBeDisabled()
  564. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  565. await expect(groupRow.locator('.team-avatar__member')).toHaveCount(1)
  566. await expect(page.locator('.message--assistant')).toHaveCount(3)
  567. await expect(second.locator('.desktop-sidebar .sidebar-item').filter({ hasText: '产品开发团队' }).locator('.team-avatar__member')).toHaveCount(1)
  568. await page.reload()
  569. await page.getByRole('button', { name: '聊天设置', exact: true }).click()
  570. await expect(dialog.getByRole('checkbox', { name: '开发工程师', exact: true })).not.toBeChecked()
  571. await dialog.getByRole('button', { name: '取消', exact: true }).click()
  572. await createAgent(page, '新成员')
  573. await page.goto(groupURL)
  574. await page.getByRole('button', { name: '聊天设置', exact: true }).click()
  575. await dialog.getByRole('checkbox', { name: '新成员', exact: true }).check()
  576. await dialog.getByRole('checkbox', { name: '产品经理', exact: true }).scrollIntoViewIfNeeded()
  577. await page.screenshot({ path: testInfo.outputPath('member-settings.png'), fullPage: true })
  578. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  579. await expect(groupRow.locator('.team-avatar__member')).toHaveCount(2)
  580. await expect(groupRow.locator('[aria-label="开发工程师 的头像"]')).toHaveCount(0)
  581. await expect(groupRow.locator('[aria-label="新成员 的头像"]')).toHaveCount(1)
  582. await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('请@新成员继续')
  583. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  584. await expect(page.locator('.message--assistant')).toHaveCount(6)
  585. await expect(page.locator('.message--assistant').nth(4)).toContainText('我是新成员')
  586. await page.goto('/files')
  587. await page.getByRole('button',{name:'查看来源',exact:true}).first().click()
  588. await expect(page).toHaveURL(groupURL)
  589. await groupRow.click({ button: 'right' })
  590. page.once('dialog', dialog => dialog.accept())
  591. await page.getByRole('menuitem', { name: '归档聊天', exact: true }).click()
  592. await expect(page.locator('.desktop-sidebar .sidebar-item')).toHaveCount(3)
  593. await page.locator('.desktop-sidebar .sidebar-search-trigger').click()
  594. const search = page.getByRole('dialog', { name: '搜索聊天', exact: true })
  595. await expect(search).toBeVisible()
  596. await search.getByRole('searchbox', { name: '搜索聊天', exact: true }).fill('产品开发')
  597. await expect(search.getByRole('listitem')).toHaveCount(0)
  598. await search.getByRole('tab', { name: '已归档', exact: true }).click()
  599. await expect(search.getByRole('searchbox')).toHaveValue('产品开发')
  600. await expect(search.getByRole('listitem')).toHaveCount(1)
  601. await page.screenshot({ path: testInfo.outputPath('archived-chat-search.png'), fullPage: true })
  602. await search.getByRole('listitem').getByRole('button').filter({ hasText: '产品开发团队' }).click()
  603. await expect(search).not.toBeVisible()
  604. await expect(page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行')).toBeDisabled()
  605. await page.goto(directURL)
  606. await expect(page.locator('.message--assistant')).toHaveCount(1)
  607. await expect(page.locator('.message--assistant')).toContainText('我是产品经理')
  608. await page.goto('/chat')
  609. await expect(page).toHaveURL(/\/chat/)
  610. expect(pluginCalls).toEqual([])
  611. await second.close()
  612. await page.goto('/conversations')
  613. await openCreate(page, '新建群聊')
  614. await dialog.locator('summary').filter({hasText:'从团队模板选择'}).click()
  615. await expect(dialog.getByRole('button', { name: '信息收集团队', exact: true })).toBeDisabled()
  616. await dialog.getByRole('button', { name: '取消', exact: true }).click()
  617. await createAgent(page, '模板成员四')
  618. await createAgent(page, '模板成员五')
  619. await openCreate(page, '新建群聊')
  620. await dialog.locator('summary').filter({hasText:'从团队模板选择'}).click()
  621. for (const name of ['信息收集团队', '产品设计团队', '软件开发团队', '文案书写团队', '项目管理团队', '数据分析团队', '会议协作团队', '运维保障团队']) {
  622. await expect(dialog.getByRole('button', { name, exact: true })).toBeEnabled()
  623. }
  624. await page.screenshot({ path: testInfo.outputPath('restored-team-presets.png'), fullPage: true })
  625. await dialog.getByRole('button', { name: '产品设计团队', exact: true }).click()
  626. await expect(dialog.getByRole('textbox', { name: '名称', exact: true })).toHaveValue('产品设计团队')
  627. await dialog.getByText('高级协作设置', { exact: true }).click()
  628. await dialog.getByRole('combobox', { name: '协作方式', exact: true }).selectOption('host')
  629. await dialog.getByRole('combobox', { name: '产品负责人对应的机器人', exact: true }).selectOption({ label: '产品经理' })
  630. await dialog.getByRole('combobox', { name: '交互设计对应的机器人', exact: true }).selectOption({ label: '开发工程师' })
  631. const [submitted] = await Promise.all([
  632. page.waitForRequest(r => r.method() === 'POST' && r.url().endsWith('/api/app/conversations')),
  633. dialog.getByRole('button', { name: '保存', exact: true }).click(),
  634. ])
  635. const payload = submitted.postDataJSON()
  636. expect(new Set(payload.memberIds).size).toBe(5)
  637. expect(Object.keys(payload.memberRoles)).toHaveLength(5)
  638. expect(payload.memberRoles[payload.administratorId].name).toBe('产品负责人')
  639. await expect(page.getByRole('heading', { name: '产品设计团队', exact: true })).toBeVisible()
  640. await page.getByRole('button', { name: '聊天设置', exact: true }).click()
  641. await expect(dialog.getByText('产品经理 · 产品负责人', { exact: false })).toBeVisible()
  642. await expect(dialog.getByText('开发工程师 · 交互设计', { exact: false })).toBeVisible()
  643. await dialog.getByRole('button', { name: '取消', exact: true }).click()
  644. await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('请汇总设计方案')
  645. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  646. await expect(page.locator('.message--assistant')).toContainText('我是产品经理')
  647. const conversationPath = new URL(page.url()).pathname.replace('/conversations/', '/api/app/conversations/')
  648. await expect.poll(async () => {
  649. const c = (await (await page.request.get(conversationPath)).json()).conversation
  650. return { active: Boolean(c.activeRunId), queued: c.queuedMessageCount }
  651. }).toEqual({ active: false, queued: 0 })
  652. const composer = page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行')
  653. await composer.fill('[hold-workspace] 正在执行的任务')
  654. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  655. await expect(page.getByRole('button', { name: '停止生成', exact: true })).toBeVisible()
  656. await expect.poll(async () => (await (await page.request.get(conversationPath)).json()).conversation.queuedMessageCount).toBe(0)
  657. await composer.fill('后续排队任务')
  658. await expect(page.getByRole('button', { name: '发送消息', exact: true })).toBeEnabled()
  659. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  660. await expect(page.locator('.message--user').last()).toContainText('后续排队任务')
  661. const detail = await (await page.request.get(new URL(page.url()).pathname.replace('/conversations/', '/api/app/conversations/'))).json()
  662. expect(detail.conversation.queuedMessageCount).toBe(1)
  663. await page.request.post('http://127.0.0.1:19120/__release')
  664. await expect.poll(async () => (await (await page.request.get(`/api/app/conversations/${detail.conversation.id}`)).json()).conversation.activeRunId).toBeUndefined()
  665. await page.setViewportSize({ width: 390, height: 844 })
  666. await page.getByRole('button', { name: '返回 Bot 列表', exact: true }).click()
  667. await expect(rail).toBeVisible()
  668. await expect(rail).toHaveCSS('width', '390px')
  669. await expect(page.locator('.mobile-header')).toBeHidden()
  670. await expect(rail.locator('.sidebar-feature-nav')).toHaveCount(0)
  671. await page.screenshot({ path: testInfo.outputPath('mobile-bot-list.png') })
  672. await rail.getByRole('button', { name: '新建', exact: true }).click()
  673. await expect(page.getByRole('menuitem', { name: '新建 Bot', exact: true })).toBeVisible()
  674. await page.keyboard.press('Escape')
  675. await rail.getByRole('button', { name: '搜索', exact: true }).click()
  676. await expect(page.getByRole('dialog', { name: '搜索聊天' })).toBeVisible()
  677. await expect(page.getByRole('tab', { name: '未归档', exact: true })).toBeVisible()
  678. await page.getByRole('button', { name: '关闭搜索', exact: true }).click()
  679. await rail.locator('.sidebar-account-switcher__main').click()
  680. await page.getByRole('menuitem', { name: '进入聊天模式', exact: true }).click()
  681. await expect(page).toHaveURL(/\/chat$/)
  682. await page.goto('/')
  683. await expect(page).toHaveURL(/\/chat$/)
  684. await page.setViewportSize({ width: 1280, height: 800 })
  685. await page.getByRole('button', { name: '设置与模式', exact: true }).click()
  686. await page.getByRole('menuitem', { name: '进入 Bot 模式', exact: true }).click()
  687. await page.goto('/')
  688. await expect(page).toHaveURL(/\/conversations$/)
  689. await page.reload()
  690. await expect(rail.locator('.bot-list-header')).toBeVisible()
  691. expect(pluginCalls).toEqual([])
  692. })
  693. test('subaccount allocation and Bot-only navigation work through the browser', async ({ page, browser }, testInfo) => {
  694. await login(page)
  695. await page.locator('.desktop-sidebar .sidebar-account-switcher__main').click()
  696. await page.getByRole('menuitem', { name: '我的设置', exact: true }).click()
  697. const settings = page.getByRole('dialog', { name: '我的设置', exact: true })
  698. await settings.getByRole('button', { name: '用户与权限', exact: true }).click()
  699. const username = `child-${Date.now()}`
  700. await settings.locator('input[name=managed-username]').fill(username)
  701. await settings.locator('input[name=managed-temporary-password]').fill('temporary-pass')
  702. await settings.getByRole('listbox', { name: '新子账号的基础机器人' }).selectOption('default')
  703. await settings.getByRole('button', { name: '创建用户', exact: true }).click()
  704. await expect(settings.getByRole('listbox', { name: `分配给 ${username} 的基础机器人`, exact: true })).toHaveValues(['default'])
  705. await page.screenshot({ path: testInfo.outputPath('admin-agent-allocation.png'), fullPage: true })
  706. const childContext = await browser.newContext({ viewport: { width: 1280, height: 800 } })
  707. const child = await childContext.newPage()
  708. await child.goto(new URL('/chat', page.url()).href)
  709. await child.getByRole('textbox', { name: '账号', exact: true }).fill(username)
  710. await child.getByRole('textbox', { name: '密码', exact: true }).fill('temporary-pass')
  711. await child.getByRole('button', { name: '登录', exact: true }).click()
  712. await child.getByLabel('当前密码', { exact: true }).fill('temporary-pass')
  713. await child.getByLabel('新密码', { exact: true }).fill('permanent-pass')
  714. await child.getByLabel('确认新密码', { exact: true }).fill('permanent-pass')
  715. await child.getByRole('button', { name: '保存并进入夭夭', exact: true }).click()
  716. await expect(child).toHaveURL(/\/conversations$/)
  717. await expect(child.getByRole('heading', { name: '还没有聊天' })).toBeVisible()
  718. await child.locator('.desktop-sidebar .sidebar-account-switcher__main').click()
  719. await expect(child.getByRole('menu', { name: '账号菜单' }).getByRole('menuitem')).toHaveText(['我的设置', '关于', '帮助'])
  720. await child.keyboard.press('Escape')
  721. await openCreate(child, '新建 Bot')
  722. const dialog = child.getByRole('dialog')
  723. await expect(dialog.getByLabel('基础机器人').locator('option')).toHaveCount(1)
  724. await expect(dialog.getByLabel('基础机器人').locator('option')).toContainText('通用助手')
  725. await dialog.getByLabel('基础机器人').scrollIntoViewIfNeeded()
  726. await child.screenshot({ path: testInfo.outputPath('subaccount-assigned-source.png'), fullPage: true })
  727. await dialog.getByRole('textbox', { name: '名称', exact: true }).fill('子账号助手')
  728. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  729. await expect(child.getByRole('heading', { name: '子账号助手', exact: true })).toBeVisible()
  730. for (const path of ['/history', '/kanban', '/files', '/chat']) {
  731. await child.goto(new URL(path, page.url()).href)
  732. await expect(child).toHaveURL(/\/conversations$/)
  733. }
  734. await childContext.close()
  735. })
  736. for (const mode of ['普通聊天', 'Bot 单聊', '群聊', '普通长回复'] as const) {
  737. test(`${mode} 在完成前格式化流式 Markdown 并保留最终内容`, async ({ page }, testInfo) => {
  738. await login(page)
  739. if (mode.startsWith('普通')) {
  740. await page.goto('/chat')
  741. await page.getByRole('button', { name: '新建聊天', exact: true }).click()
  742. } else {
  743. await createAgent(page, `${mode}流式验证助手`)
  744. if (mode === '群聊') {
  745. await createAgent(page, '群聊流式协作成员')
  746. await openCreate(page, '新建群聊')
  747. const dialog = page.getByRole('dialog')
  748. await dialog.getByRole('textbox', { name: '名称', exact: true }).fill('流式验证群')
  749. await dialog.getByRole('checkbox', { name: `${mode}流式验证助手`, exact: true }).check()
  750. await dialog.getByRole('checkbox', { name: '群聊流式协作成员', exact: true }).check()
  751. await dialog.getByText('高级协作设置', { exact: true }).click()
  752. await dialog.getByRole('combobox', { name: '协作方式', exact: true }).selectOption('host')
  753. await dialog.getByRole('combobox', { name: '负责人', exact: true }).selectOption({ label: `${mode}流式验证助手` })
  754. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  755. await expect(page.getByRole('heading', { name: '流式验证群', exact: true })).toBeVisible()
  756. }
  757. }
  758. await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill(`[streaming-markdown] ${mode === '普通长回复' ? '[long]' : ''} 演示排版`)
  759. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  760. const message = page.locator('.message--assistant').last()
  761. await expect(message.locator('.markdown--streaming h1')).toHaveText('流式标题')
  762. await expect(message.locator('strong').filter({ hasText: '即时格式化' })).toBeVisible()
  763. await expect(message.locator('li')).toHaveText(['第一项', '第二项'])
  764. await expect(message.locator('pre code').first()).toContainText('const answer = 42')
  765. await expect(message).not.toContainText('最终完整标记')
  766. await page.screenshot({ path: testInfo.outputPath('streaming-markdown.png'), fullPage: true })
  767. if (mode === '普通长回复') {
  768. await expect(message.getByText('流式末尾标记', { exact: true })).toBeInViewport()
  769. await page.locator('.timeline').evaluate(el => { el.scrollTop = 0; el.dispatchEvent(new Event('scroll')) })
  770. await expect(message.getByRole('heading', { name: '流式标题', exact: true })).toBeInViewport()
  771. }
  772. const released = await page.request.post('http://127.0.0.1:19120/__release')
  773. expect(released.ok()).toBe(true)
  774. await expect(message).toContainText('最终完整标记')
  775. await expect(message.locator('table')).toContainText('项目')
  776. await expect(message.locator('.markdown--streaming')).toHaveCount(0)
  777. if (mode === '普通长回复') {
  778. await expect(message.getByRole('heading', { name: '流式标题', exact: true })).toBeInViewport()
  779. await expect(message.getByText('最终完整标记', { exact: true })).not.toBeInViewport()
  780. }
  781. })
  782. }
  783. test('only chat messages introduce files across transcript and library', async ({ page }, testInfo) => {
  784. await login(page)
  785. await createAgent(page, '文件展示验收')
  786. await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('[message-files] 请发送报告')
  787. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  788. const report = page.locator('.message--assistant .file-link-card').first()
  789. await expect(report).toBeVisible()
  790. const process = page.locator('.turn-trace')
  791. await expect(process).toHaveCount(0)
  792. await page.locator('.composer-tool[title="显示思考"]').click()
  793. await expect(process).toHaveCount(1)
  794. await process.locator('summary').first().click()
  795. await expect(process).toContainText('/tmp/process.pdf')
  796. await expect(process.locator('img, .file-link-card')).toHaveCount(0)
  797. const conversationId = new URL(page.url()).pathname.split('/').at(-1)!
  798. const files = await (await page.request.get(`/api/app/files?session_id=${encodeURIComponent(conversationId)}`)).json()
  799. expect(files.items.map((file: { name: string }) => file.name)).toEqual(['workspace-report.txt'])
  800. await report.click()
  801. const preview = page.getByRole('dialog', { name: '预览 workspace-report.txt', exact: true })
  802. await expect(preview).toContainText('Fixture report')
  803. await preview.getByRole('button', { name: '关闭预览' }).click()
  804. await page.reload()
  805. await expect(page.locator('.message--assistant .file-link-card')).toHaveCount(1)
  806. await expect(page.locator('.turn-trace')).toHaveCount(0)
  807. await page.locator('.composer-tool[title="显示思考"]').click()
  808. await page.locator('.turn-trace summary').first().click()
  809. await page.setViewportSize({ width: 1280, height: 1100 })
  810. await page.screenshot({ path: testInfo.outputPath('message-files-web.png') })
  811. })
  812. test('Bot transcript switches from cache and preserves the viewport during history and live updates', async ({ page }, testInfo) => {
  813. await login(page)
  814. const bootstrap = await (await page.request.get('/api/app/bootstrap')).json()
  815. const headers = { 'X-CSRF-Token': bootstrap.csrfToken }
  816. const seed = await (await page.request.post('/__test/workspace-transcript', { headers })).json()
  817. try {
  818. await page.goto(`/conversations/${seed.conversationId}`)
  819. await expect(page.locator('.message')).toHaveCount(50)
  820. const scroller = page.locator('.timeline')
  821. for (let index = 0; index < 4; index++) {
  822. await scroller.evaluate(el => { el.scrollTop = 0 })
  823. const before = await page.locator('.message').first().getAttribute('data-message-id')
  824. await page.getByRole('button', { name: '加载更早消息', exact: true }).click()
  825. await expect(page.locator('.message')).toHaveCount(100 + index * 50)
  826. expect(await page.locator(`[data-message-id="${before}"]`).evaluate(el => {
  827. const scroller = el.closest('.timeline')!; return el.getBoundingClientRect().top - scroller.getBoundingClientRect().top
  828. })).toBeGreaterThanOrEqual(-10)
  829. }
  830. // Returning keeps loaded history in memory but mounts only the 120-message tail.
  831. await page.locator('.desktop-sidebar .bot-logo-trigger').click()
  832. await expect(page.locator('.desktop-sidebar .sidebar-item').filter({ hasText: '长会话性能验收' })).toBeVisible()
  833. const requests: string[] = []
  834. page.on('request', request => { if (request.method() === 'GET') requests.push(new URL(request.url()).pathname) })
  835. await page.locator(`.desktop-sidebar [data-sidebar-id="${seed.conversationId}"]`).click()
  836. await expect(page.locator('.message')).toHaveCount(120)
  837. expect(requests).not.toContain(`/api/app/conversations/${seed.conversationId}`)
  838. await scroller.hover(); await page.mouse.wheel(0, -600)
  839. await expect(page.getByRole('button', { name: '回到底部', exact: true })).toBeVisible()
  840. const top = await scroller.evaluate(el => el.scrollTop)
  841. await page.request.post(`/__test/workspace-transcript?id=${seed.conversationId}`, { headers })
  842. await expect(page.locator('.message').last()).toContainText('实时追加的内容')
  843. expect(Math.abs(await scroller.evaluate(el => el.scrollTop) - top)).toBeLessThan(4)
  844. expect(requests).not.toContain('/api/app/agents')
  845. expect(requests).not.toContain('/api/app/events')
  846. await page.screenshot({ path: testInfo.outputPath('bot-cached-transcript.png') })
  847. await page.setViewportSize({ width: 375, height: 812 })
  848. await page.emulateMedia({ colorScheme: 'dark', reducedMotion: 'reduce' })
  849. await expect(page.getByRole('textbox', { name: '输入消息,Enter 发送,Shift + Enter 换行' })).toBeVisible()
  850. await page.screenshot({ path: testInfo.outputPath('bot-cached-transcript-mobile-dark.png') })
  851. } finally {
  852. await page.request.patch(`/api/app/agents/${seed.agentId}`, { headers, data: { archived: true } })
  853. await page.request.delete(`/api/app/agents/${seed.agentId}`, { headers })
  854. }
  855. })
  856. test('Bot startup loads only the selected transcript and fetches large tool output after expansion', async ({ page }) => {
  857. await login(page)
  858. const bootstrap = await (await page.request.get('/api/app/bootstrap')).json()
  859. const headers = { 'X-CSRF-Token': bootstrap.csrfToken }
  860. const seeded = await page.request.post('/__test/workspace-transcript?tools=large', { headers })
  861. expect(seeded.ok(), await seeded.text()).toBe(true)
  862. const seed = await seeded.json()
  863. const requests: string[] = []
  864. page.on('request', request => { if (request.method() === 'GET') requests.push(request.url()) })
  865. const snapshot = page.waitForResponse(response => response.url().includes('/api/app/workspace/snapshot?'))
  866. await page.goto('/conversations')
  867. expect((await (await snapshot).json()).details).toEqual([])
  868. await page.locator(`.desktop-sidebar [data-sidebar-id="${seed.conversationId}"]`).click()
  869. await expect(page.locator('.message')).toHaveCount(50)
  870. await page.locator('.composer-tool[title="显示思考"]').click()
  871. await page.locator('.turn-trace summary').click()
  872. const tool = page.locator('.tool-trace').filter({ hasText: 'read_file' })
  873. await expect(tool).toBeVisible()
  874. expect(requests.some(url => url.includes('/tools/'))).toBe(false)
  875. await tool.getByRole('button', { name: /read_file/ }).click()
  876. await expect(tool.locator('pre').last()).toContainText('工具输出末尾')
  877. expect(requests.filter(url => url.includes('/tools/'))).toHaveLength(1)
  878. const reloaded = page.waitForResponse(response => response.url().includes('/api/app/workspace/snapshot?'))
  879. await page.reload()
  880. const selected = await (await reloaded).json()
  881. expect(selected.details).toHaveLength(1)
  882. expect(selected.details[0].conversation.id).toBe(seed.conversationId)
  883. expect(JSON.stringify(selected)).not.toContain('工具输出末尾')
  884. await expect(page.locator('.message')).toHaveCount(50)
  885. })
  886. test('account update checks show loading, available versions and retry on desktop and phone', async ({ page }, testInfo) => {
  887. await login(page)
  888. const current = { schemaVersion: 1, releaseVersion: '0.4.17', webVersion: '0.4.17', gitTag: 'v0.4.17' }
  889. const status = { current, latest: { ...current, webVersion: '0.4.18', releaseVersion: '0.4.18', gitTag: 'v0.4.18' }, supported: true, installationMode: 'source', updateAvailable: true, canRollback: false, releasePageUrl: 'https://github.com/Lsamien/yaoyao/releases/tag/v0.4.18' }
  890. await page.route('**/api/app/system/update/status', route => route.fulfill({ json: status }))
  891. let failed = false
  892. let releaseCheck: (() => void) | undefined
  893. await page.route('**/api/app/system/update/check', async route => {
  894. await new Promise<void>(resolve => { releaseCheck = resolve })
  895. await route.fulfill(failed ? { status: 502, json: { error: '暂时无法连接更新服务' } } : { json: status })
  896. })
  897. for (const width of [1280, 390]) {
  898. await page.setViewportSize({ width, height: 866 })
  899. await page.emulateMedia({ colorScheme: width === 390 ? 'dark' : 'light', reducedMotion: 'reduce' })
  900. const account = page.locator('.desktop-sidebar .sidebar-account-switcher__main')
  901. await expect(page.locator('.sidebar-settings-trigger')).toHaveCount(0)
  902. await account.click()
  903. // The menu's dismiss layer receives the second pointer click over the account.
  904. const accountRect = (await account.boundingBox())!
  905. await page.mouse.click(accountRect.x + accountRect.width / 2, accountRect.y + accountRect.height / 2)
  906. await expect(page.getByRole('menu', { name: '账号菜单' })).toHaveCount(0)
  907. await account.click()
  908. await page.screenshot({ path: testInfo.outputPath(`update-menu-${width}.png`) })
  909. await page.getByRole('menuitem', { name: '检测更新', exact: true }).click()
  910. const dialog = page.getByRole('dialog', { name: '检测更新', exact: true })
  911. await expect(dialog.getByRole('status')).toHaveText('正在检测更新…')
  912. await expect(dialog.getByRole('button', { name: '正在检测…', exact: true })).toBeDisabled()
  913. await expect.poll(() => Boolean(releaseCheck)).toBe(true)
  914. releaseCheck!(); releaseCheck = undefined
  915. await expect(dialog.getByRole('status')).toHaveText('发现新版本 0.4.18')
  916. await page.screenshot({ path: testInfo.outputPath(`update-available-${width}.png`) })
  917. expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true)
  918. failed = true
  919. await dialog.getByRole('button', { name: '重新检测', exact: true }).click()
  920. await expect.poll(() => Boolean(releaseCheck)).toBe(true)
  921. releaseCheck!(); releaseCheck = undefined
  922. await expect(dialog.getByRole('alert')).toContainText('暂时无法连接更新服务')
  923. await expect(dialog.getByRole('button', { name: '前往更新', exact: true })).toHaveCount(0)
  924. failed = false
  925. await dialog.getByRole('button', { name: '重试', exact: true }).click()
  926. await expect.poll(() => Boolean(releaseCheck)).toBe(true)
  927. releaseCheck!(); releaseCheck = undefined
  928. await expect(dialog.getByRole('button', { name: '前往更新', exact: true })).toBeVisible()
  929. await page.keyboard.press('Escape')
  930. await expect(dialog).toHaveCount(0)
  931. await expect(account).toBeFocused()
  932. }
  933. })
  934. test('self-registered subaccount approval supports Bot replies, reload and isolation', async ({ page, browser }, testInfo) => {
  935. const childContext = await browser.newContext({ viewport: { width: 1280, height: 800 } })
  936. const child = await childContext.newPage()
  937. const username = `registered-${Date.now()}`
  938. const denied: string[] = []
  939. child.on('response', response => { if (response.status() === 403 && response.url().includes('/api/app/')) denied.push(new URL(response.url()).pathname) })
  940. try {
  941. await child.goto('/conversations')
  942. await child.getByRole('button', { name: '没有账号?注册子账号' }).click()
  943. await child.getByRole('textbox', { name: '账号', exact: true }).fill(username)
  944. await child.getByLabel('密码', { exact: true }).fill('child-password')
  945. await child.getByLabel('确认密码', { exact: true }).fill('child-password')
  946. await child.getByRole('button', { name: '注册子账号', exact: true }).click()
  947. await expect(child.getByRole('status')).toContainText('注册成功')
  948. await child.getByLabel('密码', { exact: true }).fill('child-password')
  949. await child.getByRole('button', { name: '登录', exact: true }).click()
  950. await expect(child.getByRole('alert')).toContainText('尚未开通')
  951. await login(page)
  952. await page.locator('.desktop-sidebar .sidebar-account-switcher__main').click()
  953. await page.getByRole('menuitem', { name: '我的设置', exact: true }).click()
  954. const settings = page.getByRole('dialog', { name: '我的设置', exact: true })
  955. await settings.getByRole('button', { name: '用户与权限', exact: true }).click()
  956. const row = settings.locator('.user').filter({ hasText: username })
  957. await expect(row).toContainText('待管理员开通')
  958. await expect(row.getByRole('button', { name: '分配并开通' })).toBeDisabled()
  959. await row.getByRole('listbox').selectOption('default')
  960. await row.getByRole('button', { name: '分配并开通' }).click()
  961. await expect(row).toContainText('普通用户')
  962. await child.getByLabel('密码', { exact: true }).fill('child-password')
  963. await child.getByRole('button', { name: '登录', exact: true }).click()
  964. await expect(child.getByRole('heading', { name: '还没有聊天' })).toBeVisible()
  965. denied.length = 0
  966. await openCreate(child, '新建 Bot')
  967. const dialog = child.getByRole('dialog')
  968. await expect(dialog.getByLabel('基础机器人').locator('option')).toHaveCount(1)
  969. await dialog.getByRole('textbox', { name: '名称', exact: true }).fill('注册验收助手')
  970. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  971. await expect(child.getByRole('heading', { name: '注册验收助手', exact: true })).toBeVisible()
  972. const composer = child.getByRole('textbox', { name: '输入消息,Enter 发送,Shift + Enter 换行' })
  973. await composer.fill('注册后验证 Bot 回复')
  974. await composer.press('Enter')
  975. await expect.poll(async () => {
  976. const id = new URL(child.url()).pathname.split('/').at(-1)
  977. const response = await child.request.get(`/api/app/conversations/${id}/messages`)
  978. const value = await response.json()
  979. return value.messages?.some((m: any) => m.role === 'assistant' && m.status === 'complete' && m.content)
  980. }).toBe(true)
  981. await expect(child.getByText('会话独立保存', { exact: true })).toBeVisible()
  982. await childContext.setOffline(true)
  983. await expect(child.getByText('网络已断开,恢复连接后将自动同步', { exact: true })).toBeVisible()
  984. await childContext.setOffline(false)
  985. await expect(child.getByText('网络已断开,恢复连接后将自动同步', { exact: true })).toBeHidden({ timeout: 15_000 })
  986. await child.reload()
  987. await expect(child.getByRole('heading', { name: '注册验收助手', exact: true })).toBeVisible()
  988. await expect(child.getByText('注册后验证 Bot 回复', { exact: true }).first()).toBeVisible()
  989. expect((await (await page.request.get('/api/app/agents')).json()).agents.some((a: any) => a.name === '注册验收助手')).toBe(false)
  990. expect(denied).toEqual([])
  991. await child.screenshot({ path: testInfo.outputPath('registered-subaccount-bot.png'), fullPage: true })
  992. } finally { await childContext.close() }
  993. })