@@ -11,8 +11,14 @@ import sinon from 'sinon'
1111import { Messenger } from './framework/messenger'
1212import { registerAuthHook , using , closeAllEditors } from 'aws-core-vscode/test'
1313import { loginToIdC } from './utils/setup'
14- import { codewhispererDiagnosticSourceLabel } from 'aws-core-vscode/codewhisperer'
14+ import {
15+ codewhispererDiagnosticSourceLabel ,
16+ invalidFileTypeChatMessage ,
17+ CodeAnalysisScope ,
18+ SecurityScanStep ,
19+ } from 'aws-core-vscode/codewhisperer'
1520import path from 'path'
21+ import { ScanAction , scanProgressMessage } from '../../../src/app/amazonqScan/models/constants'
1622
1723function getWorkspaceFolder ( ) : string {
1824 return (
@@ -119,7 +125,6 @@ describe('Amazon Q Code Review', function () {
119125 } )
120126
121127 describe ( 'Quick action availability' , ( ) => {
122- console . log ( 'running this test' )
123128 it ( 'Shows /review when code review is enabled' , async ( ) => {
124129 const command = tab . findCommand ( '/review' )
125130 if ( ! command . length ) {
@@ -161,15 +166,12 @@ describe('Amazon Q Code Review', function () {
161166 it ( 'Shows appropriate message when no file is open' , async ( ) => {
162167 await validateInitialChatMessage ( )
163168
164- tab . clickButton ( 'runFileScan' )
169+ tab . clickButton ( ScanAction . RUN_FILE_SCAN )
165170
166171 await waitForChatItems ( 5 )
167172 const noFileMessage = tab . getChatItems ( ) [ 5 ]
168173 assert . deepStrictEqual ( noFileMessage . type , 'answer' )
169- assert . deepStrictEqual (
170- noFileMessage . body ,
171- 'Sorry, your current active window is not a source code file. Make sure you select a source file as your primary context.'
172- )
174+ assert . deepStrictEqual ( noFileMessage . body , invalidFileTypeChatMessage )
173175 } )
174176 } )
175177
@@ -186,61 +188,41 @@ describe('Amazon Q Code Review', function () {
186188 const document = await vscode . workspace . openTextDocument ( filePath )
187189 await vscode . window . showTextDocument ( document )
188190
189- tab . clickButton ( 'runFileScan' )
191+ tab . clickButton ( ScanAction . RUN_FILE_SCAN )
190192
191193 await waitForChatItems ( 6 )
192194 const scanningInProgressMessage = tab . getChatItems ( ) [ 6 ]
193195 assert . deepStrictEqual (
194196 scanningInProgressMessage . body ,
195- "Okay, I'm reviewing `ProblematicCode.java` for code issues.\n\nThis may take a few minutes. I'll share my progress here.\n\n☐ Initiating code review\n\n☐ Reviewing your code \n\n☐ Processing review results \n"
197+ scanProgressMessage ( SecurityScanStep . CREATE_SCAN_JOB , CodeAnalysisScope . FILE_ON_DEMAND , fileName )
196198 )
197199
198200 const scanResultBody = await waitForReviewResults ( tab )
199201
200202 const issues = extractAndValidateIssues ( scanResultBody )
201203 assert . deepStrictEqual (
202- issues . Critical >= 3 ,
204+ issues . Critical >= 1 ,
203205 true ,
204- `critical issue ${ issues . Critical } is not larger than 2 `
206+ `critical issue ${ issues . Critical } is not larger or equal to 1 `
205207 )
206- assert . deepStrictEqual ( issues . High >= 2 , true , `high issue ${ issues . High } is not larger than 1` )
207- assert . deepStrictEqual ( issues . Medium >= 6 , true , `medium issue ${ issues . Medium } is not larger than 5` )
208- assert . deepStrictEqual ( issues . Low , 0 , `low issues ${ issues . Low } should be 0` )
209- assert . deepStrictEqual ( issues . Info , 0 , `info issues ${ issues . Info } should be 0` )
210208
211209 const uri = vscode . Uri . file ( filePath )
212210 const securityDiagnostics : vscode . Diagnostic [ ] = vscode . languages
213211 . getDiagnostics ( uri )
214212 . filter ( ( diagnostic ) => diagnostic . source === codewhispererDiagnosticSourceLabel )
215213
216- // 3 exact critical issue matches
217- hasExactlyMatchingSecurityDiagnostic (
218- securityDiagnostics ,
219- 'multilanguage-password' ,
220- 'CWE-798 - Hardcoded credentials' ,
221- 10 ,
222- 11
223- )
224-
214+ // 1 exact critical issue matches
225215 hasExactlyMatchingSecurityDiagnostic (
226216 securityDiagnostics ,
227217 'java-do-not-hardcode-database-password' ,
228218 'CWE-798 - Hardcoded credentials' ,
229219 20 ,
230220 21
231221 )
232-
233- hasExactlyMatchingSecurityDiagnostic (
234- securityDiagnostics ,
235- 'java-crypto-compliance' ,
236- 'CWE-327,328,326,208,1240 - Insecure cryptography' ,
237- 55 ,
238- 56
239- )
240222 } )
241223
242224 it ( '/review project gives findings' , async ( ) => {
243- tab . clickButton ( 'runProjectScan' )
225+ tab . clickButton ( ScanAction . RUN_PROJECT_SCAN )
244226
245227 const scanResultBody = await waitForReviewResults ( tab )
246228 extractAndValidateIssues ( scanResultBody )
@@ -261,19 +243,19 @@ describe('Amazon Q Code Review', function () {
261243 const editor = vscode . window . activeTextEditor
262244
263245 if ( editor ) {
264- const position = new vscode . Position ( 55 , 0 )
246+ const position = new vscode . Position ( 20 , 0 )
265247 await editor . edit ( ( editBuilder ) => {
266248 editBuilder . insert ( position , '// amazonq-ignore-next-line\n' )
267249 } )
268250 }
269251 } )
270252
271253 it ( '/review file respect ignored line findings' , async ( ) => {
272- tab . clickButton ( 'runFileScan' )
254+ tab . clickButton ( ScanAction . RUN_FILE_SCAN )
273255 } )
274256
275257 it ( '/review project respect ignored line findings' , async ( ) => {
276- tab . clickButton ( 'runProjectScan' )
258+ tab . clickButton ( ScanAction . RUN_PROJECT_SCAN )
277259 } )
278260
279261 afterEach ( async ( ) => {
@@ -287,17 +269,17 @@ describe('Amazon Q Code Review', function () {
287269 // cannot find this ignored issue
288270 hasExactlyMatchingSecurityDiagnostic (
289271 securityDiagnostics ,
290- 'java-crypto-compliance ' ,
291- 'CWE-327,328,326,208,1240 - Insecure cryptography ' ,
292- 56 ,
293- 57 ,
272+ 'java-do-not-hardcode-database-password ' ,
273+ 'CWE-798 - Hardcoded credentials ' ,
274+ 21 ,
275+ 22 ,
294276 0
295277 )
296278
297279 const editor = vscode . window . activeTextEditor
298280 if ( editor ) {
299281 await editor . edit ( ( editBuilder ) => {
300- const lineRange = editor . document . lineAt ( 55 ) . rangeIncludingLineBreak
282+ const lineRange = editor . document . lineAt ( 20 ) . rangeIncludingLineBreak
301283 editBuilder . delete ( lineRange )
302284 } )
303285 }
0 commit comments