@@ -105,6 +105,12 @@ describe("OpenAI embedding batch output", () => {
105105 vi . useFakeTimers ( ) ;
106106 vi . setSystemTime ( 0 ) ;
107107 const setTimeoutSpy = vi . spyOn ( globalThis , "setTimeout" ) ;
108+ // Provider error-body reads own independent 10s chunk timers; only poll
109+ // delays belong to the embedding batch's 1s operation deadline.
110+ const pollTimeoutCalls = ( ) =>
111+ setTimeoutSpy . mock . calls . filter ( ( [ , timeout ] ) =>
112+ scenario . expectedWaits . includes ( Number ( timeout ) ) ,
113+ ) ;
108114 let statusCalls = 0 ;
109115 const fetchImpl = vi . fn ( async ( input : RequestInfo | URL , init ?: RequestInit ) => {
110116 const url = fetchInputUrl ( input ) ;
@@ -158,18 +164,17 @@ describe("OpenAI embedding batch output", () => {
158164 }
159165 } ,
160166 } ) ;
161- const rejection = expect ( result ) . rejects . toThrow ( "openai batch batch-0 timed out after 1000ms" ) ;
167+ const rejection = expect ( result ) . rejects . toMatchObject ( {
168+ message : "openai batch batch-0 timed out after 1000ms" ,
169+ ...( scenario . retryFirstStatus ? { cause : { status : 503 } } : { } ) ,
170+ } ) ;
162171
163172 for ( const [ index , waitMs ] of scenario . expectedWaits . entries ( ) ) {
164- for (
165- let attempt = 0 ;
166- attempt < 100 && setTimeoutSpy . mock . calls . length < index + 1 ;
167- attempt ++
168- ) {
173+ for ( let attempt = 0 ; attempt < 100 && pollTimeoutCalls ( ) . length < index + 1 ; attempt ++ ) {
169174 await Promise . resolve ( ) ;
170175 }
171- expect ( setTimeoutSpy ) . toHaveBeenCalledTimes ( index + 1 ) ;
172- expect ( setTimeoutSpy . mock . calls [ index ] ?. [ 1 ] ) . toBe ( waitMs ) ;
176+ expect ( pollTimeoutCalls ( ) ) . toHaveLength ( index + 1 ) ;
177+ expect ( pollTimeoutCalls ( ) [ index ] ?. [ 1 ] ) . toBe ( waitMs ) ;
173178 await vi . advanceTimersByTimeAsync ( waitMs ) ;
174179 }
175180 await rejection ;
0 commit comments