feat(agents): 复用 Yuxi 头像上传与展示

This commit is contained in:
brother7 committed 2026-10-12 13:48:38 +08:00
1 parent 0ca744fb9b
commit 235af24d6c
16 files changed
+381 -32

No files matched your search

+23 -1
View File
@@ -11,6 +11,8 @@ test('personal cloud Agent creation, draft save and leave protection in Electron
await app.evaluate(({ ipcMain, BrowserWindow }) => {
BrowserWindow.getAllWindows()[0].setSize(1366, 768);
let draft: Record<string, unknown> | null = null;
let avatarUploads = 0;
const iconUrl = (icon: unknown) => icon ? 'https://avatars.example.test' + icon : null;
let recent: unknown = null;
const versions: { version: number; draft_revision: number; created_at: string }[] = [];
let knowledgeCatalogLoads = 0;
@@ -38,6 +40,10 @@ test('personal cloud Agent creation, draft save and leave protection in Electron
});
if (path.startsWith('/api/cloud-agents/')) {
const body = typeof request.body === 'string' ? JSON.parse(request.body) : request.body ?? {};
if (path.endsWith('/avatars/pick')) {
const icon = `/api/storage/public/images/avatar-${++avatarUploads}.png`;
return result({ icon, icon_url: iconUrl(icon) });
}
if (path.endsWith('/knowledge/pick')) {
knowledgeUploaded = true;
return result({ ...knowledgeFile, status: 'uploaded', chunk_count: 0, available: false, processing_task: null });
@@ -86,16 +92,19 @@ test('personal cloud Agent creation, draft save and leave protection in Electron
}
if (method === 'POST') draft = {
slug: 'ml-' + 'a'.repeat(32), name: body.name, purpose: body.purpose, system_prompt: body.purpose,
icon: body.icon ?? null, icon_url: iconUrl(body.icon),
draft_revision: 1, updated_at: '2026-09-10T00:00:00Z',
configuration, published_version: null, enabled: true,
};
if (method === 'PATCH') draft = { ...draft, name: body.name, purpose: body.purpose, system_prompt: body.system_prompt, configuration: body.configuration, draft_revision: Number(draft?.draft_revision ?? 1) + 1 };
if (method === 'PATCH') draft = { ...draft, name: body.name, purpose: body.purpose, icon: body.icon ?? null, icon_url: iconUrl(body.icon), system_prompt: body.system_prompt, configuration: body.configuration, draft_revision: Number(draft?.draft_revision ?? 1) + 1 };
if (method === 'GET' && (path.endsWith('/agents') || path.endsWith('/bootstrap'))) return result({ agents: draft ? [draft] : [], next_cursor: null });
return result(draft);
}
return result({ success: true });
});
});
await page.route('https://avatars.example.test/**', route => route.fulfill({ contentType: 'image/png',
body: Buffer.from('iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAALUlEQVR4nGOssXrLQEvARFPTRy0YtWDUglELRi0YtWDUglELRi0YtWDUAioCAGYEAeMrBAV7AAAAAElFTkSuQmCC', 'base64') }));
await page.goto(applicationUrl);
await page.getByTestId('ai-module-option-cloud_agents').click();
await expect(page.getByTestId('sidebar-cloud-agents-navigation')).toBeVisible();
@@ -106,9 +115,15 @@ test('personal cloud Agent creation, draft save and leave protection in Electron
await page.getByRole('button', { name: '先给我提示', exact: true }).click();
await page.getByLabel('名称', { exact: true }).fill('我的写作搭档');
await page.getByLabel('用途', { exact: true }).fill('整理灵感,把想法写成清晰的文章');
await page.getByRole('button', { name: '上传头像', exact: true }).click();
await expect(page.getByRole('img', { name: '我的写作搭档头像', exact: true })).toHaveAttribute('src', /avatar-1\.png$/);
await page.screenshot({ path: testInfo.outputPath('cloud-agent-create-requirements.png') });
await page.getByRole('button', { name: '下一步:试一试', exact: true }).click();
await expect(page.getByTestId('cloud-agent-editor')).toBeVisible();
await expect(page.getByRole('group', { name: '智能体头像' }).getByRole('img')).toHaveAttribute('src', /avatar-1\.png$/);
await page.getByRole('button', { name: '更换头像', exact: true }).click();
await expect(page.getByRole('group', { name: '智能体头像' }).getByRole('img')).toHaveAttribute('src', /avatar-2\.png$/);
await expect.poll(() => page.getByRole('group', { name: '智能体头像' }).getByRole('img').evaluate(el => (el as HTMLImageElement).naturalWidth)).toBe(32);
await page.getByLabel('特别要求').fill('使用简洁自然的中文。先理解我的目的,再协助梳理结构。');
await expect(page.getByLabel('模型', { exact: true })).toHaveValue('test-model');
await expect(page.getByRole('button', { name: '先给我提示', exact: true })).toHaveAttribute('aria-pressed', 'true');
@@ -117,6 +132,7 @@ test('personal cloud Agent creation, draft save and leave protection in Electron
await page.getByRole('button', { name: '继续编辑', exact: true }).click();
await page.getByRole('button', { name: '保存并开始试用', exact: true }).click();
await expect(page.getByRole('button', { name: '已保存', exact: true })).toBeVisible();
await expect(page.getByRole('group', { name: '智能体头像' }).getByRole('img')).toHaveAttribute('src', /avatar-2\.png$/);
await expect(page.getByTestId('titlebar-page-title')).toHaveText('智能体工作区');
const requirementsTab = page.getByRole('tab', { name: '我的要求', exact: true });
const advancedTab = page.getByRole('tab', { name: '高级设置', exact: true });
@@ -313,6 +329,12 @@ test('personal cloud Agent creation, draft save and leave protection in Electron
await expect(page.getByLabel('保存后启用')).not.toBeChecked();
await page.getByRole('button', { name: '取消', exact: true }).click();
await page.screenshot({ path: testInfo.outputPath('cloud-agent-schedules.png') });
await page.getByRole('navigation', { name: '智能体工作区' }).getByRole('button', { name: '编辑', exact: true }).click();
await page.getByRole('tab', { name: '我的要求', exact: true }).click();
await page.getByRole('button', { name: '移除头像', exact: true }).click();
await page.getByRole('button', { name: '保存草稿', exact: true }).click();
await expect(page.getByRole('button', { name: '已保存', exact: true })).toBeVisible();
await expect(page.getByRole('group', { name: '智能体头像' }).getByRole('img', { name: '我的新版写作搭档默认头像' })).toBeVisible();
} finally {
await app.evaluate(({ BrowserWindow }) => { for (const win of BrowserWindow.getAllWindows()) win.destroy(); }).catch(() => undefined);
await closeElectronApp(app);