@@ -675,6 +675,62 @@ describe('KernelBackend', () => {
675675 }
676676 } ) ;
677677
678+ it ( 'openSession() warns and omits out-of-range telemetry knobs, falling back to kernel defaults' , async ( ) => {
679+ const savedEnv = process . env . DATABRICKS_TELEMETRY_DISABLED ;
680+ delete process . env . DATABRICKS_TELEMETRY_DISABLED ;
681+
682+ const warnings : Array < { level : LogLevel ; message : string } > = [ ] ;
683+ const logger : IDBSQLLogger = {
684+ log ( level : LogLevel , message : string ) : void {
685+ warnings . push ( { level, message } ) ;
686+ } ,
687+ } ;
688+
689+ const connection = new FakeNativeConnection ( ) ;
690+ const binding = makeBinding ( connection ) ;
691+ const backend = new KernelBackend ( {
692+ context : makeContext ( logger , {
693+ // `0` is out of range for the `> 0` guard; negative is out of range for the `>= 0` guard.
694+ telemetryBatchSize : 0 ,
695+ telemetryCircuitBreakerThreshold : - 1 ,
696+ telemetryMaxRetries : - 5 ,
697+ } ) ,
698+ nativeBinding : binding ,
699+ } ) ;
700+
701+ try {
702+ await backend . connect ( {
703+ host : 'workspace.example' ,
704+ path : '/sql/1.0/warehouses/xyz' ,
705+ token : 'dapi-token' ,
706+ } as ConnectionOptions ) ;
707+ await backend . openSession ( { } ) ;
708+
709+ const args = binding . openSessionStub . firstCall . args [ 0 ] as Record < string , unknown > ;
710+ // Rejected knobs are omitted from the forwarded napi options so the kernel default applies.
711+ expect ( args . telemetryBatchSize ) . to . equal ( undefined ) ;
712+ expect ( args . telemetryCircuitBreakerThreshold ) . to . equal ( undefined ) ;
713+ expect ( args . telemetryMaxRetries ) . to . equal ( undefined ) ;
714+
715+ const warnFor = ( name : string ) =>
716+ warnings . find ( ( w ) => w . level === LogLevel . warn && w . message . includes ( `'${ name } '` ) ) ;
717+ expect ( warnFor ( 'telemetryBatchSize' ) , 'expected a warn for telemetryBatchSize' ) . to . not . equal ( undefined ) ;
718+ expect ( warnFor ( 'telemetryBatchSize' ) ! . message ) . to . contain ( 'greater than zero' ) ;
719+ expect (
720+ warnFor ( 'telemetryCircuitBreakerThreshold' ) ,
721+ 'expected a warn for telemetryCircuitBreakerThreshold' ,
722+ ) . to . not . equal ( undefined ) ;
723+ expect ( warnFor ( 'telemetryMaxRetries' ) , 'expected a warn for telemetryMaxRetries' ) . to . not . equal ( undefined ) ;
724+ expect ( warnFor ( 'telemetryMaxRetries' ) ! . message ) . to . contain ( 'zero or greater' ) ;
725+ } finally {
726+ if ( savedEnv === undefined ) {
727+ delete process . env . DATABRICKS_TELEMETRY_DISABLED ;
728+ } else {
729+ process . env . DATABRICKS_TELEMETRY_DISABLED = savedEnv ;
730+ }
731+ }
732+ } ) ;
733+
678734 it ( 'openSession() serializes session-level queryTags into sessionConf.QUERY_TAGS' , async ( ) => {
679735 const connection = new FakeNativeConnection ( ) ;
680736 const binding = makeBinding ( connection ) ;
0 commit comments