import { describe, it, expect } from 'vitest' import { containsLeakedBoilerplate, isDegenerateText, sanitizeForSpeech, SPEECH_FALLBACK_REPLY } from '../../src/main/ai/speechSafety' describe('containsLeakedBoilerplate()', () => { it('should detect leaked English model boilerplate with no French words', () => { expect( containsLeakedBoilerplate( 'Use the results below to formulate an answer to the user question with additional information needed' ) ).toBe(true) }) it('should not flag a normal French reply', () => { expect(containsLeakedBoilerplate('Bonjour, comment puis-je aider ?')).toBe(false) }) }) describe('isDegenerateText()', () => { it('should detect a non-Latin corrupted reply', () => { expect(isDegenerateText('的问题是什么呢我不知道该怎么办才好呢')).toBe(true) }) it('should not flag a normal French reply', () => { expect(isDegenerateText('Bonjour, comment puis-je aider ?')).toBe(false) }) it('should not flag an empty string', () => { expect(isDegenerateText('')).toBe(false) }) }) describe('sanitizeForSpeech()', () => { it('should replace a leaked English boilerplate reply with the safe fallback message', () => { expect( sanitizeForSpeech( 'Use the results below to formulate an answer to the user question with additional information needed' ) ).toBe(SPEECH_FALLBACK_REPLY) }) it('should replace a degenerate (non-Latin) reply with the safe fallback message', () => { expect(sanitizeForSpeech('的问题是什么呢我不知道该怎么办才好呢')).toBe(SPEECH_FALLBACK_REPLY) }) it('should return the original text when it is a normal French reply', () => { expect(sanitizeForSpeech('Bonjour, comment puis-je aider ?')).toBe( 'Bonjour, comment puis-je aider ?' ) }) })