Skip to content

Commit e87fe92

Browse files
committed
Bug fixes in build and execute
1 parent 1b76a80 commit e87fe92

File tree

7 files changed

+99
-61
lines changed

7 files changed

+99
-61
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/CodeTestChatItems.kt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,26 @@ fun testGenProgressField(value: Int) = ProgressField(
4343
actions = listOf(cancelTestGenButton)
4444
)
4545

46-
val buildAndExecuteProgrogressField = ProgressField(
46+
//val buildAndExecuteProgrogressField = ProgressField(
47+
// status = "default",
48+
// value= -1,
49+
// text = message("testgen.progressbar.build_and_execute"),
50+
// actions = listOf(cancelTestGenBuildAndExecuteButton)
51+
//)
52+
53+
54+
val fixingTestCasesProgressField = ProgressField(
4755
status = "default",
48-
text = message("testgen.progressbar.build_and_execute"),
56+
value= -1,
57+
text = message("testgen.progressbar.fixing_test_cases"),
4958
actions = listOf(cancelTestGenBuildAndExecuteButton)
5059
)
60+
61+
fun createProgressField(messageKey: String): ProgressField {
62+
return ProgressField(
63+
status = "default",
64+
value = -1,
65+
text = message(messageKey),
66+
actions = listOf(cancelTestGenBuildAndExecuteButton)
67+
)
68+
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/CodeWhispererUTGChatManager.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import software.aws.toolkits.jetbrains.services.amazonqCodeTest.model.PreviousUT
3737
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.model.ShortAnswer
3838
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.BuildAndExecuteProgressStatus
3939
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.Session
40+
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.utils.constructBuildAndExecutionSummaryText
4041
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency
4142
import software.aws.toolkits.jetbrains.services.codewhisperer.codetest.CodeTestException
4243
import software.aws.toolkits.jetbrains.services.codewhisperer.codetest.fileTooLarge
@@ -94,7 +95,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
9495
codeTestChatHelper.updateUI(
9596
promptInputDisabledState = true,
9697
promptInputProgress = session.listOfTestGenerationJobId.takeUnless { it.isEmpty() }
97-
?.let { buildAndExecuteProgrogressField }
98+
?.let { fixingTestCasesProgressField }
9899
?: testGenProgressField(0)
99100
)
100101

@@ -269,11 +270,13 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
269270
promptInputProgress = if (session.listOfTestGenerationJobId.size == 1) {
270271
testGenProgressField(progressRate)
271272
} else {
272-
buildAndExecuteProgrogressField
273+
// fixingTestCasesProgressField
274+
createProgressField("testgen.progressbar.fixing_test_cases")
273275
}
276+
274277
)
275278
}
276-
279+
throwIfCancelled(session)
277280
// polling every 2 seconds to reduce # of API calls
278281
delay(2000)
279282
}
@@ -300,6 +303,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
300303
LOG.info { "ExportResultArchive latency: ${calculateTotalLatency(startTime, Instant.now())}" }
301304
}
302305
)
306+
throwIfCancelled(session)
303307
val result = byteArray.reduce { acc, next -> acc + next } // To map the result it is needed to combine the full byte array
304308
storeGeneratedTestDiffs(result, session)
305309
if (!session.isGeneratingTests) {
@@ -332,6 +336,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
332336
)
333337
)
334338
} else {
339+
throwIfCancelled(session)
335340
if (previousIterationContext == null) {
336341
// show another card as the answer
337342
val viewDiffMessageId = codeTestChatHelper.addAnswer(
@@ -354,13 +359,15 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
354359
promptInputProgress = testGenCompletedField,
355360
)
356361
} else {
362+
val updatedText = constructBuildAndExecutionSummaryText(BuildAndExecuteProgressStatus.PROCESS_TEST_RESULTS, codeTestChatHelper)
357363
codeTestChatHelper.updateAnswer(
358364
CodeTestChatMessageContent(
359365
type = ChatMessageType.Answer,
360366
buttons = listOf(Button("utg_view_diff", "View Diff", keepCardAfterClick = true, position = "outside", status = "info")),
361367
fileList = listOf(getTestFilePathRelativeToRoot(shortAnswer)),
362368
projectRootName = project.name,
363-
codeReference = codeReference
369+
codeReference = codeReference,
370+
message = updatedText
364371
),
365372
messageIdOverride = previousIterationContext.buildAndExecuteMessageId
366373
)
@@ -374,6 +381,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
374381
promptInputPlaceholder = message("testgen.placeholder.view_diff"),
375382
promptInputProgress = testGenCompletedField,
376383
)
384+
throwIfCancelled(session)
377385
delay(1000)
378386
}
379387

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ import software.aws.toolkits.jetbrains.services.amazonqCodeTest.CodeWhispererUTG
6161
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.ConversationState
6262
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.FEATURE_NAME
6363
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.InboundAppMessagesHandler
64+
//import software.aws.toolkits.jetbrains.services.amazonqCodeTest.buildAndExecuteProgrogressField
65+
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.createProgressField
66+
//import software.aws.toolkits.jetbrains.services.amazonqCodeTest.fixingTestCasesProgressField
6467
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.messages.Button
6568
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.messages.CodeTestChatMessage
6669
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.messages.CodeTestChatMessageContent
@@ -71,6 +74,8 @@ import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.BuildSta
7174
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.Session
7275
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.UTG_CHAT_MAX_ITERATION
7376
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.storage.ChatSessionStorage
77+
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.testGenCompletedField
78+
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.testGenProgressField
7479
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.utils.constructBuildAndExecutionSummaryText
7580
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.utils.runBuildOrTestCommand
7681
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.messages.sendAuthNeededException
@@ -743,6 +748,7 @@ class CodeTestChatController(
743748
)
744749
codeTestChatHelper.updateUI(
745750
promptInputDisabledState = true,
751+
promptInputPlaceholder = message("testgen.placeholder.select_an_action_to_proceed"),
746752
)
747753
} else if (session.listOfTestGenerationJobId.size < 4) {
748754
// Already built and executed once, display # of iterations left message
@@ -777,6 +783,7 @@ class CodeTestChatController(
777783
)
778784
codeTestChatHelper.updateUI(
779785
promptInputDisabledState = true,
786+
promptInputPlaceholder = message("testgen.placeholder.waiting_on_your_inputs"),
780787
)
781788
} else {
782789
// TODO: change this hardcoded string
@@ -980,6 +987,10 @@ class CodeTestChatController(
980987
// handle both "Proceed" and "Build and execute" button clicks since their actions are similar
981988
// TODO: show install dependencies card if needed
982989
session.conversationState = ConversationState.IN_PROGRESS
990+
codeTestChatHelper.updateUI(
991+
promptInputDisabledState = true,
992+
promptInputProgress = createProgressField("testgen.progressbar.build_and_execute")
993+
)
983994

984995
// display build in progress card
985996
val taskContext = session.buildAndExecuteTaskContext
@@ -1005,7 +1016,8 @@ class CodeTestChatController(
10051016
context.project,
10061017
isBuildCommand = true,
10071018
taskContext,
1008-
session.testFileRelativePathToProjectRoot
1019+
session.testFileRelativePathToProjectRoot,
1020+
codeTestChatHelper
10091021
)
10101022
while (taskContext.buildExitCode < 0) {
10111023
// wait until build command finished
@@ -1022,6 +1034,11 @@ class CodeTestChatController(
10221034
canBeVoted = false
10231035
)
10241036
)
1037+
codeTestChatHelper.updateUI(
1038+
promptInputProgress = testGenCompletedField,
1039+
)
1040+
delay(1000)
1041+
codeTestChatHelper.sendUpdatePromptProgress(session.tabId, null)
10251042
AmazonqTelemetry.unitTestGeneration(
10261043
count = session.listOfTestGenerationJobId.size.toLong() - 1,
10271044
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
@@ -1054,9 +1071,8 @@ class CodeTestChatController(
10541071

10551072
taskContext.progressStatus = BuildAndExecuteProgressStatus.BUILD_FAILED
10561073
updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId)
1057-
taskContext.progressStatus = BuildAndExecuteProgressStatus.FIXING_TEST_CASES
1074+
taskContext.progressStatus = BuildAndExecuteProgressStatus.RUN_EXECUTION_TESTS
10581075
val buildAndExecuteMessageId = updateBuildAndExecuteProgressCard(taskContext.progressStatus, messageId)
1059-
10601076
val previousUTGIterationContext = PreviousUTGIterationContext(
10611077
buildLogFile = buildLogsFile,
10621078
testLogFile = null,
@@ -1071,7 +1087,6 @@ class CodeTestChatController(
10711087
context.project
10721088
).generateTests(session.userPrompt, codeTestChatHelper, previousUTGIterationContext, null)
10731089
job?.join()
1074-
10751090
return
10761091
}
10771092
}
@@ -1088,6 +1103,11 @@ class CodeTestChatController(
10881103
canBeVoted = false
10891104
)
10901105
)
1106+
codeTestChatHelper.updateUI(
1107+
promptInputDisabledState = true,
1108+
promptInputPlaceholder = message("testgen.placeholder.modifyCommand"),
1109+
)
1110+
10911111
session.conversationState = ConversationState.WAITING_FOR_BUILD_COMMAND_INPUT
10921112
}
10931113
"utg_install_and_continue" -> {
@@ -1120,11 +1140,11 @@ class CodeTestChatController(
11201140
sessionCleanUp(codeTestChatHelper.getActiveSession().tabId)
11211141
}
11221142

1123-
private suspend fun updateBuildAndExecuteProgressCard(
1143+
suspend fun updateBuildAndExecuteProgressCard(
11241144
currentStatus: BuildAndExecuteProgressStatus,
11251145
messageId: String?,
11261146
): String? {
1127-
val updatedText = constructBuildAndExecutionSummaryText(currentStatus)
1147+
val updatedText = constructBuildAndExecutionSummaryText(currentStatus, codeTestChatHelper)
11281148

11291149
if (currentStatus == BuildAndExecuteProgressStatus.RUN_BUILD) {
11301150
val buildAndExecuteMessageId = codeTestChatHelper.addAnswer(

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/model/BuildAndExecuteStatusIcon.kt

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,3 @@ enum class BuildAndExecuteStatusIcon(val icon: String) {
1212
FAILED("<span style=\"color: red;\">&#10060;</span>"),
1313
}
1414

15-
fun getBuildIcon(progressStatus: BuildAndExecuteProgressStatus) =
16-
if (progressStatus < BuildAndExecuteProgressStatus.RUN_BUILD) {
17-
BuildAndExecuteStatusIcon.WAIT.icon
18-
} else if (progressStatus == BuildAndExecuteProgressStatus.RUN_BUILD) {
19-
BuildAndExecuteStatusIcon.CURRENT.icon
20-
} else if (progressStatus == BuildAndExecuteProgressStatus.BUILD_FAILED || progressStatus == BuildAndExecuteProgressStatus.FIXING_TEST_CASES) {
21-
BuildAndExecuteStatusIcon.FAILED.icon
22-
} else {
23-
BuildAndExecuteStatusIcon.DONE.icon
24-
}
25-
26-
fun getExecutionIcon(progressStatus: BuildAndExecuteProgressStatus) =
27-
if (progressStatus < BuildAndExecuteProgressStatus.RUN_EXECUTION_TESTS) {
28-
BuildAndExecuteStatusIcon.WAIT.icon
29-
} else if (progressStatus == BuildAndExecuteProgressStatus.RUN_EXECUTION_TESTS) {
30-
BuildAndExecuteStatusIcon.CURRENT.icon
31-
} else if (progressStatus == BuildAndExecuteProgressStatus.BUILD_FAILED || progressStatus == BuildAndExecuteProgressStatus.FIXING_TEST_CASES) {
32-
BuildAndExecuteStatusIcon.FAILED.icon
33-
} else {
34-
BuildAndExecuteStatusIcon.DONE.icon
35-
}
36-
37-
fun getFixingTestCasesIcon(progressStatus: BuildAndExecuteProgressStatus) =
38-
if (progressStatus == BuildAndExecuteProgressStatus.BUILD_FAILED) {
39-
BuildAndExecuteStatusIcon.DONE.icon
40-
} else if (progressStatus == BuildAndExecuteProgressStatus.FIXING_TEST_CASES) {
41-
BuildAndExecuteStatusIcon.CURRENT.icon
42-
} else if (progressStatus >= BuildAndExecuteProgressStatus.PROCESS_TEST_RESULTS) {
43-
BuildAndExecuteStatusIcon.DONE.icon
44-
} else {
45-
BuildAndExecuteStatusIcon.WAIT.icon
46-
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/session/Session.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ data class Session(val tabId: String) {
3737

3838
// First iteration will have a value of 1
3939
var userPrompt: String = ""
40-
var iteration: Int = 0
4140
var projectRoot: String = "/"
4241
var shortAnswer: ShortAnswer = ShortAnswer()
4342
var selectedFile: VirtualFile? = null
@@ -68,7 +67,6 @@ enum class BuildAndExecuteProgressStatus {
6867
RUN_BUILD,
6968
BUILD_FAILED,
7069
RUN_EXECUTION_TESTS,
71-
TESTS_EXECUTED,
7270
FIXING_TEST_CASES,
7371
PROCESS_TEST_RESULTS,
7472
}

0 commit comments

Comments
 (0)