import { describe, expect, it } from 'vitest'; import { parseCsvDocument } from '../../src/importers/csv-importer'; import { parseJsonDocument } from '../../src/importers/json-importer'; import { extractSourceDocument, selectSourceExtractor } from '../../src/importers/source-extractor-registry'; import { sourceMetadata } from './import-source-fixtures'; describe('source extractor registry', () => { it('uses the generic tabular fallback without assigning canonical field roles', () => { const text = 'Rule;Severity\nSYN-1;High'; const document = parseCsvDocument(sourceMetadata('synthetic.csv', text.length, 'text/csv'), text); const result = extractSourceDocument(document); expect(result).toMatchObject({ extractor: { kind: 'source-extractor', id: 'generic-table-source-extractor', version: '1.0.0' }, processing: { stage: 'extraction', status: 'complete' } }); expect(result.candidates).toHaveLength(1); expect(result.candidates[0]).toMatchObject({ source: { fileName: 'synthetic.csv', tableIndex: 0, rowIndex: 1 }, fields: [ { key: 'column-0', label: 'Rule', originalValue: 'SYN-1', decodedValue: 'SYN-1' }, { key: 'column-1', label: 'Severity', originalValue: 'High', decodedValue: 'High' } ] }); expect(result.candidates[0].fields.some(field => 'role' in field)).toBe(false); }); it('selects the native object extractor and preserves nested JSON values', () => { const text = JSON.stringify([ { id: 'SYN-1', details: { enabled: true, score: 7 } }, { id: 'SYN-2', details: { enabled: false, score: 3 } } ]); const document = parseJsonDocument(sourceMetadata('synthetic.json', text.length, 'application/json'), text); const selected = selectSourceExtractor(document); const result = extractSourceDocument(document); expect(selected).toMatchObject({ extractor: { id: 'native-object-source-extractor' }, match: { score: 1 } }); expect(result.candidates).toHaveLength(2); expect(result.candidates[0]).toMatchObject({ source: { fileName: 'synthetic.json', objectPath: '$[0]' }, fields: [ { key: 'id', originalValue: 'SYN-1', source: { objectPath: '$[0].id' } }, { key: 'details', originalValue: { enabled: true, score: 7 }, source: { objectPath: '$[0].details' } } ] }); }); });