Skip to content

Commit 1bdcdc1

Browse files
committed
Adding build and execute for /tesdt
1 parent 219ac6b commit 1bdcdc1

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

packages/core/src/amazonqTest/chat/controller/controller.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {
6262
} from '../../../codewhisperer/models/constants'
6363
import { UserWrittenCodeTracker } from '../../../codewhisperer/tracker/userWrittenCodeTracker'
6464
import { ReferenceLogViewProvider } from '../../../codewhisperer/service/referenceLogViewProvider'
65+
import { Auth } from '../../../auth/auth'
6566

6667
export interface TestChatControllerEventEmitters {
6768
readonly tabOpened: vscode.EventEmitter<any>
@@ -760,8 +761,10 @@ export class TestController {
760761
session.linesOfCodeGenerated
761762
)
762763

763-
// await this.endSession(message, FollowUpTypes.SkipBuildAndFinish)
764-
// return
764+
if (!Auth.instance.isInternalAmazonUser()) {
765+
await this.endSession(message, FollowUpTypes.SkipBuildAndFinish)
766+
return
767+
}
765768

766769
if (session.listOfTestGenerationJobId.length === 1) {
767770
this.startInitialBuild(message)
@@ -901,12 +904,17 @@ export class TestController {
901904

902905
private startInitialBuild(data: any) {
903906
// TODO: Remove the fallback build command after stable version of backend build command.
904-
const userMessage = `Would you like me to help build and execute the test? I will need you to let me know what build command to run if you do.`
907+
const userMessage = `Would you like me to help build and execute the test? I’ll run following commands.\n\`\`\`sh\n${this.sessionStorage.getSession().shortAnswer?.buildCommand}\n`
905908
const followUps: FollowUps = {
906909
text: '',
907910
options: [
908911
{
909-
pillText: `Specify command then build and execute`,
912+
pillText: `Build and execute`,
913+
type: FollowUpTypes.BuildAndExecute,
914+
status: 'primary',
915+
},
916+
{
917+
pillText: `Modify command`,
910918
type: FollowUpTypes.ModifyCommands,
911919
status: 'primary',
912920
},
@@ -936,7 +944,6 @@ export class TestController {
936944
const listOfInstallationDependencies = ['']
937945
const installationDependencies = listOfInstallationDependencies.join('\n')
938946

939-
this.messenger.sendMessage('Build and execute', data.tabID, 'prompt')
940947
telemetry.ui_click.emit({ elementId: 'unitTestGeneration_buildAndExecute' })
941948

942949
if (installationDependencies.length > 0) {
@@ -985,11 +992,6 @@ export class TestController {
985992
// const installationDependencies = session.shortAnswer?.installationDependencies ?? []
986993
// MOCK: ignoring the installation case until backend send response
987994
const installationDependencies: string[] = []
988-
const buildCommands = session.updatedBuildCommands
989-
if (!buildCommands) {
990-
throw new Error('Build command not found')
991-
return
992-
}
993995

994996
this.messenger.sendBuildProgressMessage({
995997
tabID: data.tabID,
@@ -1061,7 +1063,7 @@ export class TestController {
10611063
messageId: TestNamedMessages.TEST_GENERATION_BUILD_STATUS_MESSAGE,
10621064
})
10631065

1064-
const buildStatus = await runBuildCommand(buildCommands)
1066+
const buildStatus = await runBuildCommand(this.getBuildCommands())
10651067
session.buildStatus = buildStatus
10661068

10671069
if (buildStatus === BuildStatus.FAILURE) {
@@ -1189,10 +1191,17 @@ export class TestController {
11891191
fileList: this.checkCodeDiffLengthAndBuildStatus({ codeDiffLength, buildStatus: session.buildStatus })
11901192
? {
11911193
fileTreeTitle: 'READY FOR REVIEW',
1192-
rootFolderTitle: 'tests',
1194+
rootFolderTitle: path.basename(session.projectRootPath),
11931195
filePaths: [session.generatedFilePath],
11941196
}
11951197
: undefined,
1198+
codeReference: session.references.map(
1199+
(ref: ShortAnswerReference) =>
1200+
({
1201+
...ref,
1202+
information: `${ref.licenseName} - <a href="${ref.url}">${ref.repository}</a>`,
1203+
}) as CodeReference
1204+
),
11961205
})
11971206
this.messenger.sendBuildProgressMessage({
11981207
tabID: data.tabID,
@@ -1221,7 +1230,7 @@ export class TestController {
12211230

12221231
private modifyBuildCommand(data: any) {
12231232
this.sessionStorage.getSession().conversationState = ConversationState.WAITING_FOR_BUILD_COMMMAND_INPUT
1224-
this.messenger.sendMessage('Specify commands then build', data.tabID, 'prompt')
1233+
this.messenger.sendMessage('Modify Command', data.tabID, 'prompt')
12251234
telemetry.ui_click.emit({ elementId: 'unitTestGeneration_modifyCommand' })
12261235
this.messenger.sendMessage(
12271236
'Sure, provide all command lines you’d like me to run to build.',
@@ -1334,21 +1343,16 @@ export class TestController {
13341343
}
13351344

13361345
// TODO: return build command when product approves
1337-
// private getBuildCommands = (): string[] => {
1338-
// const session = this.sessionStorage.getSession()
1339-
// if (session.updatedBuildCommands?.length) {
1340-
// return [...session.updatedBuildCommands]
1341-
// }
1342-
1343-
// // For Internal amazon users only
1344-
// if (Auth.instance.isInternalAmazonUser()) {
1345-
// return ['brazil-build release']
1346-
// }
1347-
1348-
// if (session.shortAnswer && Array.isArray(session.shortAnswer?.buildCommands)) {
1349-
// return [...session.shortAnswer.buildCommands]
1350-
// }
1351-
1352-
// return ['source qdev-wbr/.venv/bin/activate && pytest --continue-on-collection-errors']
1353-
// }
1346+
private getBuildCommands = (): string[] => {
1347+
const session = this.sessionStorage.getSession()
1348+
if (session.updatedBuildCommands?.length) {
1349+
return [...session.updatedBuildCommands]
1350+
}
1351+
1352+
if (session.shortAnswer && session.shortAnswer?.buildCommand) {
1353+
return [session.shortAnswer.buildCommand]
1354+
}
1355+
// TODO: Add a generic command here for external launch according to the build system.
1356+
return ['brazil-build release']
1357+
}
13541358
}

packages/core/src/codewhisperer/commands/startTestGeneration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function runLocalBuild(
212212
if (spawnResult.stderr) {
213213
spawnResult.stderr.on('data', async (data) => {
214214
const output = data.toString().trim()
215-
getLogger().warn(`BUILD ERROR: ${output}`)
215+
getLogger().warn(`${output}`)
216216
buildLogs += output
217217
})
218218
}

packages/core/src/codewhisperer/models/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ export interface ShortAnswerReference {
11771177

11781178
export interface ShortAnswer {
11791179
testFilePath: string
1180-
buildCommands: string[]
1180+
buildCommand: string
11811181
planSummary: string
11821182
sourceFilePath?: string
11831183
testFramework?: string

0 commit comments

Comments
 (0)