Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "feature",
"description" : "Add back build and execute for Internal Amazon Customers."
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mockitoKotlin = "5.4.0"
mockk = "1.13.10"
nimbus-jose-jwt = "9.40"
node-gradle = "7.0.2"
telemetryGenerator = "1.0.297"
telemetryGenerator = "1.0.299"
testLogger = "4.0.0"
testRetry = "1.5.10"
# test-only; platform provides slf4j transitively at runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ fun testGenProgressField(value: Int) = ProgressField(
valueText = "$value%",
actions = listOf(cancelTestGenButton)
)

val buildAndExecuteProgrogressField = ProgressField(
status = "default",
text = message("testgen.progressbar.build_and_execute"),
actions = listOf(cancelTestGenButton)
)
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import software.aws.toolkits.jetbrains.services.amazonqCodeTest.model.PreviousUT
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.model.ShortAnswer
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.BuildAndExecuteProgressStatus
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.Session
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.utils.combineBuildAndExecuteLogFiles
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency
import software.aws.toolkits.jetbrains.services.codewhisperer.codetest.CodeTestException
import software.aws.toolkits.jetbrains.services.codewhisperer.codetest.fileTooLarge
Expand All @@ -63,6 +62,7 @@ import java.nio.file.Path
import java.nio.file.Paths
import java.time.Duration
import java.time.Instant
import java.util.UUID
import java.util.concurrent.atomic.AtomicBoolean
import java.util.zip.ZipInputStream

Expand All @@ -89,12 +89,24 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
val session = codeTestChatHelper.getActiveSession()
session.isGeneratingTests = true
session.iteration++
if (session.testGenerationJobGroupName.isNullOrEmpty()) {
session.testGenerationJobGroupName = UUID.randomUUID().toString()
}
val final = session.testGenerationJobGroupName

if (session.iteration == 1) {
codeTestChatHelper.updateUI(
promptInputDisabledState = true,
promptInputProgress = testGenProgressField(0),
)
} else {
codeTestChatHelper.updateUI(
promptInputDisabledState = true,
promptInputProgress = buildAndExecuteProgrogressField,
)
}

// Set the Progress bar to "Generating unit tests..."
codeTestChatHelper.updateUI(
promptInputDisabledState = true,
promptInputProgress = testGenProgressField(0),
)

val codeTestResponseContext = createUploadUrl(codeTestChatHelper, previousIterationContext)
session.srcPayloadSize = codeTestResponseContext.payloadContext.srcPayloadSize
Expand Down Expand Up @@ -137,7 +149,8 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
)
.build()
),
userInput = prompt
userInput = prompt,
testGenerationJobGroupName = final
)
delay(200)
response?.testGenerationJob() != null
Expand Down Expand Up @@ -198,6 +211,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
// Setting default value to 0 if the value is null or invalid
session.numberOfUnitTestCasesGenerated = shortAnswer.numberOfTestMethods
session.testFileRelativePathToProjectRoot = getTestFilePathRelativeToRoot(shortAnswer)
session.shortAnswer = shortAnswer

// update test summary card in success case
if (previousIterationContext == null) {
Expand Down Expand Up @@ -261,7 +275,11 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
}
codeTestChatHelper.updateUI(
promptInputDisabledState = true,
promptInputProgress = testGenProgressField(progressRate),
promptInputProgress = if (session.iteration == 1) {
testGenProgressField(0)
} else {
buildAndExecuteProgrogressField
}
)
}

Expand Down Expand Up @@ -469,10 +487,8 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
previousIterationContext.selectedFile
}

val combinedBuildAndExecuteLogFile = combineBuildAndExecuteLogFiles(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove combineBuildAndExecuteLogFiles function as this is not being used

previousIterationContext?.buildLogFile,
previousIterationContext?.testLogFile
)
val combinedBuildAndExecuteLogFile =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable declaration is not needed here, if required can we change variable name to buildLogFile etc..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keeped this in case we need excute in the future, will do it in the next pr.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

previousIterationContext?.buildLogFile
val codeTestSessionConfig = CodeTestSessionConfig(file, project, combinedBuildAndExecuteLogFile)
codeTestChatHelper.getActiveSession().projectRoot = codeTestSessionConfig.projectRoot.path

Expand All @@ -481,8 +497,13 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
return codeWhispererCodeTestSession.run(codeTestChatHelper, previousIterationContext)
}

private fun startTestGeneration(uploadId: String, targetCode: List<TargetCode>, userInput: String): StartTestGenerationResponse =
CodeWhispererClientAdaptor.getInstance(project).startTestGeneration(uploadId, targetCode, userInput)
private fun startTestGeneration(
uploadId: String,
targetCode: List<TargetCode>,
userInput: String,
testGenerationJobGroupName: String,
): StartTestGenerationResponse =
CodeWhispererClientAdaptor.getInstance(project).startTestGeneration(uploadId, targetCode, userInput, testGenerationJobGroupName)

private fun getTestGenerationStatus(jobId: String, jobGroupName: String): GetTestGenerationResponse =
CodeWhispererClientAdaptor.getInstance(project).getTestGeneration(jobId, jobGroupName)
Expand Down Expand Up @@ -566,25 +587,44 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
canBeVoted = false
)
)
if (session.iteration == 1) {
AmazonqTelemetry.utgGenerateTests(
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
hasUserPromptSupplied = session.hasUserPromptSupplied,
isFileInWorkspace = true,
isSupportedLanguage = true,
credentialStartUrl = getStartUrl(project),
jobGroup = session.testGenerationJobGroupName,
jobId = session.testGenerationJob,
result = if (e.message == message("testgen.message.cancelled")) MetricResult.Cancelled else MetricResult.Failed,

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead
reason = (e as CodeTestException).code ?: "DefaultError",
reasonDesc = if (e.message == message("testgen.message.cancelled")) "${e.code}: ${e.message}" else e.message,
perfClientLatency = (Instant.now().toEpochMilli() - session.startTimeOfTestGeneration),
isCodeBlockSelected = session.isCodeBlockSelected,
artifactsUploadDuration = session.artifactUploadDuration,
buildPayloadBytes = session.srcPayloadSize,
buildZipFileBytes = session.srcZipFileSize,
requestId = session.startTestGenerationRequestId
)
} else {
AmazonqTelemetry.unitTestGeneration(
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
hasUserPromptSupplied = session.hasUserPromptSupplied,
isSupportedLanguage = true,
credentialStartUrl = getStartUrl(project),
jobGroup = session.testGenerationJobGroupName,
jobId = session.testGenerationJob,
result = if (e.message == message("testgen.message.cancelled")) MetricResult.Cancelled else MetricResult.Failed,
reason = (e as CodeTestException).code ?: "DefaultError",
reasonDesc = if (e.message == message("testgen.message.cancelled")) "${e.code}: ${e.message}" else e.message,

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead
perfClientLatency = (Instant.now().toEpochMilli() - session.startTimeOfTestGeneration),
isCodeBlockSelected = session.isCodeBlockSelected,
artifactsUploadDuration = session.artifactUploadDuration,
buildZipFileBytes = session.srcZipFileSize,
requestId = session.startTestGenerationRequestId
)
}

AmazonqTelemetry.utgGenerateTests(
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
hasUserPromptSupplied = session.hasUserPromptSupplied,
isFileInWorkspace = true,
isSupportedLanguage = true,
credentialStartUrl = getStartUrl(project),
jobGroup = session.testGenerationJobGroupName,
jobId = session.testGenerationJob,
result = if (e.message == message("testgen.message.cancelled")) MetricResult.Cancelled else MetricResult.Failed,
reason = (e as CodeTestException).code ?: "DefaultError",
reasonDesc = if (e.message == message("testgen.message.cancelled")) "${e.code}: ${e.message}" else e.message,
perfClientLatency = (Instant.now().toEpochMilli() - session.startTimeOfTestGeneration),
isCodeBlockSelected = session.isCodeBlockSelected,
artifactsUploadDuration = session.artifactUploadDuration,
buildPayloadBytes = session.srcPayloadSize,
buildZipFileBytes = session.srcZipFileSize,
requestId = session.startTestGenerationRequestId
)
session.isGeneratingTests = false
} finally {
// Reset the flow if there is any error
Expand Down
Loading
Loading