@@ -116,6 +116,7 @@ class CodeTestChatController(
116
116
private val authController : AuthController = AuthController (),
117
117
private val cs : CoroutineScope ,
118
118
) : InboundAppMessagesHandler {
119
+ var buildResult = false
119
120
val messenger = context.messagesFromAppToUi
120
121
private val codeTestChatHelper = CodeTestChatHelper (context.messagesFromAppToUi, chatSessionStorage)
121
122
private val supportedLanguage = setOf (" python" , " java" )
@@ -666,28 +667,59 @@ class CodeTestChatController(
666
667
667
668
UiTelemetry .click(null as Project ? , " unitTestGeneration_acceptDiff" )
668
669
669
- AmazonqTelemetry .utgGenerateTests(
670
- cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
671
- hasUserPromptSupplied = session.hasUserPromptSupplied,
672
- isFileInWorkspace = true ,
673
- isSupportedLanguage = true ,
674
- credentialStartUrl = getStartUrl(project = context.project),
675
- jobGroup = session.testGenerationJobGroupName,
676
- jobId = session.testGenerationJob,
677
- acceptedCount = session.numberOfUnitTestCasesGenerated?.toLong(),
678
- generatedCount = session.numberOfUnitTestCasesGenerated?.toLong(),
679
- acceptedLinesCount = session.linesOfCodeGenerated?.toLong(),
680
- generatedLinesCount = session.linesOfCodeGenerated?.toLong(),
681
- acceptedCharactersCount = session.charsOfCodeGenerated?.toLong(),
682
- generatedCharactersCount = session.charsOfCodeGenerated?.toLong(),
683
- result = MetricResult .Succeeded ,
684
- perfClientLatency = session.latencyOfTestGeneration,
685
- isCodeBlockSelected = session.isCodeBlockSelected,
686
- artifactsUploadDuration = session.artifactUploadDuration,
687
- buildPayloadBytes = session.srcPayloadSize,
688
- buildZipFileBytes = session.srcZipFileSize,
689
- requestId = session.startTestGenerationRequestId
690
- )
670
+ if (session.iteration == 1 ){
671
+ AmazonqTelemetry .utgGenerateTests(
672
+ cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
673
+ hasUserPromptSupplied = session.hasUserPromptSupplied,
674
+ isFileInWorkspace = true ,
675
+ isSupportedLanguage = true ,
676
+ credentialStartUrl = getStartUrl(project = context.project),
677
+ jobGroup = session.testGenerationJobGroupName,
678
+ jobId = session.testGenerationJob,
679
+ acceptedCount = session.numberOfUnitTestCasesGenerated?.toLong(),
680
+ generatedCount = session.numberOfUnitTestCasesGenerated?.toLong(),
681
+ acceptedLinesCount = session.linesOfCodeGenerated?.toLong(),
682
+ generatedLinesCount = session.linesOfCodeGenerated?.toLong(),
683
+ acceptedCharactersCount = session.charsOfCodeGenerated?.toLong(),
684
+ generatedCharactersCount = session.charsOfCodeGenerated?.toLong(),
685
+ result = MetricResult .Succeeded ,
686
+ perfClientLatency = session.latencyOfTestGeneration,
687
+ isCodeBlockSelected = session.isCodeBlockSelected,
688
+ artifactsUploadDuration = session.artifactUploadDuration,
689
+ buildPayloadBytes = session.srcPayloadSize,
690
+ buildZipFileBytes = session.srcZipFileSize,
691
+ requestId = session.startTestGenerationRequestId
692
+ )
693
+ }else {
694
+ AmazonqTelemetry .unitTestGeneration(
695
+ count = session.iteration.toLong() - 1 ,
696
+ cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
697
+ hasUserPromptSupplied = session.hasUserPromptSupplied,
698
+ isSupportedLanguage = true ,
699
+ credentialStartUrl = getStartUrl(project = context.project),
700
+ jobGroup = session.testGenerationJobGroupName,
701
+ jobId = session.testGenerationJob,
702
+ acceptedCount = session.numberOfUnitTestCasesGenerated?.toLong(),
703
+ generatedCount = session.numberOfUnitTestCasesGenerated?.toLong(),
704
+ acceptedLinesCount = session.linesOfCodeGenerated?.toLong(),
705
+ generatedLinesCount = session.linesOfCodeGenerated?.toLong(),
706
+ acceptedCharactersCount = session.charsOfCodeGenerated?.toLong(),
707
+ generatedCharactersCount = session.charsOfCodeGenerated?.toLong(),
708
+ result = if (buildResult){
709
+ MetricResult .Succeeded
710
+ }else {
711
+ MetricResult .Failed
712
+ },
713
+ perfClientLatency = session.latencyOfTestGeneration,
714
+ isCodeBlockSelected = session.isCodeBlockSelected,
715
+ artifactsUploadDuration = session.artifactUploadDuration,
716
+ buildZipFileBytes = session.srcZipFileSize,
717
+ requestId = session.startTestGenerationRequestId,
718
+ update = session.updateBuildCommands,
719
+ )
720
+ }
721
+
722
+
691
723
codeTestChatHelper.addAnswer(
692
724
CodeTestChatMessageContent (
693
725
message = message(" testgen.message.success" ),
@@ -784,11 +816,10 @@ class CodeTestChatController(
784
816
)
785
817
} else {
786
818
// TODO: change this hardcoded string
787
- val monthlyLimitString = " 25 out of 30"
788
819
codeTestChatHelper.addAnswer(
789
820
CodeTestChatMessageContent (
790
821
message = """
791
- You have gone through all three iterations and this unit test generation workflow is complete. You have $monthlyLimitString Amazon Q Developer Agent invocations left this month .
822
+ You have gone through both iterations and this unit test generation workflow is complete.
792
823
""" .trimIndent(),
793
824
type = ChatMessageType .Answer ,
794
825
)
@@ -863,28 +894,58 @@ class CodeTestChatController(
863
894
}
864
895
865
896
UiTelemetry .click(null as Project ? , " unitTestGeneration_rejectDiff" )
866
- AmazonqTelemetry .utgGenerateTests(
867
- cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
868
- hasUserPromptSupplied = session.hasUserPromptSupplied,
869
- isFileInWorkspace = true ,
870
- isSupportedLanguage = true ,
871
- credentialStartUrl = getStartUrl(project = context.project),
872
- jobGroup = session.testGenerationJobGroupName,
873
- jobId = session.testGenerationJob,
874
- acceptedCount = 0 ,
875
- generatedCount = session.numberOfUnitTestCasesGenerated?.toLong(),
876
- acceptedLinesCount = 0 ,
877
- generatedLinesCount = session.linesOfCodeGenerated?.toLong(),
878
- acceptedCharactersCount = 0 ,
879
- generatedCharactersCount = session.charsOfCodeGenerated?.toLong(),
880
- result = MetricResult .Succeeded ,
881
- perfClientLatency = session.latencyOfTestGeneration,
882
- isCodeBlockSelected = session.isCodeBlockSelected,
883
- artifactsUploadDuration = session.artifactUploadDuration,
884
- buildPayloadBytes = session.srcPayloadSize,
885
- buildZipFileBytes = session.srcZipFileSize,
886
- requestId = session.startTestGenerationRequestId
887
- )
897
+ if (session.iteration == 1 ){
898
+ AmazonqTelemetry .utgGenerateTests(
899
+ cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
900
+ hasUserPromptSupplied = session.hasUserPromptSupplied,
901
+ isFileInWorkspace = true ,
902
+ isSupportedLanguage = true ,
903
+ credentialStartUrl = getStartUrl(project = context.project),
904
+ jobGroup = session.testGenerationJobGroupName,
905
+ jobId = session.testGenerationJob,
906
+ acceptedCount = 0 ,
907
+ generatedCount = session.numberOfUnitTestCasesGenerated?.toLong(),
908
+ acceptedLinesCount = 0 ,
909
+ generatedLinesCount = session.linesOfCodeGenerated?.toLong(),
910
+ acceptedCharactersCount = 0 ,
911
+ generatedCharactersCount = session.charsOfCodeGenerated?.toLong(),
912
+ result = MetricResult .Succeeded ,
913
+ perfClientLatency = session.latencyOfTestGeneration,
914
+ isCodeBlockSelected = session.isCodeBlockSelected,
915
+ artifactsUploadDuration = session.artifactUploadDuration,
916
+ buildPayloadBytes = session.srcPayloadSize,
917
+ buildZipFileBytes = session.srcZipFileSize,
918
+ requestId = session.startTestGenerationRequestId
919
+ )
920
+ }else {
921
+ AmazonqTelemetry .unitTestGeneration(
922
+ count = session.iteration.toLong() - 1 ,
923
+ cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
924
+ hasUserPromptSupplied = session.hasUserPromptSupplied,
925
+ isSupportedLanguage = true ,
926
+ credentialStartUrl = getStartUrl(project = context.project),
927
+ jobGroup = session.testGenerationJobGroupName,
928
+ jobId = session.testGenerationJob,
929
+ acceptedCount = 0 ,
930
+ generatedCount = session.numberOfUnitTestCasesGenerated?.toLong(),
931
+ acceptedLinesCount = 0 ,
932
+ generatedLinesCount = session.linesOfCodeGenerated?.toLong(),
933
+ acceptedCharactersCount = 0 ,
934
+ generatedCharactersCount = session.charsOfCodeGenerated?.toLong(),
935
+ result = if (buildResult){
936
+ MetricResult .Succeeded
937
+ }else {
938
+ MetricResult .Failed
939
+ },
940
+ perfClientLatency = session.latencyOfTestGeneration,
941
+ isCodeBlockSelected = session.isCodeBlockSelected,
942
+ artifactsUploadDuration = session.artifactUploadDuration,
943
+ buildZipFileBytes = session.srcZipFileSize,
944
+ requestId = session.startTestGenerationRequestId,
945
+ update = session.updateBuildCommands,
946
+ )
947
+ }
948
+
888
949
sessionCleanUp(message.tabId)
889
950
}
890
951
" utg_skip_and_finish" -> {
@@ -922,7 +983,7 @@ class CodeTestChatController(
922
983
" tmpFile for build logs:\n ${buildLogsFile.path} "
923
984
}
924
985
925
- runBuildOrTestCommand(taskContext.buildCommand, buildLogsFile, context.project, isBuildCommand = true , taskContext, session.projectRoot )
986
+ runBuildOrTestCommand(taskContext.buildCommand, buildLogsFile, context.project, isBuildCommand = true , taskContext, session.testFileRelativePathToProjectRoot )
926
987
while (taskContext.buildExitCode < 0 ) {
927
988
// wait until build command finished
928
989
delay(1000 )
@@ -938,6 +999,7 @@ class CodeTestChatController(
938
999
canBeVoted = false
939
1000
)
940
1001
)
1002
+ buildResult = true
941
1003
sessionCleanUp(message.tabId)
942
1004
return
943
1005
}
@@ -1029,6 +1091,7 @@ class CodeTestChatController(
1029
1091
}
1030
1092
" utg_modify_command" -> {
1031
1093
// TODO allow user input to modify the command
1094
+ session.updateBuildCommands = true
1032
1095
codeTestChatHelper.addAnswer(
1033
1096
CodeTestChatMessageContent (
1034
1097
message = """
0 commit comments