@@ -94,6 +94,7 @@ describe('Telemetry Metrics', () => {
9494 let recordFlickerFrameModule : typeof import ( './metrics.js' ) . recordFlickerFrame ;
9595 let recordExitFailModule : typeof import ( './metrics.js' ) . recordExitFail ;
9696 let recordAgentRunMetricsModule : typeof import ( './metrics.js' ) . recordAgentRunMetrics ;
97+ let recordLinesChangedModule : typeof import ( './metrics.js' ) . recordLinesChanged ;
9798
9899 beforeEach ( async ( ) => {
99100 vi . resetModules ( ) ;
@@ -136,6 +137,7 @@ describe('Telemetry Metrics', () => {
136137 recordFlickerFrameModule = metricsJsModule . recordFlickerFrame ;
137138 recordExitFailModule = metricsJsModule . recordExitFail ;
138139 recordAgentRunMetricsModule = metricsJsModule . recordAgentRunMetrics ;
140+ recordLinesChangedModule = metricsJsModule . recordLinesChanged ;
139141
140142 const otelApiModule = await import ( '@opentelemetry/api' ) ;
141143
@@ -348,6 +350,53 @@ describe('Telemetry Metrics', () => {
348350 } ) ;
349351 } ) ;
350352
353+ describe ( 'recordLinesChanged metric' , ( ) => {
354+ const mockConfig = {
355+ getSessionId : ( ) => 'test-session-id' ,
356+ getTelemetryEnabled : ( ) => true ,
357+ } as unknown as Config ;
358+
359+ it ( 'should not record lines added/removed if not initialized' , ( ) => {
360+ recordLinesChangedModule ( mockConfig , 10 , 'added' , {
361+ function_name : 'fn' ,
362+ } ) ;
363+ recordLinesChangedModule ( mockConfig , 5 , 'removed' , {
364+ function_name : 'fn' ,
365+ } ) ;
366+ expect ( mockCounterAddFn ) . not . toHaveBeenCalled ( ) ;
367+ } ) ;
368+
369+ it ( 'should record lines added with function_name after initialization' , ( ) => {
370+ initializeMetricsModule ( mockConfig ) ;
371+ mockCounterAddFn . mockClear ( ) ;
372+ recordLinesChangedModule ( mockConfig , 10 , 'added' , {
373+ function_name : 'my-fn' ,
374+ } ) ;
375+ expect ( mockCounterAddFn ) . toHaveBeenCalledWith ( 10 , {
376+ 'session.id' : 'test-session-id' ,
377+ 'installation.id' : 'test-installation-id' ,
378+ 'user.email' : 'test@example.com' ,
379+ type : 'added' ,
380+ function_name : 'my-fn' ,
381+ } ) ;
382+ } ) ;
383+
384+ it ( 'should record lines removed with function_name after initialization' , ( ) => {
385+ initializeMetricsModule ( mockConfig ) ;
386+ mockCounterAddFn . mockClear ( ) ;
387+ recordLinesChangedModule ( mockConfig , 7 , 'removed' , {
388+ function_name : 'my-fn' ,
389+ } ) ;
390+ expect ( mockCounterAddFn ) . toHaveBeenCalledWith ( 7 , {
391+ 'session.id' : 'test-session-id' ,
392+ 'installation.id' : 'test-installation-id' ,
393+ 'user.email' : 'test@example.com' ,
394+ type : 'removed' ,
395+ function_name : 'my-fn' ,
396+ } ) ;
397+ } ) ;
398+ } ) ;
399+
351400 describe ( 'recordFileOperationMetric' , ( ) => {
352401 const mockConfig = {
353402 getSessionId : ( ) => 'test-session-id' ,
0 commit comments