import { test, expect } from '@playwright/test' test('team permission defaults off, saves, reloads and revokes in the Agent editor', 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 expect(page.getByRole('heading',{name:'还没有聊天'})).toBeVisible() await page.locator('.desktop-sidebar .sidebar-create-trigger').click() await page.getByRole('menuitem',{name:'新建 Bot',exact:true}).click() const dialog=page.getByRole('dialog'), permission=dialog.getByRole('checkbox',{name:'允许组建团队',exact:true}) await dialog.getByRole('textbox',{name:'名称',exact:true}).fill('组队老板') await expect(permission).not.toBeChecked() await permission.check() await permission.scrollIntoViewIfNeeded() await page.screenshot({path:testInfo.outputPath('team-permission-desktop.png')}) const saved=page.waitForResponse(r=>r.request().method()==='POST' && r.url().endsWith('/api/app/agents')) await dialog.getByRole('button',{name:'保存',exact:true}).click() const response=await saved expect(response.ok(),await response.text()).toBe(true) const agent=(await response.json()).agent expect(agent.canManageTeam).toBe(true) await page.reload() await expect(page.getByRole('heading',{name:'组队老板',exact:true})).toBeVisible() const edit=page.getByRole('button',{name:'聊天设置',exact:true}) await edit.click() await expect(permission).toBeChecked() await page.setViewportSize({width:375,height:812}) await page.emulateMedia({colorScheme:'dark',reducedMotion:'reduce'}) await permission.scrollIntoViewIfNeeded() await page.screenshot({path:testInfo.outputPath('team-permission-mobile.png')}) await permission.uncheck() const revoked=page.waitForResponse(r=>r.request().method()==='PATCH' && r.url().endsWith(`/api/app/agents/${agent.id}`)) await dialog.getByRole('button',{name:'保存',exact:true}).click() expect((await (await revoked).json()).agent.canManageTeam).toBe(false) expect((await (await page.request.get('/api/app/agents')).json()).agents.find((a:any)=>a.id===agent.id).canManageTeam).toBe(false) }) test('task plans show owners and keep independent text and attachment drafts when switching tasks',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 expect(page.locator('.desktop-sidebar .sidebar-create-trigger')).toBeVisible() const seeded=await page.request.post('/__test/task-plan?helper=1',{data:{}}) expect(seeded.ok()).toBe(true) const ids=await seeded.json() await page.goto(`/conversations/${ids.sourceConversationId}`) await page.getByRole('link',{name:'打开任务',exact:true}).click() await expect(page).toHaveURL(new RegExp(`/conversations/${ids.conversationId}\\?taskId=${ids.firstTaskId}`)) await page.locator('details.task-plan summary').click() await expect(page.locator('.task-plan')).toContainText('研究资料') await expect(page.locator('.task-plan')).toContainText('验收研究员') await expect(page.locator('.task-plan')).toContainText('临时助手') await page.screenshot({path:testInfo.outputPath('task-helper-active.png')}) const composer=page.getByRole('textbox',{name:'输入消息,Enter 发送,Shift + Enter 换行'}) await composer.fill('调研任务的草稿') await page.locator('.composer-area input[type=file]').first().setInputFiles({name:'draft.txt',mimeType:'text/plain',buffer:Buffer.from('待发送附件')}) await page.getByRole('combobox',{name:'当前任务'}).selectOption(ids.secondTaskId) await expect(composer).toHaveValue('') await composer.fill('独立任务的草稿') await page.getByRole('combobox',{name:'当前任务'}).selectOption(ids.firstTaskId) await expect(composer).toHaveValue('调研任务的草稿') await expect(page.locator('.composer-attachments')).toContainText('draft.txt') await page.screenshot({path:testInfo.outputPath('task-plan-drafts.png')}) if(!await page.getByRole('button',{name:'停止任务',exact:true}).isVisible())await page.locator('details.task-plan summary').click() await page.getByRole('button',{name:'停止任务',exact:true}).click() await expect(page.locator('.task-plan')).toContainText('已停止') await expect(page.locator('.task-plan')).toContainText('已退役') if(!await page.getByText('验收研究员(临时) · 临时助手', {exact:false}).first().isVisible())await page.locator('details.task-plan summary').click() await page.screenshot({path:testInfo.outputPath('task-helper-retired.png')}) }) test('registers an execution node, 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.getByRole('button',{name:/^(打开设置中心|设置与模式)$/}).first().click() if(await page.getByRole('menuitem',{name:'进入设置',exact:true}).isVisible())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.runner-settings summary').click() const panel=dialog.getByRole('region',{name:'执行节点设置'}) await panel.getByRole('textbox',{name:'节点名称',exact:true}).fill('隔离测试 Mac') await panel.getByRole('textbox',{name:'允许的 Profile'}).fill('default') await panel.getByRole('checkbox',{name:'启用隔离电脑 Worker'}).check() await panel.getByRole('textbox',{name:'兼容镜像 ID'}).fill('sha256:'+'a'.repeat(64)) await panel.getByRole('textbox',{name:'Hermes Python 路径'}).fill('/fixture/venv/bin/python') await panel.getByRole('textbox',{name:'Hermes 源码目录'}).fill('/fixture/hermes-agent') await panel.getByRole('textbox',{name:'Hermes 配置目录'}).fill('/fixture/hermes') await panel.scrollIntoViewIfNeeded() await page.screenshot({path:testInfo.outputPath('runner-registration.png')}) await panel.getByRole('button',{name:'注册节点',exact:true}).click() await expect(panel).toContainText('待连接') const downloaded=page.waitForEvent('download') await panel.getByRole('button',{name:'下载 Runner 配置',exact:true}).click() const download=await downloaded expect(download.suggestedFilename()).toBe('runner.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,allowedProfiles:['default'],artifactRoots:[],computers:{network:'public-proxy',runtime:'docker',python:'/fixture/venv/bin/python',hermesHome:'/fixture/hermes'}}) expect(configuration.token.length).toBeGreaterThan(32) const result=await (await page.request.get('/api/app/admin/runners')).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:'停用 隔离测试 Mac'}).scrollIntoViewIfNeeded() await page.screenshot({path:testInfo.outputPath('runner-registered-mobile.png')}) await panel.getByRole('button',{name:'停用 隔离测试 Mac'}).click() await expect(panel).toContainText('已停用') expect((await (await page.request.get('/api/app/admin/runners')).json()).runners.find((r:any)=>r.id===configuration.runnerId).enabled).toBe(false) }) test('configures the Agent computer in its chat panel and keeps preparation in app settings',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-create-trigger').click();await page.getByRole('menuitem',{name:'新建 Bot',exact:true}).click() const editor=page.getByRole('dialog');await editor.getByRole('textbox',{name:'名称',exact:true}).fill('尚未配置的本地电脑') await expect(editor.getByRole('combobox',{name:'执行环境'})).toHaveCount(0) await editor.getByRole('button',{name:'保存',exact:true}).click() await page.getByRole('button',{name:'电脑',exact:true}).click() const dock=page.getByRole('complementary',{name:'Agent 电脑面板'}) const vmTab=dock.getByRole('tab',{name:'本地虚拟机',exact:true}) await vmTab.click() await expect(vmTab).toHaveAttribute('aria-selected','true') await expect(dock.getByRole('button',{name:'设置本地虚拟机',exact:true})).toBeVisible() await page.screenshot({path:testInfo.outputPath('local-vm-unconfigured-agent.png')}) }) async function login(page:any,ready=false){ 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 expect(page.locator('.desktop-sidebar .sidebar-create-trigger')).toBeVisible() await page.request.post('/__test/local-vm'+(ready?'?ready=1':''),{data:{}}) } test('Local VM settings replace the image catalog and prepare the managed desktop',async({page},testInfo)=>{ await login(page) await expect(page.getByRole('button',{name:'电脑与环境',exact:true})).toHaveCount(0) await page.getByRole('button',{name:'设置与模式',exact:true}).first().click() await page.getByRole('menuitem',{name:'进入设置',exact:true}).click() const settings=page.getByRole('dialog',{name:'设置中心'}) await settings.getByRole('button',{name:'本地虚拟机',exact:true}).click() const panel=settings.getByRole('region',{name:'本地虚拟机设置'}) await expect(panel).toContainText('隔离方式') await expect(panel.getByRole('button',{name:'上传并导入'})).toHaveCount(0) await panel.getByRole('button',{name:'准备本地虚拟机',exact:true}).click() await expect(panel).toContainText('虚拟机环境已就绪') await panel.getByRole('combobox',{name:'虚拟机数量上限'}).selectOption('3') await expect(panel.getByRole('combobox',{name:'虚拟机数量上限'})).toHaveValue('3') await panel.getByRole('heading',{name:'本地虚拟机',exact:true}).scrollIntoViewIfNeeded() await page.screenshot({path:testInfo.outputPath('local-vm-settings.png')}) expect((await page.request.get('/api/app/admin/runners/11111111-1111-4111-8111-111111111111/images')).status()).toBe(404) }) test('Agent computer appears as a right panel and opens an interactive desktop',async({page},testInfo)=>{ await login(page) 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:'Agent 电脑面板'}) await expect(dock).toBeVisible();await expect(dock).toContainText('本地虚拟机') await dock.getByRole('button',{name:'设置本地虚拟机',exact:true}).click() const settings=page.getByRole('dialog',{name:'设置中心'}) await settings.getByRole('button',{name:'准备本地虚拟机',exact:true}).click() await settings.getByRole('button',{name:'关闭设置中心',exact:true}).click() await expect(dock.getByRole('button',{name:/创建.*的虚拟机/})).toBeVisible({timeout:12000}) await dock.getByRole('button',{name:/创建.*的虚拟机/}).click() await expect(dock.getByRole('img')).toBeVisible() const bounds=await dock.boundingBox();expect(bounds!.x).toBeGreaterThan(500) await page.screenshot({path:testInfo.outputPath('agent-local-vm-panel.png')}) expect((await(await page.request.get('/__test/computer')).json()).actions).toEqual([]) await dock.getByRole('button',{name:'打开桌面',exact:true}).click() const viewer=page.getByRole('dialog',{name:'隔离电脑',exact:true}) await expect(viewer).toContainText('人工控制中') await viewer.getByRole('button',{name:'键盘与操作',exact:true}).click() await viewer.getByRole('textbox',{name:'输入到电脑',exact:true}).fill('本地虚拟机交互验收') await viewer.getByRole('button',{name:'输入文字',exact:true}).click() await expect.poll(async()=>(await(await page.request.get('/__test/computer')).json()).actions).toEqual([{kind:'text',text:'本地虚拟机交互验收'}]) await viewer.getByRole('img').dblclick() await expect.poll(async()=>(await(await page.request.get('/__test/computer')).json()).actions.filter((a:any)=>a.kind==='click')).toMatchObject([{kind:'click',button:'left',count:2}]) await viewer.getByRole('button',{name:'交还并关闭',exact:true}).click() await dock.getByRole('button',{name:'停止虚拟机',exact:true}).click() await expect(dock.getByRole('button',{name:'启动虚拟机',exact:true})).toBeVisible() }) test('two desktops are watch-only on opening and release before changing the controlled pane',async({page},testInfo)=>{ await login(page,true) const first=await(await page.request.post('/__test/computer',{data:{}})).json() const second=await(await page.request.post('/__test/computer',{data:{}})).json() await page.goto(`/conversations/${first.conversationId}`) await page.getByRole('button',{name:'电脑',exact:true}).click() const dock=page.getByRole('complementary',{name:'Agent 电脑面板'}) await expect(dock.getByRole('button',{name:'打开双桌面'})).toBeVisible() await dock.getByRole('button',{name:'打开双桌面'}).click() const workspace=page.getByRole('main',{name:'双桌面工作区'}) await expect(workspace.locator('.pane')).toHaveCount(2) await workspace.getByRole('combobox',{name:'选择桌面 2'}).selectOption(second.agentId) await expect(workspace.locator('.pane').last().getByRole('img')).toBeVisible() await expect(workspace.getByRole('button',{name:'接管电脑',exact:true})).toHaveCount(2) await workspace.locator('.pane').first().getByRole('button',{name:'接管电脑',exact:true}).click() await expect(workspace.locator('.pane').first()).toContainText('人工控制中') await workspace.locator('.pane').last().getByRole('button',{name:'接管电脑',exact:true}).click() await expect(workspace.locator('.pane').first().getByRole('button',{name:'接管电脑',exact:true})).toBeVisible() await expect(workspace.locator('.pane').last()).toContainText('人工控制中') await page.screenshot({path:testInfo.outputPath('local-vm-two-desktops.png')}) await workspace.getByRole('button',{name:'交还并关闭',exact:true}).click() await expect(workspace).toHaveCount(0) })