@@ -134,30 +134,35 @@ describe("loadFromAzureFrontDoor", function() {
134134 const kv2_updated = createMockedKeyValue ( { key : "app.key2" , value : "value2-updated" } ) ;
135135 const kv3 = createMockedKeyValue ( { key : "app.key3" , value : "value3" } ) ;
136136
137- const stub = sinon . stub ( AppConfigurationClient . prototype , "listConfigurationSettings" ) ;
137+ const listStub = sinon . stub ( AppConfigurationClient . prototype , "listConfigurationSettings" ) ;
138+ const checkStub = sinon . stub ( AppConfigurationClient . prototype , "checkConfigurationSettings" as any ) ;
138139
139- stub . onCall ( 0 ) . returns ( getCachedIterator ( [
140+ // Initial load
141+ listStub . onCall ( 0 ) . returns ( getCachedIterator ( [
140142 { items : [ kv1 , kv2 ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:00Z" ) } }
141143 ] ) ) ;
142144
143- stub . onCall ( 1 ) . returns ( getCachedIterator ( [
145+ // 1st refresh: check (HEAD) detects change, then reload (GET)
146+ checkStub . onCall ( 0 ) . returns ( getCachedIterator ( [
144147 { items : [ kv1 , kv2_updated ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:01Z" ) } }
145148 ] ) ) ;
146- stub . onCall ( 2 ) . returns ( getCachedIterator ( [
149+ listStub . onCall ( 1 ) . returns ( getCachedIterator ( [
147150 { items : [ kv1 , kv2_updated ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:01Z" ) } }
148151 ] ) ) ;
149152
150- stub . onCall ( 3 ) . returns ( getCachedIterator ( [
153+ // 2nd refresh: check (HEAD) detects change, then reload (GET)
154+ checkStub . onCall ( 1 ) . returns ( getCachedIterator ( [
151155 { items : [ kv1 ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:03Z" ) } }
152156 ] ) ) ;
153- stub . onCall ( 4 ) . returns ( getCachedIterator ( [
157+ listStub . onCall ( 2 ) . returns ( getCachedIterator ( [
154158 { items : [ kv1 ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:03Z" ) } }
155159 ] ) ) ;
156160
157- stub . onCall ( 5 ) . returns ( getCachedIterator ( [
161+ // 3rd refresh: check (HEAD) detects change, then reload (GET)
162+ checkStub . onCall ( 2 ) . returns ( getCachedIterator ( [
158163 { items : [ kv1 , kv3 ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:05Z" ) } }
159164 ] ) ) ;
160- stub . onCall ( 6 ) . returns ( getCachedIterator ( [
165+ listStub . onCall ( 3 ) . returns ( getCachedIterator ( [
161166 { items : [ kv1 , kv3 ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:05Z" ) } }
162167 ] ) ) ;
163168
@@ -192,19 +197,22 @@ describe("loadFromAzureFrontDoor", function() {
192197 const ff = createMockedFeatureFlag ( "Beta" ) ;
193198 const ff_updated = createMockedFeatureFlag ( "Beta" , { enabled : false } ) ;
194199
195- const stub = sinon . stub ( AppConfigurationClient . prototype , "listConfigurationSettings" ) ;
200+ const listStub = sinon . stub ( AppConfigurationClient . prototype , "listConfigurationSettings" ) ;
201+ const checkStub = sinon . stub ( AppConfigurationClient . prototype , "checkConfigurationSettings" as any ) ;
196202
197- stub . onCall ( 0 ) . returns ( getCachedIterator ( [
203+ // Initial load: onCall(0) = default KV selector, onCall(1) = feature flags
204+ listStub . onCall ( 0 ) . returns ( getCachedIterator ( [
198205 { items : [ ff ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:00Z" ) } }
199206 ] ) ) ;
200- stub . onCall ( 1 ) . returns ( getCachedIterator ( [
207+ listStub . onCall ( 1 ) . returns ( getCachedIterator ( [
201208 { items : [ ff ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:00Z" ) } }
202209 ] ) ) ;
203210
204- stub . onCall ( 2 ) . returns ( getCachedIterator ( [
211+ // 1st refresh: check (HEAD) detects change, then reload (GET)
212+ checkStub . onCall ( 0 ) . returns ( getCachedIterator ( [
205213 { items : [ ff_updated ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:03Z" ) } }
206214 ] ) ) ;
207- stub . onCall ( 3 ) . returns ( getCachedIterator ( [
215+ listStub . onCall ( 2 ) . returns ( getCachedIterator ( [
208216 { items : [ ff_updated ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:03Z" ) } }
209217 ] ) ) ;
210218
@@ -235,18 +243,23 @@ describe("loadFromAzureFrontDoor", function() {
235243 const kv1_stale = createMockedKeyValue ( { key : "app.key1" , value : "stale-value" } ) ;
236244 const kv1_new = createMockedKeyValue ( { key : "app.key1" , value : "new-value" } ) ;
237245
238- const stub = sinon . stub ( AppConfigurationClient . prototype , "listConfigurationSettings" ) ;
239- stub . onCall ( 0 ) . returns ( getCachedIterator ( [
246+ const listStub = sinon . stub ( AppConfigurationClient . prototype , "listConfigurationSettings" ) ;
247+ const checkStub = sinon . stub ( AppConfigurationClient . prototype , "checkConfigurationSettings" as any ) ;
248+
249+ // Initial load
250+ listStub . onCall ( 0 ) . returns ( getCachedIterator ( [
240251 { items : [ kv1 ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:01Z" ) } }
241252 ] ) ) ;
242253
243- stub . onCall ( 1 ) . returns ( getCachedIterator ( [
244- { items : [ kv1_stale ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:00Z" ) } } // stale response, should not trigger refresh
254+ // 1st refresh: check (HEAD) returns stale response, should not trigger refresh
255+ checkStub . onCall ( 0 ) . returns ( getCachedIterator ( [
256+ { items : [ kv1_stale ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:00Z" ) } }
245257 ] ) ) ;
246- stub . onCall ( 2 ) . returns ( getCachedIterator ( [
247- { items : [ kv1_new ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:02Z" ) } } // new response, should trigger refresh
258+ // 2nd refresh: check (HEAD) detects change, then reload (GET)
259+ checkStub . onCall ( 1 ) . returns ( getCachedIterator ( [
260+ { items : [ kv1_new ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:02Z" ) } }
248261 ] ) ) ;
249- stub . onCall ( 3 ) . returns ( getCachedIterator ( [
262+ listStub . onCall ( 1 ) . returns ( getCachedIterator ( [
250263 { items : [ kv1_new ] , response : { status : 200 , headers : createTimestampHeaders ( "2025-09-07T00:00:02Z" ) } }
251264 ] ) ) ;
252265
0 commit comments