1+ import * as fs from "fs" ;
2+ import * as path from "path" ;
3+
14import * as core from "@actions/core" ;
25import test , { ExecutionContext } from "ava" ;
36import * as sinon from "sinon" ;
@@ -8,6 +11,7 @@ import * as apiClient from "./api-client";
811import * as codeql from "./codeql" ;
912import * as configUtils from "./config-utils" ;
1013import * as debugArtifacts from "./debug-artifacts" ;
14+ import { getTempDiagnosticPath } from "./diagnostics" ;
1115import { EnvVar } from "./environment" ;
1216import { Feature } from "./feature-flags" ;
1317import * as initActionPostHelper from "./init-action-post-helper" ;
@@ -35,6 +39,47 @@ const NUM_BYTES_PER_GIB = 1024 * 1024 * 1024;
3539
3640setupTests ( test ) ;
3741
42+ test . serial ( "generateFailedSarif picks up unwritten diagnostics" , async ( t ) =>
43+ util . withTmpDir ( async ( tmpDir ) => {
44+ const logger = new RecordingLogger ( ) ;
45+
46+ const tempDiagDir = getTempDiagnosticPath ( tmpDir ) ;
47+ fs . mkdirSync ( tempDiagDir ) ;
48+
49+ const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
50+ const diagnosticsExport = sinon
51+ . stub ( codeqlObject , "diagnosticsExport" )
52+ . resolves ( ) ;
53+
54+ sinon . stub ( codeql , "getCodeQL" ) . resolves ( codeqlObject ) ;
55+
56+ const sarifFile = path . join ( tmpDir , "failed.sarif" ) ;
57+ const result = await initActionPostHelper . generateFailedSarif (
58+ logger ,
59+ createFeatures ( [ ] ) ,
60+ createTestConfig ( {
61+ tempDir : tmpDir ,
62+ // Explicitly undefined to ensure we get the "no database" path.
63+ dbLocation : undefined ,
64+ } ) ,
65+ "category" ,
66+ "" ,
67+ sarifFile ,
68+ ) ;
69+
70+ t . truthy ( result ) ;
71+ t . is ( diagnosticsExport . callCount , 1 ) ;
72+ t . true (
73+ diagnosticsExport . calledOnceWith (
74+ sarifFile ,
75+ "category" ,
76+ sinon . match . any ,
77+ tempDiagDir ,
78+ ) ,
79+ ) ;
80+ } ) ,
81+ ) ;
82+
3883test . serial ( "init-post action with debug mode off" , async ( t ) => {
3984 return await util . withTmpDir ( async ( tmpDir ) => {
4085 setupActionsVars ( tmpDir , tmpDir ) ;
0 commit comments