Skip to content

Commit 26483bf

Browse files
committed
Merge branch 'master' of github.com:leigaol/aws-toolkit-vscode into internal_falcon_release
2 parents eb6bbcb + d1758c2 commit 26483bf

File tree

20 files changed

+180
-67
lines changed

20 files changed

+180
-67
lines changed

buildspec/release/80notify.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: 0.2
2+
3+
phases:
4+
install:
5+
runtime-versions:
6+
nodejs: 20
7+
8+
pre_build:
9+
commands:
10+
# Check for implicit env vars passed from the release pipeline.
11+
- test -n "${NOTIFY_URL}"
12+
- test -n "${TARGET_EXTENSION}"
13+
14+
build:
15+
commands:
16+
- echo "TARGET_EXTENSION=${TARGET_EXTENSION}"
17+
- EXTENSION_NAME=$([ "$TARGET_EXTENSION" = "amazonq" ] && echo "Amazon Q" || echo "AWS Toolkit")
18+
- VERSION=$(node -e "console.log(require('./packages/${TARGET_EXTENSION}/package.json').version);")
19+
- CHANGELOG=$(cat packages/${TARGET_EXTENSION}/CHANGELOG.md | perl -ne 'BEGIN{$/="\n\n"} print if $. == 2')
20+
- MESSAGE=$(envsubst < "$GITHUB_WORKSPACE/buildspec/release/notify.txt")
21+
- DATA="{'Content':'${MESSAGE}'}"
22+
- |
23+
# TODO: Enable for prod only after testing
24+
if [ "$STAGE" = "prod" ]; then
25+
echo "SKIPPED (stage=${STAGE}): 'curl -v POST \"[SLACK_URL]\" -H \"Content-Type:application/json\" --data $DATA'"
26+
exit 0
27+
fi
28+
curl -v POST "${NOTIFY_URL}" -H "Content-Type:application/json" --data $DATA

buildspec/release/notify.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Released ${EXTENSION_NAME} v${VERSION} for VSCode
2+
3+
${CHANGELOG}
4+
5+
Changelog: https://github.com/aws/aws-toolkit-vscode/blob/master/packages/${TARGET_EXTENSION}/CHANGELOG.md
6+
Release Arifact: https://github.com/aws/aws-toolkit-vscode/releases/tag/${TARGET_EXTENSION}/v${VERSION}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "/dev and /doc: Multi-root workspace with duplicate files causes infinite 'Uploading code...' loop"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "/transform: allow View Summary button to work even after accepting diff"
4+
}

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/amazonq/test/unit/amazonqFeatureDev/util/files.test.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { fs, AmazonqCreateUpload, ZipStream } from 'aws-core-vscode/shared'
1515
import { MetricName, Span } from 'aws-core-vscode/telemetry'
1616
import sinon from 'sinon'
1717
import { CodeWhispererSettings } from 'aws-core-vscode/codewhisperer'
18+
import { CurrentWsFolders } from 'aws-core-vscode/amazonq'
19+
import path from 'path'
1820

1921
const testDevfilePrepareRepo = async (devfileEnabled: boolean) => {
2022
const files: Record<string, string> = {
@@ -44,19 +46,24 @@ const testDevfilePrepareRepo = async (devfileEnabled: boolean) => {
4446
.stub(CodeWhispererSettings.instance, 'getAutoBuildSetting')
4547
.returns(devfileEnabled ? { [workspace.uri.fsPath]: true } : {})
4648

47-
await testPrepareRepoData(workspace, expectedFiles)
49+
await testPrepareRepoData([workspace], expectedFiles)
4850
}
4951

5052
const testPrepareRepoData = async (
51-
workspace: vscode.WorkspaceFolder,
53+
workspaces: vscode.WorkspaceFolder[],
5254
expectedFiles: string[],
5355
expectedTelemetryMetrics?: Array<{ metricName: MetricName; value: any }>
5456
) => {
5557
expectedFiles.sort((a, b) => a.localeCompare(b))
5658
const telemetry = new TelemetryHelper()
57-
const result = await prepareRepoData([workspace.uri.fsPath], [workspace], telemetry, {
58-
record: () => {},
59-
} as unknown as Span<AmazonqCreateUpload>)
59+
const result = await prepareRepoData(
60+
workspaces.map((ws) => ws.uri.fsPath),
61+
workspaces as CurrentWsFolders,
62+
telemetry,
63+
{
64+
record: () => {},
65+
} as unknown as Span<AmazonqCreateUpload>
66+
)
6067

6168
assert.strictEqual(Buffer.isBuffer(result.zipFileBuffer), true)
6269
// checksum is not the same across different test executions because some unique random folder names are generated
@@ -87,7 +94,7 @@ describe('file utils', () => {
8794
await folder.write('file2.md', 'test content')
8895
const workspace = getWorkspaceFolder(folder.path)
8996

90-
await testPrepareRepoData(workspace, ['file1.md', 'file2.md'])
97+
await testPrepareRepoData([workspace], ['file1.md', 'file2.md'])
9198
})
9299

93100
it('prepareRepoData ignores denied file extensions', async function () {
@@ -96,7 +103,7 @@ describe('file utils', () => {
96103
const workspace = getWorkspaceFolder(folder.path)
97104

98105
await testPrepareRepoData(
99-
workspace,
106+
[workspace],
100107
[],
101108
[{ metricName: 'amazonq_bundleExtensionIgnored', value: { filenameExt: 'mp4', count: 1 } }]
102109
)
@@ -126,5 +133,18 @@ describe('file utils', () => {
126133
ContentLengthError
127134
)
128135
})
136+
137+
it('prepareRepoData properly handles multi-root workspaces', async function () {
138+
const folder = await TestFolder.create()
139+
const testFilePath = 'innerFolder/file.md'
140+
await folder.write(testFilePath, 'test content')
141+
142+
// Add a folder and its subfolder to the workspace
143+
const workspace1 = getWorkspaceFolder(folder.path)
144+
const workspace2 = getWorkspaceFolder(folder.path + '/innerFolder')
145+
const folderName = path.basename(folder.path)
146+
147+
await testPrepareRepoData([workspace1, workspace2], [`${folderName}_${workspace1.name}/${testFilePath}`])
148+
})
129149
})
130150
})

packages/core/src/amazonq/util/files.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ export async function prepareRepoData(
4848

4949
let totalBytes = 0
5050
const ignoredExtensionMap = new Map<string, number>()
51+
const addedFilePaths = new Set()
5152

5253
for (const file of files) {
54+
if (addedFilePaths.has(file.zipFilePath)) {
55+
continue
56+
}
57+
addedFilePaths.add(file.zipFilePath)
58+
5359
let fileSize
5460
try {
5561
fileSize = (await fs.stat(file.fileUri)).size

packages/core/src/amazonq/webview/ui/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ export const createMynahUI = (
639639
mynahUI.addChatItem(tabID, {
640640
type: ChatItemType.ANSWER_STREAM,
641641
})
642-
} else if (tabType === 'gumby') {
642+
} else if (tabType === 'gumby' || tabType === 'testgen') {
643643
connector.requestAnswer(tabID, {
644644
chatMessage: prompt.prompt ?? '',
645645
})

0 commit comments

Comments
 (0)