| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import { test, expect } from '@playwright/test'
- test('registers a computer, downloads its private config and disables it', async ({ page }, testInfo) => {
- await page.goto('/conversations')
- await page.getByRole('textbox', { name: '账号', exact: true }).fill('fixture')
- await page.getByRole('textbox', { name: '密码', exact: true }).fill('fixture-pass')
- await page.getByRole('button', { name: '登录', exact: true }).click()
- await page.locator('.desktop-sidebar .sidebar-account-switcher__main').click()
- await page.getByRole('menuitem', { name: '我的设置', exact: true }).click()
- const dialog = page.getByRole('dialog', { name: '我的设置' })
- await dialog.getByRole('button', { name: 'Hermes 连接', exact: true }).click()
- await dialog.locator('details.desktop-host-settings summary').click()
- const panel = dialog.getByRole('region', { name: '电脑设置' })
- await expect(panel).toContainText('尚未注册电脑')
- await panel.getByRole('textbox', { name: '电脑名称', exact: true }).fill('书房 iMac')
- await page.screenshot({ path: testInfo.outputPath('desktop-host-registration.png') })
- await panel.getByRole('button', { name: '注册电脑', exact: true }).click()
- await expect(panel).toContainText('待连接')
- const downloaded = page.waitForEvent('download')
- await panel.getByRole('button', { name: '下载电脑配置', exact: true }).click()
- const download = await downloaded
- expect(download.suggestedFilename()).toBe('desktop-host.json')
- const stream = await download.createReadStream(); const chunks: Buffer[] = []
- for await (const chunk of stream!) chunks.push(Buffer.from(chunk))
- const configuration = JSON.parse(Buffer.concat(chunks).toString())
- expect(configuration).toMatchObject({ protocol: 1, serverURL: expect.stringMatching(/^https?:\/\//) })
- expect(configuration.hostId).toMatch(/^[0-9a-f-]{36}$/)
- expect(configuration.token.length).toBeGreaterThan(32)
- const result = await (await page.request.get('/api/app/admin/desktop-hosts')).json()
- expect(JSON.stringify(result)).not.toContain(configuration.token)
- expect(JSON.stringify(result)).not.toContain('tokenHash')
- await page.setViewportSize({ width: 390, height: 844 })
- await panel.getByRole('button', { name: '停用 书房 iMac' }).scrollIntoViewIfNeeded()
- await page.screenshot({ path: testInfo.outputPath('desktop-host-registered-mobile.png') })
- await panel.getByRole('button', { name: '停用 书房 iMac' }).click()
- await expect(panel).toContainText('已停用')
- expect((await (await page.request.get('/api/app/admin/desktop-hosts')).json()).hosts.find((h: any) => h.id === configuration.hostId).enabled).toBe(false)
- })
- test('shows globally available hosts for a legacy Bot without per-Bot switches', async ({ page }, testInfo) => {
- await page.goto('/conversations')
- await page.getByRole('textbox', { name: '账号', exact: true }).fill('fixture')
- await page.getByRole('textbox', { name: '密码', exact: true }).fill('fixture-pass')
- await page.getByRole('button', { name: '登录', exact: true }).click()
- await page.locator('.desktop-sidebar .sidebar-account-switcher__main').click()
- await page.getByRole('menuitem', { name: '我的设置', exact: true }).click()
- const dialog = page.getByRole('dialog', { name: '我的设置' })
- await dialog.getByRole('button', { name: 'Hermes 连接', exact: true }).click()
- await dialog.locator('details.desktop-host-settings summary').click()
- const panel = dialog.getByRole('region', { name: '电脑设置' })
- await panel.getByRole('textbox', { name: '电脑名称', exact: true }).fill('客厅 Mac mini')
- await panel.getByRole('button', { name: '注册电脑', exact: true }).click()
- await expect(panel).toContainText('待连接')
- const downloaded = page.waitForEvent('download')
- await panel.getByRole('button', { name: '下载电脑配置', exact: true }).click()
- const stream = await (await downloaded).createReadStream(); const chunks: Buffer[] = []
- for await (const chunk of stream!) chunks.push(Buffer.from(chunk))
- const configuration = JSON.parse(Buffer.concat(chunks).toString())
- const hostInfo = { id: crypto.randomUUID(), name: '客厅 Mac mini', platform: 'darwin', screen: true, accessibility: true, approved: [] }
- const exchange = () => page.request.post(`/api/desktop-host/v1/${configuration.hostId}/exchange`, {
- headers: { Authorization: `Bearer ${configuration.token}`, 'x-desktop-host-protocol': '1' },
- data: { host: hostInfo, results: [] },
- })
- expect((await (await exchange()).json()).commands).toEqual([])
- const seed = await (await page.request.post('/__test/computer?off=1', { data: {} })).json()
- await page.goto(`/conversations/${seed.conversationId}`)
- await page.getByRole('button', { name: '电脑与定时任务', exact: true }).click()
- const dock = page.getByRole('complementary', { name: '机器人电脑面板' })
- await expect(dock.locator('.env-check')).toHaveCount(0)
- await expect(dock.getByRole('combobox', { name: '操作的电脑', exact: true })).toHaveCount(0)
- const hostCard = dock.locator('.host-permission', { hasText: '客厅 Mac mini' })
- await expect(hostCard).toBeVisible()
- await expect(hostCard).toContainText('在线')
- await hostCard.scrollIntoViewIfNeeded()
- await page.screenshot({ path: testInfo.outputPath('desktop-host-global-permissions.png') })
- const agents = (await (await page.request.get('/api/app/agents')).json()).agents
- const updated = agents.find((a: any) => a.id === seed.agentId)
- expect(updated).toMatchObject({ envs: { vm: true, desktop: true } })
- expect(updated.desktopHost).toBeUndefined()
- })
|