@@ -42,7 +42,7 @@ describe('FeatureFlagCache', () => {
4242 expect ( ctx ) . to . not . be . undefined ;
4343 expect ( ctx . refCount ) . to . equal ( 1 ) ;
4444 expect ( ctx . cacheDuration ) . to . equal ( 15 * 60 * 1000 ) ; // 15 minutes
45- expect ( ctx . telemetryEnabled ) . to . be . undefined ;
45+ expect ( ctx . flags . size ) . to . equal ( 0 ) ; // Empty flags map initially
4646 expect ( ctx . lastFetched ) . to . be . undefined ;
4747 } ) ;
4848
@@ -137,8 +137,16 @@ describe('FeatureFlagCache', () => {
137137 const cache = new FeatureFlagCache ( context ) ;
138138 const host = 'test-host.databricks.com' ;
139139
140- // Stub the private fetchFeatureFlag method
141- const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlag' ) . resolves ( true ) ;
140+ // Stub the private fetchFeatureFlags method to populate flags Map
141+ const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlags' ) . callsFake ( async ( ) => {
142+ const ctx = ( cache as any ) . contexts . get ( host ) ;
143+ if ( ctx ) {
144+ ctx . flags . set (
145+ 'databricks.partnerplatform.clientConfigsFeatureFlags.enableTelemetryForNodeJs' ,
146+ 'true' ,
147+ ) ;
148+ }
149+ } ) ;
142150
143151 cache . getOrCreateContext ( host ) ;
144152 const enabled = await cache . isTelemetryEnabled ( host ) ;
@@ -155,7 +163,15 @@ describe('FeatureFlagCache', () => {
155163 const cache = new FeatureFlagCache ( context ) ;
156164 const host = 'test-host.databricks.com' ;
157165
158- const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlag' ) . resolves ( true ) ;
166+ const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlags' ) . callsFake ( async ( ) => {
167+ const ctx = ( cache as any ) . contexts . get ( host ) ;
168+ if ( ctx ) {
169+ ctx . flags . set (
170+ 'databricks.partnerplatform.clientConfigsFeatureFlags.enableTelemetryForNodeJs' ,
171+ 'true' ,
172+ ) ;
173+ }
174+ } ) ;
159175
160176 cache . getOrCreateContext ( host ) ;
161177
@@ -179,9 +195,18 @@ describe('FeatureFlagCache', () => {
179195 const cache = new FeatureFlagCache ( context ) ;
180196 const host = 'test-host.databricks.com' ;
181197
182- const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlag' ) ;
183- fetchStub . onFirstCall ( ) . resolves ( true ) ;
184- fetchStub . onSecondCall ( ) . resolves ( false ) ;
198+ let callCount = 0 ;
199+ const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlags' ) . callsFake ( async ( ) => {
200+ const ctx = ( cache as any ) . contexts . get ( host ) ;
201+ if ( ctx ) {
202+ callCount ++ ;
203+ // First call returns true, second returns false
204+ ctx . flags . set (
205+ 'databricks.partnerplatform.clientConfigsFeatureFlags.enableTelemetryForNodeJs' ,
206+ callCount === 1 ? 'true' : 'false' ,
207+ ) ;
208+ }
209+ } ) ;
185210
186211 cache . getOrCreateContext ( host ) ;
187212
@@ -207,24 +232,24 @@ describe('FeatureFlagCache', () => {
207232 const cache = new FeatureFlagCache ( context ) ;
208233 const host = 'test-host.databricks.com' ;
209234
210- const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlag ' ) . rejects ( new Error ( 'Network error' ) ) ;
235+ const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlags ' ) . rejects ( new Error ( 'Network error' ) ) ;
211236
212237 cache . getOrCreateContext ( host ) ;
213238 const enabled = await cache . isTelemetryEnabled ( host ) ;
214239
215240 expect ( enabled ) . to . be . false ;
216- expect ( logSpy . calledWith ( LogLevel . debug , 'Error fetching feature flag : Network error' ) ) . to . be . true ;
241+ expect ( logSpy . calledWith ( LogLevel . debug , 'Error fetching feature flags : Network error' ) ) . to . be . true ;
217242
218243 fetchStub . restore ( ) ;
219244 logSpy . restore ( ) ;
220245 } ) ;
221246
222- it ( 'should not propagate exceptions from fetchFeatureFlag ' , async ( ) => {
247+ it ( 'should not propagate exceptions from fetchFeatureFlags ' , async ( ) => {
223248 const context = new ClientContextStub ( ) ;
224249 const cache = new FeatureFlagCache ( context ) ;
225250 const host = 'test-host.databricks.com' ;
226251
227- const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlag ' ) . rejects ( new Error ( 'Network error' ) ) ;
252+ const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlags ' ) . rejects ( new Error ( 'Network error' ) ) ;
228253
229254 cache . getOrCreateContext ( host ) ;
230255
@@ -235,12 +260,13 @@ describe('FeatureFlagCache', () => {
235260 fetchStub . restore ( ) ;
236261 } ) ;
237262
238- it ( 'should return false when telemetryEnabled is undefined ' , async ( ) => {
263+ it ( 'should return false when flag is not set in the map ' , async ( ) => {
239264 const context = new ClientContextStub ( ) ;
240265 const cache = new FeatureFlagCache ( context ) ;
241266 const host = 'test-host.databricks.com' ;
242267
243- const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlag' ) . resolves ( undefined ) ;
268+ // Stub fetchFeatureFlags to do nothing (leaves flags map empty)
269+ const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlags' ) . resolves ( ) ;
244270
245271 cache . getOrCreateContext ( host ) ;
246272 const enabled = await cache . isTelemetryEnabled ( host ) ;
@@ -251,15 +277,19 @@ describe('FeatureFlagCache', () => {
251277 } ) ;
252278 } ) ;
253279
254- describe ( 'fetchFeatureFlag ' , ( ) => {
255- it ( 'should return false as placeholder implementation ' , async ( ) => {
280+ describe ( 'fetchFeatureFlags ' , ( ) => {
281+ it ( 'should handle fetch errors gracefully ' , async ( ) => {
256282 const context = new ClientContextStub ( ) ;
257283 const cache = new FeatureFlagCache ( context ) ;
258284 const host = 'test-host.databricks.com' ;
259285
260- // Access private method through any cast
261- const result = await ( cache as any ) . fetchFeatureFlag ( host ) ;
262- expect ( result ) . to . be . false ;
286+ cache . getOrCreateContext ( host ) ;
287+
288+ // Access private method through any cast - should not throw even if fetch fails
289+ await ( cache as any ) . fetchFeatureFlags ( host ) ;
290+
291+ // Should log at debug level but not throw
292+ // Exact behavior depends on network conditions, this just verifies no exception
263293 } ) ;
264294 } ) ;
265295
@@ -269,7 +299,15 @@ describe('FeatureFlagCache', () => {
269299 const cache = new FeatureFlagCache ( context ) ;
270300 const host = 'test-host.databricks.com' ;
271301
272- const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlag' ) . resolves ( true ) ;
302+ const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlags' ) . callsFake ( async ( ) => {
303+ const ctx = ( cache as any ) . contexts . get ( host ) ;
304+ if ( ctx ) {
305+ ctx . flags . set (
306+ 'databricks.partnerplatform.clientConfigsFeatureFlags.enableTelemetryForNodeJs' ,
307+ 'true' ,
308+ ) ;
309+ }
310+ } ) ;
273311
274312 // Simulate 3 connections to same host
275313 cache . getOrCreateContext ( host ) ;
@@ -301,9 +339,16 @@ describe('FeatureFlagCache', () => {
301339 const host1 = 'host1.databricks.com' ;
302340 const host2 = 'host2.databricks.com' ;
303341
304- const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlag' ) ;
305- fetchStub . withArgs ( host1 ) . resolves ( true ) ;
306- fetchStub . withArgs ( host2 ) . resolves ( false ) ;
342+ const fetchStub = sinon . stub ( cache as any , 'fetchFeatureFlags' ) . callsFake ( async ( host : string ) => {
343+ const ctx = ( cache as any ) . contexts . get ( host ) ;
344+ if ( ctx ) {
345+ // host1 returns true, host2 returns false
346+ ctx . flags . set (
347+ 'databricks.partnerplatform.clientConfigsFeatureFlags.enableTelemetryForNodeJs' ,
348+ host === host1 ? 'true' : 'false' ,
349+ ) ;
350+ }
351+ } ) ;
307352
308353 cache . getOrCreateContext ( host1 ) ;
309354 cache . getOrCreateContext ( host2 ) ;
0 commit comments