"""Tests for the Whisper segment confidence gate.""" from stt_daemon.transcriber import accept_segment class _Seg: def __init__(self, text="hello", no_speech_prob=0.1, avg_logprob=-0.3): self.text = text self.no_speech_prob = no_speech_prob self.avg_logprob = avg_logprob def test_accepts_confident_speech(): assert accept_segment(_Seg(), 0.6, -1.0) def test_rejects_high_no_speech_prob(): assert not accept_segment(_Seg(no_speech_prob=0.9), 0.6, -1.0) def test_rejects_low_avg_logprob(): assert not accept_segment(_Seg(avg_logprob=-1.5), 0.6, -1.0) def test_threshold_boundary_is_accepted(): assert accept_segment(_Seg(no_speech_prob=0.6, avg_logprob=-1.0), 0.6, -1.0) def test_missing_attributes_default_to_accept(): class Bare: text = "x" assert accept_segment(Bare(), 0.6, -1.0)