Skip to content

Commit 5d26f9a

Browse files
authored
fix(amazonq): Prevent adding same file twice for /doc and /dev (aws#6568)
## Problem Stuck on "Uploading code..." for /dev and /doc in a multi-root workspace with the same file paths in it multiple times. ## Solution Add a check to prevent same file from being added to archive twice Fixes issue aws#6566 --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent c892f7f commit 5d26f9a

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed
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+
}

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

0 commit comments

Comments
 (0)