@@ -419,6 +419,125 @@ describe('InlineCompletionManager', () => {
419419 assert . deepStrictEqual ( ( r3 as InlineCompletionItem [ ] ) [ 0 ] . range ?. end , new Position ( 1 , 26 ) )
420420 } )
421421 } )
422+
423+ it ( 'should return empty array and emit telemetry when edit suggestion is active' , async ( ) => {
424+ provider = new AmazonQInlineCompletionItemProvider (
425+ languageClient ,
426+ recommendationService ,
427+ mockSessionManager ,
428+ inlineTutorialAnnotation ,
429+ documentEventListener
430+ )
431+
432+ // Stub the private method to return true (following existing pattern)
433+ sandbox . stub ( provider as any , 'isEditSuggestionActive' ) . returns ( true )
434+
435+ const result = await provider . provideInlineCompletionItems (
436+ mockDocument ,
437+ mockPosition ,
438+ mockContext ,
439+ mockToken
440+ )
441+
442+ // Should return empty array
443+ assert . deepStrictEqual ( result , [ ] )
444+
445+ // Should emit telemetry for each completion suggestion
446+ assert . strictEqual ( sendNotificationStub . callCount , 2 ) // For both mockSuggestions
447+
448+ // Verify telemetry parameters for first call
449+ const firstCall = sendNotificationStub . getCall ( 0 )
450+ assert . strictEqual ( firstCall . args [ 0 ] , 'aws/logInlineCompletionSessionResults' )
451+ const sessionResult = Object . values ( firstCall . args [ 1 ] . completionSessionResult ) [ 0 ] as any
452+ assert . strictEqual ( sessionResult . seen , false )
453+ assert . strictEqual ( sessionResult . accepted , false )
454+ assert . strictEqual ( sessionResult . discarded , true )
455+ } )
456+
457+ it ( 'should only emit telemetry for non-inline-edit items when edit is active' , async ( ) => {
458+ provider = new AmazonQInlineCompletionItemProvider (
459+ languageClient ,
460+ recommendationService ,
461+ mockSessionManager ,
462+ inlineTutorialAnnotation ,
463+ documentEventListener
464+ )
465+
466+ sandbox . stub ( provider as any , 'isEditSuggestionActive' ) . returns ( true )
467+
468+ // Mix of inline edits and completions
469+ const mixedSuggestions = [
470+ { itemId : 'edit1' , insertText : 'diff' , isInlineEdit : true } ,
471+ { itemId : 'completion1' , insertText : 'code' , isInlineEdit : false } ,
472+ ]
473+ getActiveRecommendationStub . returns ( mixedSuggestions )
474+
475+ const result = await provider . provideInlineCompletionItems (
476+ mockDocument ,
477+ mockPosition ,
478+ mockContext ,
479+ mockToken
480+ )
481+
482+ // Should return empty array
483+ assert . deepStrictEqual ( result , [ ] )
484+
485+ // Should only emit telemetry for completion, not inline edit
486+ assert . strictEqual ( sendNotificationStub . callCount , 1 )
487+ const call = sendNotificationStub . getCall ( 0 )
488+ assert ( call . args [ 1 ] . completionSessionResult [ 'completion1' ] )
489+ assert ( ! call . args [ 1 ] . completionSessionResult [ 'edit1' ] )
490+ } )
491+
492+ it ( 'should not emit telemetry for items without itemId when edit is active' , async ( ) => {
493+ provider = new AmazonQInlineCompletionItemProvider (
494+ languageClient ,
495+ recommendationService ,
496+ mockSessionManager ,
497+ inlineTutorialAnnotation ,
498+ documentEventListener
499+ )
500+
501+ sandbox . stub ( provider as any , 'isEditSuggestionActive' ) . returns ( true )
502+
503+ // Set up suggestions where some don't have itemId
504+ const suggestionsWithoutId = [
505+ { insertText : 'code' , isInlineEdit : false } , // No itemId
506+ { itemId : 'completion1' , insertText : 'code' , isInlineEdit : false } ,
507+ ]
508+ getActiveRecommendationStub . returns ( suggestionsWithoutId )
509+
510+ const result = await provider . provideInlineCompletionItems (
511+ mockDocument ,
512+ mockPosition ,
513+ mockContext ,
514+ mockToken
515+ )
516+
517+ // Should return empty array
518+ assert . deepStrictEqual ( result , [ ] )
519+
520+ // Should only emit telemetry for the item with itemId
521+ assert . strictEqual ( sendNotificationStub . callCount , 1 )
522+ const call = sendNotificationStub . getCall ( 0 )
523+ assert ( call . args [ 1 ] . completionSessionResult [ 'completion1' ] )
524+ } )
525+
526+ describe ( 'isEditSuggestionActive' , ( ) => {
527+ it ( 'should return false when no edit suggestion is active' , ( ) => {
528+ provider = new AmazonQInlineCompletionItemProvider (
529+ languageClient ,
530+ recommendationService ,
531+ mockSessionManager ,
532+ inlineTutorialAnnotation ,
533+ documentEventListener
534+ )
535+
536+ // Since getContext returns undefined by default, this should return false
537+ const result = ( provider as any ) . isEditSuggestionActive ( )
538+ assert . strictEqual ( result , false )
539+ } )
540+ } )
422541 } )
423542 } )
424543} )
0 commit comments