import { test, expect, type Page } from '@playwright/test' async function login(page: Page) { 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() } async function createAgent(page: Page, name: string) { await page.getByRole('button', { name: '+ 创建 Agent', exact: true }).click() const dialog = page.getByRole('dialog') await dialog.getByRole('textbox', { name: '名称', exact: true }).fill(name) await dialog .getByRole('textbox', { name: '角色提示词与规则', exact: true }) .fill(`你是${name},每次回复给出验收证据。`) await dialog.getByRole('button', { name: `使用颜色 ${name === '产品经理' ? '#e78531' : '#0ea5c6'}`, exact: true }).click() await dialog.locator('.mascot-grid--shape button').filter({ hasText: name === '产品经理' ? '圆形' : '小三角' }).first().click() await dialog.getByRole('button', { name: '保存', exact: true }).click() await expect(page.getByRole('heading', { name, exact: true })).toBeVisible() } test('created roles and editable teams share a durable chat list without plugin calls', async ({ page, context, }, testInfo) => { const pluginCalls: string[] = [] page.on('request', (r) => { if (r.url().includes('/plugins/yaoyao')) pluginCalls.push(r.url()) }) await login(page) await page.addInitScript(() => { Object.defineProperty(crypto, 'randomUUID', { value: undefined, configurable: true }) }) await page.reload() await createAgent(page, '产品经理') await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('请说明角色职责') await page.getByRole('button', { name: '发送消息', exact: true }).click() await expect(page.locator('.message--assistant')).toContainText('我是产品经理') await expect(page.locator('.message--assistant a').first()).toHaveAttribute( 'href', /\/api\/app\/files\/.+\/download/, ) await page.getByRole('button', {name:'置顶聊天',exact:true}).click() await expect(page.getByRole('button', {name:'取消置顶',exact:true})).toBeVisible() const directURL = page.url() await createAgent(page, '开发工程师') await expect(page.locator('.message')).toHaveCount(0) await page.getByRole('button', { name: '+ 创建群聊', exact: true }).click() const dialog = page.getByRole('dialog') await dialog.getByRole('textbox', { name: '名称', exact: true }).fill('产品开发团队') await dialog.getByRole('checkbox', { name: '产品经理', exact: true }).check() await dialog.getByRole('checkbox', { name: '开发工程师', exact: true }).check() await dialog .getByRole('combobox', { name: '管理员', exact: true }) .selectOption({ label: '产品经理' }) await dialog.getByRole('button', { name: '保存', exact: true }).click() await expect(page.getByRole('heading', { name: '产品开发团队', exact: true })).toBeVisible() await expect(page.locator('.desktop-sidebar .sidebar-item')).toHaveCount(3) // Every cluster portrait must be the same portrait shown in that member's direct chat. const groupRow = page.locator('.desktop-sidebar .sidebar-item').filter({ hasText: '产品开发团队' }) await expect(groupRow.locator('.team-avatar__member')).toHaveCount(2) for (const name of ['产品经理', '开发工程师']) { const portrait = `.agent-avatar[aria-label="${name} 的头像"]` const direct = page.locator('.desktop-sidebar .sidebar-item').filter({ hasText: name }).filter({ hasNot: page.locator('.team-avatar') }).locator(portrait) const member = groupRow.locator(portrait) await expect(member.locator('stop[offset="0.5"]')).toHaveAttribute('stop-color', await direct.locator('stop[offset="0.5"]').getAttribute('stop-color') || '') expect(await member.locator('.agent-avatar__body > :first-child').evaluate(el => el.tagName)) .toBe(await direct.locator('.agent-avatar__body > :first-child').evaluate(el => el.tagName)) } await expect(page.locator('.desktop-sidebar')).not.toContainText('话题') await expect(page.locator('.desktop-sidebar .sidebar-account-switcher')).not.toContainText( '通用助手', ) await page.getByRole('button', { name: '聊天设置', exact: true }).click() await expect(dialog.getByRole('checkbox', { name: '产品经理', exact: true })).toBeDisabled() await expect(dialog.getByRole('checkbox', { name: '开发工程师', exact: true })).toBeEnabled() await dialog.getByRole('button', { name: '取消', exact: true }).click() await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('请@开发工程师给出实现结果') await page.getByRole('button', { name: '发送消息', exact: true }).click() await expect(page.locator('.message--assistant')).toHaveCount(2) await expect(page.locator('.message--assistant').first()).toContainText('我是开发工程师') await expect(page.locator('.run-status')).toHaveCount(0) const second = await context.newPage() await second.goto(page.url()) await expect(second.locator('.message--assistant')).toHaveCount(2) await page.screenshot({ path: testInfo.outputPath('mixed-chats.png'), fullPage: true }) const groupURL=page.url() await page.getByRole('button', { name: '聊天设置', exact: true }).click() await dialog.getByRole('checkbox', { name: '开发工程师', exact: true }).uncheck() await expect(dialog.getByRole('checkbox', { name: '产品经理', exact: true })).toBeDisabled() await dialog.getByRole('button', { name: '保存', exact: true }).click() await expect(groupRow.locator('.team-avatar__member')).toHaveCount(1) await expect(page.locator('.message--assistant')).toHaveCount(2) await expect(second.locator('.desktop-sidebar .sidebar-item').filter({ hasText: '产品开发团队' }).locator('.team-avatar__member')).toHaveCount(1) await page.reload() await page.getByRole('button', { name: '聊天设置', exact: true }).click() await expect(dialog.getByRole('checkbox', { name: '开发工程师', exact: true })).not.toBeChecked() await dialog.getByRole('button', { name: '取消', exact: true }).click() await createAgent(page, '新成员') await page.goto(groupURL) await page.getByRole('button', { name: '聊天设置', exact: true }).click() await dialog.getByRole('checkbox', { name: '新成员', exact: true }).check() await dialog.getByRole('checkbox', { name: '产品经理', exact: true }).scrollIntoViewIfNeeded() await page.screenshot({ path: testInfo.outputPath('member-settings.png'), fullPage: true }) await dialog.getByRole('button', { name: '保存', exact: true }).click() await expect(groupRow.locator('.team-avatar__member')).toHaveCount(2) await expect(groupRow.locator('[aria-label="开发工程师 的头像"]')).toHaveCount(0) await expect(groupRow.locator('[aria-label="新成员 的头像"]')).toHaveCount(1) await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('请@新成员继续') await page.getByRole('button', { name: '发送消息', exact: true }).click() await expect(page.locator('.message--assistant')).toHaveCount(4) await expect(page.locator('.message--assistant').nth(2)).toContainText('我是新成员') await page.getByRole('button',{name:'文件库',exact:true}).click() await page.getByRole('button',{name:'查看来源',exact:true}).first().click() await expect(page).toHaveURL(groupURL) await page.getByRole('button', { name: '归档聊天', exact: true }).click() await expect(page.locator('.desktop-sidebar .sidebar-item')).toHaveCount(3) await page.getByRole('checkbox', { name: '显示已归档', exact: true }).first().check() await expect(page.locator('.desktop-sidebar .sidebar-item')).toHaveCount(1) await page.getByRole('button', { name: '恢复聊天', exact: true }).click() await page.goto(directURL) await expect(page.locator('.message--assistant')).toHaveCount(1) await expect(page.locator('.message--assistant')).toContainText('我是产品经理') await page.getByRole('button', { name: '原生对话', exact: true }).click() await expect(page).toHaveURL(/\/chat/) expect(pluginCalls).toEqual([]) await second.close() })