@@ -15,6 +15,7 @@ import { getRunnerLogger } from "./logging";
1515import { OverlayDatabaseMode } from "./overlay/overlay-database-mode" ;
1616import * as overlayStatus from "./overlay/status" ;
1717import { parseRepositoryNwo } from "./repository" ;
18+ import { JobStatus } from "./status-report" ;
1819import {
1920 createFeatures ,
2021 createTestConfig ,
@@ -58,6 +59,7 @@ test.serial("init-post action with debug mode off", async (t) => {
5859 createTestConfig ( { debugMode : false } ) ,
5960 parseRepositoryNwo ( "github/codeql-action" ) ,
6061 createFeatures ( [ ] ) ,
62+ "success" ,
6163 getRunnerLogger ( true ) ,
6264 ) ;
6365
@@ -80,6 +82,7 @@ test.serial("init-post action with debug mode on", async (t) => {
8082 createTestConfig ( { debugMode : true } ) ,
8183 parseRepositoryNwo ( "github/codeql-action" ) ,
8284 createFeatures ( [ ] ) ,
85+ "success" ,
8386 getRunnerLogger ( true ) ,
8487 ) ;
8588
@@ -375,6 +378,7 @@ test.serial(
375378 } ) ,
376379 parseRepositoryNwo ( "github/codeql-action" ) ,
377380 createFeatures ( [ Feature . OverlayAnalysisStatusSave ] ) ,
381+ "success" ,
378382 getRunnerLogger ( true ) ,
379383 ) ;
380384
@@ -443,6 +447,7 @@ test.serial(
443447 } ) ,
444448 parseRepositoryNwo ( "github/codeql-action" ) ,
445449 createFeatures ( [ ] ) ,
450+ "success" ,
446451 getRunnerLogger ( true ) ,
447452 ) ;
448453
@@ -480,6 +485,7 @@ test.serial("does not save overlay status when build successful", async (t) => {
480485 } ) ,
481486 parseRepositoryNwo ( "github/codeql-action" ) ,
482487 createFeatures ( [ Feature . OverlayAnalysisStatusSave ] ) ,
488+ "success" ,
483489 getRunnerLogger ( true ) ,
484490 ) ;
485491
@@ -517,6 +523,7 @@ test.serial(
517523 } ) ,
518524 parseRepositoryNwo ( "github/codeql-action" ) ,
519525 createFeatures ( [ ] ) ,
526+ "success" ,
520527 getRunnerLogger ( true ) ,
521528 ) ;
522529
@@ -528,6 +535,94 @@ test.serial(
528535 } ,
529536) ;
530537
538+ /**
539+ * Runs `uploadFailureInfo` for an overlay-base job that did not complete successfully, for a job
540+ * that the Actions runtime environment reports as cancelled.
541+ */
542+ async function testCancelledOverlayJob ( {
543+ jobStatus = "cancelled" ,
544+ codeQlReportedError = false ,
545+ } : {
546+ jobStatus ?: string ;
547+ codeQlReportedError ?: boolean ;
548+ } = { } ) {
549+ return await util . withTmpDir ( async ( tmpDir ) => {
550+ setupActionsVars ( tmpDir , tmpDir ) ;
551+ delete process . env [ EnvVar . ANALYZE_DID_COMPLETE_SUCCESSFULLY ] ;
552+ if ( codeQlReportedError ) {
553+ process . env [ EnvVar . JOB_STATUS ] = JobStatus . FailureStatus ;
554+ } else {
555+ delete process . env [ EnvVar . JOB_STATUS ] ;
556+ }
557+
558+ sinon . stub ( util , "checkDiskUsage" ) . resolves ( {
559+ numAvailableBytes : 100 * NUM_BYTES_PER_GIB ,
560+ numTotalBytes : 200 * NUM_BYTES_PER_GIB ,
561+ } ) ;
562+
563+ const saveOverlayStatusStub = sinon
564+ . stub ( overlayStatus , "saveOverlayStatus" )
565+ . resolves ( true ) ;
566+
567+ await initActionPostHelper . uploadFailureInfo (
568+ sinon . spy ( ) ,
569+ sinon . spy ( ) ,
570+ codeql . createStubCodeQL ( { } ) ,
571+ createTestConfig ( {
572+ debugMode : false ,
573+ languages : [ "javascript" ] ,
574+ overlayDatabaseMode : OverlayDatabaseMode . OverlayBase ,
575+ } ) ,
576+ parseRepositoryNwo ( "github/codeql-action" ) ,
577+ createFeatures ( [ Feature . OverlayAnalysisStatusSave ] ) ,
578+ jobStatus ,
579+ getRunnerLogger ( true ) ,
580+ ) ;
581+
582+ return { saveOverlayStatusStub } ;
583+ } ) ;
584+ }
585+
586+ test . serial (
587+ "does not save overlay status when the job was cancelled" ,
588+ async ( t ) => {
589+ const { saveOverlayStatusStub } = await testCancelledOverlayJob ( ) ;
590+
591+ t . true (
592+ saveOverlayStatusStub . notCalled ,
593+ "a cancellation tells us nothing about whether the analysis would have succeeded" ,
594+ ) ;
595+ } ,
596+ ) ;
597+
598+ test . serial (
599+ "saves overlay status when the job failed rather than being cancelled" ,
600+ async ( t ) => {
601+ const { saveOverlayStatusStub } = await testCancelledOverlayJob ( {
602+ jobStatus : "failure" ,
603+ } ) ;
604+
605+ t . true (
606+ saveOverlayStatusStub . calledOnce ,
607+ "only cancellations are treated as unrelated to the analysis" ,
608+ ) ;
609+ } ,
610+ ) ;
611+
612+ test . serial (
613+ "saves overlay status when a CodeQL Action reported an error before the run was cancelled" ,
614+ async ( t ) => {
615+ const { saveOverlayStatusStub } = await testCancelledOverlayJob ( {
616+ codeQlReportedError : true ,
617+ } ) ;
618+
619+ t . true (
620+ saveOverlayStatusStub . calledOnce ,
621+ "the analysis genuinely failed, even though the run was later cancelled" ,
622+ ) ;
623+ } ,
624+ ) ;
625+
531626function createTestWorkflow (
532627 steps : workflow . WorkflowJobStep [ ] ,
533628) : workflow . Workflow {
0 commit comments