Skip to content

Commit

Permalink
fixing tests and addressing comments to remove redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
ntarakad-aws committed Nov 17, 2024
1 parent 4875b2b commit 261642a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
*/
import assert from 'assert'
import sinon from 'sinon'
import os from 'os'
import { DiffModel, AddedChangeNode, ModifiedChangeNode } from 'aws-core-vscode/codewhisperer/node'
import { DescriptionContent } from 'aws-core-vscode/codewhisperer'
import path from 'path'
import { getTestResourceFilePath } from './amazonQGumbyUtil'
import { fs } from 'aws-core-vscode/shared'
// eslint-disable-next-line no-restricted-imports
import { createTestWorkspace } from '../../../../core/dist/src/test/testUtil'

describe('DiffModel', function () {
let parsedTestDescriptions: DescriptionContent
Expand Down Expand Up @@ -44,8 +45,6 @@ describe('DiffModel', function () {
1
)

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

const workspacePath = os.tmpdir()
const fileAmount = 1
const workspaceFolder = await createTestWorkspace(fileAmount, { fileContent: '' })

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

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

testDiffModel.parseDiff(
getTestResourceFilePath('resources/files/modifiedFile.diff'),
workspacePath,
workspaceFolder.uri.fsPath,
parsedTestDescriptions.content[0],
1
)

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

assert.strictEqual(change instanceof ModifiedChangeNode, true)

await fs.delete(path.join(workspacePath, 'README.md'), { recursive: true })
await fs.delete(path.join(workspaceFolder.uri.fsPath, 'README.md'), { recursive: true })
})

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 () {
const testDiffModel = new DiffModel()
const testDiffModel = new DiffModel() //try to see if you can reuse that test model from above

const workspacePath = os.tmpdir()
const fileAmount = 1
const workspaceFolder = await createTestWorkspace(fileAmount, { fileContent: '' })

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

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

testDiffModel.parseDiff(
getTestResourceFilePath('resources/files/modifiedFile.diff'),
workspacePath,
workspaceFolder.uri.fsPath,
undefined,
1
)

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

assert.strictEqual(change instanceof ModifiedChangeNode, true)

await fs.delete(path.join(workspacePath, 'README.md'), { recursive: true })
await fs.delete(path.join(workspaceFolder.uri.fsPath, 'README.md'), { recursive: true })
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ export class GumbyController {
this.messenger.sendDependencyVersionsFoundMessage(data.dependencies, data.tabID)
}

private async HILDependencySelectionUploaded(data: { tabID: string }) {
private HILDependencySelectionUploaded(data: { tabID: string }) {
this.sessionStorage.getSession().conversationState = ConversationState.JOB_SUBMITTED
this.messenger.sendHILResumeMessage(data.tabID)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ export class Messenger {
value: JDKVersion.JDK11,
label: JDKVersion.JDK11,
},
{
value: JDKVersion.JDK17,
label: JDKVersion.JDK17,
},
{
value: JDKVersion.UNSUPPORTED,
label: 'Other',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export default class MessengerUtils {
javaHomePrompt += ` ${CodeWhispererConstants.macJavaVersionHomeHelpChatMessage(1.8)}`
} else if (jdkVersion === JDKVersion.JDK11) {
javaHomePrompt += ` ${CodeWhispererConstants.macJavaVersionHomeHelpChatMessage(11)}`
} else if (jdkVersion === JDKVersion.JDK17) {
javaHomePrompt += ` ${CodeWhispererConstants.macJavaVersionHomeHelpChatMessage(17)}`
}
} else {
javaHomePrompt += ` ${CodeWhispererConstants.linuxJavaHomeHelpChatMessage}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ async function validateJavaHome(): Promise<boolean> {
javaVersionUsedByMaven = JDKVersion.JDK8
} else if (javaVersionUsedByMaven === '11.') {
javaVersionUsedByMaven = JDKVersion.JDK11
} else if (javaVersionUsedByMaven === '17.') {
javaVersionUsedByMaven = JDKVersion.JDK17
}
}
if (javaVersionUsedByMaven !== transformByQState.getSourceJDKVersion()) {
Expand Down Expand Up @@ -784,7 +786,6 @@ export async function postTransformationJob() {
transformByQState.getChatControllers()?.transformationFinished.fire({
message: chatMessage,
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: true,
})
const durationInMs = calculateTotalLatency(CodeTransformTelemetryState.instance.getStartTime())
const resultStatusMessage = transformByQState.getStatus()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ export async function zipCode(
transformByQState.getChatControllers()?.transformationFinished.fire({
message: CodeWhispererConstants.projectSizeTooLargeChatMessage,
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: true,
})
throw new ZipExceedsSizeLimitError()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ export class ProposedTransformationExplorer {
transformByQState.getChatControllers()?.transformationFinished.fire({
message: `${CodeWhispererConstants.errorDownloadingDiffChatMessage} The download failed due to: ${downloadErrorMessage}`,
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: true,
})
await setContext('gumby.reviewState', TransformByQReviewStatus.NotStarted)
getLogger().error(`CodeTransformation: ExportResultArchive error = ${downloadErrorMessage}`)
Expand Down Expand Up @@ -484,7 +483,6 @@ export class ProposedTransformationExplorer {
transformByQState.getChatControllers()?.transformationFinished.fire({
message: CodeWhispererConstants.viewProposedChangesChatMessage,
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: true,
})
await vscode.commands.executeCommand('aws.amazonq.transformationHub.summary.reveal')
} catch (e: any) {
Expand All @@ -493,7 +491,6 @@ export class ProposedTransformationExplorer {
transformByQState.getChatControllers()?.transformationFinished.fire({
message: `${CodeWhispererConstants.errorDeserializingDiffChatMessage} ${deserializeErrorMessage}`,
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: true,
})
void vscode.window.showErrorMessage(
`${CodeWhispererConstants.errorDeserializingDiffNotification} ${deserializeErrorMessage}`
Expand Down Expand Up @@ -544,31 +541,17 @@ export class ProposedTransformationExplorer {
}

//We do this to ensure that the changesAppliedChatMessage is only sent to user when they accept the first diff.patch
if (diffModel.currentPatchIndex === patchFiles.length - 1) {
transformByQState.getChatControllers()?.transformationFinished.fire({
message: CodeWhispererConstants.changesAppliedChatMessageMultipleDiffs(
diffModel.currentPatchIndex,
patchFiles.length,
patchFilesDescriptions
? patchFilesDescriptions.content[diffModel.currentPatchIndex].name
: undefined
),
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: true,
})
} else {
transformByQState.getChatControllers()?.transformationFinished.fire({
message: CodeWhispererConstants.changesAppliedChatMessageMultipleDiffs(
diffModel.currentPatchIndex,
patchFiles.length,
patchFilesDescriptions
? patchFilesDescriptions.content[diffModel.currentPatchIndex].name
: undefined
),
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: false,
})
}
transformByQState.getChatControllers()?.transformationFinished.fire({
message: CodeWhispererConstants.changesAppliedChatMessageMultipleDiffs(
diffModel.currentPatchIndex,
patchFiles.length,
patchFilesDescriptions
? patchFilesDescriptions.content[diffModel.currentPatchIndex].name
: undefined
),
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: diffModel.currentPatchIndex === patchFiles.length - 1,
})

// Load the next patch file
diffModel.currentPatchIndex++
Expand Down Expand Up @@ -607,7 +590,6 @@ export class ProposedTransformationExplorer {

transformByQState.getChatControllers()?.transformationFinished.fire({
tabID: ChatSessionManager.Instance.getSession().tabID,
includeStartNewTransformationButton: true,
})

telemetry.codeTransform_viewArtifact.emit({
Expand Down

0 comments on commit 261642a

Please sign in to comment.