-
Notifications
You must be signed in to change notification settings - Fork 747
feat(amazonq): enable displayFindings tool #7799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9763dd4
feat(amazonq): enable displayFindings tool
blakelaz-amazon e23ebf3
fix(amazonq): handle agentic CodeAnalysisScope
blakelaz-amazon 16043d7
Merge branch 'aws:master' into display-findings-tool
singhAws 0351838
fix(amazonq): Add comment explaining displayFindings feature flag
blakelaz-amazon 78f6572
fix(amazonq): add unit test for new mergeIssuesDisplayFindings method
blakelaz-amazon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| import * as vscode from 'vscode' | ||
| import { AggregatedCodeScanIssue, CodeScanIssue, SuggestedFix } from '../models/model' | ||
| import { randomUUID } from '../../shared/crypto' | ||
| import { displayFindingsDetectorName } from '../models/constants' | ||
|
|
||
| export class SecurityIssueProvider { | ||
| static #instance: SecurityIssueProvider | ||
|
|
@@ -161,6 +162,30 @@ export class SecurityIssueProvider { | |
| ) | ||
| } | ||
|
|
||
| public mergeIssuesDisplayFindings(newIssues: AggregatedCodeScanIssue, fromQCA: boolean) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add tests for this? |
||
| const existingGroup = this._issues.find((group) => group.filePath === newIssues.filePath) | ||
| if (!existingGroup) { | ||
| this._issues.push(newIssues) | ||
| return | ||
| } | ||
|
|
||
| this._issues = this._issues.map((group) => | ||
| group.filePath !== newIssues.filePath | ||
| ? group | ||
| : { | ||
| ...group, | ||
| issues: [ | ||
| ...group.issues.filter( | ||
| // if the incoming findings are from QCA review, then keep only existing findings from displayFindings | ||
| // if the incoming findings are not from QCA review, then keep only the existing QCA findings | ||
| (issue) => fromQCA === (issue.detectorName === displayFindingsDetectorName) | ||
| ), | ||
| ...newIssues.issues, | ||
| ], | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| private isExistingIssue(issue: CodeScanIssue, filePath: string) { | ||
| return this._issues | ||
| .find((group) => group.filePath === filePath) | ||
|
|
||
88 changes: 88 additions & 0 deletions
88
packages/core/src/test/codewhisperer/mergeIssuesDisplayFindings.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import assert from 'assert' | ||
| import { SecurityIssueProvider } from '../../codewhisperer/service/securityIssueProvider' | ||
| import { createCodeScanIssue } from './testUtil' | ||
| import { displayFindingsDetectorName } from '../../codewhisperer/models/constants' | ||
| import { AggregatedCodeScanIssue } from '../../codewhisperer/models/model' | ||
|
|
||
| describe('mergeIssuesDisplayFindings', () => { | ||
| let provider: SecurityIssueProvider | ||
| const testFilePath = '/test/file.py' | ||
|
|
||
| beforeEach(() => { | ||
| provider = Object.create(SecurityIssueProvider.prototype) | ||
| provider.issues = [] | ||
| }) | ||
|
|
||
| it('should add new issues when no existing group', () => { | ||
| const newIssues: AggregatedCodeScanIssue = { | ||
| filePath: testFilePath, | ||
| issues: [createCodeScanIssue({ findingId: 'new-1' })], | ||
| } | ||
|
|
||
| provider.mergeIssuesDisplayFindings(newIssues, true) | ||
|
|
||
| assert.strictEqual(provider.issues.length, 1) | ||
| assert.strictEqual(provider.issues[0].filePath, testFilePath) | ||
| assert.strictEqual(provider.issues[0].issues.length, 1) | ||
| assert.strictEqual(provider.issues[0].issues[0].findingId, 'new-1') | ||
| }) | ||
|
|
||
| it('should keep displayFindings when fromQCA is true', () => { | ||
| provider.issues = [ | ||
| { | ||
| filePath: testFilePath, | ||
| issues: [ | ||
| createCodeScanIssue({ findingId: 'qca-1', detectorName: 'QCA-detector' }), | ||
| createCodeScanIssue({ findingId: 'display-1', detectorName: displayFindingsDetectorName }), | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| const newIssues: AggregatedCodeScanIssue = { | ||
| filePath: testFilePath, | ||
| issues: [createCodeScanIssue({ findingId: 'new-qca-1', detectorName: 'QCA-detector' })], | ||
| } | ||
|
|
||
| provider.mergeIssuesDisplayFindings(newIssues, true) | ||
|
|
||
| assert.strictEqual(provider.issues.length, 1) | ||
| assert.strictEqual(provider.issues[0].issues.length, 2) | ||
|
|
||
| const findingIds = provider.issues[0].issues.map((issue) => issue.findingId) | ||
| assert.ok(findingIds.includes('display-1')) | ||
| assert.ok(findingIds.includes('new-qca-1')) | ||
| assert.ok(!findingIds.includes('qca-1')) | ||
| }) | ||
|
|
||
| it('should keep QCA findings when fromQCA is false', () => { | ||
| provider.issues = [ | ||
| { | ||
| filePath: testFilePath, | ||
| issues: [ | ||
| createCodeScanIssue({ findingId: 'qca-1', detectorName: 'QCA-detector' }), | ||
| createCodeScanIssue({ findingId: 'display-1', detectorName: displayFindingsDetectorName }), | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| const newIssues: AggregatedCodeScanIssue = { | ||
| filePath: testFilePath, | ||
| issues: [createCodeScanIssue({ findingId: 'new-display-1', detectorName: displayFindingsDetectorName })], | ||
| } | ||
|
|
||
| provider.mergeIssuesDisplayFindings(newIssues, false) | ||
|
|
||
| assert.strictEqual(provider.issues.length, 1) | ||
| assert.strictEqual(provider.issues[0].issues.length, 2) | ||
|
|
||
| const findingIds = provider.issues[0].issues.map((issue) => issue.findingId) | ||
| assert.ok(findingIds.includes('qca-1')) | ||
| assert.ok(findingIds.includes('new-display-1')) | ||
| assert.ok(!findingIds.includes('display-1')) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.