@@ -105,68 +105,94 @@ describe("OpenAI memory embedding adapter", () => {
105105 expect ( JSON . stringify ( current . cacheKeyData ) ) . not . toContain ( "fixture-secret" ) ;
106106 } ) ;
107107
108- it ( "keeps rotated proxy credentials out of tenant-specific embedding cache identity" , async ( ) => {
109- const createForTenant = async (
110- tenant : string ,
111- proxyApiKey : string ,
112- proxyHeaderName = "X-Api-Key" ,
113- ) => {
114- const client = await resolveRemoteEmbeddingBearerClient ( {
115- provider : "bailian-embedding" ,
116- defaultBaseUrl : "https://embeddings.example/v1" ,
117- options : {
118- config : { models : { } } as never ,
119- model : "text-embedding-v3" ,
120- remote : {
121- apiKey : "fixture-secret" ,
122- headers : {
123- [ proxyHeaderName ] : proxyApiKey ,
124- "X-Deployment" : tenant ,
125- "X-Tenant" : tenant ,
126- version : "tenant-api-v2" ,
127- "User-Agent" : "tenant-client/2" ,
108+ it . each ( [
109+ {
110+ name : "proxy" ,
111+ providerId : "bailian-embedding" ,
112+ baseUrl : "https://embeddings.example/v1" ,
113+ headerName : "X-Api-Key" ,
114+ rotatedHeaderName : "x-aPI-kEY" ,
115+ } ,
116+ {
117+ name : "Azure OpenAI" ,
118+ providerId : "openai" ,
119+ baseUrl : "https://qa-resource.openai.azure.com/openai/v1" ,
120+ headerName : "api-key" ,
121+ rotatedHeaderName : "Api-Key" ,
122+ } ,
123+ ] ) (
124+ "keeps rotated $name credentials out of tenant-specific embedding cache identity" ,
125+ async ( { providerId, baseUrl, headerName, rotatedHeaderName } ) => {
126+ const createForTenant = async (
127+ tenant : string ,
128+ proxyApiKey : string ,
129+ proxyHeaderName = headerName ,
130+ ) => {
131+ const client = await resolveRemoteEmbeddingBearerClient ( {
132+ provider : providerId ,
133+ defaultBaseUrl : baseUrl ,
134+ options : {
135+ config : { models : { } } as never ,
136+ model : "text-embedding-v3" ,
137+ remote : {
138+ baseUrl,
139+ apiKey : "fixture-secret" ,
140+ headers : {
141+ [ proxyHeaderName ] : proxyApiKey ,
142+ "X-Deployment" : tenant ,
143+ "X-Tenant" : tenant ,
144+ version : "tenant-api-v2" ,
145+ "User-Agent" : "tenant-client/2" ,
146+ } ,
128147 } ,
129148 } ,
130- } ,
131- } ) ;
132- expect ( client . headers ) . toMatchObject ( {
133- Authorization : "Bearer fixture-secret" ,
134- [ proxyHeaderName ] : proxyApiKey ,
135- "X-Deployment" : tenant ,
136- } ) ;
137- mocks . createOpenAiEmbeddingProvider . mockResolvedValueOnce ( {
138- provider,
139- client : { ...client , model : "text-embedding-v3" } ,
140- } ) ;
141- return await openAiMemoryEmbeddingProviderAdapter . create ( {
142- config : { } as never ,
143- provider : "bailian-embedding" ,
144- model : "text-embedding-v3" ,
145- fallback : "none" ,
146- } ) ;
147- } ;
149+ } ) ;
150+ expect ( client . headers ) . toMatchObject ( {
151+ Authorization : "Bearer fixture-secret" ,
152+ [ proxyHeaderName ] : proxyApiKey ,
153+ "X-Deployment" : tenant ,
154+ } ) ;
155+ mocks . createOpenAiEmbeddingProvider . mockResolvedValueOnce ( {
156+ provider,
157+ client : { ...client , model : "text-embedding-v3" } ,
158+ } ) ;
159+ return await openAiMemoryEmbeddingProviderAdapter . create ( {
160+ config : { } as never ,
161+ provider : providerId ,
162+ model : "text-embedding-v3" ,
163+ fallback : "none" ,
164+ } ) ;
165+ } ;
148166
149- const first = await createForTenant ( "tenant-a" , "proxy-key-before-rotation" ) ;
150- const rotated = await createForTenant ( "tenant-a" , "proxy-key-after-rotation" , "x-aPI-kEY" ) ;
151- const second = await createForTenant ( "tenant-b" , "proxy-key-after-rotation" ) ;
152- const headers = first . runtime ?. cacheKeyData ?. headers ;
153-
154- expect ( headers ) . toEqual (
155- expect . arrayContaining ( [
156- [ "X-Deployment" , "tenant-a" ] ,
157- [ "X-Tenant" , "tenant-a" ] ,
158- [ "version" , "tenant-api-v2" ] ,
159- [ "User-Agent" , "tenant-client/2" ] ,
160- ] ) ,
161- ) ;
162- expect ( first . runtime ?. cacheKeyData ) . toEqual ( rotated . runtime ?. cacheKeyData ) ;
163- expect ( hashText ( JSON . stringify ( first . runtime ?. cacheKeyData ) ) ) . toBe (
164- hashText ( JSON . stringify ( rotated . runtime ?. cacheKeyData ) ) ,
165- ) ;
166- expect ( first . runtime ?. cacheKeyData ) . not . toEqual ( second . runtime ?. cacheKeyData ) ;
167- expect ( JSON . stringify ( first . runtime ?. cacheKeyData ) ) . not . toContain ( "fixture-secret" ) ;
168- expect ( JSON . stringify ( first . runtime ?. cacheKeyData ) ) . not . toContain ( "proxy-key-before-rotation" ) ;
169- } ) ;
167+ const first = await createForTenant ( "tenant-a" , "proxy-key-before-rotation" ) ;
168+ const rotated = await createForTenant (
169+ "tenant-a" ,
170+ "proxy-key-after-rotation" ,
171+ rotatedHeaderName ,
172+ ) ;
173+ const second = await createForTenant ( "tenant-b" , "proxy-key-after-rotation" ) ;
174+ const headers = first . runtime ?. cacheKeyData ?. headers ;
175+
176+ expect ( headers ) . toEqual (
177+ expect . arrayContaining ( [
178+ [ "X-Deployment" , "tenant-a" ] ,
179+ [ "X-Tenant" , "tenant-a" ] ,
180+ [ "version" , "tenant-api-v2" ] ,
181+ [ "User-Agent" , "tenant-client/2" ] ,
182+ ] ) ,
183+ ) ;
184+ expect ( first . runtime ?. cacheKeyData ) . toEqual ( rotated . runtime ?. cacheKeyData ) ;
185+ expect ( hashText ( JSON . stringify ( first . runtime ?. cacheKeyData ) ) ) . toBe (
186+ hashText ( JSON . stringify ( rotated . runtime ?. cacheKeyData ) ) ,
187+ ) ;
188+ expect ( first . runtime ?. cacheKeyData ) . not . toEqual ( second . runtime ?. cacheKeyData ) ;
189+ expect ( JSON . stringify ( first . runtime ?. cacheKeyData ) ) . not . toContain ( "fixture-secret" ) ;
190+ expect ( JSON . stringify ( first . runtime ?. cacheKeyData ) ) . not . toContain (
191+ "proxy-key-before-rotation" ,
192+ ) ;
193+ expect ( first . runtime ?. cacheKeyData ) . toMatchObject ( { provider : providerId , baseUrl } ) ;
194+ } ,
195+ ) ;
170196
171197 it ( "sends document input_type in OpenAI batch embedding requests" , async ( ) => {
172198 const result = await openAiMemoryEmbeddingProviderAdapter . create ( {
0 commit comments