@@ -25,7 +25,7 @@ import {
2525} from "./debug-artifacts" ;
2626import * as dependencyCaching from "./dependency-caching" ;
2727import { getTempDiagnosticPath } from "./diagnostics" ;
28- import { EnvVar , ReadOnlyEnv } from "./environment" ;
28+ import { EnvVar , isInTestMode , ReadOnlyEnv } from "./environment" ;
2929import { Feature , FeatureEnablement } from "./feature-flags" ;
3030import { Logger } from "./logging" ;
3131import { OverlayDatabaseMode } from "./overlay/overlay-database-mode" ;
@@ -253,6 +253,19 @@ async function maybeUploadFailedSarif(
253253 logger ,
254254 { isUnsuccessfulExecution : true } ,
255255 ) ;
256+
257+ // If we are in test mode, `uploadFiles` will not have uploaded the failed SARIF file
258+ // and instead will have written it to disk. Upload it as a workflow artifact so that
259+ // we can inspect it in validation jobs.
260+ if ( uploadResult . sarifID && isInTestMode ( ) ) {
261+ await uploadSarifArtifact ( logger , "test-mode-sarif" , {
262+ // We defaulted to CodeScanning in the `uploadFiles` call above.
263+ sarifFile : uploadLib . getSavedPayloadPath ( CodeScanning . kind ) ,
264+ category : failedSarif . category ,
265+ checkoutPath : failedSarif . checkoutPath ,
266+ } ) ;
267+ }
268+
256269 return uploadResult
257270 ? { ...uploadResult . statusReport , sarifID : uploadResult . sarifID }
258271 : { } ;
@@ -271,7 +284,15 @@ async function maybeUploadFailedSarifArtifact(
271284 }
272285
273286 const failedSarif = failedSarifResult . value ;
287+ return uploadSarifArtifact ( logger , "sarif-artifact" , failedSarif ) ;
288+ }
274289
290+ /** Uploads a failed SARIF file as workflow artifact. */
291+ async function uploadSarifArtifact (
292+ logger : Logger ,
293+ prefix : string ,
294+ failedSarif : FailedSarifInfo ,
295+ ) : Promise < UploadFailedSarifResult > {
275296 logger . info (
276297 `Uploading failed SARIF file ${ failedSarif . sarifFile } as artifact` ,
277298 ) ;
@@ -280,7 +301,7 @@ async function maybeUploadFailedSarifArtifact(
280301 const client = await getArtifactUploaderClient ( logger , gitHubVersion . type ) ;
281302
282303 const suffix = getArtifactSuffix ( actionsUtil . getOptionalInput ( "matrix" ) ) ;
283- const name = sanitizeArtifactName ( `sarif-artifact -${ suffix } ` ) ;
304+ const name = sanitizeArtifactName ( `${ prefix } -${ suffix } ` ) ;
284305 await client . uploadArtifact (
285306 name ,
286307 [ path . normalize ( failedSarif . sarifFile ) ] ,
0 commit comments