@@ -111,3 +111,56 @@ test("classifies a 200 that is not JSON instead of leaking a SyntaxError", async
111111 reason : { category : "protocol_mismatch" } ,
112112 } ) ;
113113} ) ;
114+
115+ test ( "sends only configured fields to {baseURL}/embeddings" , async ( ) => {
116+ harness = setupHarness ( ) ;
117+ const stream = harness . scenario . createStream ( ) ;
118+ harness . scenario . whenRequestBodyMatches (
119+ ( body , req ) =>
120+ req . url === "https://embed.example/v1/embeddings" &&
121+ ! req . headers . has ( "authorization" ) &&
122+ body === JSON . stringify ( { model : CONFIG . model , input : [ "a" ] } ) ,
123+ stream ,
124+ ) ;
125+ stream . enqueueAll (
126+ [ new TextEncoder ( ) . encode ( '{"data":[{"index":0,"embedding":[1]}]}' ) ] ,
127+ { startAt : 1 } ,
128+ ) ;
129+ const pending = embedTexts ( [ "a" ] , CONFIG , { deps : harness . deps } ) ;
130+ expect ( await run ( harness , pending ) ) . toEqual ( [ [ 1 ] ] ) ;
131+ } ) ;
132+
133+ test ( "sends a bearer token only when apiKey is set" , async ( ) => {
134+ harness = setupHarness ( ) ;
135+ const stream = harness . scenario . createStream ( ) ;
136+ harness . scenario . whenRequestMatches (
137+ ( req ) => req . headers . get ( "authorization" ) === "Bearer sk-test" ,
138+ stream ,
139+ ) ;
140+ stream . enqueueAll (
141+ [ new TextEncoder ( ) . encode ( '{"data":[{"index":0,"embedding":[1]}]}' ) ] ,
142+ { startAt : 1 } ,
143+ ) ;
144+ const pending = embedTexts (
145+ [ "a" ] ,
146+ { ...CONFIG , apiKey : "sk-test" } ,
147+ { deps : harness . deps } ,
148+ ) ;
149+ expect ( await run ( harness , pending ) ) . toEqual ( [ [ 1 ] ] ) ;
150+ } ) ;
151+
152+ test ( "returns [] for empty input without a request" , async ( ) => {
153+ harness = setupHarness ( ) ;
154+ const pending = embedTexts ( [ ] , CONFIG , { deps : harness . deps } ) ;
155+ expect ( await run ( harness , pending ) ) . toEqual ( [ ] ) ;
156+ } ) ;
157+
158+ test ( "rejects a non-positive batchSize before any request" , async ( ) => {
159+ harness = setupHarness ( ) ;
160+ for ( const batchSize of [ 0 , - 1 , 1.5 ] ) {
161+ await expect (
162+ embedTexts ( [ "a" ] , { ...CONFIG , batchSize } , { deps : harness . deps } ) ,
163+ ) . rejects . toThrow ( ) ;
164+ }
165+ await harness . run ( ) ;
166+ } ) ;
0 commit comments