Skip to content

Commit 08bedbc

Browse files
authored
fix(amazonq): Q infers source file from active test file for UTG. (#6549)
## Problem - If user tries to run `/test` on the test file, Q considers test file as source file and starts the test generation on the test file. ## Solution - If user tries to run `/test` on the test file, Q infers the context from the original source file and generate tests accordingly. - No change in functionality, minor change in UX filename. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 228199d commit 08bedbc

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Amazon Q /test: Q identify active test file and infer source file for test generation."
4+
}

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ export class TestController {
494494
* Get Diff from exportResultArchive API
495495
*/
496496
ChatSessionManager.Instance.setIsInProgress(true)
497-
await startTestGenerationProcess(fileName, filePath, message.prompt, tabID, true, selectionRange)
497+
await startTestGenerationProcess(filePath, message.prompt, tabID, true, selectionRange)
498498
}
499499
} catch (err: any) {
500500
// TODO: refactor error handling to be more robust
@@ -549,12 +549,15 @@ export class TestController {
549549
testGenerationJobGroupName: string
550550
testGenerationJobId: string
551551
type: ChatItemType
552-
fileName: string
552+
filePath: string
553553
}) {
554554
this.messenger.sendShortSummary({
555555
type: 'answer',
556556
tabID: message.tabID,
557-
message: testGenSummaryMessage(message.fileName, message.shortAnswer?.planSummary?.replaceAll('```', '')),
557+
message: testGenSummaryMessage(
558+
path.basename(message.shortAnswer?.sourceFilePath ?? message.filePath),
559+
message.shortAnswer?.planSummary?.replaceAll('```', '')
560+
),
558561
canBeVoted: true,
559562
filePath: message.shortAnswer?.testFilePath,
560563
})
@@ -1117,13 +1120,7 @@ export class TestController {
11171120
canBeVoted: false,
11181121
messageId: TestNamedMessages.TEST_GENERATION_BUILD_STATUS_MESSAGE,
11191122
})
1120-
await startTestGenerationProcess(
1121-
path.basename(session.sourceFilePath),
1122-
session.sourceFilePath,
1123-
'',
1124-
data.tabID,
1125-
false
1126-
)
1123+
await startTestGenerationProcess(session.sourceFilePath, '', data.tabID, false)
11271124
}
11281125
// TODO: Skip this if startTestGenerationProcess timeouts
11291126
if (session.generatedFilePath) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { Range } from '../client/codewhispereruserclient'
2828
let spawnResult: ChildProcess | null = null
2929
let isCancelled = false
3030
export async function startTestGenerationProcess(
31-
fileName: string,
3231
filePath: string,
3332
userInputPrompt: string,
3433
tabID: string,
@@ -116,7 +115,7 @@ export async function startTestGenerationProcess(
116115
const jobStatus = await pollTestJobStatus(
117116
testJob.testGenerationJob.testGenerationJobId,
118117
testJob.testGenerationJob.testGenerationJobGroupName,
119-
fileName,
118+
filePath,
120119
initialExecution
121120
)
122121
// TODO: Send status to test summary

packages/core/src/codewhisperer/service/testGenHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export async function createTestJob(
129129
export async function pollTestJobStatus(
130130
jobId: string,
131131
jobGroupName: string,
132-
fileName: string,
132+
filePath: string,
133133
initialExecution: boolean
134134
) {
135135
const session = ChatSessionManager.Instance.getSession()
@@ -187,7 +187,7 @@ export async function pollTestJobStatus(
187187
shortAnswer,
188188
testGenerationJobGroupName: resp.testGenerationJob?.testGenerationJobGroupName,
189189
testGenerationJobId: resp.testGenerationJob?.testGenerationJobId,
190-
fileName,
190+
filePath,
191191
})
192192
}
193193
}

0 commit comments

Comments
 (0)