import { describe, expect, it } from 'vitest'; import type { ImportedDataset } from '../../src/domain/dataset'; import type { ImportPreviewEntry } from '../../src/domain/import-workflow'; import { createCanonicalImportBatch } from '../../src/importers/canonical-import'; function entry(fileName: string, profileId: string, scanTool: string): ImportPreviewEntry { const dataset: ImportedDataset = { fileName, fileSize: 10, lastModified: 0, format: 'CSV', rawText: '', sheets: [], profileId, profileVersion: '1.0.0', scanTool }; return { id: fileName, fileName, sizeBytes: 10, lastModified: 0, sha256: fileName.padEnd(64, '0').slice(0, 64), status: 'ready', selected: true, format: 'CSV', toolId: profileId, toolName: scanTool, confidence: profileId === 'generic' ? 'unknown' : 'high', confidenceScore: profileId === 'generic' ? 0 : 0.9, tableCount: 0, recordCount: 0, rowCount: 0, warningMessages: [], errorMessages: [], unassignedFields: [], mappingsToConfirm: 0, dataset }; } describe('canonical multi-file scan tool inference', () => { it('keeps per-file profiles while associating a single recognized scanner with the scan run', () => { const batch = createCanonicalImportBatch('batch-1', [ entry('Assessment_summary.csv', 'generic', 'Tabular Data'), entry('Indicators_results.csv', 'purple-knight', 'PurpleKnight'), entry('SI000134.csv', 'generic', 'Tabular Data') ], '2026-07-18T08:00:00.000Z'); expect(batch.model.scanRuns[0].tool).toEqual({ id: 'purple-knight', name: 'PurpleKnight' }); expect(batch.model.importFiles.map(file => file.detectedTool.id)).toEqual([ 'generic', 'purple-knight', 'generic' ]); expect(batch.model.importFiles[0].detection.reasons).not.toContain(expect.stringContaining('Mehrdatei-Scan')); }); it('does not overwrite distinct recognized tools in a heterogeneous batch', () => { const batch = createCanonicalImportBatch('batch-2', [ entry('purple.csv', 'purple-knight', 'PurpleKnight'), entry('ping.html', 'pingcastle', 'PingCastle') ], '2026-07-18T08:00:00.000Z'); expect(batch.model.scanRuns[0].tool.id).toBe('multiple'); expect(batch.model.importFiles.map(file => file.detectedTool.id)).toEqual(['purple-knight', 'pingcastle']); }); });