2020-06-26 17:22:19 +01:00
"use strict" ;
2021-07-27 17:59:59 +01:00
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
2023-01-18 20:00:33 +00:00
var desc = Object . getOwnPropertyDescriptor ( m , k ) ;
if ( ! desc || ( "get" in desc ? ! m . _ _esModule : desc . writable || desc . configurable ) ) {
desc = { enumerable : true , get : function ( ) { return m [ k ] ; } } ;
}
Object . defineProperty ( o , k2 , desc ) ;
2021-07-27 17:59:59 +01:00
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
2020-06-26 17:22:19 +01:00
var _ _importStar = ( this && this . _ _importStar ) || function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
2021-07-27 17:59:59 +01:00
if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . prototype . hasOwnProperty . call ( mod , k ) ) _ _createBinding ( result , mod , k ) ;
_ _setModuleDefault ( result , mod ) ;
2020-06-26 17:22:19 +01:00
return result ;
} ;
var _ _importDefault = ( this && this . _ _importDefault ) || function ( mod ) {
return ( mod && mod . _ _esModule ) ? mod : { "default" : mod } ;
} ;
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2022-06-27 16:01:48 +00:00
exports . stubToolRunnerConstructor = void 0 ;
2022-06-19 16:44:24 -07:00
const fs = _ _importStar ( require ( "fs" ) ) ;
2021-11-03 13:19:01 -07:00
const toolrunner = _ _importStar ( require ( "@actions/exec/lib/toolrunner" ) ) ;
2020-06-26 17:22:19 +01:00
const toolcache = _ _importStar ( require ( "@actions/tool-cache" ) ) ;
2022-12-02 14:05:21 +01:00
const safeWhich = _ _importStar ( require ( "@chrisgavin/safe-which" ) ) ;
2020-09-29 14:43:37 +01:00
const ava _1 = _ _importDefault ( require ( "ava" ) ) ;
2022-06-19 16:44:24 -07:00
const del _1 = _ _importDefault ( require ( "del" ) ) ;
const yaml = _ _importStar ( require ( "js-yaml" ) ) ;
2020-10-01 11:03:30 +01:00
const nock _1 = _ _importDefault ( require ( "nock" ) ) ;
2021-11-03 13:19:01 -07:00
const sinon = _ _importStar ( require ( "sinon" ) ) ;
2022-11-23 18:19:25 +00:00
const actionsUtil = _ _importStar ( require ( "./actions-util" ) ) ;
2024-03-14 17:56:11 +00:00
const cli _errors _1 = require ( "./cli-errors" ) ;
2020-10-01 11:03:30 +01:00
const codeql = _ _importStar ( require ( "./codeql" ) ) ;
const defaults = _ _importStar ( require ( "./defaults.json" ) ) ;
2022-05-09 12:02:19 +00:00
const languages _1 = require ( "./languages" ) ;
2020-08-25 16:19:15 +01:00
const logging _1 = require ( "./logging" ) ;
2023-07-19 17:30:23 +01:00
const setup _codeql _1 = require ( "./setup-codeql" ) ;
2020-06-26 17:22:19 +01:00
const testing _utils _1 = require ( "./testing-utils" ) ;
2024-04-03 15:39:22 +01:00
const tools _features _1 = require ( "./tools-features" ) ;
2020-10-01 11:03:30 +01:00
const util = _ _importStar ( require ( "./util" ) ) ;
2021-06-01 14:49:07 -07:00
const util _1 = require ( "./util" ) ;
2021-09-10 13:53:13 -07:00
( 0 , testing _utils _1 . setupTests ) ( ava _1 . default ) ;
2022-06-19 16:44:24 -07:00
let stubConfig ;
2021-05-20 15:20:32 -07:00
ava _1 . default . beforeEach ( ( ) => {
2022-11-14 16:37:48 +00:00
( 0 , util _1 . initializeEnvironment ) ( "1.2.3" ) ;
2024-01-30 18:57:41 +00:00
stubConfig = ( 0 , testing _utils _1 . createTestConfig ) ( {
2022-06-19 16:44:24 -07:00
languages : [ languages _1 . Language . cpp ] ,
2024-01-30 18:57:41 +00:00
} ) ;
2021-05-20 15:20:32 -07:00
} ) ;
2023-05-16 14:47:12 +01:00
async function installIntoToolcache ( { apiDetails = testing _utils _1 . SAMPLE _DOTCOM _API _DETAILS , cliVersion , isPinned , tagName , tmpDir , } ) {
const url = ( 0 , testing _utils _1 . mockBundleDownloadApi ) ( { apiDetails , isPinned , tagName } ) ;
2023-02-08 15:20:51 +00:00
await codeql . setupCodeQL ( cliVersion !== undefined ? undefined : url , apiDetails , tmpDir , util . GitHubVariant . GHES , cliVersion !== undefined
2023-07-07 15:02:59 +01:00
? { cliVersion , tagName }
2023-05-16 14:47:12 +01:00
: testing _utils _1 . SAMPLE _DEFAULT _CLI _VERSION , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2023-01-09 18:18:52 +00:00
}
2023-05-16 14:47:12 +01:00
function mockReleaseApi ( { apiDetails = testing _utils _1 . SAMPLE _DOTCOM _API _DETAILS , assetNames , tagName , } ) {
2023-01-12 20:44:05 +00:00
return ( 0 , nock _1 . default ) ( apiDetails . apiURL )
. get ( ` /repos/github/codeql-action/releases/tags/ ${ tagName } ` )
. reply ( 200 , {
assets : assetNames . map ( ( name ) => ( {
name ,
} ) ) ,
tag _name : tagName ,
} ) ;
}
function mockApiDetails ( apiDetails ) {
// This is a workaround to mock `api.getApiDetails()` since it doesn't seem to be possible to
// mock this directly. The difficulty is that `getApiDetails()` is called locally in
// `api-client.ts`, but `sinon.stub(api, "getApiDetails")` only affects calls to
// `getApiDetails()` via an imported `api` module.
sinon
. stub ( actionsUtil , "getRequiredInput" )
. withArgs ( "token" )
. returns ( apiDetails . auth ) ;
const requiredEnvParamStub = sinon . stub ( util , "getRequiredEnvParam" ) ;
requiredEnvParamStub . withArgs ( "GITHUB_SERVER_URL" ) . returns ( apiDetails . url ) ;
requiredEnvParamStub
. withArgs ( "GITHUB_API_URL" )
. returns ( apiDetails . apiURL || "" ) ;
2023-01-09 18:18:52 +00:00
}
( 0 , ava _1 . default ) ( "downloads and caches explicitly requested bundles that aren't in the toolcache" , async ( t ) => {
2020-06-26 17:22:19 +01:00
await util . withTmpDir ( async ( tmpDir ) => {
2021-09-10 13:53:13 -07:00
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
2020-09-14 10:44:43 +01:00
const versions = [ "20200601" , "20200610" ] ;
2020-06-26 17:22:19 +01:00
for ( let i = 0 ; i < versions . length ; i ++ ) {
const version = versions [ i ] ;
2023-05-16 14:47:12 +01:00
const url = ( 0 , testing _utils _1 . mockBundleDownloadApi ) ( {
2023-01-09 18:18:52 +00:00
tagName : ` codeql-bundle- ${ version } ` ,
isPinned : false ,
} ) ;
2023-05-16 14:47:12 +01:00
const result = await codeql . setupCodeQL ( url , testing _utils _1 . SAMPLE _DOTCOM _API _DETAILS , tmpDir , util . GitHubVariant . DOTCOM , testing _utils _1 . SAMPLE _DEFAULT _CLI _VERSION , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2020-09-14 10:44:43 +01:00
t . assert ( toolcache . find ( "CodeQL" , ` 0.0.0- ${ version } ` ) ) ;
2023-01-10 13:16:22 +00:00
t . is ( result . toolsVersion , ` 0.0.0- ${ version } ` ) ;
2023-07-19 17:30:23 +01:00
t . is ( result . toolsSource , setup _codeql _1 . ToolsSource . Download ) ;
2023-01-27 01:03:57 -08:00
t . assert ( Number . isInteger ( result . toolsDownloadDurationMs ) ) ;
2020-06-26 17:22:19 +01:00
}
2022-08-16 15:38:55 +01:00
t . is ( toolcache . findAllVersions ( "CodeQL" ) . length , 2 ) ;
2020-09-22 14:38:27 +01:00
} ) ;
} ) ;
2023-08-10 14:36:04 +01:00
( 0 , ava _1 . default ) ( "caches semantically versioned bundles using their semantic version number" , async ( t ) => {
await util . withTmpDir ( async ( tmpDir ) => {
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
const url = ( 0 , testing _utils _1 . mockBundleDownloadApi ) ( {
tagName : ` codeql-bundle-v2.14.0 ` ,
isPinned : false ,
} ) ;
const result = await codeql . setupCodeQL ( url , testing _utils _1 . SAMPLE _DOTCOM _API _DETAILS , tmpDir , util . GitHubVariant . DOTCOM , testing _utils _1 . SAMPLE _DEFAULT _CLI _VERSION , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
t . is ( toolcache . findAllVersions ( "CodeQL" ) . length , 1 ) ;
t . assert ( toolcache . find ( "CodeQL" , ` 2.14.0 ` ) ) ;
t . is ( result . toolsVersion , ` 2.14.0 ` ) ;
t . is ( result . toolsSource , setup _codeql _1 . ToolsSource . Download ) ;
t . assert ( Number . isInteger ( result . toolsDownloadDurationMs ) ) ;
} ) ;
} ) ;
2023-01-09 18:18:52 +00:00
( 0 , ava _1 . default ) ( "downloads an explicitly requested bundle even if a different version is cached" , async ( t ) => {
2020-09-22 14:38:27 +01:00
await util . withTmpDir ( async ( tmpDir ) => {
2021-09-10 13:53:13 -07:00
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
2023-01-09 18:18:52 +00:00
await installIntoToolcache ( {
tagName : "codeql-bundle-20200601" ,
2022-08-16 15:38:55 +01:00
isPinned : true ,
tmpDir ,
} ) ;
2023-05-16 14:47:12 +01:00
const url = ( 0 , testing _utils _1 . mockBundleDownloadApi ) ( {
2023-01-09 18:18:52 +00:00
tagName : "codeql-bundle-20200610" ,
2022-10-05 09:16:42 -07:00
} ) ;
2023-05-16 14:47:12 +01:00
const result = await codeql . setupCodeQL ( url , testing _utils _1 . SAMPLE _DOTCOM _API _DETAILS , tmpDir , util . GitHubVariant . DOTCOM , testing _utils _1 . SAMPLE _DEFAULT _CLI _VERSION , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2020-09-22 14:38:27 +01:00
t . assert ( toolcache . find ( "CodeQL" , "0.0.0-20200610" ) ) ;
2023-01-10 13:16:22 +00:00
t . deepEqual ( result . toolsVersion , "0.0.0-20200610" ) ;
2023-07-19 17:30:23 +01:00
t . is ( result . toolsSource , setup _codeql _1 . ToolsSource . Download ) ;
2023-01-27 01:03:57 -08:00
t . assert ( Number . isInteger ( result . toolsDownloadDurationMs ) ) ;
2020-09-22 14:38:27 +01:00
} ) ;
} ) ;
2023-01-18 15:55:23 +00:00
const EXPLICITLY _REQUESTED _BUNDLE _TEST _CASES = [
{
cliVersion : "2.10.0" ,
expectedToolcacheVersion : "2.10.0-20200610" ,
} ,
{
cliVersion : "2.10.0-pre" ,
expectedToolcacheVersion : "0.0.0-20200610" ,
} ,
2023-01-20 15:30:57 +00:00
{
cliVersion : "2.10.0+202006100101" ,
expectedToolcacheVersion : "0.0.0-20200610" ,
} ,
2023-01-18 15:55:23 +00:00
] ;
for ( const { cliVersion , expectedToolcacheVersion , } of EXPLICITLY _REQUESTED _BUNDLE _TEST _CASES ) {
( 0 , ava _1 . default ) ( ` caches an explicitly requested bundle containing CLI ${ cliVersion } as ${ expectedToolcacheVersion } ` , async ( t ) => {
await util . withTmpDir ( async ( tmpDir ) => {
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
2023-05-16 14:47:12 +01:00
mockApiDetails ( testing _utils _1 . SAMPLE _DOTCOM _API _DETAILS ) ;
2023-01-18 15:55:23 +00:00
sinon . stub ( actionsUtil , "isRunningLocalAction" ) . returns ( true ) ;
const releaseApiMock = mockReleaseApi ( {
assetNames : [ ` cli-version- ${ cliVersion } .txt ` ] ,
tagName : "codeql-bundle-20200610" ,
} ) ;
2023-05-16 14:47:12 +01:00
const url = ( 0 , testing _utils _1 . mockBundleDownloadApi ) ( {
2023-01-18 15:55:23 +00:00
tagName : "codeql-bundle-20200610" ,
} ) ;
2023-05-16 14:47:12 +01:00
const result = await codeql . setupCodeQL ( url , testing _utils _1 . SAMPLE _DOTCOM _API _DETAILS , tmpDir , util . GitHubVariant . DOTCOM , testing _utils _1 . SAMPLE _DEFAULT _CLI _VERSION , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2023-01-18 15:55:23 +00:00
t . assert ( releaseApiMock . isDone ( ) , "Releases API should have been called" ) ;
t . assert ( toolcache . find ( "CodeQL" , expectedToolcacheVersion ) ) ;
t . deepEqual ( result . toolsVersion , cliVersion ) ;
2023-07-19 17:30:23 +01:00
t . is ( result . toolsSource , setup _codeql _1 . ToolsSource . Download ) ;
2023-01-27 01:03:57 -08:00
t . assert ( Number . isInteger ( result . toolsDownloadDurationMs ) ) ;
2022-08-16 15:38:55 +01:00
} ) ;
2020-09-22 14:38:27 +01:00
} ) ;
2023-01-18 15:55:23 +00:00
}
2023-07-07 14:52:52 +01:00
for ( const toolcacheVersion of [
2023-01-26 11:16:13 +00:00
// Test that we use the tools from the toolcache when `SAMPLE_DEFAULT_CLI_VERSION` is requested
// and `SAMPLE_DEFAULT_CLI_VERSION-` is in the toolcache.
2023-07-07 14:52:52 +01:00
testing _utils _1 . SAMPLE _DEFAULT _CLI _VERSION . cliVersion ,
` ${ testing _utils _1 . SAMPLE _DEFAULT _CLI _VERSION . cliVersion } -20230101 ` ,
2023-01-12 15:39:26 +00:00
] ) {
2023-05-16 14:47:12 +01:00
( 0 , ava _1 . default ) ( ` uses tools from toolcache when ${ testing _utils _1 . SAMPLE _DEFAULT _CLI _VERSION . cliVersion } is requested and ` +
2023-01-26 11:16:13 +00:00
` ${ toolcacheVersion } is installed ` , async ( t ) => {
2023-01-10 13:37:46 +00:00
await util . withTmpDir ( async ( tmpDir ) => {
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
2023-01-26 11:16:13 +00:00
sinon
. stub ( toolcache , "find" )
. withArgs ( "CodeQL" , toolcacheVersion )
. returns ( "path/to/cached/codeql" ) ;
sinon . stub ( toolcache , "findAllVersions" ) . returns ( [ toolcacheVersion ] ) ;
2023-05-16 14:47:12 +01:00
const result = await codeql . setupCodeQL ( undefined , testing _utils _1 . SAMPLE _DOTCOM _API _DETAILS , tmpDir , util . GitHubVariant . DOTCOM , testing _utils _1 . SAMPLE _DEFAULT _CLI _VERSION , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
t . is ( result . toolsVersion , testing _utils _1 . SAMPLE _DEFAULT _CLI _VERSION . cliVersion ) ;
2023-07-19 17:30:23 +01:00
t . is ( result . toolsSource , setup _codeql _1 . ToolsSource . Toolcache ) ;
2023-01-26 11:16:13 +00:00
t . is ( result . toolsDownloadDurationMs , undefined ) ;
2022-10-05 09:16:42 -07:00
} ) ;
2023-01-10 13:37:46 +00:00
} ) ;
}
2024-01-08 13:28:35 +00:00
( 0 , ava _1 . default ) ( ` uses a cached bundle when no tools input is given on GHES ` , async ( t ) => {
await util . withTmpDir ( async ( tmpDir ) => {
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
await installIntoToolcache ( {
tagName : "codeql-bundle-20200601" ,
isPinned : true ,
tmpDir ,
2022-08-16 15:38:55 +01:00
} ) ;
2024-01-08 13:28:35 +00:00
const result = await codeql . setupCodeQL ( undefined , testing _utils _1 . SAMPLE _DOTCOM _API _DETAILS , tmpDir , util . GitHubVariant . GHES , {
cliVersion : defaults . cliVersion ,
tagName : defaults . bundleVersion ,
} , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
t . deepEqual ( result . toolsVersion , "0.0.0-20200601" ) ;
t . is ( result . toolsSource , setup _codeql _1 . ToolsSource . Toolcache ) ;
t . is ( result . toolsDownloadDurationMs , undefined ) ;
const cachedVersions = toolcache . findAllVersions ( "CodeQL" ) ;
t . is ( cachedVersions . length , 1 ) ;
2020-09-22 14:38:27 +01:00
} ) ;
2024-01-08 13:28:35 +00:00
} ) ;
( 0 , ava _1 . default ) ( ` downloads bundle if only an unpinned version is cached on GHES ` , async ( t ) => {
await util . withTmpDir ( async ( tmpDir ) => {
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
await installIntoToolcache ( {
tagName : "codeql-bundle-20200601" ,
isPinned : false ,
tmpDir ,
} ) ;
( 0 , testing _utils _1 . mockBundleDownloadApi ) ( {
tagName : defaults . bundleVersion ,
2022-08-16 15:38:55 +01:00
} ) ;
2024-01-08 13:28:35 +00:00
const result = await codeql . setupCodeQL ( undefined , testing _utils _1 . SAMPLE _DOTCOM _API _DETAILS , tmpDir , util . GitHubVariant . GHES , {
cliVersion : defaults . cliVersion ,
tagName : defaults . bundleVersion ,
} , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
t . deepEqual ( result . toolsVersion , defaults . cliVersion ) ;
t . is ( result . toolsSource , setup _codeql _1 . ToolsSource . Download ) ;
t . assert ( Number . isInteger ( result . toolsDownloadDurationMs ) ) ;
const cachedVersions = toolcache . findAllVersions ( "CodeQL" ) ;
t . is ( cachedVersions . length , 2 ) ;
2020-09-22 14:38:27 +01:00
} ) ;
2024-01-08 13:28:35 +00:00
} ) ;
2023-01-09 18:18:52 +00:00
( 0 , ava _1 . default ) ( 'downloads bundle if "latest" tools specified but not cached' , async ( t ) => {
2020-09-22 14:38:27 +01:00
await util . withTmpDir ( async ( tmpDir ) => {
2021-09-10 13:53:13 -07:00
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
2023-01-09 18:18:52 +00:00
await installIntoToolcache ( {
tagName : "codeql-bundle-20200601" ,
2022-08-16 15:38:55 +01:00
isPinned : true ,
tmpDir ,
} ) ;
2023-05-16 14:47:12 +01:00
( 0 , testing _utils _1 . mockBundleDownloadApi ) ( {
2023-01-09 18:18:52 +00:00
tagName : defaults . bundleVersion ,
2022-08-16 15:38:55 +01:00
} ) ;
2023-05-16 14:47:12 +01:00
const result = await codeql . setupCodeQL ( "latest" , testing _utils _1 . SAMPLE _DOTCOM _API _DETAILS , tmpDir , util . GitHubVariant . DOTCOM , testing _utils _1 . SAMPLE _DEFAULT _CLI _VERSION , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2023-01-10 13:16:22 +00:00
t . deepEqual ( result . toolsVersion , defaults . cliVersion ) ;
2023-07-19 17:30:23 +01:00
t . is ( result . toolsSource , setup _codeql _1 . ToolsSource . Download ) ;
2023-01-27 01:03:57 -08:00
t . assert ( Number . isInteger ( result . toolsDownloadDurationMs ) ) ;
2020-09-22 14:38:27 +01:00
const cachedVersions = toolcache . findAllVersions ( "CodeQL" ) ;
2020-06-26 17:22:19 +01:00
t . is ( cachedVersions . length , 2 ) ;
} ) ;
} ) ;
2023-02-06 16:12:29 +00:00
( 0 , ava _1 . default ) ( "bundle URL from another repo is cached as 0.0.0-bundleVersion" , async ( t ) => {
await util . withTmpDir ( async ( tmpDir ) => {
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
2023-05-16 14:47:12 +01:00
mockApiDetails ( testing _utils _1 . SAMPLE _DOTCOM _API _DETAILS ) ;
2023-02-06 16:12:29 +00:00
sinon . stub ( actionsUtil , "isRunningLocalAction" ) . returns ( true ) ;
const releasesApiMock = mockReleaseApi ( {
2024-04-09 12:29:14 +01:00
assetNames : [ "cli-version-2.12.6.txt" ] ,
2023-02-06 16:12:29 +00:00
tagName : "codeql-bundle-20230203" ,
} ) ;
2023-05-16 14:47:12 +01:00
( 0 , testing _utils _1 . mockBundleDownloadApi ) ( {
2023-04-04 12:21:07 -07:00
repo : "codeql-testing/codeql-cli-nightlies" ,
2023-02-06 16:12:29 +00:00
platformSpecific : false ,
tagName : "codeql-bundle-20230203" ,
} ) ;
2023-05-16 14:47:12 +01:00
const result = await codeql . setupCodeQL ( "https://github.com/codeql-testing/codeql-cli-nightlies/releases/download/codeql-bundle-20230203/codeql-bundle.tar.gz" , testing _utils _1 . SAMPLE _DOTCOM _API _DETAILS , tmpDir , util . GitHubVariant . DOTCOM , testing _utils _1 . SAMPLE _DEFAULT _CLI _VERSION , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2023-02-06 16:12:29 +00:00
t . is ( result . toolsVersion , "0.0.0-20230203" ) ;
2023-07-19 17:30:23 +01:00
t . is ( result . toolsSource , setup _codeql _1 . ToolsSource . Download ) ;
2023-02-06 16:12:29 +00:00
t . true ( Number . isInteger ( result . toolsDownloadDurationMs ) ) ;
const cachedVersions = toolcache . findAllVersions ( "CodeQL" ) ;
t . is ( cachedVersions . length , 1 ) ;
t . is ( cachedVersions [ 0 ] , "0.0.0-20230203" ) ;
t . false ( releasesApiMock . isDone ( ) ) ;
} ) ;
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "getExtraOptions works for explicit paths" , ( t ) => {
2020-09-14 10:44:43 +01:00
t . deepEqual ( codeql . getExtraOptions ( { } , [ "foo" ] , [ ] ) , [ ] ) ;
t . deepEqual ( codeql . getExtraOptions ( { foo : [ 42 ] } , [ "foo" ] , [ ] ) , [ "42" ] ) ;
t . deepEqual ( codeql . getExtraOptions ( { foo : { bar : [ 42 ] } } , [ "foo" , "bar" ] , [ ] ) , [ "42" ] ) ;
2020-08-10 09:25:14 +02:00
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "getExtraOptions works for wildcards" , ( t ) => {
2020-09-14 10:44:43 +01:00
t . deepEqual ( codeql . getExtraOptions ( { "*" : [ 42 ] } , [ "foo" ] , [ ] ) , [ "42" ] ) ;
2020-08-10 09:25:14 +02:00
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "getExtraOptions works for wildcards and explicit paths" , ( t ) => {
2020-09-14 10:44:43 +01:00
const o1 = { "*" : [ 42 ] , foo : [ 87 ] } ;
t . deepEqual ( codeql . getExtraOptions ( o1 , [ "foo" ] , [ ] ) , [ "42" , "87" ] ) ;
const o2 = { "*" : [ 42 ] , foo : [ 87 ] } ;
t . deepEqual ( codeql . getExtraOptions ( o2 , [ "foo" , "bar" ] , [ ] ) , [ "42" ] ) ;
const o3 = { "*" : [ 42 ] , foo : { "*" : [ 87 ] , bar : [ 99 ] } } ;
const p = [ "foo" , "bar" ] ;
t . deepEqual ( codeql . getExtraOptions ( o3 , p , [ ] ) , [ "42" , "87" , "99" ] ) ;
2020-08-10 09:25:14 +02:00
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "getExtraOptions throws for bad content" , ( t ) => {
2020-09-14 10:44:43 +01:00
t . throws ( ( ) => codeql . getExtraOptions ( { "*" : 42 } , [ "foo" ] , [ ] ) ) ;
t . throws ( ( ) => codeql . getExtraOptions ( { foo : 87 } , [ "foo" ] , [ ] ) ) ;
t . throws ( ( ) => codeql . getExtraOptions ( { "*" : [ 42 ] , foo : { "*" : 87 , bar : [ 99 ] } } , [ "foo" , "bar" ] , [ ] ) ) ;
2020-08-10 09:25:14 +02:00
} ) ;
2022-06-19 16:44:24 -07:00
// Test macro for ensuring different variants of injected augmented configurations
const injectedConfigMacro = ava _1 . default . macro ( {
exec : async ( t , augmentationProperties , configOverride , expectedConfig ) => {
2022-10-05 15:54:07 -07:00
await util . withTmpDir ( async ( tempDir ) => {
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
2024-01-04 14:39:36 +00:00
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( ( 0 , testing _utils _1 . makeVersionInfo ) ( "1.0.0" ) ) ;
2022-10-05 15:54:07 -07:00
const thisStubConfig = {
... stubConfig ,
... configOverride ,
tempDir ,
augmentationProperties ,
} ;
2024-04-11 20:31:01 +01:00
await codeqlObject . databaseInitCluster ( thisStubConfig , "" , undefined , undefined , ( 0 , testing _utils _1 . createFeatures ) ( [ ] ) , ( 0 , logging _1 . getRunnerLogger ) ( true ) ) ;
2022-10-05 15:54:07 -07:00
const args = runnerConstructorStub . firstCall . args [ 1 ] ;
// should have used an config file
const configArg = args . find ( ( arg ) => arg . startsWith ( "--codescanning-config=" ) ) ;
t . truthy ( configArg , "Should have injected a codescanning config" ) ;
const configFile = configArg . split ( "=" ) [ 1 ] ;
const augmentedConfig = yaml . load ( fs . readFileSync ( configFile , "utf8" ) ) ;
t . deepEqual ( augmentedConfig , expectedConfig ) ;
await ( 0 , del _1 . default ) ( configFile , { force : true } ) ;
} ) ;
2022-06-19 16:44:24 -07:00
} ,
title : ( providedTitle = "" ) => ` databaseInitCluster() injected config: ${ providedTitle } ` ,
} ) ;
( 0 , ava _1 . default ) ( "basic" , injectedConfigMacro , {
queriesInputCombines : false ,
packsInputCombines : false ,
} , { } , { } ) ;
( 0 , ava _1 . default ) ( "injected packs from input" , injectedConfigMacro , {
queriesInputCombines : false ,
packsInputCombines : false ,
packsInput : [ "xxx" , "yyy" ] ,
} , { } , {
packs : [ "xxx" , "yyy" ] ,
} ) ;
( 0 , ava _1 . default ) ( "injected packs from input with existing packs combines" , injectedConfigMacro , {
queriesInputCombines : false ,
packsInputCombines : true ,
packsInput : [ "xxx" , "yyy" ] ,
} , {
originalUserInput : {
packs : {
cpp : [ "codeql/something-else" ] ,
} ,
} ,
} , {
packs : {
cpp : [ "codeql/something-else" , "xxx" , "yyy" ] ,
} ,
} ) ;
( 0 , ava _1 . default ) ( "injected packs from input with existing packs overrides" , injectedConfigMacro , {
queriesInputCombines : false ,
packsInputCombines : false ,
packsInput : [ "xxx" , "yyy" ] ,
} , {
originalUserInput : {
packs : {
cpp : [ "codeql/something-else" ] ,
} ,
} ,
} , {
packs : [ "xxx" , "yyy" ] ,
} ) ;
// similar, but with queries
( 0 , ava _1 . default ) ( "injected queries from input" , injectedConfigMacro , {
queriesInputCombines : false ,
packsInputCombines : false ,
queriesInput : [ { uses : "xxx" } , { uses : "yyy" } ] ,
} , { } , {
queries : [
{
uses : "xxx" ,
} ,
{
uses : "yyy" ,
} ,
] ,
} ) ;
( 0 , ava _1 . default ) ( "injected queries from input overrides" , injectedConfigMacro , {
queriesInputCombines : false ,
packsInputCombines : false ,
queriesInput : [ { uses : "xxx" } , { uses : "yyy" } ] ,
} , {
originalUserInput : {
queries : [ { uses : "zzz" } ] ,
} ,
} , {
queries : [
{
uses : "xxx" ,
} ,
{
uses : "yyy" ,
} ,
] ,
} ) ;
( 0 , ava _1 . default ) ( "injected queries from input combines" , injectedConfigMacro , {
queriesInputCombines : true ,
packsInputCombines : false ,
queriesInput : [ { uses : "xxx" } , { uses : "yyy" } ] ,
} , {
originalUserInput : {
queries : [ { uses : "zzz" } ] ,
} ,
} , {
queries : [
{
uses : "zzz" ,
} ,
{
uses : "xxx" ,
} ,
{
uses : "yyy" ,
} ,
] ,
} ) ;
( 0 , ava _1 . default ) ( "injected queries from input combines 2" , injectedConfigMacro , {
queriesInputCombines : true ,
packsInputCombines : true ,
queriesInput : [ { uses : "xxx" } , { uses : "yyy" } ] ,
} , { } , {
queries : [
{
uses : "xxx" ,
} ,
{
uses : "yyy" ,
} ,
] ,
} ) ;
( 0 , ava _1 . default ) ( "injected queries and packs, but empty" , injectedConfigMacro , {
queriesInputCombines : true ,
packsInputCombines : true ,
queriesInput : [ ] ,
packsInput : [ ] ,
} , {
originalUserInput : {
packs : [ ] ,
queries : [ ] ,
} ,
} , { } ) ;
2024-01-04 14:39:36 +00:00
( 0 , ava _1 . default ) ( "passes a code scanning config AND qlconfig to the CLI" , async ( t ) => {
2023-03-06 10:23:28 +00:00
await util . withTmpDir ( async ( tempDir ) => {
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
2024-04-09 12:29:14 +01:00
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( ( 0 , testing _utils _1 . makeVersionInfo ) ( "2.12.6" ) ) ;
2024-04-11 20:31:01 +01:00
await codeqlObject . databaseInitCluster ( { ... stubConfig , tempDir } , "" , undefined , "/path/to/qlconfig.yml" , ( 0 , testing _utils _1 . createFeatures ) ( [ ] ) , ( 0 , logging _1 . getRunnerLogger ) ( true ) ) ;
2023-03-06 10:23:28 +00:00
const args = runnerConstructorStub . firstCall . args [ 1 ] ;
// should have used a config file
const hasCodeScanningConfigArg = args . some ( ( arg ) => arg . startsWith ( "--codescanning-config=" ) ) ;
t . true ( hasCodeScanningConfigArg , "Should have injected a qlconfig" ) ;
// should have passed a qlconfig file
2023-03-06 10:46:36 +00:00
const hasQlconfigArg = args . some ( ( arg ) => arg . startsWith ( "--qlconfig-file=" ) ) ;
2023-03-06 10:23:28 +00:00
t . truthy ( hasQlconfigArg , "Should have injected a codescanning config" ) ;
} ) ;
2023-02-09 11:19:27 -08:00
} ) ;
2023-03-06 10:26:34 +00:00
( 0 , ava _1 . default ) ( "does not pass a qlconfig to the CLI when it is undefined" , async ( t ) => {
await util . withTmpDir ( async ( tempDir ) => {
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
2024-04-09 12:29:14 +01:00
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( ( 0 , testing _utils _1 . makeVersionInfo ) ( "2.12.6" ) ) ;
2024-01-04 14:39:36 +00:00
await codeqlObject . databaseInitCluster ( { ... stubConfig , tempDir } , "" , undefined , undefined , // undefined qlconfigFile
2024-04-11 20:31:01 +01:00
( 0 , testing _utils _1 . createFeatures ) ( [ ] ) , ( 0 , logging _1 . getRunnerLogger ) ( true ) ) ;
2023-03-06 10:26:34 +00:00
const args = runnerConstructorStub . firstCall . args [ 1 ] ;
2023-03-06 10:46:36 +00:00
const hasQlconfigArg = args . some ( ( arg ) => arg . startsWith ( "--qlconfig-file=" ) ) ;
2023-03-06 10:26:34 +00:00
t . false ( hasQlconfigArg , "should NOT have injected a qlconfig" ) ;
2023-03-06 10:23:28 +00:00
} ) ;
2022-06-19 16:44:24 -07:00
} ) ;
2023-07-18 13:28:06 +01:00
const NEW _ANALYSIS _SUMMARY _TEST _CASES = [
{
2024-04-03 15:39:22 +01:00
codeqlVersion : ( 0 , testing _utils _1 . makeVersionInfo ) ( "2.15.0" , {
[ tools _features _1 . ToolsFeature . AnalysisSummaryV2IsDefault ] : true ,
} ) ,
2023-10-25 17:24:22 +01:00
githubVersion : {
type : util . GitHubVariant . DOTCOM ,
} ,
2024-04-03 15:39:22 +01:00
flagPassed : false ,
2023-07-18 13:28:06 +01:00
negativeFlagPassed : false ,
} ,
{
2024-04-03 15:39:22 +01:00
codeqlVersion : ( 0 , testing _utils _1 . makeVersionInfo ) ( "2.15.0" ) ,
2023-10-25 17:24:22 +01:00
githubVersion : {
2024-04-03 15:39:22 +01:00
type : util . GitHubVariant . DOTCOM ,
2023-10-25 17:24:22 +01:00
} ,
flagPassed : true ,
negativeFlagPassed : false ,
} ,
{
2024-04-03 15:39:22 +01:00
codeqlVersion : ( 0 , testing _utils _1 . makeVersionInfo ) ( "2.15.0" ) ,
2023-10-25 17:24:22 +01:00
githubVersion : {
type : util . GitHubVariant . GHES ,
2024-04-03 15:39:22 +01:00
version : "3.9.0" ,
2023-10-25 17:24:22 +01:00
} ,
2024-04-03 15:39:22 +01:00
flagPassed : true ,
negativeFlagPassed : false ,
2023-07-18 13:28:06 +01:00
} ,
{
2024-04-03 15:39:22 +01:00
codeqlVersion : ( 0 , testing _utils _1 . makeVersionInfo ) ( "2.14.6" ) ,
2023-10-25 17:24:22 +01:00
githubVersion : {
type : util . GitHubVariant . DOTCOM ,
} ,
2023-07-18 13:28:06 +01:00
flagPassed : false ,
negativeFlagPassed : false ,
} ,
] ;
2023-10-25 17:24:22 +01:00
for ( const { codeqlVersion , flagPassed , githubVersion , negativeFlagPassed , } of NEW _ANALYSIS _SUMMARY _TEST _CASES ) {
2023-07-18 13:28:06 +01:00
( 0 , ava _1 . default ) ( ` database interpret-results passes ${ flagPassed
? "--new-analysis-summary"
: negativeFlagPassed
? "--no-new-analysis-summary"
2024-04-03 15:39:22 +01:00
: "nothing" } for CodeQL version ${ JSON . stringify ( codeqlVersion ) } and ${ util . GitHubVariant [ githubVersion . type ] } ${ githubVersion . version ? ` ${ githubVersion . version } ` : "" } ` , async ( t ) => {
2023-07-18 13:28:06 +01:00
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
2024-04-03 15:39:22 +01:00
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( codeqlVersion ) ;
2023-07-18 13:28:06 +01:00
// safeWhich throws because of the test CodeQL object.
sinon . stub ( safeWhich , "safeWhich" ) . resolves ( "" ) ;
2023-10-25 17:24:22 +01:00
await codeqlObject . databaseInterpretResults ( "" , [ ] , "" , "" , "" , "-v" , "" , Object . assign ( { } , stubConfig , { gitHubVersion : githubVersion } ) , ( 0 , testing _utils _1 . createFeatures ) ( [ ] ) , ( 0 , logging _1 . getRunnerLogger ) ( true ) ) ;
2023-07-18 13:28:06 +01:00
t . is ( runnerConstructorStub . firstCall . args [ 1 ] . includes ( "--new-analysis-summary" ) , flagPassed , ` --new-analysis-summary should ${ flagPassed ? "" : "n't" } be passed ` ) ;
t . is ( runnerConstructorStub . firstCall . args [ 1 ] . includes ( "--no-new-analysis-summary" ) , negativeFlagPassed , ` --no-new-analysis-summary should ${ negativeFlagPassed ? "" : "n't" } be passed ` ) ;
} ) ;
}
2024-04-09 12:29:14 +01:00
( 0 , ava _1 . default ) ( "database finalize does not override no code found error on CodeQL 2.12.6" , async ( t ) => {
2023-07-20 18:41:28 +01:00
const cliMessage = "CodeQL did not detect any code written in languages supported by CodeQL. Review our troubleshooting guide at " +
"https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build." ;
stubToolRunnerConstructor ( 32 , cliMessage ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
2024-04-09 12:29:14 +01:00
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( ( 0 , testing _utils _1 . makeVersionInfo ) ( "2.12.6" ) ) ;
2023-07-20 18:41:28 +01:00
// safeWhich throws because of the test CodeQL object.
sinon . stub ( safeWhich , "safeWhich" ) . resolves ( "" ) ;
2024-03-13 18:22:37 +00:00
await t . throwsAsync ( async ( ) => await codeqlObject . finalizeDatabase ( "db" , "--threads=2" , "--ram=2048" , false ) , {
2023-07-21 11:40:07 +01:00
message : 'Encountered a fatal error while running "codeql-for-testing database finalize --finalize-dataset --threads=2 --ram=2048 db". ' +
2023-10-06 15:53:15 +01:00
` Exit code was 32 and last log line was: ${ cliMessage } See the logs for more details. ` ,
2023-07-20 18:41:28 +01:00
} ) ;
} ) ;
2023-07-21 15:27:57 +01:00
( 0 , ava _1 . default ) ( "runTool summarizes several fatal errors" , async ( t ) => {
const heapError = "A fatal error occurred: Evaluator heap must be at least 384.00 MiB" ;
const datasetImportError = "A fatal error occurred: Dataset import for /home/runner/work/_temp/codeql_databases/javascript/db-javascript failed with code 2" ;
const cliStderr = ` Running TRAP import for CodeQL database at /home/runner/work/_temp/codeql_databases/javascript... \n ` +
` ${ heapError } \n ${ datasetImportError } . ` ;
stubToolRunnerConstructor ( 32 , cliStderr ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
2024-04-09 12:29:14 +01:00
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( ( 0 , testing _utils _1 . makeVersionInfo ) ( "2.12.6" ) ) ;
2023-07-21 15:27:57 +01:00
// safeWhich throws because of the test CodeQL object.
sinon . stub ( safeWhich , "safeWhich" ) . resolves ( "" ) ;
2024-03-13 18:22:37 +00:00
await t . throwsAsync ( async ( ) => await codeqlObject . finalizeDatabase ( "db" , "--threads=2" , "--ram=2048" , false ) , {
2024-02-14 05:57:38 -08:00
instanceOf : util . ConfigurationError ,
message : new RegExp ( 'Encountered a fatal error while running \\"codeql-for-testing database finalize --finalize-dataset --threads=2 --ram=2048 db\\"\\. ' +
` Exit code was 32 and error was: ${ datasetImportError . replaceAll ( "." , "\\." ) } \\ . Context: ${ heapError . replaceAll ( "." , "\\." ) } \\ . See the logs for more details \\ . ` ) ,
2023-10-06 15:53:15 +01:00
} ) ;
} ) ;
2024-03-14 17:56:11 +00:00
( 0 , ava _1 . default ) ( "runTool summarizes autobuilder errors" , async ( t ) => {
const stderr = `
[2019-09-18 12:00:00] [autobuild] A non-error message
[2019-09-18 12:00:00] Untagged message
[2019-09-18 12:00:00] [autobuild] [ERROR] Start of the error message
[2019-09-18 12:00:00] [autobuild] An interspersed non-error message
[2019-09-18 12:00:01] [autobuild] [ERROR] Some more context about the error message
[2019-09-18 12:00:01] [autobuild] [ERROR] continued
[2019-09-18 12:00:01] [autobuild] [ERROR] and finished here.
[2019-09-18 12:00:01] [autobuild] A non-error message
` ;
stubToolRunnerConstructor ( 1 , stderr ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
2024-04-09 12:29:14 +01:00
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( ( 0 , testing _utils _1 . makeVersionInfo ) ( "2.12.6" ) ) ;
2024-03-14 17:56:11 +00:00
sinon . stub ( codeqlObject , "resolveExtractor" ) . resolves ( "/path/to/extractor" ) ;
// safeWhich throws because of the test CodeQL object.
sinon . stub ( safeWhich , "safeWhich" ) . resolves ( "" ) ;
2024-05-09 14:25:25 +01:00
await t . throwsAsync ( async ( ) => await codeqlObject . runAutobuild ( stubConfig , languages _1 . Language . java ) , {
2024-03-14 17:56:11 +00:00
instanceOf : cli _errors _1 . CommandInvocationError ,
message : "We were unable to automatically build your code. Please provide manual build steps. " +
"For more information, see " +
"https://docs.github.com/en/code-security/code-scanning/troubleshooting-code-scanning/automatic-build-failed. " +
"Encountered the following error: Start of the error message\n" +
" Some more context about the error message\n" +
" continued\n" +
" and finished here." ,
} ) ;
} ) ;
2024-03-15 11:24:50 +00:00
( 0 , ava _1 . default ) ( "runTool truncates long autobuilder errors" , async ( t ) => {
const stderr = Array . from ( { length : 20 } , ( _ , i ) => ` [2019-09-18 12:00:00] [autobuild] [ERROR] line ${ i + 1 } ` ) . join ( "\n" ) ;
stubToolRunnerConstructor ( 1 , stderr ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
2024-04-09 12:29:14 +01:00
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( ( 0 , testing _utils _1 . makeVersionInfo ) ( "2.12.6" ) ) ;
2024-03-15 11:24:50 +00:00
sinon . stub ( codeqlObject , "resolveExtractor" ) . resolves ( "/path/to/extractor" ) ;
// safeWhich throws because of the test CodeQL object.
sinon . stub ( safeWhich , "safeWhich" ) . resolves ( "" ) ;
2024-05-09 14:25:25 +01:00
await t . throwsAsync ( async ( ) => await codeqlObject . runAutobuild ( stubConfig , languages _1 . Language . java ) , {
2024-03-15 11:24:50 +00:00
instanceOf : cli _errors _1 . CommandInvocationError ,
message : "We were unable to automatically build your code. Please provide manual build steps. " +
"For more information, see " +
"https://docs.github.com/en/code-security/code-scanning/troubleshooting-code-scanning/automatic-build-failed. " +
"Encountered the following error: " +
` ${ Array . from ( { length : 10 } , (_, i) => ` line$ { i + 1 } ` ).join(" \n ")} \n (truncated) ` ,
} ) ;
} ) ;
2023-10-06 15:53:15 +01:00
( 0 , ava _1 . default ) ( "runTool outputs last line of stderr if fatal error could not be found" , async ( t ) => {
const cliStderr = "line1\nline2\nline3\nline4\nline5" ;
stubToolRunnerConstructor ( 32 , cliStderr ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
2024-04-09 12:29:14 +01:00
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( ( 0 , testing _utils _1 . makeVersionInfo ) ( "2.12.6" ) ) ;
2023-10-06 15:53:15 +01:00
// safeWhich throws because of the test CodeQL object.
sinon . stub ( safeWhich , "safeWhich" ) . resolves ( "" ) ;
2024-03-13 18:22:37 +00:00
await t . throwsAsync ( async ( ) => await codeqlObject . finalizeDatabase ( "db" , "--threads=2" , "--ram=2048" , false ) , {
2024-02-14 05:57:38 -08:00
instanceOf : util . ConfigurationError ,
message : new RegExp ( 'Encountered a fatal error while running \\"codeql-for-testing database finalize --finalize-dataset --threads=2 --ram=2048 db\\"\\. ' +
"Exit code was 32 and last log line was: line5\\. See the logs for more details\\." ) ,
2023-07-21 15:27:57 +01:00
} ) ;
} ) ;
2024-04-16 18:02:18 +01:00
( 0 , ava _1 . default ) ( "Avoids duplicating --overwrite flag if specified in CODEQL_ACTION_EXTRA_OPTIONS" , async ( t ) => {
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( ( 0 , testing _utils _1 . makeVersionInfo ) ( "2.12.6" ) ) ;
// safeWhich throws because of the test CodeQL object.
sinon . stub ( safeWhich , "safeWhich" ) . resolves ( "" ) ;
process . env [ "CODEQL_ACTION_EXTRA_OPTIONS" ] =
'{ "database": { "init": ["--overwrite"] } }' ;
2024-04-16 19:01:20 +01:00
await codeqlObject . databaseInitCluster ( stubConfig , "sourceRoot" , undefined , undefined , ( 0 , testing _utils _1 . createFeatures ) ( [ ] ) , ( 0 , logging _1 . getRunnerLogger ) ( false ) ) ;
2024-04-16 18:02:18 +01:00
t . true ( runnerConstructorStub . calledOnce ) ;
const args = runnerConstructorStub . firstCall . args [ 1 ] ;
t . is ( args . filter ( ( option ) => option === "--overwrite" ) . length , 1 , "--overwrite should only be passed once" ) ;
// Clean up
const configArg = args . find ( ( arg ) => arg . startsWith ( "--codescanning-config=" ) ) ;
t . truthy ( configArg , "Should have injected a codescanning config" ) ;
const configFile = configArg . split ( "=" ) [ 1 ] ;
await ( 0 , del _1 . default ) ( configFile , { force : true } ) ;
} ) ;
2023-07-20 18:16:02 +01:00
function stubToolRunnerConstructor ( exitCode = 0 , stderr ) {
2021-11-03 13:19:01 -07:00
const runnerObjectStub = sinon . createStubInstance ( toolrunner . ToolRunner ) ;
const runnerConstructorStub = sinon . stub ( toolrunner , "ToolRunner" ) ;
2023-07-20 18:16:02 +01:00
let stderrListener = undefined ;
runnerConstructorStub . callsFake ( ( _cmd , _args , options ) => {
stderrListener = options . listeners ? . stderr ;
return runnerObjectStub ;
} ) ;
runnerObjectStub . exec . callsFake ( async ( ) => {
if ( stderrListener !== undefined && stderr !== undefined ) {
stderrListener ( Buffer . from ( stderr ) ) ;
}
return exitCode ;
} ) ;
2021-11-03 13:19:01 -07:00
return runnerConstructorStub ;
}
2022-06-27 16:01:48 +00:00
exports . stubToolRunnerConstructor = stubToolRunnerConstructor ;
2020-06-26 17:22:19 +01:00
//# sourceMappingURL=codeql.test.js.map