@@ -26,7 +26,7 @@ import {
2626import MessengerUtils , { ButtonActions } from './messenger/messengerUtils'
2727import { getTelemetryReasonDesc , isAwsError } from '../../../shared/errors'
2828import { ChatItemType } from '../../../amazonq/commons/model'
29- import { ProgressField } from '@aws/mynah-ui'
29+ import { ChatItemButton , MynahIcons , ProgressField } from '@aws/mynah-ui'
3030import { FollowUpTypes } from '../../../amazonq/commons/types'
3131import {
3232 cancelBuild ,
@@ -63,6 +63,9 @@ import {
6363} from '../../../codewhisperer/models/constants'
6464import { UserWrittenCodeTracker } from '../../../codewhisperer/tracker/userWrittenCodeTracker'
6565import { ReferenceLogViewProvider } from '../../../codewhisperer/service/referenceLogViewProvider'
66+ import { submitFeedback } from '../../../feedback/vue/submitFeedback'
67+ import { placeholder } from '../../../shared/vscode/commands2'
68+ import { Auth } from '../../../auth/auth'
6669
6770export interface TestChatControllerEventEmitters {
6871 readonly tabOpened : vscode . EventEmitter < any >
@@ -307,10 +310,22 @@ export class TestController {
307310 )
308311 if ( session . stopIteration ) {
309312 // Error from Science
310- this . messenger . sendMessage ( data . error . uiMessage . replaceAll ( '```' , '' ) , data . tabID , 'answer' )
313+ this . messenger . sendMessage (
314+ data . error . uiMessage . replaceAll ( '```' , '' ) ,
315+ data . tabID ,
316+ 'answer' ,
317+ 'testGenErrorMessage' ,
318+ this . getFeedbackButtons ( )
319+ )
311320 } else {
312321 isCancel
313- ? this . messenger . sendMessage ( data . error . uiMessage , data . tabID , 'answer' )
322+ ? this . messenger . sendMessage (
323+ data . error . uiMessage ,
324+ data . tabID ,
325+ 'answer' ,
326+ 'testGenErrorMessage' ,
327+ this . getFeedbackButtons ( )
328+ )
314329 : this . sendErrorMessage ( data )
315330 }
316331 await this . sessionCleanUp ( )
@@ -330,7 +345,9 @@ export class TestController {
330345 return this . messenger . sendMessage (
331346 i18n ( 'AWS.amazonq.featureDev.error.monthlyLimitReached' ) ,
332347 tabID ,
333- 'answer'
348+ 'answer' ,
349+ 'testGenErrorMessage' ,
350+ this . getFeedbackButtons ( )
334351 )
335352 }
336353 if ( error . message . includes ( 'Too many requests' ) ) {
@@ -362,6 +379,7 @@ export class TestController {
362379 // This function handles actions if user clicked on any Button one of these cases will be executed
363380 private async handleFormActionClicked ( data : any ) {
364381 const typedAction = MessengerUtils . stringToEnumValue ( ButtonActions , data . action as any )
382+ let getFeedbackCommentData = ''
365383 switch ( typedAction ) {
366384 case ButtonActions . STOP_TEST_GEN :
367385 testGenState . setToCancelling ( )
@@ -374,6 +392,16 @@ export class TestController {
374392 this . messenger . sendChatInputEnabled ( data . tabID , true )
375393 await this . sessionCleanUp ( )
376394 break
395+ case ButtonActions . PROVIDE_FEEDBACK :
396+ getFeedbackCommentData = `Q Test Generation: RequestId: ${ this . sessionStorage . getSession ( ) . startTestGenerationRequestId } , TestGenerationJobId: ${ this . sessionStorage . getSession ( ) . testGenerationJob ?. testGenerationJobId } `
397+ void submitFeedback ( placeholder , 'Amazon Q' , getFeedbackCommentData )
398+ telemetry . ui_click . emit ( { elementId : 'unitTestGeneration_provideFeedback' } )
399+ this . messenger . sendMessage (
400+ 'Unit test generation completed. Thanks for providing feedback.' ,
401+ data . tabID ,
402+ 'answer'
403+ )
404+ break
377405 }
378406 }
379407 // This function handles actions if user gives any input from the chatInput box
@@ -403,12 +431,31 @@ export class TestController {
403431 }
404432 }
405433
434+ private getFeedbackButtons ( ) : ChatItemButton [ ] {
435+ const buttons : ChatItemButton [ ] = [ ]
436+ if ( Auth . instance . isInternalAmazonUser ( ) ) {
437+ buttons . push ( {
438+ keepCardAfterClick : false ,
439+ text : 'How can we make /test better?' ,
440+ id : ButtonActions . PROVIDE_FEEDBACK ,
441+ disabled : false , // allow button to be re-clicked
442+ position : 'outside' ,
443+ icon : 'comment' as MynahIcons ,
444+ } )
445+ }
446+ return buttons
447+ }
448+
406449 /**
407450 * Start Test Generation and show the code results
408451 */
409452
410453 private async startTestGen ( message : any , regenerateTests : boolean ) {
411454 const session : Session = this . sessionStorage . getSession ( )
455+ // Perform session cleanup before start of unit test generation workflow unless there is an existing job in progress.
456+ if ( ! ChatSessionManager . Instance . getIsInProgress ( ) ) {
457+ await this . sessionCleanUp ( )
458+ }
412459 const tabID = this . sessionStorage . setActiveTab ( message . tabID )
413460 getLogger ( ) . debug ( 'startTestGen message: %O' , message )
414461 getLogger ( ) . debug ( 'startTestGen tabId: %O' , message . tabID )
@@ -909,7 +956,13 @@ export class TestController {
909956
910957 // TODO: Check if there are more cases to endSession if yes create a enum or type for step
911958 private async endSession ( data : any , step : FollowUpTypes ) {
912- this . messenger . sendMessage ( 'Unit test generation completed.' , data . tabID , 'answer' )
959+ this . messenger . sendMessage (
960+ 'Unit test generation completed.' ,
961+ data . tabID ,
962+ 'answer' ,
963+ 'testGenEndSessionMessage' ,
964+ this . getFeedbackButtons ( )
965+ )
913966
914967 const session = this . sessionStorage . getSession ( )
915968 if ( step === FollowUpTypes . RejectCode ) {
@@ -1342,7 +1395,7 @@ export class TestController {
13421395 }
13431396 session . listOfTestGenerationJobId = [ ]
13441397 session . testGenerationJobGroupName = undefined
1345- session . testGenerationJob = undefined
1398+ // session.testGenerationJob = undefined
13461399 session . updatedBuildCommands = undefined
13471400 session . shortAnswer = undefined
13481401 session . testCoveragePercentage = 0
0 commit comments