Refine personal Agent cards and configuration

This commit is contained in:
鲨鱼辣椒 committed 2026-10-12 17:45:02 +08:00
1 parent c14d996c05
commit 8b40463a9f
17 files changed
+555 -412

No files matched your search

+51 -29
View File
@@ -11,19 +11,20 @@ const agent = (character: string, name: string, published: boolean, extra: Parti
});
const readyAgent = agent('a', '我的故事搭档', true);
const draftAgent = agent('b', '我的英语陪练', false);
const draftAgent = agent('b', '我的英语陪练', false, { purpose: '' });
const disabledAgent = agent('c', '暂停使用的助手', true, { enabled: false });
const archivedAgent = agent('d', '以前的学习助手', true, { archived: true });
async function openHome(app: ElectronApplication, agents: CloudAgentDraft[]): Promise<Page> {
async function openHome(app: ElectronApplication, agents: CloudAgentDraft[], failArchiveOnce = false): Promise<Page> {
const page = await getStableWindow(app);
await expect(page.getByTestId('ai-module-selection-page')).toBeVisible();
const applicationUrl = page.url();
await page.goto('about:blank');
// The UI fixture owns the Host API boundary. These tests never send a real message or publish an Agent.
await app.evaluate(({ ipcMain, BrowserWindow }, items) => {
await app.evaluate(({ ipcMain, BrowserWindow }, { items, failArchiveOnce }) => {
BrowserWindow.getAllWindows()[0].setSize(1366, 768);
let recent: unknown = null;
let archiveAttempts = 0;
const result = (json: unknown) => ({ ok: true, data: { status: 200, ok: true, json } });
ipcMain.removeHandler('hostapi:fetch');
ipcMain.handle('hostapi:fetch', async (_event, request: { path?: string; method?: string; body?: string }) => {
@@ -57,6 +58,13 @@ async function openHome(app: ElectronApplication, agents: CloudAgentDraft[]): Pr
const body = JSON.parse(request.body ?? '{}');
const selected = items.find(item => item.slug === body.input?.slug) ?? items[0];
switch (body.operation) {
case 'archiveAgent': {
archiveAttempts += 1;
if (failArchiveOnce && archiveAttempts === 1) throw new Error('暂时无法删除,请稍后重试');
if (!selected) throw new Error('Unknown fixture Agent');
selected.archived = body.input.archived;
return result(selected);
}
case 'catalog': return result({ models: [{ id: 'fixture-model', name: '创作模型' }], resources: {}, pricing: null });
case 'resources': return result({ mcps: [], skills: [], subagents: [] });
case 'knowledge': return result({ databases: [], models: [] });
@@ -75,7 +83,7 @@ async function openHome(app: ElectronApplication, agents: CloudAgentDraft[]): Pr
}
throw new Error('Unexpected homepage fixture request ' + path);
});
}, agents);
}, { items: agents, failArchiveOnce });
await page.goto(applicationUrl);
await page.getByTestId('ai-module-option-cloud_agents').click();
await expect(page.getByTestId('cloud-agents-page')).toBeVisible();
@@ -87,7 +95,10 @@ test('Agent homepage guides the first creation without starter tiles', async ({
try {
const page = await openHome(app, []);
const home = page.getByTestId('cloud-agents-page');
await expect(home.getByRole('heading', { name: '我的智能体', exact: true })).toBeVisible();
await expect(home.getByRole('heading', { name: 'Hi,今天想创造还是想聊聊?', exact: true })).toBeVisible();
await expect(home.getByRole('heading', { name: '我的智能体', exact: true })).toHaveCount(0);
await expect(page.getByText('智能体工作区', { exact: true })).toHaveCount(0);
await expect(home.getByRole('button', { name: '更多', exact: true })).toHaveCount(0);
await expect(home.getByRole('heading', { name: '做一个属于你的 AI 助手吧', exact: true })).toBeVisible();
await expect(home.getByRole('article')).toHaveCount(0);
await expect(home.getByRole('button', { name: /故事搭档|英语陪练|学习Friend/ })).toHaveCount(0);
@@ -125,6 +136,8 @@ test('Agent cards open conversation, adjustment and unfinished creation explicit
await expect(ready.getByRole('button', { name: '调整', exact: true })).toBeVisible();
await expect(draft.getByRole('button', { name: '继续制作', exact: true })).toBeVisible();
await expect(draft.getByRole('button', { name: '和它聊聊', exact: true })).toHaveCount(0);
await expect(draft.locator('.agent-home-purpose')).toHaveCount(0);
await expect(draft.getByRole('button', { name: `删除${draftAgent.name}`, exact: true })).toBeVisible();
await expect(disabled.getByRole('button', { name: '查看与调整', exact: true })).toBeVisible();
await expect(disabled.getByRole('button', { name: '和它聊聊', exact: true })).toHaveCount(0);
await page.screenshot({ path: testInfo.outputPath('cloud-agent-home-populated.png') });
@@ -137,46 +150,55 @@ test('Agent cards open conversation, adjustment and unfinished creation explicit
await ready.getByRole('button', { name: '和它聊聊', exact: true }).click();
await expect(page.getByRole('region', { name: '智能体对话', exact: true })).toBeVisible();
await expect(page.getByRole('navigation', { name: '智能体工作区' }).getByRole('button', { name: '聊天', exact: true })).toHaveAttribute('aria-current', 'page');
await expect(page.getByTestId('cloud-agent-editor').getByRole('button', { name: '聊天', exact: true })).toHaveCount(0);
await page.getByTestId('cloud-agent-editor').getByRole('button', { name: '我的智能体', exact: true }).click();
await expect(ready).toBeVisible();
await ready.getByRole('button', { name: '调整', exact: true }).click();
await expect(page.getByRole('navigation', { name: '智能体工作区' }).getByRole('button', { name: '配置', exact: true })).toHaveAttribute('aria-current', 'page');
await expect(page.getByRole('tab', { name: '模型与提示词', exact: true })).toHaveAttribute('aria-selected', 'true');
await expect(page.getByRole('tab', { name: '介绍与提示词', exact: true })).toHaveAttribute('aria-selected', 'true');
await expect(page.getByTestId('cloud-agent-editor').getByRole('button', { name: /^(聊天|自动任务|使用与接入)$/ })).toHaveCount(0);
await expect(page.getByTestId('cloud-agent-editor').getByRole('button', { name: '修改头像', exact: true })).toBeVisible();
await expect(page.getByRole('img', { name: readyAgent.name + '默认头像', exact: true })).toBeVisible();
await expect(page.getByLabel('提示词', { exact: true })).toHaveValue(readyAgent.system_prompt);
await page.getByTestId('cloud-agent-editor').getByRole('button', { name: '我的智能体', exact: true }).click();
await draft.getByRole('button', { name: '继续制作', exact: true }).click();
await expect(page.getByRole('navigation', { name: '智能体工作区' }).getByRole('button', { name: '配置', exact: true })).toHaveAttribute('aria-current', 'page');
await expect(page.getByRole('tab', { name: '模型与提示词', exact: true })).toHaveAttribute('aria-selected', 'true');
await expect(page.getByRole('tab', { name: '介绍与提示词', exact: true })).toHaveAttribute('aria-selected', 'true');
await expect(page.getByLabel('一句话介绍', { exact: true })).toHaveValue('');
await expect(page.getByLabel('名称', { exact: true })).toHaveValue(draftAgent.name);
await expect(page.getByLabel('提示词', { exact: true })).toHaveValue(draftAgent.system_prompt);
} finally { await closeElectronApp(app); }
});
test('Secondary sharing, activity and archived Agents remain reachable from More', async ({ launchElectronApp }) => {
test('Agent deletion confirms, preserves a failed card for retry and keeps other cards', async ({ launchElectronApp }, testInfo) => {
const app = await launchElectronApp({ skipSetup: true });
try {
const page = await openHome(app, [readyAgent, archivedAgent]);
const page = await openHome(app, [readyAgent, draftAgent, archivedAgent], true);
const home = page.getByTestId('cloud-agents-page');
await expect(home.getByRole('article', { name: archivedAgent.name, exact: true })).toHaveCount(0);
await home.getByRole('button', { name: '更多', exact: true }).click();
await page.getByRole('menuitemcheckbox', { name: '查看已归档智能体', exact: true }).click();
const archived = home.getByRole('article', { name: archivedAgent.name, exact: true });
await expect(archived).toBeVisible();
await expect(home.getByRole('article', { name: readyAgent.name, exact: true })).toBeVisible();
await expect(archived.getByRole('button', { name: '查看与调整', exact: true })).toBeVisible();
await expect(archived.getByRole('button', { name: '和它聊聊', exact: true })).toHaveCount(0);
await home.getByRole('button', { name: '更多', exact: true }).click();
await page.getByRole('menuitem', { name: '收到的分享', exact: true }).click();
await expect(page.getByText('还没有收到分享', { exact: true })).toBeVisible();
await page.getByRole('button', { name: '返回我的智能体', exact: true }).click();
await expect(home.getByRole('heading', { name: '我的智能体', exact: true })).toBeVisible();
await home.getByRole('button', { name: '更多', exact: true }).click();
await page.getByRole('menuitem', { name: '活动', exact: true }).click();
await expect(page.getByText('还没有运行记录', { exact: true })).toBeVisible();
await page.getByRole('button', { name: '返回我的智能体', exact: true }).click();
await expect(home.getByRole('heading', { name: '我的智能体', exact: true })).toBeVisible();
await expect(home.getByRole('button', { name: '更多', exact: true })).toHaveCount(0);
await expect(home.getByText('收到的分享', { exact: true })).toHaveCount(0);
await expect(home.getByText('活动', { exact: true })).toHaveCount(0);
await expect(home.getByText('查看已归档智能体', { exact: true })).toHaveCount(0);
const ready = home.getByRole('article', { name: readyAgent.name, exact: true });
const draft = home.getByRole('article', { name: draftAgent.name, exact: true });
await ready.getByRole('button', { name: `删除${readyAgent.name}`, exact: true }).click();
const dialog = page.getByRole('dialog', { name: `删除「${readyAgent.name}」?`, exact: true });
await expect(dialog.getByText('它会从「我的智能体」中移除,并停止后续使用。已有的聊天记录会保留。', { exact: true })).toBeVisible();
await expect(dialog.getByRole('button', { name: '取消', exact: true })).toBeFocused();
await dialog.getByRole('button', { name: '取消', exact: true }).click();
await expect(dialog).toBeHidden();
await expect(ready).toBeVisible();
await ready.getByRole('button', { name: `删除${readyAgent.name}`, exact: true }).click();
await dialog.getByRole('button', { name: '删除', exact: true }).click();
await expect(dialog.getByRole('alert')).toContainText('智能体仍在列表中,你可以重试。');
await page.screenshot({ path: testInfo.outputPath('cloud-agent-home-delete-retry.png') });
await dialog.getByRole('button', { name: '重试删除', exact: true }).click();
await expect(dialog).toBeHidden();
await expect(ready).toHaveCount(0);
await expect(draft).toBeVisible();
await expect(home.getByRole('article')).toHaveCount(1);
await page.reload();
await expect(home.getByRole('heading', { name: 'Hi,今天想创造还是想聊聊?', exact: true })).toBeVisible();
await expect(ready).toHaveCount(0);
await expect(draft).toBeVisible();
} finally { await closeElectronApp(app); }
});