Skip to content

Commit 71650e5

Browse files
authored
Merge pull request #6681 from ashishrp-aws/payloadManifest
fix(amazonq): /test file collection usecase adds more patterns to filtering.
2 parents 2c2bdce + 2932fa1 commit 71650e5

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

packages/core/src/codewhisperer/models/constants.ts

+25
Original file line numberDiff line numberDiff line change
@@ -896,3 +896,28 @@ export enum SecurityScanStep {
896896
}
897897

898898
export const amazonqCodeIssueDetailsTabTitle = 'Code Issue Details'
899+
900+
export const testGenExcludePatterns = [
901+
'**/annotation-generated-src/*',
902+
'**/annotation-generated-tst/*',
903+
'**/build/*',
904+
'**/env/*',
905+
'**/release-info/*',
906+
'**/*.jar',
907+
'**/*.exe',
908+
'**/*.a',
909+
'**/*.map',
910+
'**/*.graph',
911+
'**/*.so',
912+
'**/*.csv',
913+
'**/*.dylib',
914+
'**/*.parquet',
915+
'**/*.xlsx',
916+
'**/*.tar.gz',
917+
'**/*.tar',
918+
'**/*.pack',
919+
'**/*.pkg',
920+
'**/*.pkl',
921+
'**/*.deb',
922+
'**/*.model',
923+
]

packages/core/src/codewhisperer/util/zipUtil.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { fs } from '../../shared/fs/fs'
1313
import { getLoggerForScope } from '../service/securityScanHandler'
1414
import { runtimeLanguageContext } from './runtimeLanguageContext'
1515
import { CodewhispererLanguage } from '../../shared/telemetry/telemetry.gen'
16-
import { CurrentWsFolders, collectFiles } from '../../shared/utilities/workspaceUtils'
16+
import { CurrentWsFolders, collectFiles, defaultExcludePatterns } from '../../shared/utilities/workspaceUtils'
1717
import {
1818
FileSizeExceededError,
1919
NoActiveFileError,
@@ -412,11 +412,18 @@ export class ZipUtil {
412412

413413
const sourceFiles = await collectFiles(
414414
projectPaths,
415-
vscode.workspace.workspaceFolders as CurrentWsFolders,
415+
(useCase === FeatureUseCase.TEST_GENERATION
416+
? [...(vscode.workspace.workspaceFolders ?? [])].sort(
417+
(a, b) => b.uri.fsPath.length - a.uri.fsPath.length
418+
)
419+
: vscode.workspace.workspaceFolders) as CurrentWsFolders,
416420
{
417421
maxSizeBytes: this.getProjectScanPayloadSizeLimitInBytes(),
418-
},
419-
useCase
422+
excludePatterns:
423+
useCase === FeatureUseCase.TEST_GENERATION
424+
? [...CodeWhispererConstants.testGenExcludePatterns, ...defaultExcludePatterns]
425+
: defaultExcludePatterns,
426+
}
420427
)
421428
for (const file of sourceFiles) {
422429
const projectName = path.basename(file.workspaceFolder.uri.fsPath)

packages/core/src/shared/utilities/workspaceUtils.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import fs from '../fs/fs'
2020
import { ChildProcess } from './processUtils'
2121
import { isWin } from '../vscode/env'
2222
import { maxRepoSizeBytes } from '../../amazonqFeatureDev/constants'
23-
import { FeatureUseCase } from '../../codewhisperer/models/constants'
2423

2524
type GitIgnoreRelativeAcceptor = {
2625
folderPath: string
@@ -224,18 +223,12 @@ export function getWorkspaceRelativePath(
224223
workspaceFolders?: readonly vscode.WorkspaceFolder[]
225224
} = {
226225
workspaceFolders: vscode.workspace.workspaceFolders,
227-
},
228-
useCase?: FeatureUseCase
226+
}
229227
): { relativePath: string; workspaceFolder: vscode.WorkspaceFolder } | undefined {
230228
if (!override.workspaceFolders) {
231229
return
232230
}
233-
let folders = override.workspaceFolders
234-
if (useCase && useCase === FeatureUseCase.TEST_GENERATION) {
235-
// Sort workspace folders by path length (descending) to prioritize deeper paths
236-
// TODO: Need to enable this for entire Q
237-
folders = [...override.workspaceFolders].sort((a, b) => b.uri.fsPath.length - a.uri.fsPath.length)
238-
}
231+
const folders = override.workspaceFolders
239232

240233
for (const folder of folders) {
241234
if (isInDirectory(folder.uri.fsPath, childPath)) {
@@ -361,8 +354,7 @@ export async function collectFiles(
361354
excludeByGitIgnore?: boolean // default true
362355
excludePatterns?: string[] // default defaultExcludePatterns
363356
filterFn?: CollectFilesFilter
364-
},
365-
useCase?: FeatureUseCase
357+
}
366358
): Promise<CollectFilesResultItem[]> {
367359
const storage: Awaited<CollectFilesResultItem[]> = []
368360

@@ -408,7 +400,7 @@ export async function collectFiles(
408400
const files = excludeByGitIgnore ? await filterOutGitignoredFiles(rootPath, allFiles, false) : allFiles
409401

410402
for (const file of files) {
411-
const relativePath = getWorkspaceRelativePath(file.fsPath, { workspaceFolders }, useCase)
403+
const relativePath = getWorkspaceRelativePath(file.fsPath, { workspaceFolders })
412404
if (!relativePath) {
413405
continue
414406
}

0 commit comments

Comments
 (0)