@@ -50,7 +50,7 @@ func TestRecordResponseTracksInterimThenFinal(t *testing.T) {
5050 require .Equal (t , []string {"hello world" }, s .segments )
5151}
5252
53- func TestRecordResponseCommitsInterimAcrossPauseLikeReset (t * testing.T ) {
53+ func TestRecordResponseReplacesDivergentInterimWithoutPrecommit (t * testing.T ) {
5454 s := & Stream {}
5555
5656 s .recordResponse (& asrpb.StreamingRecognizeResponse {
@@ -67,10 +67,89 @@ func TestRecordResponseCommitsInterimAcrossPauseLikeReset(t *testing.T) {
6767 }},
6868 })
6969
70+ require .Empty (t , s .segments )
71+ segments := collectSegments (s .segments , s .lastInterim )
72+ require .Equal (t , []string {"second phrase" }, segments )
73+ }
74+
75+ func TestRecordResponseCommitsStableDivergentInterimForPartialRecovery (t * testing.T ) {
76+ s := & Stream {}
77+
78+ s .recordResponse (& asrpb.StreamingRecognizeResponse {
79+ Results : []* asrpb.StreamingRecognitionResult {{
80+ IsFinal : false ,
81+ Stability : 0.95 ,
82+ Alternatives : []* asrpb.SpeechRecognitionAlternative {{Transcript : "first phrase" }},
83+ }},
84+ })
85+
86+ s .recordResponse (& asrpb.StreamingRecognizeResponse {
87+ Results : []* asrpb.StreamingRecognitionResult {{
88+ IsFinal : false ,
89+ Stability : 0.20 ,
90+ Alternatives : []* asrpb.SpeechRecognitionAlternative {{Transcript : "second phrase" }},
91+ }},
92+ })
93+
94+ require .Equal (t , []string {"first phrase" }, s .segments )
7095 segments := collectSegments (s .segments , s .lastInterim )
7196 require .Equal (t , []string {"first phrase" , "second phrase" }, segments )
7297}
7398
99+ func TestRecordResponseDoesNotPrependStaleInterimBeforeFinal (t * testing.T ) {
100+ s := & Stream {}
101+
102+ s .recordResponse (& asrpb.StreamingRecognizeResponse {
103+ Results : []* asrpb.StreamingRecognitionResult {{
104+ IsFinal : false ,
105+ Stability : 0.05 ,
106+ Alternatives : []* asrpb.SpeechRecognitionAlternative {{Transcript : "stale words" }},
107+ }},
108+ })
109+
110+ s .recordResponse (& asrpb.StreamingRecognizeResponse {
111+ Results : []* asrpb.StreamingRecognitionResult {{
112+ IsFinal : false ,
113+ Stability : 0.30 ,
114+ Alternatives : []* asrpb.SpeechRecognitionAlternative {{Transcript : "hello world" }},
115+ }},
116+ })
117+
118+ s .recordResponse (& asrpb.StreamingRecognizeResponse {
119+ Results : []* asrpb.StreamingRecognitionResult {{
120+ IsFinal : true ,
121+ Alternatives : []* asrpb.SpeechRecognitionAlternative {{Transcript : "hello world" }},
122+ }},
123+ })
124+
125+ segments := collectSegments (s .segments , s .lastInterim )
126+ require .Equal (t , []string {"hello world" }, segments )
127+ }
128+
129+ func TestRecordResponseTreatsSuffixCorrectionAsContinuation (t * testing.T ) {
130+ s := & Stream {}
131+
132+ s .recordResponse (& asrpb.StreamingRecognizeResponse {
133+ Results : []* asrpb.StreamingRecognitionResult {{
134+ IsFinal : false ,
135+ Stability : 0.95 ,
136+ Alternatives : []* asrpb.SpeechRecognitionAlternative {{Transcript : "replace reply replied on the review thread with details" }},
137+ }},
138+ })
139+
140+ s .recordResponse (& asrpb.StreamingRecognizeResponse {
141+ Results : []* asrpb.StreamingRecognitionResult {{
142+ IsFinal : false ,
143+ Stability : 0.95 ,
144+ Alternatives : []* asrpb.SpeechRecognitionAlternative {{Transcript : "replied on the review thread with details" }},
145+ }},
146+ })
147+
148+ require .Empty (t , s .segments )
149+ segments := collectSegments (s .segments , s .lastInterim )
150+ require .Equal (t , []string {"replied on the review thread with details" }, segments )
151+ }
152+
74153func TestAppendSegmentDedupAndPrefixMerge (t * testing.T ) {
75154 segments := appendSegment (nil , "hello" )
76155 require .Equal (t , []string {"hello" }, segments )
@@ -94,7 +173,13 @@ func TestCleanSegmentAndInterimContinuation(t *testing.T) {
94173
95174 require .True (t , isInterimContinuation ("hello" , "hello world" ))
96175 require .True (t , isInterimContinuation ("hello world" , "hello" ))
176+ require .True (t , isInterimContinuation ("replace reply replied on thread" , "replied on thread" ))
97177 require .False (t , isInterimContinuation ("first phrase" , "second phrase" ))
178+
179+ require .False (t , shouldCommitPriorInterimOnDivergence ("first phrase" , 0.2 , "second phrase" ))
180+ require .True (t , shouldCommitPriorInterimOnDivergence ("first phrase" , 0.9 , "second phrase" ))
181+ require .True (t , shouldCommitPriorInterimOnDivergence ("Done." , 0.1 , "new sentence" ))
182+ require .False (t , shouldCommitPriorInterimOnDivergence ("replace reply replied on thread" , 0.95 , "replied on thread" ))
98183}
99184
100185func TestDialStreamEndToEndWithDebugSinkAndSpeechContexts (t * testing.T ) {
0 commit comments