66import * as vscode from 'vscode'
77import assert from 'assert'
88import {
9- assertTelemetry ,
109 closeAllEditors ,
1110 getTestWindow ,
1211 registerAuthHook ,
@@ -65,21 +64,25 @@ describe('Amazon Q Inline', async function () {
6564 }
6665 }
6766
68- async function waitForTelemetry ( ) {
69- const ok = await waitUntil (
70- async ( ) =>
71- globals . telemetry . logger . query ( {
72- metricName : 'codewhisperer_userTriggerDecision' ,
73- } ) . length > 0 ,
74- waitOptions
75- )
67+ async function lastTriggerDecision ( ) {
68+ const ok = await waitUntil ( async ( ) => {
69+ const telem = globals . telemetry . logger . query ( {
70+ metricName : 'codewhisperer_userTriggerDecision' ,
71+ } )
72+ return telem . some ( ( item ) => item . codewhispererSuggestionState !== 'Empty' )
73+ } , waitOptions )
7674 if ( ! ok ) {
7775 assert . fail ( 'Telemetry failed to be emitted' )
7876 }
77+
78+ const events = globals . telemetry . logger . query ( {
79+ metricName : 'codewhisperer_userTriggerDecision' ,
80+ } )
81+ return events [ events . length - 1 ] . codewhispererSuggestionState
7982 }
8083
8184 for ( const [ name , invokeCompletion ] of [
82- [ 'automatic' , async ( ) => await vscode . commands . executeCommand ( 'type' , { text : '\n' } ) ] ,
85+ [ 'automatic' , async ( ) => vscode . commands . executeCommand ( 'type' , { text : '\n' } ) ] ,
8386 [ 'manual' , async ( ) => Commands . tryExecute ( 'aws.amazonq.invokeInlineCompletion' ) ] ,
8487 ] as const ) {
8588 describe ( `${ name } invoke` , async function ( ) {
@@ -119,10 +122,8 @@ describe('Amazon Q Inline', async function () {
119122
120123 assert . ok ( suggestionAccepted , 'Editor contents should have changed' )
121124
122- await waitForTelemetry ( )
123- assertTelemetry ( 'codewhisperer_userTriggerDecision' , {
124- codewhispererSuggestionState : 'Accept' ,
125- } )
125+ const decision = await lastTriggerDecision ( )
126+ assert . deepStrictEqual ( decision , 'Accept' )
126127 } )
127128
128129 it ( `${ name } invoke reject` , async function ( ) {
@@ -132,10 +133,8 @@ describe('Amazon Q Inline', async function () {
132133 // Contents haven't changed
133134 assert . deepStrictEqual ( vscode . window . activeTextEditor ?. document . getText ( ) , originalEditorContents )
134135
135- await waitForTelemetry ( )
136- assertTelemetry ( 'codewhisperer_userTriggerDecision' , {
137- codewhispererSuggestionState : 'Reject' ,
138- } )
136+ const decision = await lastTriggerDecision ( )
137+ assert . deepStrictEqual ( decision , 'Reject' )
139138 } )
140139
141140 it ( `${ name } invoke discard` , async function ( ) {
0 commit comments