Skip to content

Commit adda8af

Browse files
committed
fixing tests and addressing comments to remove redundancy
1 parent e63ab97 commit adda8af

File tree

7 files changed

+33
-48
lines changed

7 files changed

+33
-48
lines changed

packages/amazonq/test/unit/amazonqGumby/transformationResultsHandler.test.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
*/
55
import assert from 'assert'
66
import sinon from 'sinon'
7-
import os from 'os'
87
import { DiffModel, AddedChangeNode, ModifiedChangeNode } from 'aws-core-vscode/codewhisperer/node'
98
import { DescriptionContent } from 'aws-core-vscode/codewhisperer'
109
import path from 'path'
1110
import { getTestResourceFilePath } from './amazonQGumbyUtil'
1211
import { fs } from 'aws-core-vscode/shared'
12+
// eslint-disable-next-line no-restricted-imports
13+
import { createTestWorkspace } from '../../../../core/dist/src/test/testUtil'
1314

1415
describe('DiffModel', function () {
1516
let parsedTestDescriptions: DescriptionContent
@@ -44,8 +45,6 @@ describe('DiffModel', function () {
4445
1
4546
)
4647

47-
assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
48-
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
4948
assert.strictEqual(
5049
testDiffModel.patchFileNodes[0].patchFilePath,
5150
getTestResourceFilePath('resources/files/addedFile.diff')
@@ -59,24 +58,23 @@ describe('DiffModel', function () {
5958
it('WHEN parsing a diff patch where a file was modified THEN returns an array representing the modified file', async function () {
6059
const testDiffModel = new DiffModel()
6160

62-
const workspacePath = os.tmpdir()
61+
const fileAmount = 1
62+
const workspaceFolder = await createTestWorkspace(fileAmount, { fileContent: '' })
6363

6464
sinon.replace(fs, 'exists', async (path) => true)
6565

6666
await fs.writeFile(
67-
path.join(workspacePath, 'README.md'),
67+
path.join(workspaceFolder.uri.fsPath, 'README.md'),
6868
'This guide walks you through using Gradle to build a simple Java project.'
6969
)
7070

7171
testDiffModel.parseDiff(
7272
getTestResourceFilePath('resources/files/modifiedFile.diff'),
73-
workspacePath,
73+
workspaceFolder.uri.fsPath,
7474
parsedTestDescriptions.content[0],
7575
1
7676
)
7777

78-
assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
79-
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
8078
assert.strictEqual(
8179
testDiffModel.patchFileNodes[0].patchFilePath,
8280
getTestResourceFilePath('resources/files/modifiedFile.diff')
@@ -86,30 +84,29 @@ describe('DiffModel', function () {
8684

8785
assert.strictEqual(change instanceof ModifiedChangeNode, true)
8886

89-
await fs.delete(path.join(workspacePath, 'README.md'), { recursive: true })
87+
await fs.delete(path.join(workspaceFolder.uri.fsPath, 'README.md'), { recursive: true })
9088
})
9189

9290
it('WHEN parsing a diff patch where diff.json is not present and a file was modified THEN returns an array representing the modified file', async function () {
93-
const testDiffModel = new DiffModel()
91+
const testDiffModel = new DiffModel() //try to see if you can reuse that test model from above
9492

95-
const workspacePath = os.tmpdir()
93+
const fileAmount = 1
94+
const workspaceFolder = await createTestWorkspace(fileAmount, { fileContent: '' })
9695

9796
sinon.replace(fs, 'exists', async (path) => true)
9897

9998
await fs.writeFile(
100-
path.join(workspacePath, 'README.md'),
99+
path.join(workspaceFolder.uri.fsPath, 'README.md'),
101100
'This guide walks you through using Gradle to build a simple Java project.'
102101
)
103102

104103
testDiffModel.parseDiff(
105104
getTestResourceFilePath('resources/files/modifiedFile.diff'),
106-
workspacePath,
105+
workspaceFolder.uri.fsPath,
107106
undefined,
108107
1
109108
)
110109

111-
assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
112-
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
113110
assert.strictEqual(
114111
testDiffModel.patchFileNodes[0].patchFilePath,
115112
getTestResourceFilePath('resources/files/modifiedFile.diff')
@@ -119,6 +116,6 @@ describe('DiffModel', function () {
119116

120117
assert.strictEqual(change instanceof ModifiedChangeNode, true)
121118

122-
await fs.delete(path.join(workspacePath, 'README.md'), { recursive: true })
119+
await fs.delete(path.join(workspaceFolder.uri.fsPath, 'README.md'), { recursive: true })
123120
})
124121
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ export class GumbyController {
632632
this.messenger.sendDependencyVersionsFoundMessage(data.dependencies, data.tabID)
633633
}
634634

635-
private async HILDependencySelectionUploaded(data: { tabID: string }) {
635+
private HILDependencySelectionUploaded(data: { tabID: string }) {
636636
this.sessionStorage.getSession().conversationState = ConversationState.JOB_SUBMITTED
637637
this.messenger.sendHILResumeMessage(data.tabID)
638638
}

packages/core/src/amazonqGumby/chat/controller/messenger/messenger.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ export class Messenger {
230230
value: JDKVersion.JDK11,
231231
label: JDKVersion.JDK11,
232232
},
233+
{
234+
value: JDKVersion.JDK17,
235+
label: JDKVersion.JDK17,
236+
},
233237
{
234238
value: JDKVersion.UNSUPPORTED,
235239
label: 'Other',

packages/core/src/amazonqGumby/chat/controller/messenger/messengerUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export default class MessengerUtils {
4949
javaHomePrompt += ` ${CodeWhispererConstants.macJavaVersionHomeHelpChatMessage(1.8)}`
5050
} else if (jdkVersion === JDKVersion.JDK11) {
5151
javaHomePrompt += ` ${CodeWhispererConstants.macJavaVersionHomeHelpChatMessage(11)}`
52+
} else if (jdkVersion === JDKVersion.JDK17) {
53+
javaHomePrompt += ` ${CodeWhispererConstants.macJavaVersionHomeHelpChatMessage(17)}`
5254
}
5355
} else {
5456
javaHomePrompt += ` ${CodeWhispererConstants.linuxJavaHomeHelpChatMessage}`

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ async function validateJavaHome(): Promise<boolean> {
177177
javaVersionUsedByMaven = JDKVersion.JDK8
178178
} else if (javaVersionUsedByMaven === '11.') {
179179
javaVersionUsedByMaven = JDKVersion.JDK11
180+
} else if (javaVersionUsedByMaven === '17.') {
181+
javaVersionUsedByMaven = JDKVersion.JDK17
180182
}
181183
}
182184
if (javaVersionUsedByMaven !== transformByQState.getSourceJDKVersion()) {
@@ -819,7 +821,6 @@ export async function postTransformationJob() {
819821
transformByQState.getChatControllers()?.transformationFinished.fire({
820822
message: chatMessage,
821823
tabID: ChatSessionManager.Instance.getSession().tabID,
822-
includeStartNewTransformationButton: true,
823824
})
824825
const durationInMs = calculateTotalLatency(CodeTransformTelemetryState.instance.getStartTime())
825826
const resultStatusMessage = transformByQState.getStatus()

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ export async function zipCode(
409409
transformByQState.getChatControllers()?.transformationFinished.fire({
410410
message: CodeWhispererConstants.projectSizeTooLargeChatMessage,
411411
tabID: ChatSessionManager.Instance.getSession().tabID,
412-
includeStartNewTransformationButton: true,
413412
})
414413
throw new ZipExceedsSizeLimitError()
415414
}

packages/core/src/codewhisperer/service/transformByQ/transformationResultsViewProvider.ts

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ export class ProposedTransformationExplorer {
420420
transformByQState.getChatControllers()?.transformationFinished.fire({
421421
message: `${CodeWhispererConstants.errorDownloadingDiffChatMessage} The download failed due to: ${downloadErrorMessage}`,
422422
tabID: ChatSessionManager.Instance.getSession().tabID,
423-
includeStartNewTransformationButton: true,
424423
})
425424
await setContext('gumby.reviewState', TransformByQReviewStatus.NotStarted)
426425
getLogger().error(`CodeTransformation: ExportResultArchive error = ${downloadErrorMessage}`)
@@ -490,7 +489,6 @@ export class ProposedTransformationExplorer {
490489
transformByQState.getChatControllers()?.transformationFinished.fire({
491490
message: CodeWhispererConstants.viewProposedChangesChatMessage,
492491
tabID: ChatSessionManager.Instance.getSession().tabID,
493-
includeStartNewTransformationButton: true,
494492
})
495493
await vscode.commands.executeCommand('aws.amazonq.transformationHub.summary.reveal')
496494
} catch (e: any) {
@@ -499,7 +497,6 @@ export class ProposedTransformationExplorer {
499497
transformByQState.getChatControllers()?.transformationFinished.fire({
500498
message: `${CodeWhispererConstants.errorDeserializingDiffChatMessage} ${deserializeErrorMessage}`,
501499
tabID: ChatSessionManager.Instance.getSession().tabID,
502-
includeStartNewTransformationButton: true,
503500
})
504501
void vscode.window.showErrorMessage(
505502
`${CodeWhispererConstants.errorDeserializingDiffNotification} ${deserializeErrorMessage}`
@@ -550,31 +547,17 @@ export class ProposedTransformationExplorer {
550547
}
551548

552549
//We do this to ensure that the changesAppliedChatMessage is only sent to user when they accept the first diff.patch
553-
if (diffModel.currentPatchIndex === patchFiles.length - 1) {
554-
transformByQState.getChatControllers()?.transformationFinished.fire({
555-
message: CodeWhispererConstants.changesAppliedChatMessageMultipleDiffs(
556-
diffModel.currentPatchIndex,
557-
patchFiles.length,
558-
patchFilesDescriptions
559-
? patchFilesDescriptions.content[diffModel.currentPatchIndex].name
560-
: undefined
561-
),
562-
tabID: ChatSessionManager.Instance.getSession().tabID,
563-
includeStartNewTransformationButton: true,
564-
})
565-
} else {
566-
transformByQState.getChatControllers()?.transformationFinished.fire({
567-
message: CodeWhispererConstants.changesAppliedChatMessageMultipleDiffs(
568-
diffModel.currentPatchIndex,
569-
patchFiles.length,
570-
patchFilesDescriptions
571-
? patchFilesDescriptions.content[diffModel.currentPatchIndex].name
572-
: undefined
573-
),
574-
tabID: ChatSessionManager.Instance.getSession().tabID,
575-
includeStartNewTransformationButton: false,
576-
})
577-
}
550+
transformByQState.getChatControllers()?.transformationFinished.fire({
551+
message: CodeWhispererConstants.changesAppliedChatMessageMultipleDiffs(
552+
diffModel.currentPatchIndex,
553+
patchFiles.length,
554+
patchFilesDescriptions
555+
? patchFilesDescriptions.content[diffModel.currentPatchIndex].name
556+
: undefined
557+
),
558+
tabID: ChatSessionManager.Instance.getSession().tabID,
559+
includeStartNewTransformationButton: diffModel.currentPatchIndex === patchFiles.length - 1,
560+
})
578561

579562
// Load the next patch file
580563
diffModel.currentPatchIndex++
@@ -613,7 +596,6 @@ export class ProposedTransformationExplorer {
613596

614597
transformByQState.getChatControllers()?.transformationFinished.fire({
615598
tabID: ChatSessionManager.Instance.getSession().tabID,
616-
includeStartNewTransformationButton: true,
617599
})
618600

619601
telemetry.codeTransform_viewArtifact.emit({

0 commit comments

Comments
 (0)