-
{`edge:${selectedEdgeData.source.id}->${selectedEdgeData.target.id}`}
-
{`predicates:${edgeDetail?.edge?.predicates?.join(',') ?? 'none'}`}
-
{`paragraphs:${edgeDetail?.paragraphs?.length ?? 0}`}
-
-
- ) : null
- ),
- RelationDetailDialog: () => null,
- ParagraphDetailDialog: () => null,
-}))
-
-vi.mock('@/lib/memory-api', () => ({
- getMemoryGraph: vi.fn(),
- getMemoryGraphSearch: vi.fn(),
- getMemoryGraphNodeDetail: vi.fn(),
- getMemoryGraphEdgeDetail: vi.fn(),
- previewMemoryDelete: vi.fn(),
- executeMemoryDelete: vi.fn(),
- restoreMemoryDelete: vi.fn(),
-}))
-
-describe('KnowledgeGraphPage', () => {
- beforeEach(() => {
- navigateMock.mockReset()
- toastMock.mockReset()
- vi.mocked(memoryApi.getMemoryGraph).mockResolvedValue({
- success: true,
- nodes: [
- { id: 'alpha', name: 'Alpha' },
- { id: 'beta', name: 'Beta' },
- ],
- edges: [
- {
- source: 'alpha',
- target: 'beta',
- weight: 1,
- predicates: ['关联'],
- relation_count: 1,
- evidence_count: 2,
- relation_hashes: ['rel-1'],
- label: '关联',
- },
- ],
- total_nodes: 2,
- total_edges: 1,
- })
- vi.mocked(memoryApi.getMemoryGraphSearch).mockResolvedValue({
- success: true,
- query: 'alpha',
- limit: 50,
- count: 0,
- items: [],
- })
- vi.mocked(memoryApi.getMemoryGraphNodeDetail).mockResolvedValue({
- success: true,
- node: { id: 'alpha', type: 'entity', content: 'Alpha', hash: 'entity-1', appearance_count: 3 },
- relations: [
- {
- hash: 'rel-1',
- subject: 'alpha',
- predicate: '关联',
- object: 'beta',
- text: 'alpha 关联 beta',
- confidence: 0.9,
- paragraph_count: 1,
- paragraph_hashes: ['p-1'],
- source_paragraph: 'p-1',
- },
- ],
- paragraphs: [
- {
- hash: 'p-1',
- content: 'Alpha 提到了 Beta',
- preview: 'Alpha 提到了 Beta',
- source: 'demo',
- entity_count: 2,
- relation_count: 1,
- entities: ['Alpha', 'Beta'],
- relations: ['alpha 关联 beta'],
- },
- ],
- evidence_graph: {
- nodes: [
- { id: 'entity:alpha', type: 'entity', content: 'Alpha' },
- { id: 'relation:rel-1', type: 'relation', content: 'alpha 关联 beta' },
- { id: 'paragraph:p-1', type: 'paragraph', content: 'Alpha 提到了 Beta' },
- ],
- edges: [
- { source: 'paragraph:p-1', target: 'entity:alpha', kind: 'mentions', label: '提及', weight: 1 },
- { source: 'paragraph:p-1', target: 'relation:rel-1', kind: 'supports', label: '支撑', weight: 1 },
- ],
- focus_entities: ['alpha'],
- },
- })
- vi.mocked(memoryApi.getMemoryGraphEdgeDetail).mockResolvedValue({
- success: true,
- edge: {
- source: 'alpha',
- target: 'beta',
- weight: 1,
- predicates: ['关联'],
- relation_count: 1,
- evidence_count: 1,
- relation_hashes: ['rel-1'],
- label: '关联',
- },
- relations: [
- {
- hash: 'rel-1',
- subject: 'alpha',
- predicate: '关联',
- object: 'beta',
- text: 'alpha 关联 beta',
- confidence: 0.9,
- paragraph_count: 1,
- paragraph_hashes: ['p-1'],
- source_paragraph: 'p-1',
- },
- ],
- paragraphs: [
- {
- hash: 'p-1',
- content: 'Alpha 提到了 Beta',
- preview: 'Alpha 提到了 Beta',
- source: 'demo',
- entity_count: 2,
- relation_count: 1,
- entities: ['Alpha', 'Beta'],
- relations: ['alpha 关联 beta'],
- },
- ],
- evidence_graph: {
- nodes: [
- { id: 'entity:alpha', type: 'entity', content: 'Alpha' },
- { id: 'entity:beta', type: 'entity', content: 'Beta' },
- { id: 'relation:rel-1', type: 'relation', content: 'alpha 关联 beta' },
- ],
- edges: [
- { source: 'relation:rel-1', target: 'entity:alpha', kind: 'subject', label: '主语', weight: 1 },
- { source: 'relation:rel-1', target: 'entity:beta', kind: 'object', label: '宾语', weight: 1 },
- ],
- focus_entities: ['alpha', 'beta'],
- },
- })
- vi.mocked(memoryApi.previewMemoryDelete).mockResolvedValue({
- success: true,
- mode: 'mixed',
- selector: { entity_hashes: ['entity-1'] },
- counts: { entities: 1, relations: 1, paragraphs: 1 },
- sources: ['demo'],
- items: [{ item_type: 'entity', item_hash: 'entity-1', label: 'Alpha' }],
- item_count: 1,
- dry_run: true,
- } as never)
- vi.mocked(memoryApi.executeMemoryDelete).mockResolvedValue({
- success: true,
- mode: 'mixed',
- operation_id: 'del-1',
- counts: { entities: 1, relations: 1, paragraphs: 1 },
- sources: ['demo'],
- deleted_count: 3,
- deleted_entity_count: 1,
- deleted_relation_count: 1,
- deleted_paragraph_count: 1,
- deleted_source_count: 0,
- } as never)
- vi.mocked(memoryApi.restoreMemoryDelete).mockResolvedValue({ success: true } as never)
- })
-
- it('calls backend graph search and renders no-hit state', async () => {
- const user = userEvent.setup()
-
- render(