feat(knowledge): 展示文档处理进度并自动衔接导入索引

This commit is contained in:
2026-09-15 12:34:52 +08:00
parent b0bf7a49eb
commit fee2f4c2f3
10 changed files with 616 additions and 125 deletions

View File

@@ -13,6 +13,10 @@ test('personal cloud Agent creation, draft save and leave protection in Electron
let draft: Record<string, unknown> | null = null;
let recent: unknown = null;
let knowledgeCatalogLoads = 0;
let knowledgeCreated = false;
let knowledgeUploaded = false;
let knowledgeStage = -1;
const knowledgeFile = { file_id: 'document', name: '本体(Ontology)学习路线图.pdf', size: 34000, error: null };
let limits: { request_limit_points: string | null; daily_limit_points: string | null } = { request_limit_points: null, daily_limit_points: null };
const jobs: Record<string, unknown>[] = [];
const configuration = { model: '', tools: [], knowledges: [], mcps: [], skills: [], preload_skills: [], subagents: [], tool_approval_mode: 'default', max_execution_steps: 40, max_output_tokens: 4096, max_run_seconds: 600 };
@@ -33,12 +37,28 @@ 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('/knowledge/pick')) {
knowledgeUploaded = true;
return result({ ...knowledgeFile, status: 'uploaded', chunk_count: 0, available: false, processing_task: null });
}
if (path.endsWith('/recovery')) return result({ recent, pending: [] });
if (path.endsWith('/recovery/recent')) { recent = body; return result({ saved: true }); }
if (path.endsWith('/actions')) {
const input = body.input ?? {};
if (body.operation === 'catalog') return result({ models: [{ id: 'test-model', name: '创作模型' }], resources: {}, pricing: null });
if (body.operation === 'knowledge') return result({ databases: [], models: ++knowledgeCatalogLoads === 1 ? [] : [{ id: 'fixture:test-embedding', name: '资料向量模型', dimension: 1024 }] });
if (body.operation === 'knowledge') return result({ databases: knowledgeCreated ? [{ kb_id: 'kb', name: '我的创作资料' }] : [], models: ++knowledgeCatalogLoads === 1 ? [] : [{ id: 'fixture:test-embedding', name: '资料向量模型', dimension: 1024 }] });
if (body.operation === 'createKnowledge') { knowledgeCreated = true; return result({ kb_id: 'kb', name: '我的创作资料' }); }
if (body.operation === 'processKnowledge') { knowledgeStage = 0; return result({ task_id: 'process-document' }); }
if (body.operation === 'knowledgeFiles') {
const stage = knowledgeStage;
if (knowledgeStage >= 0) knowledgeStage++;
return result({ next_offset: null, files: knowledgeUploaded ? [
{ ...knowledgeFile, status: stage < 1 ? 'uploaded' : stage === 1 ? 'parsing' : stage === 2 ? 'indexing' : 'indexed',
available: stage >= 3, chunk_count: stage >= 3 ? 18 : 0,
processing_task: stage < 0 ? null : { task_id: 'process-document', status: stage === 0 ? 'pending' : stage < 3 ? 'running' : 'success', error: null } },
{ file_id: 'empty', name: '扫描文档.pdf', size: 2000, status: 'indexed', available: false, chunk_count: 0, error: null },
] : [] });
}
if (body.operation === 'resources') return result({ mcps: [], skills: [], subagents: [] });
if (body.operation === 'budget' || body.operation === 'saveBudget') {
if (body.operation === 'saveBudget') limits = input;
@@ -117,10 +137,25 @@ test('personal cloud Agent creation, draft save and leave protection in Electron
await expect(page.getByLabel('知识库名称', { exact: true })).toHaveValue('我的创作资料');
await expect(page.getByRole('button', { name: '创建并选用', exact: true })).toBeEnabled();
await expect(page.getByText('管理员配置说明', { exact: true })).toHaveCount(0);
await page.getByLabel('知识库名称', { exact: true }).fill('');
await page.getByRole('button', { name: '新建知识库', exact: true }).click();
await page.getByRole('button', { name: '创建并选用', exact: true }).click();
await expect(page.getByText('上传第一份文档,让智能体用你的资料回答。')).toBeVisible();
await page.getByRole('button', { name: '上传文档', exact: true }).click();
const document = page.getByRole('article', { name: '本体(Ontology)学习路线图.pdf' });
await expect(document.getByText('等待处理', { exact: true })).toBeVisible();
await expect(page.getByText('没有可用内容', { exact: true })).toBeVisible();
await document.scrollIntoViewIfNeeded();
await page.screenshot({ path: testInfo.outputPath('knowledge-queued.png') });
await expect(document.getByText('正在解析文档', { exact: true })).toBeVisible();
await expect(document.getByText('正在建立索引', { exact: true })).toBeVisible();
await expect(document.getByText('可用于回答', { exact: true })).toBeVisible();
await expect(document.getByText(/18 段可检索内容/)).toBeVisible();
await document.scrollIntoViewIfNeeded();
expect(await document.evaluate(el => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
await page.screenshot({ path: testInfo.outputPath('knowledge-ready.png') });
await page.getByRole('button', { name: '我的要求', exact: true }).click();
const preview = page.getByRole('region', { name: '草稿预览', exact: true });
await preview.getByRole('button', { name: '保存并重新试用', exact: true }).click();
await expect(preview.getByText('当前试用 · 修订 3')).toBeVisible();
await preview.getByRole('button', { name: '你可以怎样帮助我?请举一个例子。', exact: true }).click();
await expect(preview.getByLabel('消息')).toHaveValue('你可以怎样帮助我?请举一个例子。');
await expect(preview.getByRole('heading', { name: '创作建议' })).toHaveCount(0);
@@ -141,7 +176,7 @@ test('personal cloud Agent creation, draft save and leave protection in Electron
await expect(page.getByText('云端已保存', { exact: true })).toBeVisible();
await expect(preview.getByLabel('消息')).toHaveValue('保存后继续的问题');
await expect(preview.getByRole('heading', { name: '创作建议' })).toBeAttached();
await expect(preview.getByText('当前试用 · 修订 2')).toBeVisible();
await expect(preview.getByText('当前试用 · 修订 3')).toBeVisible();
const divider = page.getByRole('separator', { name: '调整配置与试用宽度' });
await divider.focus();
const previousRatio = Number(await divider.getAttribute('aria-valuenow'));
@@ -175,14 +210,14 @@ test('personal cloud Agent creation, draft save and leave protection in Electron
}
await app.evaluate(({ BrowserWindow }) => BrowserWindow.getAllWindows()[0].webContents.setZoomFactor(1));
await preview.getByRole('button', { name: '用最新草稿试用' }).click();
await expect(preview.getByText('当前试用 · 修订 3')).toBeVisible();
await expect(preview.getByText('当前试用 · 修订 4')).toBeVisible();
await expect(preview.getByLabel('消息')).toHaveValue('保存后继续的问题');
await preview.getByText('对比上一次试用 · 修订 2', { exact: true }).click();
await preview.getByText('对比上一次试用 · 修订 3', { exact: true }).click();
await expect(preview.getByRole('heading', { name: '创作建议' })).toBeVisible();
await preview.getByText('对比上一次试用 · 修订 2', { exact: true }).click();
await preview.getByText('对比上一次试用 · 修订 3', { exact: true }).click();
await page.getByRole('button', { name: '简单易懂', exact: true }).click();
await preview.getByRole('button', { name: '保存并重新试用', exact: true }).click();
await expect(preview.getByText('当前试用 · 修订 4')).toBeVisible();
await expect(preview.getByText('当前试用 · 修订 5')).toBeVisible();
await expect(preview.getByLabel('消息')).toHaveValue('保存后继续的问题');
await preview.getByLabel('消息').fill('');
await page.getByTestId('sidebar-module-switcher-trigger').click();