@@ -789,174 +789,6 @@ def execute_input_compliant():
789789 } )
790790 } )
791791
792- describe ( 'generateFix' , function ( ) {
793- let sandbox : sinon . SinonSandbox
794- let mockClient : Stub < DefaultCodeWhispererClient >
795- let startCodeFixGenerationStub : sinon . SinonStub
796- let filePath : string
797- let codeScanIssue : CodeScanIssue
798- let issueItem : IssueItem
799- let updateSecurityIssueWebviewMock : sinon . SinonStub
800- let updateIssueMock : sinon . SinonStub
801- let refreshTreeViewMock : sinon . SinonStub
802- let mockExtContext : ExtContext
803-
804- beforeEach ( async function ( ) {
805- sandbox = sinon . createSandbox ( )
806- mockClient = stub ( DefaultCodeWhispererClient )
807- startCodeFixGenerationStub = sinon . stub ( startCodeFixGeneration , 'startCodeFixGeneration' )
808- filePath = 'dummy/file.py'
809- codeScanIssue = createCodeScanIssue ( {
810- findingId : randomUUID ( ) ,
811- ruleId : 'dummy-rule-id' ,
812- } )
813- issueItem = new IssueItem ( filePath , codeScanIssue )
814- updateSecurityIssueWebviewMock = sinon . stub ( securityIssueWebview , 'updateSecurityIssueWebview' )
815- updateIssueMock = sinon . stub ( SecurityIssueProvider . instance , 'updateIssue' )
816- refreshTreeViewMock = sinon . stub ( SecurityIssueTreeViewProvider . instance , 'refresh' )
817- mockExtContext = await FakeExtensionContext . getFakeExtContext ( )
818- } )
819-
820- afterEach ( function ( ) {
821- sandbox . restore ( )
822- } )
823-
824- it ( 'should call generateFix command successfully' , async function ( ) {
825- startCodeFixGenerationStub . resolves ( {
826- suggestedFix : {
827- codeDiff : 'codeDiff' ,
828- description : 'description' ,
829- references : [ ] ,
830- } ,
831- jobId : 'jobId' ,
832- } )
833-
834- targetCommand = testCommand ( generateFix , mockClient , mockExtContext )
835- await targetCommand . execute ( codeScanIssue , filePath , 'webview' )
836-
837- assert . ok ( updateSecurityIssueWebviewMock . calledWith ( sinon . match ( { isGenerateFixLoading : true } ) ) )
838- assert . ok (
839- startCodeFixGenerationStub . calledWith ( mockClient , codeScanIssue , filePath , codeScanIssue . findingId )
840- )
841-
842- const expectedUpdatedIssue = {
843- ...codeScanIssue ,
844- fixJobId : 'jobId' ,
845- suggestedFixes : [ { code : 'codeDiff' , description : 'description' , references : [ ] } ] ,
846- }
847- assert . ok (
848- updateSecurityIssueWebviewMock . calledWith (
849- sinon . match ( {
850- issue : expectedUpdatedIssue ,
851- isGenerateFixLoading : false ,
852- filePath : filePath ,
853- shouldRefreshView : true ,
854- } )
855- )
856- )
857- assert . ok ( updateIssueMock . calledWith ( expectedUpdatedIssue , filePath ) )
858- assert . ok ( refreshTreeViewMock . calledOnce )
859-
860- assertTelemetry ( 'codewhisperer_codeScanIssueGenerateFix' , {
861- detectorId : codeScanIssue . detectorId ,
862- findingId : codeScanIssue . findingId ,
863- ruleId : codeScanIssue . ruleId ,
864- component : 'webview' ,
865- result : 'Succeeded' ,
866- } )
867- } )
868-
869- it ( 'should call generateFix from tree view item' , async function ( ) {
870- startCodeFixGenerationStub . resolves ( {
871- suggestedFix : {
872- codeDiff : 'codeDiff' ,
873- description : 'description' ,
874- references : [ ] ,
875- } ,
876- jobId : 'jobId' ,
877- } )
878-
879- targetCommand = testCommand ( generateFix , mockClient , mockExtContext )
880- await targetCommand . execute ( issueItem , filePath , 'tree' )
881-
882- assertTelemetry ( 'codewhisperer_codeScanIssueGenerateFix' , {
883- detectorId : codeScanIssue . detectorId ,
884- findingId : codeScanIssue . findingId ,
885- ruleId : codeScanIssue . ruleId ,
886- component : 'tree' ,
887- result : 'Succeeded' ,
888- } )
889- } )
890-
891- it ( 'should call generateFix with refresh=true to indicate fix regenerated' , async function ( ) {
892- startCodeFixGenerationStub . resolves ( {
893- suggestedFix : {
894- codeDiff : 'codeDiff' ,
895- description : 'description' ,
896- references : [ ] ,
897- } ,
898- jobId : 'jobId' ,
899- } )
900-
901- targetCommand = testCommand ( generateFix , mockClient , mockExtContext )
902- await targetCommand . execute ( codeScanIssue , filePath , 'webview' , true )
903-
904- assertTelemetry ( 'codewhisperer_codeScanIssueGenerateFix' , {
905- detectorId : codeScanIssue . detectorId ,
906- findingId : codeScanIssue . findingId ,
907- ruleId : codeScanIssue . ruleId ,
908- component : 'webview' ,
909- result : 'Succeeded' ,
910- variant : 'refresh' ,
911- } )
912- } )
913-
914- it ( 'should handle generateFix error' , async function ( ) {
915- startCodeFixGenerationStub . throws ( new Error ( 'Unexpected error' ) )
916-
917- targetCommand = testCommand ( generateFix , mockClient , mockExtContext )
918- await targetCommand . execute ( codeScanIssue , filePath , 'webview' )
919-
920- assert . ok ( updateSecurityIssueWebviewMock . calledWith ( sinon . match ( { isGenerateFixLoading : true } ) ) )
921- assert . ok (
922- updateSecurityIssueWebviewMock . calledWith (
923- sinon . match ( {
924- issue : codeScanIssue ,
925- isGenerateFixLoading : false ,
926- generateFixError : 'Unexpected error' ,
927- shouldRefreshView : false ,
928- } )
929- )
930- )
931- assert . ok ( updateIssueMock . calledWith ( codeScanIssue , filePath ) )
932- assert . ok ( refreshTreeViewMock . calledOnce )
933-
934- assertTelemetry ( 'codewhisperer_codeScanIssueGenerateFix' , {
935- detectorId : codeScanIssue . detectorId ,
936- findingId : codeScanIssue . findingId ,
937- ruleId : codeScanIssue . ruleId ,
938- component : 'webview' ,
939- result : 'Failed' ,
940- reason : 'Error' ,
941- reasonDesc : 'Unexpected error' ,
942- } )
943- } )
944-
945- it ( 'exits early for SAS findings' , async function ( ) {
946- targetCommand = testCommand ( generateFix , mockClient , mockExtContext )
947- codeScanIssue = createCodeScanIssue ( {
948- ruleId : CodeWhispererConstants . sasRuleId ,
949- } )
950- issueItem = new IssueItem ( filePath , codeScanIssue )
951- await targetCommand . execute ( codeScanIssue , filePath , 'webview' )
952- assert . ok ( updateSecurityIssueWebviewMock . notCalled )
953- assert . ok ( startCodeFixGenerationStub . notCalled )
954- assert . ok ( updateIssueMock . notCalled )
955- assert . ok ( refreshTreeViewMock . notCalled )
956- assertNoTelemetryMatch ( 'codewhisperer_codeScanIssueGenerateFix' )
957- } )
958- } )
959-
960792 describe ( 'rejectFix' , function ( ) {
961793 let mockExtensionContext : vscode . ExtensionContext
962794 let sandbox : sinon . SinonSandbox
0 commit comments