@@ -53,6 +53,7 @@ import software.aws.toolkits.jetbrains.core.AwsClientManager
53
53
import software.aws.toolkits.jetbrains.core.coroutines.EDT
54
54
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager
55
55
import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection
56
+ import software.aws.toolkits.jetbrains.core.credentials.sono.isInternalUser
56
57
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQAppInitContext
57
58
import software.aws.toolkits.jetbrains.services.amazonq.auth.AuthController
58
59
import software.aws.toolkits.jetbrains.services.amazonq.project.RelevantDocument
@@ -67,6 +68,7 @@ import software.aws.toolkits.jetbrains.services.amazonqCodeTest.messages.Incomin
67
68
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.model.PreviousUTGIterationContext
68
69
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.BuildAndExecuteProgressStatus
69
70
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.Session
71
+ import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.UTG_CHAT_MAX_ITERATION
70
72
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.storage.ChatSessionStorage
71
73
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.utils.constructBuildAndExecutionSummaryText
72
74
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.utils.runBuildOrTestCommand
@@ -617,6 +619,8 @@ class CodeTestChatController(
617
619
" utg_accept" -> {
618
620
// open the file at test path relative to the project root
619
621
val testFileAbsolutePath = Paths .get(session.projectRoot, session.testFileRelativePathToProjectRoot)
622
+ val startUrl = getStartUrl(context.project)
623
+ val isInternalUser = isInternalUser(startUrl)
620
624
openOrCreateTestFileAndApplyDiff(context.project, testFileAbsolutePath, session.generatedTestDiffs.values.first(), session.openedDiffFile)
621
625
session.codeReferences?.let { references ->
622
626
LOG .debug { " Accepted unit tests with references: $references " }
@@ -691,24 +695,27 @@ class CodeTestChatController(
691
695
canBeVoted = false
692
696
)
693
697
)
694
- sessionCleanUp(session.tabId)
698
+ if (! isInternalUser) {
699
+ sessionCleanUp(message.tabId)
700
+ return
701
+ }
702
+
695
703
codeTestChatHelper.updateUI(
696
704
promptInputDisabledState = false ,
697
705
promptInputPlaceholder = message(" testgen.placeholder.enter_slash_quick_actions" ),
698
706
)
699
- /*
707
+
700
708
val taskContext = session.buildAndExecuteTaskContext
701
709
if (session.iteration < 2 ) {
702
- taskContext.buildCommand = getBuildCommand (message.tabId)
703
- taskContext.executionCommand = getExecutionCommand(message.tabId)
710
+ taskContext.buildCommand = codeTestChatHelper.getSession (message.tabId).shortAnswer.buildCommand.toString( )
711
+
704
712
codeTestChatHelper.addAnswer(
705
713
CodeTestChatMessageContent (
706
714
message = """
707
715
Would you like me to help build and execute the test? I'll run following commands
708
716
709
717
```sh
710
718
${taskContext.buildCommand}
711
- ${taskContext.executionCommand}
712
719
```
713
720
""" .trimIndent(),
714
721
type = ChatMessageType .Answer ,
@@ -790,10 +797,9 @@ class CodeTestChatController(
790
797
promptInputPlaceholder = message(" testgen.placeholder.newtab" )
791
798
)
792
799
}
793
- */
794
800
}
795
- /*
796
- //TODO: this is for unit test regeneration build iteration loop
801
+
802
+ // TODO: this is for unit test regeneration build iteration loop
797
803
" utg_regenerate" -> {
798
804
// close the existing open diff in the editor.
799
805
ApplicationManager .getApplication().invokeLater {
@@ -810,6 +816,7 @@ class CodeTestChatController(
810
816
session.testGenerationJob,
811
817
session.testGenerationJobGroupName,
812
818
session.programmingLanguage,
819
+ IdeCategory .JETBRAINS ,
813
820
session.numberOfUnitTestCasesGenerated,
814
821
0 ,
815
822
session.linesOfCodeGenerated,
@@ -821,13 +828,12 @@ class CodeTestChatController(
821
828
" Successfully sent test generation telemetry. RequestId: ${
822
829
testGenerationEventResponse.responseMetadata().requestId()} "
823
830
}
824
- sessionCleanUp(session.tabId)
831
+ // sessionCleanUp(session.tabId)
825
832
codeTestChatHelper.updateUI(
826
833
promptInputDisabledState = false ,
827
834
promptInputPlaceholder = message(" testgen.placeholder.waiting_on_your_inputs" ),
828
835
)
829
836
}
830
- */
831
837
832
838
" utg_reject" -> {
833
839
ApplicationManager .getApplication().invokeLater {
@@ -917,43 +923,14 @@ class CodeTestChatController(
917
923
" tmpFile for build logs:\n ${buildLogsFile.path} "
918
924
}
919
925
920
- runBuildOrTestCommand(taskContext.buildCommand, buildLogsFile, context.project, isBuildCommand = true , taskContext)
926
+ runBuildOrTestCommand(taskContext.buildCommand, buildLogsFile, context.project, isBuildCommand = true , taskContext, session.projectRoot )
921
927
while (taskContext.buildExitCode < 0 ) {
922
928
// wait until build command finished
923
929
delay(1000 )
924
930
}
925
931
926
- // TODO: only go to future iterations when buildExitCode or testExitCode > 0, right now iterate regardless
927
- if (taskContext.buildExitCode > 0 ) {
928
- // TODO: handle build failure case
929
- // ...
930
- // return
931
- }
932
- taskContext.progressStatus = BuildAndExecuteProgressStatus .RUN_EXECUTION_TESTS
933
- updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration)
934
-
935
- val testLogsFile = VirtualFileManager .getInstance().findFileByNioPath(
936
- withContext(currentCoroutineContext()) {
937
- Files .createTempFile(null , null )
938
- }
939
- )
940
- if (testLogsFile == null ) {
941
- // TODO: handle no log file case
942
- return
943
- }
944
- LOG .debug {
945
- " Q TestGen session: ${codeTestChatHelper.getActiveCodeTestTabId()} : " +
946
- " tmpFile for test logs:\n ${buildLogsFile.path} "
947
- }
948
- delay(1000 )
949
- runBuildOrTestCommand(taskContext.executionCommand, testLogsFile, context.project, isBuildCommand = false , taskContext)
950
- while (taskContext.testExitCode < 0 ) {
951
- // wait until test command finished
952
- delay(1000 )
953
- }
954
-
955
- if (taskContext.testExitCode == 0 ) {
956
- taskContext.progressStatus = BuildAndExecuteProgressStatus .TESTS_EXECUTED
932
+ if (taskContext.buildExitCode == 0 ) {
933
+ taskContext.progressStatus = BuildAndExecuteProgressStatus .PROCESS_TEST_RESULTS
957
934
updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration)
958
935
codeTestChatHelper.addAnswer(
959
936
CodeTestChatMessageContent (
@@ -966,23 +943,90 @@ class CodeTestChatController(
966
943
return
967
944
}
968
945
969
- // has test failure, we will zip the latest project and invoke backend again
970
- taskContext.progressStatus = BuildAndExecuteProgressStatus . FIXING_TEST_CASES
971
- val buildAndExecuteMessageId = updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration)
946
+ // TODO: only go to future iterations when buildExitCode or testExitCode > 0, right now iterate regardless
947
+ if ( taskContext.buildExitCode > 0 ) {
948
+ // handle build failure case
972
949
973
- val previousUTGIterationContext = PreviousUTGIterationContext (
974
- buildLogFile = buildLogsFile,
975
- testLogFile = testLogsFile,
976
- selectedFile = session.selectedFile,
977
- buildAndExecuteMessageId = buildAndExecuteMessageId
978
- )
950
+ taskContext.progressStatus = BuildAndExecuteProgressStatus .BUILD_FAILED
951
+ updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration)
952
+ taskContext.progressStatus = BuildAndExecuteProgressStatus .FIXING_TEST_CASES
953
+ val buildAndExecuteMessageId = updateBuildAndExecuteProgressCard(
954
+ taskContext.progressStatus,
955
+ messageId,
956
+ session.iteration + 1
957
+ )
958
+
959
+ val previousUTGIterationContext = PreviousUTGIterationContext (
960
+ buildLogFile = buildLogsFile,
961
+ testLogFile = null ,
962
+ selectedFile = session.selectedFile,
963
+ buildAndExecuteMessageId = buildAndExecuteMessageId
964
+ )
965
+
966
+ session.isGeneratingTests = false
967
+ session.conversationState = ConversationState .IDLE
979
968
980
- val job = CodeWhispererUTGChatManager .getInstance(context.project).generateTests(" " , codeTestChatHelper, previousUTGIterationContext, null )
981
- job?.join()
969
+ val job = CodeWhispererUTGChatManager .getInstance(
970
+ context.project
971
+ ).generateTests(session.userPrompt, codeTestChatHelper, previousUTGIterationContext, null )
972
+ job?.join()
982
973
983
- taskContext.progressStatus = BuildAndExecuteProgressStatus .PROCESS_TEST_RESULTS
984
- // session.iteration already updated in generateTests
985
- updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration - 1 )
974
+ return
975
+ }
976
+ // taskContext.progressStatus = BuildAndExecuteProgressStatus.RUN_EXECUTION_TESTS
977
+ // updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration)
978
+ //
979
+ // val testLogsFile = VirtualFileManager.getInstance().findFileByNioPath(
980
+ // withContext(currentCoroutineContext()) {
981
+ // Files.createTempFile(null, null)
982
+ // }
983
+ // )
984
+ // if (testLogsFile == null) {
985
+ // // TODO: handle no log file case
986
+ // return
987
+ // }
988
+ // LOG.debug {
989
+ // "Q TestGen session: ${codeTestChatHelper.getActiveCodeTestTabId()}: " +
990
+ // "tmpFile for test logs:\n ${buildLogsFile.path}"
991
+ // }
992
+ // delay(1000)
993
+ // runBuildOrTestCommand(taskContext.executionCommand, testLogsFile, context.project, isBuildCommand = false, taskContext)
994
+ // while (taskContext.testExitCode < 0) {
995
+ // // wait until test command finished
996
+ // delay(1000)
997
+ // }
998
+ //
999
+ // if (taskContext.testExitCode == 0) {
1000
+ // taskContext.progressStatus = BuildAndExecuteProgressStatus.TESTS_EXECUTED
1001
+ // updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration)
1002
+ // codeTestChatHelper.addAnswer(
1003
+ // CodeTestChatMessageContent(
1004
+ // message = message("testgen.message.success"),
1005
+ // type = ChatMessageType.Answer,
1006
+ // canBeVoted = false
1007
+ // )
1008
+ // )
1009
+ // // sessionCleanUp(message.tabId)
1010
+ // return
1011
+ // }
1012
+ //
1013
+ // // has test failure, we will zip the latest project and invoke backend again
1014
+ // taskContext.progressStatus = BuildAndExecuteProgressStatus.FIXING_TEST_CASES
1015
+ // val buildAndExecuteMessageId = updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration)
1016
+ //
1017
+ // val previousUTGIterationContext = PreviousUTGIterationContext(
1018
+ // buildLogFile = buildLogsFile,
1019
+ // testLogFile = testLogsFile,
1020
+ // selectedFile = session.selectedFile,
1021
+ // buildAndExecuteMessageId = buildAndExecuteMessageId
1022
+ // )
1023
+ //
1024
+ // val job = CodeWhispererUTGChatManager.getInstance(context.project).generateTests("", codeTestChatHelper, previousUTGIterationContext, null)
1025
+ // job?.join()
1026
+ //
1027
+ // taskContext.progressStatus = BuildAndExecuteProgressStatus.PROCESS_TEST_RESULTS
1028
+ // // session.iteration already updated in generateTests
1029
+ // updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration - 1)
986
1030
}
987
1031
" utg_modify_command" -> {
988
1032
// TODO allow user input to modify the command
0 commit comments