Skip to content

Commit b257fed

Browse files
committed
Refactoring Build and execute
1 parent d139695 commit b257fed

File tree

8 files changed

+132
-141
lines changed

8 files changed

+132
-141
lines changed

.changes/next-release/feature-272cb837-f551-485a-9f37-43ca37aef75c.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ val cancelTestGenButton = Button(
2929
icon = "cancel"
3030
)
3131

32+
val cancelTestGenBuildAndExecuteButton = Button(
33+
id = CodeTestButtonId.StopTestGenBuildAndExecution.id,
34+
text = message("general.cancel"),
35+
icon = "cancel"
36+
)
37+
3238
fun testGenProgressField(value: Int) = ProgressField(
3339
status = "default",
3440
text = message("testgen.progressbar.generate_unit_tests"),
@@ -40,5 +46,5 @@ fun testGenProgressField(value: Int) = ProgressField(
4046
val buildAndExecuteProgrogressField = ProgressField(
4147
status = "default",
4248
text = message("testgen.progressbar.build_and_execute"),
43-
actions = listOf(cancelTestGenButton)
49+
actions = listOf(cancelTestGenBuildAndExecuteButton)
4450
)

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

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,16 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
8787
) {
8888
// 1st API call: Zip project and call CreateUploadUrl
8989
val session = codeTestChatHelper.getActiveSession()
90-
session.isGeneratingTests = true
91-
session.iteration++
9290
if (session.testGenerationJobGroupName.isEmpty()) {
9391
session.testGenerationJobGroupName = UUID.randomUUID().toString()
9492
}
95-
val final = session.testGenerationJobGroupName
9693

97-
if (session.iteration == 1) {
98-
codeTestChatHelper.updateUI(
99-
promptInputDisabledState = true,
100-
promptInputProgress = testGenProgressField(0),
101-
)
102-
} else {
103-
codeTestChatHelper.updateUI(
104-
promptInputDisabledState = true,
105-
promptInputProgress = buildAndExecuteProgrogressField,
106-
)
107-
}
108-
109-
// Set the Progress bar to "Generating unit tests..."
94+
codeTestChatHelper.updateUI(
95+
promptInputDisabledState = true,
96+
promptInputProgress = session.listOfTestGenerationJobId.takeUnless { it.isEmpty() }
97+
?.let { buildAndExecuteProgrogressField }
98+
?: testGenProgressField(0)
99+
)
110100

111101
val codeTestResponseContext = createUploadUrl(codeTestChatHelper, previousIterationContext)
112102
session.srcPayloadSize = codeTestResponseContext.payloadContext.srcPayloadSize
@@ -117,7 +107,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
117107
fileTooLarge()
118108
}
119109

120-
val createUploadUrlResponse = codeTestResponseContext.createUploadUrlResponse ?: return
110+
val createUploadUrlResponse = codeTestResponseContext.createUploadUrlResponse
121111
throwIfCancelled(session)
122112

123113
LOG.debug {
@@ -150,7 +140,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
150140
.build()
151141
),
152142
userInput = prompt,
153-
testGenerationJobGroupName = final
143+
testGenerationJobGroupName = session.testGenerationJobGroupName
154144
)
155145
delay(200)
156146
response?.testGenerationJob() != null
@@ -179,11 +169,12 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
179169
session.startTestGenerationRequestId = startTestGenerationResponse.responseMetadata().requestId()
180170
session.testGenerationJobGroupName = job.testGenerationJobGroupName()
181171
session.testGenerationJob = job.testGenerationJobId()
172+
session.listOfTestGenerationJobId += job.testGenerationJobId()
182173
throwIfCancelled(session)
183174

184175
// 3rd API call: Step 3: Polling mechanism on test job status with getTestGenStatus getTestGeneration
185176
var finished = false
186-
var testGenerationResponse: GetTestGenerationResponse? = null
177+
var testGenerationResponse: GetTestGenerationResponse?
187178

188179
var shortAnswer = ShortAnswer()
189180
LOG.debug {
@@ -275,8 +266,8 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
275266
}
276267
codeTestChatHelper.updateUI(
277268
promptInputDisabledState = true,
278-
promptInputProgress = if (session.iteration == 1) {
279-
testGenProgressField(0)
269+
promptInputProgress = if (session.listOfTestGenerationJobId.size == 1) {
270+
testGenProgressField(progressRate)
280271
} else {
281272
buildAndExecuteProgrogressField
282273
}
@@ -312,7 +303,6 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
312303
val result = byteArray.reduce { acc, next -> acc + next } // To map the result it is needed to combine the full byte array
313304
storeGeneratedTestDiffs(result, session)
314305
if (!session.isGeneratingTests) {
315-
// TODO: Modify text according to FnF
316306
codeTestChatHelper.addAnswer(
317307
CodeTestChatMessageContent(
318308
message = message("testgen.error.generic_technical_error_message"),
@@ -360,7 +350,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
360350
session.viewDiffMessageId = viewDiffMessageId
361351
codeTestChatHelper.updateUI(
362352
promptInputDisabledState = false,
363-
promptInputPlaceholder = "Specify a function(s) in the current file(optional)",
353+
// promptInputPlaceholder = "Specify a function(s) in the current file(optional)",
364354
promptInputProgress = testGenCompletedField,
365355
)
366356
} else {
@@ -486,10 +476,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
486476
} else {
487477
previousIterationContext.selectedFile
488478
}
489-
490-
val combinedBuildAndExecuteLogFile =
491-
previousIterationContext?.buildLogFile
492-
val codeTestSessionConfig = CodeTestSessionConfig(file, project, combinedBuildAndExecuteLogFile)
479+
val codeTestSessionConfig = CodeTestSessionConfig(file, project, previousIterationContext?.buildLogFile)
493480
codeTestChatHelper.getActiveSession().projectRoot = codeTestSessionConfig.projectRoot.path
494481

495482
val codeTestSessionContext = CodeTestSessionContext(project, codeTestSessionConfig)
@@ -587,7 +574,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
587574
canBeVoted = false
588575
)
589576
)
590-
if (session.iteration == 1) {
577+
if (session.listOfTestGenerationJobId.size < 2) {
591578
AmazonqTelemetry.utgGenerateTests(
592579
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
593580
hasUserPromptSupplied = session.hasUserPromptSupplied,
@@ -624,10 +611,10 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
624611
requestId = session.startTestGenerationRequestId
625612
)
626613
}
627-
628614
session.isGeneratingTests = false
629615
} finally {
630616
// Reset the flow if there is any error
617+
codeTestChatHelper.sendUpdatePromptProgress(session.tabId, null)
631618
if (!session.isGeneratingTests) {
632619
codeTestChatHelper.updateUI(
633620
promptInputProgress = cancellingProgressField

0 commit comments

Comments
 (0)