const { applyCatalogGrounding } = require('../../server/lib/scanGrounding'); describe('scan confidence honesty', () => { const catalogEntries = [ { name: 'Rose', botanicalName: 'Rosa chinensis', description: 'Catalog rose entry.', careInfo: { waterIntervalDays: 4, light: 'Full sun', temp: '15-25C' }, }, ]; const lowConfidenceAiResult = { name: 'Rose', botanicalName: 'Rosa chinensis', confidence: 0.55, description: 'Possibly a rose, image is ambiguous.', careInfo: { waterIntervalDays: 5, light: 'Full sun', temp: '15-25C' }, }; it('does not inflate a low AI confidence when a catalog match is found', () => { const { grounded, result } = applyCatalogGrounding(lowConfidenceAiResult, catalogEntries, 'en'); expect(grounded).toBe(true); // Regression: this used to be forced up to at least 0.78, presenting an // uncertain model guess as a confident identification. expect(result.confidence).toBe(0.55); }); it('keeps a high AI confidence unchanged', () => { const { result } = applyCatalogGrounding( { ...lowConfidenceAiResult, confidence: 0.9 }, catalogEntries, 'en', ); expect(result.confidence).toBe(0.9); }); it('clamps missing confidence to the neutral default without boosting it', () => { const { result } = applyCatalogGrounding( { ...lowConfidenceAiResult, confidence: undefined }, catalogEntries, 'en', ); expect(result.confidence).toBe(0.6); }); });