@@ -635,6 +635,7 @@ const singleLanguageMatrix = JSON.stringify({
635635} ) ;
636636
637637async function mockRiskAssessmentEnv ( matrix : string ) {
638+ process . env [ EnvVar . ANALYZE_DID_COMPLETE_SUCCESSFULLY ] = "false" ;
638639 process . env [ "GITHUB_JOB" ] = "analyze" ;
639640 process . env [ "GITHUB_REPOSITORY" ] = "github/codeql-action-fake-repository" ;
640641 process . env [ "GITHUB_WORKSPACE" ] =
@@ -645,8 +646,12 @@ async function mockRiskAssessmentEnv(matrix: string) {
645646 . resolves ( { type : util . GitHubVariant . GHES , version : "3.0.0" } ) ;
646647
647648 const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
648- sinon . stub ( codeqlObject , "databaseExportDiagnostics" ) . resolves ( ) ;
649- sinon . stub ( codeqlObject , "diagnosticsExport" ) . resolves ( ) ;
649+ const databaseExportDiagnostics = sinon
650+ . stub ( codeqlObject , "databaseExportDiagnostics" )
651+ . resolves ( ) ;
652+ const diagnosticsExport = sinon
653+ . stub ( codeqlObject , "diagnosticsExport" )
654+ . resolves ( ) ;
650655
651656 sinon . stub ( codeql , "getCodeQL" ) . resolves ( codeqlObject ) ;
652657
@@ -658,12 +663,13 @@ async function mockRiskAssessmentEnv(matrix: string) {
658663 . stub ( debugArtifacts , "getArtifactUploaderClient" )
659664 . value ( ( ) => artifactClient ) ;
660665
661- return [ uploadArtifact ] ;
666+ return { uploadArtifact, databaseExportDiagnostics , diagnosticsExport } ;
662667}
663668
664- test ( "tryUploadSarifIfRunFailed - uploads as artifact for risk assessments" , async ( t ) => {
669+ test ( "tryUploadSarifIfRunFailed - uploads as artifact for risk assessments (diagnosticsExport) " , async ( t ) => {
665670 const logger = new RecordingLogger ( ) ;
666- const [ uploadArtifact ] = await mockRiskAssessmentEnv ( singleLanguageMatrix ) ;
671+ const { uploadArtifact, databaseExportDiagnostics, diagnosticsExport } =
672+ await mockRiskAssessmentEnv ( singleLanguageMatrix ) ;
667673
668674 const config = createTestConfig ( {
669675 analysisKinds : [ AnalysisKind . RiskAssessment ] ,
@@ -682,16 +688,70 @@ test("tryUploadSarifIfRunFailed - uploads as artifact for risk assessments", asy
682688 const expectedName = debugArtifacts . sanitizeArtifactName (
683689 `sarif-artifact-${ debugArtifacts . getArtifactSuffix ( singleLanguageMatrix ) } ` ,
684690 ) ;
691+ const expectedFilePattern = / c o d e q l - f a i l e d - s a r i f - j a v a s c r i p t \. c s r a \. s a r i f $ / ;
685692 t . is ( result . upload_failed_run_skipped_because , undefined ) ;
686693 t . is ( result . upload_failed_run_error , undefined ) ;
687694 t . is ( result . sarifID , expectedName ) ;
688695 t . assert (
689696 uploadArtifact . calledOnceWith (
690697 expectedName ,
691- sinon . match . array ,
698+ [ sinon . match ( expectedFilePattern ) ] ,
692699 sinon . match . string ,
693700 ) ,
694701 ) ;
702+ t . assert ( databaseExportDiagnostics . notCalled ) ;
703+ t . assert (
704+ diagnosticsExport . calledOnceWith (
705+ sinon . match ( expectedFilePattern ) ,
706+ "/language:javascript" ,
707+ config ,
708+ ) ,
709+ ) ;
710+ } ) ;
711+
712+ test ( "tryUploadSarifIfRunFailed - uploads as artifact for risk assessments (databaseExportDiagnostics)" , async ( t ) => {
713+ const logger = new RecordingLogger ( ) ;
714+ const { uploadArtifact, databaseExportDiagnostics, diagnosticsExport } =
715+ await mockRiskAssessmentEnv ( singleLanguageMatrix ) ;
716+
717+ const dbLocation = "/some/path" ;
718+ const config = createTestConfig ( {
719+ analysisKinds : [ AnalysisKind . RiskAssessment ] ,
720+ codeQLCmd : "codeql-for-testing" ,
721+ languages : [ "javascript" ] ,
722+ dbLocation : "/some/path" ,
723+ } ) ;
724+ const features = createFeatures ( [ Feature . ExportDiagnosticsEnabled ] ) ;
725+
726+ const result = await initActionPostHelper . tryUploadSarifIfRunFailed (
727+ config ,
728+ parseRepositoryNwo ( "github/codeql-action-fake-repository" ) ,
729+ features ,
730+ logger ,
731+ ) ;
732+
733+ const expectedName = debugArtifacts . sanitizeArtifactName (
734+ `sarif-artifact-${ debugArtifacts . getArtifactSuffix ( singleLanguageMatrix ) } ` ,
735+ ) ;
736+ const expectedFilePattern = / c o d e q l - f a i l e d - s a r i f - j a v a s c r i p t \. c s r a \. s a r i f $ / ;
737+ t . is ( result . upload_failed_run_skipped_because , undefined ) ;
738+ t . is ( result . upload_failed_run_error , undefined ) ;
739+ t . is ( result . sarifID , expectedName ) ;
740+ t . assert (
741+ uploadArtifact . calledOnceWith (
742+ expectedName ,
743+ [ sinon . match ( expectedFilePattern ) ] ,
744+ sinon . match . string ,
745+ ) ,
746+ ) ;
747+ t . assert ( diagnosticsExport . notCalled ) ;
748+ t . assert (
749+ databaseExportDiagnostics . calledOnceWith (
750+ dbLocation ,
751+ sinon . match ( expectedFilePattern ) ,
752+ "/language:javascript" ,
753+ ) ,
754+ ) ;
695755} ) ;
696756
697757const skippedUploadTest = test . macro ( {
@@ -701,7 +761,8 @@ const skippedUploadTest = test.macro({
701761 expectedSkippedReason : string ,
702762 ) => {
703763 const logger = new RecordingLogger ( ) ;
704- const [ uploadArtifact ] = await mockRiskAssessmentEnv ( singleLanguageMatrix ) ;
764+ const { uploadArtifact, diagnosticsExport } =
765+ await mockRiskAssessmentEnv ( singleLanguageMatrix ) ;
705766 const features = createFeatures ( [ ] ) ;
706767
707768 const result = await initActionPostHelper . tryUploadSarifIfRunFailed (
@@ -713,6 +774,7 @@ const skippedUploadTest = test.macro({
713774
714775 t . is ( result . upload_failed_run_skipped_because , expectedSkippedReason ) ;
715776 t . assert ( uploadArtifact . notCalled ) ;
777+ t . assert ( diagnosticsExport . notCalled ) ;
716778 } ,
717779
718780 title : ( providedTitle : string = "" ) =>
0 commit comments