Skip to content

Commit 261642a

Browse files
committed
fixing tests and addressing comments to remove redundancy
1 parent 4875b2b commit 261642a

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
@@ -617,7 +617,7 @@ export class GumbyController {
617617
this.messenger.sendDependencyVersionsFoundMessage(data.dependencies, data.tabID)
618618
}
619619

620-
private async HILDependencySelectionUploaded(data: { tabID: string }) {
620+
private HILDependencySelectionUploaded(data: { tabID: string }) {
621621
this.sessionStorage.getSession().conversationState = ConversationState.JOB_SUBMITTED
622622
this.messenger.sendHILResumeMessage(data.tabID)
623623
}

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
@@ -174,6 +174,8 @@ async function validateJavaHome(): Promise<boolean> {
174174
javaVersionUsedByMaven = JDKVersion.JDK8
175175
} else if (javaVersionUsedByMaven === '11.') {
176176
javaVersionUsedByMaven = JDKVersion.JDK11
177+
} else if (javaVersionUsedByMaven === '17.') {
178+
javaVersionUsedByMaven = JDKVersion.JDK17
177179
}
178180
}
179181
if (javaVersionUsedByMaven !== transformByQState.getSourceJDKVersion()) {
@@ -784,7 +786,6 @@ export async function postTransformationJob() {
784786
transformByQState.getChatControllers()?.transformationFinished.fire({
785787
message: chatMessage,
786788
tabID: ChatSessionManager.Instance.getSession().tabID,
787-
includeStartNewTransformationButton: true,
788789
})
789790
const durationInMs = calculateTotalLatency(CodeTransformTelemetryState.instance.getStartTime())
790791
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
@@ -412,7 +412,6 @@ export async function zipCode(
412412
transformByQState.getChatControllers()?.transformationFinished.fire({
413413
message: CodeWhispererConstants.projectSizeTooLargeChatMessage,
414414
tabID: ChatSessionManager.Instance.getSession().tabID,
415-
includeStartNewTransformationButton: true,
416415
})
417416
throw new ZipExceedsSizeLimitError()
418417
}

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

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ export class ProposedTransformationExplorer {
414414
transformByQState.getChatControllers()?.transformationFinished.fire({
415415
message: `${CodeWhispererConstants.errorDownloadingDiffChatMessage} The download failed due to: ${downloadErrorMessage}`,
416416
tabID: ChatSessionManager.Instance.getSession().tabID,
417-
includeStartNewTransformationButton: true,
418417
})
419418
await setContext('gumby.reviewState', TransformByQReviewStatus.NotStarted)
420419
getLogger().error(`CodeTransformation: ExportResultArchive error = ${downloadErrorMessage}`)
@@ -484,7 +483,6 @@ export class ProposedTransformationExplorer {
484483
transformByQState.getChatControllers()?.transformationFinished.fire({
485484
message: CodeWhispererConstants.viewProposedChangesChatMessage,
486485
tabID: ChatSessionManager.Instance.getSession().tabID,
487-
includeStartNewTransformationButton: true,
488486
})
489487
await vscode.commands.executeCommand('aws.amazonq.transformationHub.summary.reveal')
490488
} catch (e: any) {
@@ -493,7 +491,6 @@ export class ProposedTransformationExplorer {
493491
transformByQState.getChatControllers()?.transformationFinished.fire({
494492
message: `${CodeWhispererConstants.errorDeserializingDiffChatMessage} ${deserializeErrorMessage}`,
495493
tabID: ChatSessionManager.Instance.getSession().tabID,
496-
includeStartNewTransformationButton: true,
497494
})
498495
void vscode.window.showErrorMessage(
499496
`${CodeWhispererConstants.errorDeserializingDiffNotification} ${deserializeErrorMessage}`
@@ -544,31 +541,17 @@ export class ProposedTransformationExplorer {
544541
}
545542

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

573556
// Load the next patch file
574557
diffModel.currentPatchIndex++
@@ -607,7 +590,6 @@ export class ProposedTransformationExplorer {
607590

608591
transformByQState.getChatControllers()?.transformationFinished.fire({
609592
tabID: ChatSessionManager.Instance.getSession().tabID,
610-
includeStartNewTransformationButton: true,
611593
})
612594

613595
telemetry.codeTransform_viewArtifact.emit({

0 commit comments

Comments
 (0)