import { describe, expect, it } from 'vitest'; import type { FindingDefinition, FindingOccurrence, ImportFileRecord } from '../../src/domain/canonical-model'; import { scannerResultCategories, scannerResultFrameworkReferences } from '../../src/domain/unified-result'; describe('retained framework references', () => { it('projects exact mapped values separately from categories without changing source mappings', () => { const occurrence = { sourceIdentity: { tool: { id: 'dummy-scanner' } }, originalFields: [{ key: 'attack', label: 'MITRE ATT&CK', value: 'T1110' }, { key: 'defend', label: 'MITRE D3FEND', value: 'D3-XYZ' }], fieldMappings: [ { targetRole: 'framework-reference', sourceFieldKeys: ['attack'], normalizedValue: 'T1110' }, { targetRole: 'framework-reference', sourceFieldKeys: ['defend'], normalizedValue: 'D3-XYZ' }, { targetRole: 'category', sourceFieldKeys: ['class'], normalizedValue: 'Identity' } ] } as unknown as FindingOccurrence; const references = scannerResultFrameworkReferences(occurrence); expect(references).toEqual([ { namespace: 'dummy-scanner', value: 'T1110', sourceFieldKey: 'attack', sourceLabel: 'MITRE ATT&CK' }, { namespace: 'dummy-scanner', value: 'D3-XYZ', sourceFieldKey: 'defend', sourceLabel: 'MITRE D3FEND' } ]); const categories = scannerResultCategories({} as FindingDefinition, occurrence, { processedWith: { profileId: 'dummy-scanner', profileVersion: '1.0.0' } } as ImportFileRecord); expect(categories.map(item => item.categoryLabel)).toEqual(['Identity']); expect(occurrence.fieldMappings.map(item => item.normalizedValue)).toEqual(['T1110', 'D3-XYZ', 'Identity']); }); });