@@ -1069,14 +1069,147 @@ async function fakeOverlayBaseCacheKey(
10691069 return `${ prefix } ${ suffix } ` ;
10701070}
10711071
1072+ for ( const variant of [ GitHubVariant . DOTCOM , GitHubVariant . GHEC_DR ] ) {
1073+ test . serial (
1074+ `getCodeQLSource uses overlay-aware default version for a Code Scanning PR on ${ variant } ` ,
1075+ async ( t ) => {
1076+ await withTmpDir ( async ( tmpDir ) => {
1077+ setupActionsVars ( tmpDir , tmpDir ) ;
1078+ process . env [ EnvVar . CODE_SCANNING_REF ] = "refs/heads/feature-branch" ;
1079+ process . env [ EnvVar . CODE_SCANNING_BASE_BRANCH ] = "main" ;
1080+
1081+ sinon . stub ( api , "getAutomationID" ) . resolves ( "test/" ) ;
1082+ const listStub = sinon . stub ( api , "listActionsCaches" ) . resolves ( [
1083+ {
1084+ key : await fakeOverlayBaseCacheKey (
1085+ "javascript" ,
1086+ "2.20.1" ,
1087+ "abc-1-1" ,
1088+ ) ,
1089+ } ,
1090+ ] ) ;
1091+ sinon
1092+ . stub ( toolcache , "find" )
1093+ . withArgs ( "CodeQL" , "2.20.1" )
1094+ . returns ( "/path/to/codeql-2.20.1" ) ;
1095+
1096+ const source = await setupCodeql . getCodeQLSource (
1097+ undefined ,
1098+ overlayMatchEnabledVersions ,
1099+ [ "javascript" ] ,
1100+ undefined , // otherLanguagePacksReason
1101+ true ,
1102+ SAMPLE_DOTCOM_API_DETAILS ,
1103+ variant ,
1104+ false ,
1105+ createFeatures ( [ ] ) ,
1106+ getRunnerLogger ( true ) ,
1107+ ) ;
1108+
1109+ t . assert ( listStub . calledOnce ) ;
1110+ t . is ( source . sourceType , "toolcache" ) ;
1111+ t . is ( source . toolsVersion , "2.20.1" ) ;
1112+ } ) ;
1113+ } ,
1114+ ) ;
1115+ }
1116+
1117+ test . serial (
1118+ "getCodeQLSource skips overlay-aware default version for a Code Scanning PR on GHES" ,
1119+ async ( t ) => {
1120+ await withTmpDir ( async ( tmpDir ) => {
1121+ setupActionsVars ( tmpDir , tmpDir ) ;
1122+ process . env [ EnvVar . CODE_SCANNING_REF ] = "refs/heads/feature-branch" ;
1123+ process . env [ EnvVar . CODE_SCANNING_BASE_BRANCH ] = "main" ;
1124+
1125+ sinon . stub ( api , "getAutomationID" ) . resolves ( "test/" ) ;
1126+ const listStub = sinon . stub ( api , "listActionsCaches" ) . resolves ( [
1127+ {
1128+ key : await fakeOverlayBaseCacheKey ( "javascript" , "2.20.1" , "abc-1-1" ) ,
1129+ } ,
1130+ ] ) ;
1131+ sinon
1132+ . stub ( toolcache , "find" )
1133+ . withArgs ( "CodeQL" , "2.20.2" )
1134+ . returns ( "/path/to/codeql-2.20.2" ) ;
1135+
1136+ const source = await setupCodeql . getCodeQLSource (
1137+ undefined ,
1138+ overlayMatchEnabledVersions ,
1139+ [ "javascript" ] ,
1140+ undefined , // otherLanguagePacksReason
1141+ true ,
1142+ SAMPLE_DOTCOM_API_DETAILS ,
1143+ GitHubVariant . GHES ,
1144+ false ,
1145+ createFeatures ( [ ] ) ,
1146+ getRunnerLogger ( true ) ,
1147+ ) ;
1148+
1149+ t . assert ( listStub . notCalled ) ;
1150+ t . is ( source . sourceType , "toolcache" ) ;
1151+ t . is ( source . toolsVersion , "2.20.2" ) ;
1152+ } ) ;
1153+ } ,
1154+ ) ;
1155+
10721156test . serial (
1073- "getCodeQLSource uses overlay-aware default version when requested for a PR " ,
1157+ "getCodeQLSource skips the Actions cache when only one default version is enabled " ,
10741158 async ( t ) => {
10751159 await withTmpDir ( async ( tmpDir ) => {
10761160 setupActionsVars ( tmpDir , tmpDir ) ;
10771161 process . env [ EnvVar . CODE_SCANNING_REF ] = "refs/heads/feature-branch" ;
10781162 process . env [ EnvVar . CODE_SCANNING_BASE_BRANCH ] = "main" ;
10791163
1164+ sinon . stub ( api , "getAutomationID" ) . resolves ( "test/" ) ;
1165+ const listStub = sinon . stub ( api , "listActionsCaches" ) . resolves ( [
1166+ {
1167+ key : await fakeOverlayBaseCacheKey (
1168+ "javascript" ,
1169+ SAMPLE_DEFAULT_CLI_VERSION . enabledVersions [ 0 ] . cliVersion ,
1170+ "abc-1-1" ,
1171+ ) ,
1172+ } ,
1173+ ] ) ;
1174+ sinon
1175+ . stub ( toolcache , "find" )
1176+ . withArgs (
1177+ "CodeQL" ,
1178+ SAMPLE_DEFAULT_CLI_VERSION . enabledVersions [ 0 ] . cliVersion ,
1179+ )
1180+ . returns ( "/path/to/codeql" ) ;
1181+
1182+ const source = await setupCodeql . getCodeQLSource (
1183+ undefined ,
1184+ SAMPLE_DEFAULT_CLI_VERSION ,
1185+ [ "javascript" ] ,
1186+ undefined , // otherLanguagePacksReason
1187+ true ,
1188+ SAMPLE_DOTCOM_API_DETAILS ,
1189+ GitHubVariant . DOTCOM ,
1190+ false ,
1191+ createFeatures ( [ ] ) ,
1192+ getRunnerLogger ( true ) ,
1193+ ) ;
1194+
1195+ t . assert ( listStub . notCalled ) ;
1196+ t . is ( source . sourceType , "toolcache" ) ;
1197+ t . is (
1198+ source . toolsVersion ,
1199+ SAMPLE_DEFAULT_CLI_VERSION . enabledVersions [ 0 ] . cliVersion ,
1200+ ) ;
1201+ } ) ;
1202+ } ,
1203+ ) ;
1204+
1205+ test . serial (
1206+ "getCodeQLSource skips overlay-aware default version outside pull request analysis" ,
1207+ async ( t ) => {
1208+ sinon . stub ( actionsUtil , "isAnalyzingPullRequest" ) . returns ( false ) ;
1209+
1210+ await withTmpDir ( async ( tmpDir ) => {
1211+ setupActionsVars ( tmpDir , tmpDir ) ;
1212+
10801213 sinon . stub ( api , "getAutomationID" ) . resolves ( "test/" ) ;
10811214 const listStub = sinon . stub ( api , "listActionsCaches" ) . resolves ( [
10821215 {
@@ -1085,8 +1218,8 @@ test.serial(
10851218 ] ) ;
10861219 sinon
10871220 . stub ( toolcache , "find" )
1088- . withArgs ( "CodeQL" , "2.20.1 " )
1089- . returns ( "/path/to/codeql-2.20.1 " ) ;
1221+ . withArgs ( "CodeQL" , "2.20.2 " )
1222+ . returns ( "/path/to/codeql-2.20.2 " ) ;
10901223
10911224 const source = await setupCodeql . getCodeQLSource (
10921225 undefined ,
@@ -1097,19 +1230,19 @@ test.serial(
10971230 SAMPLE_DOTCOM_API_DETAILS ,
10981231 GitHubVariant . DOTCOM ,
10991232 false ,
1100- createFeatures ( [ Feature . OverlayAnalysisMatchCodeqlVersion ] ) ,
1233+ createFeatures ( [ ] ) ,
11011234 getRunnerLogger ( true ) ,
11021235 ) ;
11031236
1104- t . assert ( listStub . calledOnce ) ;
1237+ t . assert ( listStub . notCalled ) ;
11051238 t . is ( source . sourceType , "toolcache" ) ;
1106- t . is ( source . toolsVersion , "2.20.1 " ) ;
1239+ t . is ( source . toolsVersion , "2.20.2 " ) ;
11071240 } ) ;
11081241 } ,
11091242) ;
11101243
11111244test . serial (
1112- "getCodeQLSource skips overlay-aware default version when not requested" ,
1245+ "getCodeQLSource skips overlay-aware default version when not requested for Code Scanning " ,
11131246 async ( t ) => {
11141247 await withTmpDir ( async ( tmpDir ) => {
11151248 setupActionsVars ( tmpDir , tmpDir ) ;
@@ -1136,7 +1269,7 @@ test.serial(
11361269 SAMPLE_DOTCOM_API_DETAILS ,
11371270 GitHubVariant . DOTCOM ,
11381271 false ,
1139- createFeatures ( [ Feature . OverlayAnalysisMatchCodeqlVersion ] ) ,
1272+ createFeatures ( [ ] ) ,
11401273 getRunnerLogger ( true ) ,
11411274 ) ;
11421275
@@ -1611,7 +1744,7 @@ test.serial(
16111744) ;
16121745
16131746test . serial (
1614- "getEnabledVersionsWithOverlayBaseDatabases returns flag- enabled versions present in cache, sorted desc" ,
1747+ "getEnabledVersionsWithOverlayBaseDatabases returns enabled versions present in cache, sorted desc" ,
16151748 async ( t ) => {
16161749 sinon . stub ( api , "getAutomationID" ) . resolves ( "test/" ) ;
16171750 sinon . stub ( api , "listActionsCaches" ) . resolves ( [
@@ -1632,7 +1765,6 @@ test.serial(
16321765 const result = await setupCodeql . getEnabledVersionsWithOverlayBaseDatabases (
16331766 overlayMatchEnabledVersions ,
16341767 [ "javascript" ] ,
1635- createFeatures ( [ Feature . OverlayAnalysisMatchCodeqlVersion ] ) ,
16361768 getRunnerLogger ( true ) ,
16371769 ) ;
16381770 t . deepEqual ( result , [
@@ -1643,7 +1775,7 @@ test.serial(
16431775) ;
16441776
16451777test . serial (
1646- "getEnabledVersionsWithOverlayBaseDatabases returns empty when no cached version is flag- enabled" ,
1778+ "getEnabledVersionsWithOverlayBaseDatabases returns empty when no cached version is enabled" ,
16471779 async ( t ) => {
16481780 sinon . stub ( api , "getAutomationID" ) . resolves ( "test/" ) ;
16491781 sinon . stub ( api , "listActionsCaches" ) . resolves ( [
@@ -1655,7 +1787,6 @@ test.serial(
16551787 const result = await setupCodeql . getEnabledVersionsWithOverlayBaseDatabases (
16561788 overlayMatchEnabledVersions ,
16571789 [ "javascript" ] ,
1658- createFeatures ( [ Feature . OverlayAnalysisMatchCodeqlVersion ] ) ,
16591790 getRunnerLogger ( true ) ,
16601791 ) ;
16611792 t . deepEqual ( result , [ ] ) ;
@@ -1672,7 +1803,6 @@ const noLanguagesMacro = makeMacro({
16721803 const result = await setupCodeql . getEnabledVersionsWithOverlayBaseDatabases (
16731804 overlayMatchEnabledVersions ,
16741805 rawLanguages ,
1675- createFeatures ( [ Feature . OverlayAnalysisMatchCodeqlVersion ] ) ,
16761806 getRunnerLogger ( true ) ,
16771807 ) ;
16781808 t . deepEqual ( result , [ ] ) ;
@@ -1697,7 +1827,6 @@ test.serial(
16971827 const result = await setupCodeql . getEnabledVersionsWithOverlayBaseDatabases (
16981828 overlayMatchEnabledVersions ,
16991829 [ "javascript" ] ,
1700- createFeatures ( [ Feature . OverlayAnalysisMatchCodeqlVersion ] ) ,
17011830 getRunnerLogger ( true ) ,
17021831 ) ;
17031832 t . deepEqual ( result , [ ] ) ;
@@ -1717,7 +1846,6 @@ test.serial(
17171846 const result = await setupCodeql . getEnabledVersionsWithOverlayBaseDatabases (
17181847 overlayMatchEnabledVersions ,
17191848 [ "javascript" ] ,
1720- createFeatures ( [ Feature . OverlayAnalysisMatchCodeqlVersion ] ) ,
17211849 getRunnerLogger ( true ) ,
17221850 ) ;
17231851 t . deepEqual ( result , [
@@ -1726,25 +1854,6 @@ test.serial(
17261854 } ,
17271855) ;
17281856
1729- test . serial (
1730- "getEnabledVersionsWithOverlayBaseDatabases does not list caches when the gate is off" ,
1731- async ( t ) => {
1732- const listStub = sinon . stub ( api , "listActionsCaches" ) . resolves ( [ ] ) ;
1733-
1734- const result = await setupCodeql . getEnabledVersionsWithOverlayBaseDatabases (
1735- overlayMatchEnabledVersions ,
1736- [ "javascript" ] ,
1737- createFeatures ( [ ] ) ,
1738- getRunnerLogger ( true ) ,
1739- ) ;
1740- t . deepEqual ( result , [ ] ) ;
1741- t . assert (
1742- listStub . notCalled ,
1743- "Should not list Actions caches when the gating feature flag is off." ,
1744- ) ;
1745- } ,
1746- ) ;
1747-
17481857/** The CLI version that the toolcache cleanup tests download. */
17491858const CLEANUP_CLI_VERSION = "2.21.0" ;
17501859/** The bundle version that the toolcache cleanup tests download. */
0 commit comments