@@ -34,7 +34,7 @@ describe("request tracing", function () {
3434 after ( ( ) => {
3535 } ) ;
3636
37- it ( "should have correct user agent prefix " , async ( ) => {
37+ it ( "should include the provider identifier in the user agent" , async ( ) => {
3838 try {
3939 await load ( createMockedConnectionString ( fakeEndpoint ) , {
4040 clientOptions,
@@ -44,7 +44,7 @@ describe("request tracing", function () {
4444 } ) ;
4545 } catch { /* empty */ }
4646 expect ( headerPolicy . headers ) . not . undefined ;
47- expect ( headerPolicy . headers . get ( "User-Agent" ) ) . satisfy ( ( ua : string ) => ua . startsWith ( "javascript-appconfiguration-provider" ) ) ;
47+ expect ( headerPolicy . headers . get ( "User-Agent" ) ) . satisfy ( ( ua : string ) => ua . includes ( "javascript-appconfiguration-provider" ) ) ;
4848 } ) ;
4949
5050 it ( "should have request type in correlation-context header" , async ( ) => {
@@ -204,18 +204,14 @@ describe("request tracing", function () {
204204 } ) ;
205205
206206 it ( "should have filter type in correlation-context header if feature flags use feature filters" , async ( ) => {
207- let correlationContext : string = "" ;
208- const listKvCallback = ( listOptions ) => {
209- correlationContext = listOptions ?. requestOptions ?. customHeaders [ CORRELATION_CONTEXT_HEADER_NAME ] ?? "" ;
210- } ;
211-
212207 mockAppConfigurationClientListConfigurationSettings ( [ [
213208 createMockedFeatureFlag ( "Alpha_1" , { conditions : { client_filters : [ { name : "Microsoft.TimeWindow" } ] } } ) ,
214209 createMockedFeatureFlag ( "Alpha_2" , { conditions : { client_filters : [ { name : "Microsoft.Targeting" } ] } } ) ,
215210 createMockedFeatureFlag ( "Alpha_3" , { conditions : { client_filters : [ { name : "CustomFilter" } ] } } )
216- ] ] , listKvCallback ) ;
211+ ] ] ) ;
217212
218213 const settings = await load ( createMockedConnectionString ( fakeEndpoint ) , {
214+ clientOptions,
219215 featureFlagOptions : {
220216 enabled : true ,
221217 selectors : [ { keyFilter : "*" } ] ,
@@ -226,34 +222,30 @@ describe("request tracing", function () {
226222 }
227223 } ) ;
228224
229- expect ( correlationContext ) . not . undefined ;
230- expect ( correlationContext ?. includes ( "RequestType=Startup" ) ) . eq ( true ) ;
225+ restoreMocks ( ) ;
231226
232227 await sleepInMs ( 1_000 + 1_000 ) ;
233228 try {
234229 await settings . refresh ( ) ;
235230 } catch { /* empty */ }
236231 expect ( headerPolicy . headers ) . not . undefined ;
232+ const correlationContext = headerPolicy . headers . get ( CORRELATION_CONTEXT_HEADER_NAME ) ;
237233 expect ( correlationContext ) . not . undefined ;
238- expect ( correlationContext ? .includes ( "RequestType=Watch" ) ) . eq ( true ) ;
239- expect ( correlationContext ? .includes ( "Filter=CSTM+TIME+TRGT" ) ) . eq ( true ) ;
234+ expect ( correlationContext . includes ( "RequestType=Watch" ) ) . eq ( true ) ;
235+ expect ( correlationContext . includes ( "Filter=CSTM+TIME+TRGT" ) ) . eq ( true ) ;
240236
241237 restoreMocks ( ) ;
242238 } ) ;
243239
244240 it ( "should have max variants in correlation-context header if feature flags use variants" , async ( ) => {
245- let correlationContext : string = "" ;
246- const listKvCallback = ( listOptions ) => {
247- correlationContext = listOptions ?. requestOptions ?. customHeaders [ CORRELATION_CONTEXT_HEADER_NAME ] ?? "" ;
248- } ;
249-
250241 mockAppConfigurationClientListConfigurationSettings ( [ [
251242 createMockedFeatureFlag ( "Alpha_1" , { variants : [ { name : "a" } , { name : "b" } ] } ) ,
252243 createMockedFeatureFlag ( "Alpha_2" , { variants : [ { name : "a" } , { name : "b" } , { name : "c" } ] } ) ,
253244 createMockedFeatureFlag ( "Alpha_3" , { variants : [ ] } )
254- ] ] , listKvCallback ) ;
245+ ] ] ) ;
255246
256247 const settings = await load ( createMockedConnectionString ( fakeEndpoint ) , {
248+ clientOptions,
257249 featureFlagOptions : {
258250 enabled : true ,
259251 selectors : [ { keyFilter : "*" } ] ,
@@ -264,32 +256,28 @@ describe("request tracing", function () {
264256 }
265257 } ) ;
266258
267- expect ( correlationContext ) . not . undefined ;
268- expect ( correlationContext ?. includes ( "RequestType=Startup" ) ) . eq ( true ) ;
259+ restoreMocks ( ) ;
269260
270261 await sleepInMs ( 1_000 + 1_000 ) ;
271262 try {
272263 await settings . refresh ( ) ;
273264 } catch { /* empty */ }
274265 expect ( headerPolicy . headers ) . not . undefined ;
266+ const correlationContext = headerPolicy . headers . get ( CORRELATION_CONTEXT_HEADER_NAME ) ;
275267 expect ( correlationContext ) . not . undefined ;
276- expect ( correlationContext ? .includes ( "RequestType=Watch" ) ) . eq ( true ) ;
277- expect ( correlationContext ? .includes ( "MaxVariants=3" ) ) . eq ( true ) ;
268+ expect ( correlationContext . includes ( "RequestType=Watch" ) ) . eq ( true ) ;
269+ expect ( correlationContext . includes ( "MaxVariants=3" ) ) . eq ( true ) ;
278270
279271 restoreMocks ( ) ;
280272 } ) ;
281273
282274 it ( "should have telemety tag in correlation-context header if feature flags enable telemetry" , async ( ) => {
283- let correlationContext : string = "" ;
284- const listKvCallback = ( listOptions ) => {
285- correlationContext = listOptions ?. requestOptions ?. customHeaders [ CORRELATION_CONTEXT_HEADER_NAME ] ?? "" ;
286- } ;
287-
288275 mockAppConfigurationClientListConfigurationSettings ( [ [
289276 createMockedFeatureFlag ( "Alpha_1" , { telemetry : { enabled : true } } )
290- ] ] , listKvCallback ) ;
277+ ] ] ) ;
291278
292279 const settings = await load ( createMockedConnectionString ( fakeEndpoint ) , {
280+ clientOptions,
293281 featureFlagOptions : {
294282 enabled : true ,
295283 selectors : [ { keyFilter : "*" } ] ,
@@ -300,33 +288,29 @@ describe("request tracing", function () {
300288 }
301289 } ) ;
302290
303- expect ( correlationContext ) . not . undefined ;
304- expect ( correlationContext ?. includes ( "RequestType=Startup" ) ) . eq ( true ) ;
291+ restoreMocks ( ) ;
305292
306293 await sleepInMs ( 1_000 + 1_000 ) ;
307294 try {
308295 await settings . refresh ( ) ;
309296 } catch { /* empty */ }
310297 expect ( headerPolicy . headers ) . not . undefined ;
298+ const correlationContext = headerPolicy . headers . get ( CORRELATION_CONTEXT_HEADER_NAME ) ;
311299 expect ( correlationContext ) . not . undefined ;
312- expect ( correlationContext ? .includes ( "RequestType=Watch" ) ) . eq ( true ) ;
313- expect ( correlationContext ? .includes ( "FFFeatures=Telemetry" ) ) . eq ( true ) ;
300+ expect ( correlationContext . includes ( "RequestType=Watch" ) ) . eq ( true ) ;
301+ expect ( correlationContext . includes ( "FFFeatures=Telemetry" ) ) . eq ( true ) ;
314302
315303 restoreMocks ( ) ;
316304 } ) ;
317305
318306 it ( "should have seed tag in correlation-context header if feature flags use allocation seed" , async ( ) => {
319- let correlationContext : string = "" ;
320- const listKvCallback = ( listOptions ) => {
321- correlationContext = listOptions ?. requestOptions ?. customHeaders [ CORRELATION_CONTEXT_HEADER_NAME ] ?? "" ;
322- } ;
323-
324307 mockAppConfigurationClientListConfigurationSettings ( [ [
325308 createMockedFeatureFlag ( "Alpha_1" , { telemetry : { enabled : true } } ) ,
326309 createMockedFeatureFlag ( "Alpha_2" , { allocation : { seed : "123" } } )
327- ] ] , listKvCallback ) ;
310+ ] ] ) ;
328311
329312 const settings = await load ( createMockedConnectionString ( fakeEndpoint ) , {
313+ clientOptions,
330314 featureFlagOptions : {
331315 enabled : true ,
332316 selectors : [ { keyFilter : "*" } ] ,
@@ -337,48 +321,44 @@ describe("request tracing", function () {
337321 }
338322 } ) ;
339323
340- expect ( correlationContext ) . not . undefined ;
341- expect ( correlationContext ?. includes ( "RequestType=Startup" ) ) . eq ( true ) ;
324+ restoreMocks ( ) ;
342325
343326 await sleepInMs ( 1_000 + 1_000 ) ;
344327 try {
345328 await settings . refresh ( ) ;
346329 } catch { /* empty */ }
347330 expect ( headerPolicy . headers ) . not . undefined ;
331+ const correlationContext = headerPolicy . headers . get ( CORRELATION_CONTEXT_HEADER_NAME ) ;
348332 expect ( correlationContext ) . not . undefined ;
349- expect ( correlationContext ? .includes ( "RequestType=Watch" ) ) . eq ( true ) ;
350- expect ( correlationContext ? .includes ( "FFFeatures=Seed+Telemetry" ) ) . eq ( true ) ;
333+ expect ( correlationContext . includes ( "RequestType=Watch" ) ) . eq ( true ) ;
334+ expect ( correlationContext . includes ( "FFFeatures=Seed+Telemetry" ) ) . eq ( true ) ;
351335
352336 restoreMocks ( ) ;
353337 } ) ;
354338
355339 it ( "should have AI tag in correlation-context header if key values use AI configuration" , async ( ) => {
356- let correlationContext : string = "" ;
357- const listKvCallback = ( listOptions ) => {
358- correlationContext = listOptions ?. requestOptions ?. customHeaders [ CORRELATION_CONTEXT_HEADER_NAME ] ?? "" ;
359- } ;
360-
361340 mockAppConfigurationClientListConfigurationSettings ( [ [
362341 createMockedKeyValue ( { contentType : "application/json; profile=\"https://azconfig.io/mime-profiles/ai/chat-completion\"" } )
363- ] ] , listKvCallback ) ;
342+ ] ] ) ;
364343
365344 const settings = await load ( createMockedConnectionString ( fakeEndpoint ) , {
345+ clientOptions,
366346 refreshOptions : {
367347 enabled : true ,
368348 refreshIntervalInMs : 1000
369349 }
370350 } ) ;
371351
372- expect ( correlationContext ) . not . undefined ;
373- expect ( correlationContext ?. includes ( "RequestType=Startup" ) ) . eq ( true ) ;
352+ restoreMocks ( ) ;
374353
375354 await sleepInMs ( 1000 + 1 ) ;
376355 try {
377356 await settings . refresh ( ) ;
378357 } catch { /* empty */ }
379358 expect ( headerPolicy . headers ) . not . undefined ;
359+ const correlationContext = headerPolicy . headers . get ( CORRELATION_CONTEXT_HEADER_NAME ) ;
380360 expect ( correlationContext ) . not . undefined ;
381- expect ( correlationContext ? .includes ( "Features=AI+AICC" ) ) . eq ( true ) ;
361+ expect ( correlationContext . includes ( "Features=AI+AICC" ) ) . eq ( true ) ;
382362
383363 restoreMocks ( ) ;
384364 } ) ;
0 commit comments