import assert from 'node:assert/strict' import { buildKnowledgeIngestLogModel, isKnowledgeIngestRun } from '../src/utils/knowledgeIngestLogModel.js' function buildRun() { return { status: 'running', route_json: { job_type: 'knowledge_index_sync', folder: '制度文件', phase: 'indexing', progress: { total_documents: 2, completed_documents: 1, failed_documents: 0, percent: 55 }, knowledge_ingest: { status: 'running', phase: 'indexing', current_document_id: 'doc-2', graph: { chunk_count: 5, entity_count: 3, relation_count: 2, entities: ['远光软件', '支出管理'], relations: [{ source: '远光软件', target: '支出管理', type: '关联' }] }, documents: [ { document_id: 'doc-1', name: '公司支出管理办法.pdf', folder: '制度文件', extension: 'pdf', status: 'succeeded', phase: 'indexed', chunk_count: 3, entity_count: 2, relation_count: 1, chunks: [{ id: 'chunk-1', order: 0, tokens: 21, summary: '支出管理范围' }], sections: [{ title: '第一章 总则', excerpt: '适用于公司支出。' }], events: [{ at: '2026-05-22T08:00:00Z', level: 'info', message: '完成' }] }, { document_id: 'doc-2', name: '费用审批台账.xlsx', folder: '制度文件', extension: 'xlsx', status: 'running', phase: 'indexing', chunk_count: 2, entity_count: 1, relation_count: 1 } ] } } } } function testDetectsKnowledgeIngestRun() { assert.equal(isKnowledgeIngestRun(buildRun()), true) assert.equal(isKnowledgeIngestRun({ route_json: { job_type: 'daily_check' } }), false) } function testBuildsInteractiveModel() { const model = buildKnowledgeIngestLogModel(buildRun()) assert.equal(model.available, true) assert.equal(model.folder, '制度文件') assert.equal(model.selectedDocumentId, 'doc-2') assert.equal(model.documents.length, 2) assert.equal(model.documents[0].statusLabel, '已完成') assert.equal(model.documents[0].chunks[0].summary, '支出管理范围') assert.equal(model.graph.entityCount, 3) assert.equal(model.graph.relations[0].source, '远光软件') assert.equal(model.metrics[1].value, '5') } function testFallsBackToToolCallDocuments() { const model = buildKnowledgeIngestLogModel({ status: 'succeeded', route_json: { job_type: 'knowledge_index_sync', requested_document_ids: ['doc-1'] }, tool_calls: [ { response_json: { documents: [ { document_id: 'doc-1', name: '归集结果.docx', status: 'succeeded', chunk_count: 1 } ] } } ] }) assert.equal(model.documents[0].name, '归集结果.docx') assert.equal(model.graph.chunkCount, 1) } function run() { testDetectsKnowledgeIngestRun() testBuildsInteractiveModel() testFallsBackToToolCallDocuments() console.log('knowledge ingest log model tests passed') } run()