@@ -53,6 +53,7 @@ import software.aws.toolkits.jetbrains.core.AwsClientManager
5353import software.aws.toolkits.jetbrains.core.coroutines.EDT
5454import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager
5555import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection
56+ import software.aws.toolkits.jetbrains.core.credentials.sono.isInternalUser
5657import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQAppInitContext
5758import software.aws.toolkits.jetbrains.services.amazonq.auth.AuthController
5859import software.aws.toolkits.jetbrains.services.amazonq.project.RelevantDocument
@@ -67,6 +68,7 @@ import software.aws.toolkits.jetbrains.services.amazonqCodeTest.messages.Incomin
6768import software.aws.toolkits.jetbrains.services.amazonqCodeTest.model.PreviousUTGIterationContext
6869import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.BuildAndExecuteProgressStatus
6970import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.Session
71+ import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.UTG_CHAT_MAX_ITERATION
7072import software.aws.toolkits.jetbrains.services.amazonqCodeTest.storage.ChatSessionStorage
7173import software.aws.toolkits.jetbrains.services.amazonqCodeTest.utils.constructBuildAndExecutionSummaryText
7274import software.aws.toolkits.jetbrains.services.amazonqCodeTest.utils.runBuildOrTestCommand
@@ -617,6 +619,8 @@ class CodeTestChatController(
617619 " utg_accept" -> {
618620 // open the file at test path relative to the project root
619621 val testFileAbsolutePath = Paths .get(session.projectRoot, session.testFileRelativePathToProjectRoot)
622+ val startUrl = getStartUrl(context.project)
623+ val isInternalUser = isInternalUser(startUrl)
620624 openOrCreateTestFileAndApplyDiff(context.project, testFileAbsolutePath, session.generatedTestDiffs.values.first(), session.openedDiffFile)
621625 session.codeReferences?.let { references ->
622626 LOG .debug { " Accepted unit tests with references: $references " }
@@ -691,24 +695,27 @@ class CodeTestChatController(
691695 canBeVoted = false
692696 )
693697 )
694- sessionCleanUp(session.tabId)
698+ if (! isInternalUser) {
699+ sessionCleanUp(message.tabId)
700+ return
701+ }
702+
695703 codeTestChatHelper.updateUI(
696704 promptInputDisabledState = false ,
697705 promptInputPlaceholder = message(" testgen.placeholder.enter_slash_quick_actions" ),
698706 )
699- /*
707+
700708 val taskContext = session.buildAndExecuteTaskContext
701709 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+
704712 codeTestChatHelper.addAnswer(
705713 CodeTestChatMessageContent (
706714 message = """
707715 Would you like me to help build and execute the test? I'll run following commands
708716
709717 ```sh
710718 ${taskContext.buildCommand}
711- ${taskContext.executionCommand}
712719 ```
713720 """ .trimIndent(),
714721 type = ChatMessageType .Answer ,
@@ -790,10 +797,9 @@ class CodeTestChatController(
790797 promptInputPlaceholder = message(" testgen.placeholder.newtab" )
791798 )
792799 }
793- */
794800 }
795- /*
796- //TODO: this is for unit test regeneration build iteration loop
801+
802+ // TODO: this is for unit test regeneration build iteration loop
797803 " utg_regenerate" -> {
798804 // close the existing open diff in the editor.
799805 ApplicationManager .getApplication().invokeLater {
@@ -810,6 +816,7 @@ class CodeTestChatController(
810816 session.testGenerationJob,
811817 session.testGenerationJobGroupName,
812818 session.programmingLanguage,
819+ IdeCategory .JETBRAINS ,
813820 session.numberOfUnitTestCasesGenerated,
814821 0 ,
815822 session.linesOfCodeGenerated,
@@ -821,13 +828,12 @@ class CodeTestChatController(
821828 " Successfully sent test generation telemetry. RequestId: ${
822829 testGenerationEventResponse.responseMetadata().requestId()} "
823830 }
824- sessionCleanUp(session.tabId)
831+ // sessionCleanUp(session.tabId)
825832 codeTestChatHelper.updateUI(
826833 promptInputDisabledState = false ,
827834 promptInputPlaceholder = message(" testgen.placeholder.waiting_on_your_inputs" ),
828835 )
829836 }
830- */
831837
832838 " utg_reject" -> {
833839 ApplicationManager .getApplication().invokeLater {
@@ -966,23 +972,90 @@ class CodeTestChatController(
966972 return
967973 }
968974
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)
975+ // TODO: only go to future iterations when buildExitCode or testExitCode > 0, right now iterate regardless
976+ if (taskContext.buildExitCode > 0 ) {
977+ // handle build failure case
978+
979+ taskContext.progressStatus = BuildAndExecuteProgressStatus .BUILD_FAILED
980+ updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration)
981+ taskContext.progressStatus = BuildAndExecuteProgressStatus .FIXING_TEST_CASES
982+ val buildAndExecuteMessageId = updateBuildAndExecuteProgressCard(
983+ taskContext.progressStatus,
984+ messageId,
985+ session.iteration + 1
986+ )
972987
973- val previousUTGIterationContext = PreviousUTGIterationContext (
974- buildLogFile = buildLogsFile,
975- testLogFile = testLogsFile ,
976- selectedFile = session.selectedFile,
977- buildAndExecuteMessageId = buildAndExecuteMessageId
978- )
988+ val previousUTGIterationContext = PreviousUTGIterationContext (
989+ buildLogFile = buildLogsFile,
990+ testLogFile = null ,
991+ selectedFile = session.selectedFile,
992+ buildAndExecuteMessageId = buildAndExecuteMessageId
993+ )
979994
980- val job = CodeWhispererUTGChatManager .getInstance(context.project).generateTests( " " , codeTestChatHelper, previousUTGIterationContext, null )
981- job?.join()
995+ session.isGeneratingTests = false
996+ session.conversationState = ConversationState . IDLE
982997
983- taskContext.progressStatus = BuildAndExecuteProgressStatus .PROCESS_TEST_RESULTS
984- // session.iteration already updated in generateTests
985- updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration - 1 )
998+ val job = CodeWhispererUTGChatManager .getInstance(
999+ context.project
1000+ ).generateTests(session.userPrompt, codeTestChatHelper, previousUTGIterationContext, null )
1001+ job?.join()
1002+
1003+ return
1004+ }
1005+ // taskContext.progressStatus = BuildAndExecuteProgressStatus.RUN_EXECUTION_TESTS
1006+ // updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration)
1007+ //
1008+ // val testLogsFile = VirtualFileManager.getInstance().findFileByNioPath(
1009+ // withContext(currentCoroutineContext()) {
1010+ // Files.createTempFile(null, null)
1011+ // }
1012+ // )
1013+ // if (testLogsFile == null) {
1014+ // // TODO: handle no log file case
1015+ // return
1016+ // }
1017+ // LOG.debug {
1018+ // "Q TestGen session: ${codeTestChatHelper.getActiveCodeTestTabId()}: " +
1019+ // "tmpFile for test logs:\n ${buildLogsFile.path}"
1020+ // }
1021+ // delay(1000)
1022+ // runBuildOrTestCommand(taskContext.executionCommand, testLogsFile, context.project, isBuildCommand = false, taskContext)
1023+ // while (taskContext.testExitCode < 0) {
1024+ // // wait until test command finished
1025+ // delay(1000)
1026+ // }
1027+ //
1028+ // if (taskContext.testExitCode == 0) {
1029+ // taskContext.progressStatus = BuildAndExecuteProgressStatus.TESTS_EXECUTED
1030+ // updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration)
1031+ // codeTestChatHelper.addAnswer(
1032+ // CodeTestChatMessageContent(
1033+ // message = message("testgen.message.success"),
1034+ // type = ChatMessageType.Answer,
1035+ // canBeVoted = false
1036+ // )
1037+ // )
1038+ // // sessionCleanUp(message.tabId)
1039+ // return
1040+ // }
1041+ //
1042+ // // has test failure, we will zip the latest project and invoke backend again
1043+ // taskContext.progressStatus = BuildAndExecuteProgressStatus.FIXING_TEST_CASES
1044+ // val buildAndExecuteMessageId = updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration)
1045+ //
1046+ // val previousUTGIterationContext = PreviousUTGIterationContext(
1047+ // buildLogFile = buildLogsFile,
1048+ // testLogFile = testLogsFile,
1049+ // selectedFile = session.selectedFile,
1050+ // buildAndExecuteMessageId = buildAndExecuteMessageId
1051+ // )
1052+ //
1053+ // val job = CodeWhispererUTGChatManager.getInstance(context.project).generateTests("", codeTestChatHelper, previousUTGIterationContext, null)
1054+ // job?.join()
1055+ //
1056+ // taskContext.progressStatus = BuildAndExecuteProgressStatus.PROCESS_TEST_RESULTS
1057+ // // session.iteration already updated in generateTests
1058+ // updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId, session.iteration - 1)
9861059 }
9871060 " utg_modify_command" -> {
9881061 // TODO allow user input to modify the command
0 commit comments