fix: restore chat citations and tool details
This commit is contained in:
@@ -6,8 +6,14 @@ async function mockApi(page: Page) {
|
||||
7: { id: 7, title: '历史会话', course_version_id: 1, batch_id: null, project_id: null,
|
||||
scope_locked: true, messages: [{ id: 1, role: 'user', content: '旧问题' }, { id: 2, role: 'assistant',
|
||||
content: '# 标题\n\n段落 [安全链接](https://example.com) [危险链接](javascript:alert(1)) <img src=x onerror=alert(1)>\n\n> 引用\n\n- 列表\n\n| A | B |\n|---|---|\n| 1 | 2 |\n\n```js\nconst x = 1;\n```',
|
||||
citations: [{ title: '资料.pdf', page: 2, quote: '原文摘录', url: '/api/pages/2' }, { title: '资料.pdf', page: 2, quote: '原文摘录', url: '/api/pages/2' }],
|
||||
tool_calls: [{ id: 'call-one', name: 'list_courses', status: 'completed', arguments: { course_version_id: 1 }, result: '返回 1 条记录' }] }],
|
||||
citations: [{ title: '资料.pdf', page: 2, quote: '原文摘录', url: '/api/pages/2' }, { title: '资料.pdf', page: 2, quote: '原文摘录', url: '/api/pages/2' },
|
||||
{ chunk_id: 2977, title: '综合报告.pdf', page: 48, quote: '第48页原文片段', url: '/api/pages/48' }],
|
||||
tool_calls: [{ id: 'call-one', name: 'search_project_material', status: 'completed', arguments: { project_id: 1 },
|
||||
summary: '找到 1 条引用', result: { found: true, citations: [{ page: 48, quote: '第48页原文片段' }] } },
|
||||
{ id: 'call-two', name: 'get_scores', status: 'completed', arguments: { batch_id: 3, criterion_offset: 0 },
|
||||
summary: '返回 1 项评分', result: { next_criterion_offset: 6, results: [{ rows: [{ criterion_id: 'C1', final_score: 8 }] }] } },
|
||||
{ id: 'call-legacy', name: 'search_project_material', status: 'completed', arguments: { project_id: 1 },
|
||||
summary: '找到 6 条引用', result: { found: true, citations: { count: 6 } } }] }],
|
||||
actions: [], runs: [{ id: 1, status: 'completed', tool_calls: [] }] },
|
||||
};
|
||||
let nextId = 8;
|
||||
@@ -85,11 +91,32 @@ test('markdown, citations, tool folding and narrow layout are safe', async ({ pa
|
||||
await expect(page.locator('.chat-markdown pre')).toBeVisible();
|
||||
await expect(page.locator('.chat-markdown img')).toHaveCount(0);
|
||||
await expect(page.getByText('危险链接')).not.toHaveAttribute('href');
|
||||
await expect(page.getByText('引用 · 1')).toBeVisible();
|
||||
await expect(page.getByText('资料.pdf')).toHaveCount(1);
|
||||
await expect(page.locator('.tool-detail')).not.toBeVisible();
|
||||
await page.locator('.chat-tool summary').click();
|
||||
await expect(page.locator('.tool-detail')).toBeVisible();
|
||||
await expect(page.getByText('引用 · 2')).toBeVisible();
|
||||
await expect(page.getByText('资料.pdf')).not.toBeVisible();
|
||||
await expect(page.getByText('后台进度')).toHaveCount(0);
|
||||
await expect(page.locator('.chat-tools')).toBeVisible();
|
||||
await expect(page.locator('.chat-tool').first()).not.toBeVisible();
|
||||
await expect(page.locator('.tool-detail').first()).not.toBeVisible();
|
||||
await page.locator('.chat-tool-group > summary').click();
|
||||
await expect(page.locator('.chat-tool').first()).toBeVisible();
|
||||
await expect(page.locator('.tool-detail').first()).not.toBeVisible();
|
||||
await page.locator('.chat-tool summary').first().click();
|
||||
await expect(page.locator('.tool-detail').first()).toBeVisible();
|
||||
await expect(page.locator('.tool-detail').first()).toContainText('第48页原文片段');
|
||||
await page.locator('.chat-tool').nth(1).locator('summary').click();
|
||||
await expect(page.locator('.chat-tool').nth(1).locator('.tool-detail')).toContainText('C1');
|
||||
await page.locator('.chat-tool').nth(2).locator('summary').click();
|
||||
await expect(page.locator('.chat-tool').nth(2).locator('.legacy-evidence')).toContainText('第48页原文片段');
|
||||
await page.getByRole('button', { name: '查看本轮已核验原文' }).click();
|
||||
await expect(page.locator('.chat-citation-group')).toHaveAttribute('open', '');
|
||||
await expect(page.getByText('资料.pdf')).toBeVisible();
|
||||
await expect(page.getByText('第 48 页').last()).toBeVisible();
|
||||
const positions = await page.evaluate(() => {
|
||||
const card = document.querySelector('.chat-assistant .ant-card-body');
|
||||
return ['.chat-tools', '.chat-markdown', '.chat-citations'].map(selector =>
|
||||
Array.from(card?.children || []).findIndex(child => child.matches(selector)));
|
||||
});
|
||||
expect(positions).toEqual([0, 1, 2]);
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await expect(page.locator('.ant-layout-sider')).toHaveClass(/ant-layout-sider-zero-width/);
|
||||
await expect(page.locator('.chat-scope .ant-select').first()).toBeVisible();
|
||||
|
||||
Reference in New Issue
Block a user