@@ -173,6 +173,39 @@ describe("applyEmbeddingBatchOutputLine", () => {
173173 expect ( byCustomId . get ( "req-1" ) ) . toEqual ( [ 0.1 , 0.2 ] ) ;
174174 } ) ;
175175
176+ it . each ( [
177+ { name : "non-array" , embedding : "poison" } ,
178+ { name : "array-like object" , embedding : { length : 1 } } ,
179+ { name : "boolean" , embedding : false } ,
180+ { name : "string coordinate" , embedding : [ "poison" ] } ,
181+ { name : "null coordinate" , embedding : [ null ] } ,
182+ { name : "NaN coordinate" , embedding : [ Number . NaN ] } ,
183+ { name : "positive infinity coordinate" , embedding : [ Number . POSITIVE_INFINITY ] } ,
184+ { name : "negative infinity coordinate" , embedding : [ Number . NEGATIVE_INFINITY ] } ,
185+ ] ) ( "rejects a $name instead of storing it as a valid vector" , ( { embedding } ) => {
186+ const remaining = new Set ( [ "req-invalid" ] ) ;
187+ const errors : string [ ] = [ ] ;
188+ const byCustomId = new Map < string , number [ ] > ( ) ;
189+
190+ applyEmbeddingBatchOutputLine ( {
191+ line : {
192+ custom_id : "req-invalid" ,
193+ response : {
194+ status_code : 200 ,
195+ body : { data : [ { embedding : embedding as unknown as number [ ] } ] } ,
196+ } ,
197+ } ,
198+ remaining,
199+ errors,
200+ byCustomId,
201+ } ) ;
202+
203+ expect ( remaining . has ( "req-invalid" ) ) . toBe ( false ) ;
204+ expect ( errors ) . toHaveLength ( 1 ) ;
205+ expect ( errors [ 0 ] ) . toMatch ( / ^ r e q - i n v a l i d : (?: e m p t y | i n v a l i d ) e m b e d d i n g $ / ) ;
206+ expect ( byCustomId . size ) . toBe ( 0 ) ;
207+ } ) ;
208+
176209 it ( "records provider error from line.error" , ( ) => {
177210 const remaining = new Set ( [ "req-2" ] ) ;
178211 const errors : string [ ] = [ ] ;
0 commit comments