@@ -26,7 +26,7 @@ import {
26
26
import MessengerUtils , { ButtonActions } from './messenger/messengerUtils'
27
27
import { getTelemetryReasonDesc , isAwsError } from '../../../shared/errors'
28
28
import { ChatItemType } from '../../../amazonq/commons/model'
29
- import { ProgressField } from '@aws/mynah-ui'
29
+ import { ChatItemButton , MynahIcons , ProgressField } from '@aws/mynah-ui'
30
30
import { FollowUpTypes } from '../../../amazonq/commons/types'
31
31
import {
32
32
cancelBuild ,
@@ -63,6 +63,9 @@ import {
63
63
} from '../../../codewhisperer/models/constants'
64
64
import { UserWrittenCodeTracker } from '../../../codewhisperer/tracker/userWrittenCodeTracker'
65
65
import { 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'
66
69
67
70
export interface TestChatControllerEventEmitters {
68
71
readonly tabOpened : vscode . EventEmitter < any >
@@ -307,10 +310,22 @@ export class TestController {
307
310
)
308
311
if ( session . stopIteration ) {
309
312
// 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
+ )
311
320
} else {
312
321
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
+ )
314
329
: this . sendErrorMessage ( data )
315
330
}
316
331
await this . sessionCleanUp ( )
@@ -330,7 +345,9 @@ export class TestController {
330
345
return this . messenger . sendMessage (
331
346
i18n ( 'AWS.amazonq.featureDev.error.monthlyLimitReached' ) ,
332
347
tabID ,
333
- 'answer'
348
+ 'answer' ,
349
+ 'testGenErrorMessage' ,
350
+ this . getFeedbackButtons ( )
334
351
)
335
352
}
336
353
if ( error . message . includes ( 'Too many requests' ) ) {
@@ -362,6 +379,7 @@ export class TestController {
362
379
// This function handles actions if user clicked on any Button one of these cases will be executed
363
380
private async handleFormActionClicked ( data : any ) {
364
381
const typedAction = MessengerUtils . stringToEnumValue ( ButtonActions , data . action as any )
382
+ let getFeedbackCommentData = ''
365
383
switch ( typedAction ) {
366
384
case ButtonActions . STOP_TEST_GEN :
367
385
testGenState . setToCancelling ( )
@@ -374,6 +392,16 @@ export class TestController {
374
392
this . messenger . sendChatInputEnabled ( data . tabID , true )
375
393
await this . sessionCleanUp ( )
376
394
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
377
405
}
378
406
}
379
407
// This function handles actions if user gives any input from the chatInput box
@@ -403,12 +431,31 @@ export class TestController {
403
431
}
404
432
}
405
433
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
+
406
449
/**
407
450
* Start Test Generation and show the code results
408
451
*/
409
452
410
453
private async startTestGen ( message : any , regenerateTests : boolean ) {
411
454
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
+ }
412
459
const tabID = this . sessionStorage . setActiveTab ( message . tabID )
413
460
getLogger ( ) . debug ( 'startTestGen message: %O' , message )
414
461
getLogger ( ) . debug ( 'startTestGen tabId: %O' , message . tabID )
@@ -909,7 +956,13 @@ export class TestController {
909
956
910
957
// TODO: Check if there are more cases to endSession if yes create a enum or type for step
911
958
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
+ )
913
966
914
967
const session = this . sessionStorage . getSession ( )
915
968
if ( step === FollowUpTypes . RejectCode ) {
@@ -1342,7 +1395,7 @@ export class TestController {
1342
1395
}
1343
1396
session . listOfTestGenerationJobId = [ ]
1344
1397
session . testGenerationJobGroupName = undefined
1345
- session . testGenerationJob = undefined
1398
+ // session.testGenerationJob = undefined
1346
1399
session . updatedBuildCommands = undefined
1347
1400
session . shortAnswer = undefined
1348
1401
session . testCoveragePercentage = 0
0 commit comments