Skip to content

Commit b84a8d2

Browse files
committed
Merge remote-tracking branch 'origin/master' into HEAD
2 parents 512edce + 06b3725 commit b84a8d2

File tree

18 files changed

+12799
-14461
lines changed

18 files changed

+12799
-14461
lines changed

package-lock.json

Lines changed: 11902 additions & 14430 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/amazonq/test/e2e/amazonq/testGen.test.ts

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import { qTestingFramework } from './framework/framework'
99
import sinon from 'sinon'
1010
import { Messenger } from './framework/messenger'
1111
import { FollowUpTypes } from 'aws-core-vscode/amazonq'
12-
import { registerAuthHook, using, TestFolder, closeAllEditors } from 'aws-core-vscode/test'
12+
import { registerAuthHook, using, TestFolder, closeAllEditors, getTestWorkspaceFolder } from 'aws-core-vscode/test'
1313
import { loginToIdC } from './utils/setup'
1414
import { waitUntil, workspaceUtils } from 'aws-core-vscode/shared'
15+
import * as path from 'path'
1516

1617
describe('Amazon Q Test Generation', function () {
1718
let framework: qTestingFramework
@@ -20,11 +21,13 @@ describe('Amazon Q Test Generation', function () {
2021
const testFiles = [
2122
{
2223
language: 'python',
23-
filePath: 'python3.7-image-sam-app/hello_world/app.py',
24+
filePath: 'testGenFolder/src/main/math.py',
25+
testFilePath: 'testGenFolder/src/test/test_math.py',
2426
},
2527
{
2628
language: 'java',
27-
filePath: 'java17-gradle/HelloWorldFunction/src/main/java/helloworld/App.java',
29+
filePath: 'testGenFolder/src/main/Math.java',
30+
testFilePath: 'testGenFolder/src/test/MathTest.java',
2831
},
2932
]
3033

@@ -33,14 +36,15 @@ describe('Amazon Q Test Generation', function () {
3336
// must be atleast one unsupported language here for testing
3437
{
3538
language: 'typescript',
36-
filePath: 'ts-plain-sam-app/src/app.ts',
39+
filePath: 'testGenFolder/src/main/math.ts',
3740
},
3841
{
3942
language: 'javascript',
40-
filePath: 'js-plain-sam-app/src/app.js',
43+
filePath: 'testGenFolder/src/main/math.js',
4144
},
4245
]
4346

47+
// handles opening the file since /test must be called on an active file
4448
async function setupTestDocument(filePath: string, language: string) {
4549
const document = await waitUntil(async () => {
4650
const doc = await workspaceUtils.openTextDocument(filePath)
@@ -57,7 +61,7 @@ describe('Amazon Q Test Generation', function () {
5761

5862
const activeEditor = vscode.window.activeTextEditor
5963
if (!activeEditor || activeEditor.document.uri.fsPath !== document.uri.fsPath) {
60-
assert.fail(`Failed to make temp file active`)
64+
assert.fail(`Failed to make ${language} file active`)
6165
}
6266
}
6367

@@ -68,6 +72,15 @@ describe('Amazon Q Test Generation', function () {
6872
})
6973
}
7074

75+
// clears test file to a blank file
76+
// not cleaning up test file may possibly cause bloat in CI since testFixtures does not get reset
77+
async function cleanupTestFile(testFilePath: string) {
78+
const workspaceFolder = getTestWorkspaceFolder()
79+
const absoluteTestFilePath = path.join(workspaceFolder, testFilePath)
80+
const testFileUri = vscode.Uri.file(absoluteTestFilePath)
81+
await vscode.workspace.fs.writeFile(testFileUri, Buffer.from('', 'utf-8'))
82+
}
83+
7184
before(async function () {
7285
await using(registerAuthHook('amazonq-test-account'), async () => {
7386
await loginToIdC()
@@ -112,7 +125,7 @@ describe('Amazon Q Test Generation', function () {
112125
})
113126

114127
describe('/test entry', () => {
115-
describe('Unsupported language', () => {
128+
describe('Unsupported language file', () => {
116129
const { language, filePath } = unsupportedLanguages[0]
117130

118131
beforeEach(async () => {
@@ -134,13 +147,13 @@ describe('Amazon Q Test Generation', function () {
134147
})
135148
})
136149

137-
describe('External file', async () => {
150+
describe('External file out of project', async () => {
138151
let testFolder: TestFolder
139152
let fileName: string
140153

141154
beforeEach(async () => {
142155
testFolder = await TestFolder.create()
143-
fileName = 'test.py'
156+
fileName = 'math.py'
144157
const filePath = await testFolder.write(fileName, 'def add(a, b): return a + b')
145158

146159
const document = await vscode.workspace.openTextDocument(filePath)
@@ -162,10 +175,8 @@ describe('Amazon Q Test Generation', function () {
162175
})
163176
})
164177

165-
for (const { language, filePath } of testFiles) {
166-
// skipping for now since this test is flaky. passes locally, but only half the time in CI
167-
// have tried retries for setupTestDocument, openTextDocument, and showTextDocument
168-
describe.skip(`${language} file`, () => {
178+
for (const { language, filePath, testFilePath } of testFiles) {
179+
describe(`/test on ${language} file`, () => {
169180
beforeEach(async () => {
170181
await waitUntil(async () => await setupTestDocument(filePath, language), {})
171182

@@ -177,7 +188,7 @@ describe('Amazon Q Test Generation', function () {
177188
await tab.waitForChatFinishesLoading()
178189
})
179190

180-
describe('View diff', async () => {
191+
describe('View diff of test file', async () => {
181192
it('Clicks on view diff', async () => {
182193
const chatItems = tab.getChatItems()
183194
const viewDiffMessage = chatItems[5]
@@ -190,7 +201,14 @@ describe('Amazon Q Test Generation', function () {
190201
})
191202
})
192203

193-
describe('Accept code', async () => {
204+
describe('Accept unit tests', async () => {
205+
afterEach(async () => {
206+
// this e2e test generates unit tests, so we want to clean them up after this test is done
207+
await waitUntil(async () => {
208+
await cleanupTestFile(testFilePath)
209+
}, {})
210+
})
211+
194212
it('Clicks on accept', async () => {
195213
await tab.waitForButtons([FollowUpTypes.AcceptCode, FollowUpTypes.RejectCode])
196214
tab.clickButton(FollowUpTypes.AcceptCode)
@@ -204,7 +222,7 @@ describe('Amazon Q Test Generation', function () {
204222
})
205223
})
206224

207-
describe('Reject code', async () => {
225+
describe('Reject unit tests', async () => {
208226
it('Clicks on reject', async () => {
209227
await tab.waitForButtons([FollowUpTypes.AcceptCode, FollowUpTypes.RejectCode])
210228
tab.clickButton(FollowUpTypes.RejectCode)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ import {
3939
SecurityScanTimedOutError,
4040
UploadArtifactToS3Error,
4141
} from '../models/errors'
42-
import { getTelemetryReasonDesc } from '../../shared/errors'
42+
import { getTelemetryReasonDesc, isAwsError } from '../../shared/errors'
4343
import { CodeWhispererSettings } from '../util/codewhispererSettings'
4444
import { detectCommentAboveLine } from '../../shared/utilities/commentUtils'
4545
import { runtimeLanguageContext } from '../util/runtimeLanguageContext'
4646
import { FeatureUseCase } from '../models/constants'
4747
import { UploadTestArtifactToS3Error } from '../../amazonqTest/error'
48+
import { ChatSessionManager } from '../../amazonqTest/chat/storages/chatSession'
4849

4950
export async function listScanResults(
5051
client: DefaultCodeWhispererClient,
@@ -386,6 +387,9 @@ export async function uploadArtifactToS3(
386387
} else {
387388
errorMessage = errorDesc ?? defaultMessage
388389
}
390+
if (isAwsError(error) && featureUseCase === FeatureUseCase.TEST_GENERATION) {
391+
ChatSessionManager.Instance.getSession().startTestGenerationRequestId = error.requestId
392+
}
389393
throw isCodeScan ? new UploadArtifactToS3Error(errorMessage) : new UploadTestArtifactToS3Error(errorMessage)
390394
}
391395
}

packages/core/src/lambda/vue/configEditor/samInvokeBackend.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
AwsSamDebuggerConfiguration,
1414
isCodeTargetProperties,
1515
isTemplateTargetProperties,
16+
TemplateTargetProperties,
1617
} from '../../../shared/sam/debugger/awsSamDebugConfiguration'
1718
import {
1819
DefaultAwsSamDebugConfigurationValidator,
@@ -433,15 +434,19 @@ export async function registerSamDebugInvokeVueCommand(
433434
context: vscode.ExtensionContext,
434435
params: { resource: ResourceNode }
435436
) {
436-
const launchConfig: AwsSamDebuggerConfiguration | undefined = undefined
437437
const resource = params?.resource.resource
438438
const source = 'AppBuilderLocalInvoke'
439+
const launchConfigs = await new LaunchConfiguration(resource.location).getSamDebugConfigurations()
440+
const launchConfig = launchConfigs.find(
441+
(config) => (config.invokeTarget as TemplateTargetProperties).logicalId === resource.resource.Id
442+
)
443+
439444
const webview = new WebviewPanel(context, launchConfig, {
440445
logicalId: resource.resource.Id ?? '',
441446
region: resource.region ?? '',
442447
location: resource.location.fsPath,
443448
handler: resource.resource.Handler!,
444-
runtime: resource.resource.Runtime!,
449+
runtime: launchConfig?.lambda?.runtime ?? resource.resource.Runtime!,
445450
arn: resource.functionArn ?? '',
446451
stackName: resource.stackName ?? '',
447452
environment: resource.resource.Environment,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Math functions
3+
*/
4+
public class Math {
5+
public int add(int a, int b) {
6+
return a + b;
7+
}
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function addNum(num1, num2) {
2+
return num1 + num2;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# adds two numbers
2+
def add(a, b):
3+
return a + b
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function addTwoNums(a: number, b: number): number {
2+
return a + b;
3+
}

packages/core/src/testFixtures/workspaceFolder/testGenFolder/src/test/MathTest.java

Whitespace-only changes.

packages/core/src/testFixtures/workspaceFolder/testGenFolder/src/test/test_math.py

Whitespace-only changes.

0 commit comments

Comments
 (0)