diff --git a/packages/amazonq/.changes/next-release/Bug Fix-cd65fb78-14de-4214-baac-2e998c4fb143.json b/packages/amazonq/.changes/next-release/Bug Fix-cd65fb78-14de-4214-baac-2e998c4fb143.json new file mode 100644 index 00000000000..1ab5887af81 --- /dev/null +++ b/packages/amazonq/.changes/next-release/Bug Fix-cd65fb78-14de-4214-baac-2e998c4fb143.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "description": "Amazon Q /test: Q identify active test file and infer source file for test generation." +} diff --git a/packages/core/src/amazonqTest/chat/controller/controller.ts b/packages/core/src/amazonqTest/chat/controller/controller.ts index 4467f7fcb24..10b84dba2b7 100644 --- a/packages/core/src/amazonqTest/chat/controller/controller.ts +++ b/packages/core/src/amazonqTest/chat/controller/controller.ts @@ -494,7 +494,7 @@ export class TestController { * Get Diff from exportResultArchive API */ ChatSessionManager.Instance.setIsInProgress(true) - await startTestGenerationProcess(fileName, filePath, message.prompt, tabID, true, selectionRange) + await startTestGenerationProcess(filePath, message.prompt, tabID, true, selectionRange) } } catch (err: any) { // TODO: refactor error handling to be more robust @@ -549,12 +549,15 @@ export class TestController { testGenerationJobGroupName: string testGenerationJobId: string type: ChatItemType - fileName: string + filePath: string }) { this.messenger.sendShortSummary({ type: 'answer', tabID: message.tabID, - message: testGenSummaryMessage(message.fileName, message.shortAnswer?.planSummary?.replaceAll('```', '')), + message: testGenSummaryMessage( + path.basename(message.shortAnswer?.sourceFilePath ?? message.filePath), + message.shortAnswer?.planSummary?.replaceAll('```', '') + ), canBeVoted: true, filePath: message.shortAnswer?.testFilePath, }) @@ -1117,13 +1120,7 @@ export class TestController { canBeVoted: false, messageId: TestNamedMessages.TEST_GENERATION_BUILD_STATUS_MESSAGE, }) - await startTestGenerationProcess( - path.basename(session.sourceFilePath), - session.sourceFilePath, - '', - data.tabID, - false - ) + await startTestGenerationProcess(session.sourceFilePath, '', data.tabID, false) } // TODO: Skip this if startTestGenerationProcess timeouts if (session.generatedFilePath) { diff --git a/packages/core/src/codewhisperer/commands/startTestGeneration.ts b/packages/core/src/codewhisperer/commands/startTestGeneration.ts index c394310d4f8..87928d58279 100644 --- a/packages/core/src/codewhisperer/commands/startTestGeneration.ts +++ b/packages/core/src/codewhisperer/commands/startTestGeneration.ts @@ -28,7 +28,6 @@ import { Range } from '../client/codewhispereruserclient' let spawnResult: ChildProcess | null = null let isCancelled = false export async function startTestGenerationProcess( - fileName: string, filePath: string, userInputPrompt: string, tabID: string, @@ -116,7 +115,7 @@ export async function startTestGenerationProcess( const jobStatus = await pollTestJobStatus( testJob.testGenerationJob.testGenerationJobId, testJob.testGenerationJob.testGenerationJobGroupName, - fileName, + filePath, initialExecution ) // TODO: Send status to test summary diff --git a/packages/core/src/codewhisperer/service/testGenHandler.ts b/packages/core/src/codewhisperer/service/testGenHandler.ts index fd5c07606e8..cb2875ab78e 100644 --- a/packages/core/src/codewhisperer/service/testGenHandler.ts +++ b/packages/core/src/codewhisperer/service/testGenHandler.ts @@ -129,7 +129,7 @@ export async function createTestJob( export async function pollTestJobStatus( jobId: string, jobGroupName: string, - fileName: string, + filePath: string, initialExecution: boolean ) { const session = ChatSessionManager.Instance.getSession() @@ -187,7 +187,7 @@ export async function pollTestJobStatus( shortAnswer, testGenerationJobGroupName: resp.testGenerationJob?.testGenerationJobGroupName, testGenerationJobId: resp.testGenerationJob?.testGenerationJobId, - fileName, + filePath, }) } }