@@ -87,6 +87,10 @@ test("rejects duplicate indices and undecodable base64", async () => {
8787 ] ,
8888 [
8989 { index : 0 , embedding : "!!!notbase64" } ,
90+ { index : 1 , embedding : "AAAAAA==" } ,
91+ ] ,
92+ [
93+ { index : 0 , embedding : "AAAAAA==" } ,
9094 { index : 1 , embedding : "AAA=" } ,
9195 ] ,
9296 ] ) {
@@ -111,3 +115,56 @@ test("classifies a 200 that is not JSON instead of leaking a SyntaxError", async
111115 reason : { category : "protocol_mismatch" } ,
112116 } ) ;
113117} ) ;
118+
119+ test ( "sends only configured fields to {baseURL}/embeddings" , async ( ) => {
120+ harness = setupHarness ( ) ;
121+ const stream = harness . scenario . createStream ( ) ;
122+ harness . scenario . whenRequestBodyMatches (
123+ ( body , req ) =>
124+ req . url === "https://embed.example/v1/embeddings" &&
125+ ! req . headers . has ( "authorization" ) &&
126+ body === JSON . stringify ( { model : CONFIG . model , input : [ "a" ] } ) ,
127+ stream ,
128+ ) ;
129+ stream . enqueueAll (
130+ [ new TextEncoder ( ) . encode ( '{"data":[{"index":0,"embedding":[1]}]}' ) ] ,
131+ { startAt : 1 } ,
132+ ) ;
133+ const pending = embedTexts ( [ "a" ] , CONFIG , { deps : harness . deps } ) ;
134+ expect ( await run ( harness , pending ) ) . toEqual ( [ [ 1 ] ] ) ;
135+ } ) ;
136+
137+ test ( "sends a bearer token only when apiKey is set" , async ( ) => {
138+ harness = setupHarness ( ) ;
139+ const stream = harness . scenario . createStream ( ) ;
140+ harness . scenario . whenRequestMatches (
141+ ( req ) => req . headers . get ( "authorization" ) === "Bearer sk-test" ,
142+ stream ,
143+ ) ;
144+ stream . enqueueAll (
145+ [ new TextEncoder ( ) . encode ( '{"data":[{"index":0,"embedding":[1]}]}' ) ] ,
146+ { startAt : 1 } ,
147+ ) ;
148+ const pending = embedTexts (
149+ [ "a" ] ,
150+ { ...CONFIG , apiKey : "sk-test" } ,
151+ { deps : harness . deps } ,
152+ ) ;
153+ expect ( await run ( harness , pending ) ) . toEqual ( [ [ 1 ] ] ) ;
154+ } ) ;
155+
156+ test ( "returns [] for empty input without a request" , async ( ) => {
157+ harness = setupHarness ( ) ;
158+ const pending = embedTexts ( [ ] , CONFIG , { deps : harness . deps } ) ;
159+ expect ( await run ( harness , pending ) ) . toEqual ( [ ] ) ;
160+ } ) ;
161+
162+ test ( "rejects a non-positive batchSize before any request" , async ( ) => {
163+ harness = setupHarness ( ) ;
164+ for ( const batchSize of [ 0 , - 1 , 1.5 ] ) {
165+ await expect (
166+ embedTexts ( [ "a" ] , { ...CONFIG , batchSize } , { deps : harness . deps } ) ,
167+ ) . rejects . toThrow ( / b a t c h S i z e / ) ;
168+ }
169+ await harness . run ( ) ;
170+ } ) ;
0 commit comments