@@ -3,10 +3,11 @@ import fs from "fs";
33import test from "ava" ;
44import * as sinon from "sinon" ;
55
6- import { getCodeQLForTesting } from "../codeql" ;
6+ import { getCodeQLForTesting , type CodeQL } from "../codeql" ;
77import * as diagnostics from "../diagnostics" ;
8- import { ActionsEnvVars } from "../environment" ;
8+ import { ActionsEnvVars , type Env } from "../environment" ;
99import { Feature } from "../feature-flags" ;
10+ import type { Logger } from "../logging" ;
1011import { XCODE_SELECT_LINK_PATH } from "../platform" ;
1112import {
1213 checkExpectedLogMessages ,
@@ -19,14 +20,34 @@ import {
1920 RecordingLogger ,
2021 setupTests ,
2122} from "../testing-utils" ;
22- import { withTmpDir } from "../util" ;
23+ import { BuildMode , withTmpDir } from "../util" ;
2324
2425import { checkRunnerSupportsTracedAnalysis } from "./traced" ;
2526
2627import { BuiltInLanguage } from "." ;
2728
2829setupTests ( test ) ;
2930
31+ const TEST_DEFAULT_TRACED_LANGUAGES = {
32+ [ BuiltInLanguage . swift ] : true ,
33+ [ BuiltInLanguage . go ] : true ,
34+ } ;
35+
36+ async function getCodeQLWithTracedStub (
37+ cmd : string ,
38+ logger : Logger ,
39+ env : Env ,
40+ tracedLanguages : Partial <
41+ Record < BuiltInLanguage , boolean >
42+ > = TEST_DEFAULT_TRACED_LANGUAGES ,
43+ ) : Promise < CodeQL > {
44+ const codeql = await getCodeQLForTesting ( cmd , logger , env ) ;
45+ sinon . stub ( codeql , "isTracedLanguage" ) . callsFake ( async ( language ) => {
46+ return tracedLanguages [ language ] === true ;
47+ } ) ;
48+ return codeql ;
49+ }
50+
3051const nonDarwinPlatforms : NodeJS . Platform [ ] = [ "linux" , "win32" ] ;
3152for ( const nonDarwinPlatform of nonDarwinPlatforms ) {
3253 test ( `checkRunnerSupportsTracedAnalysis throws for Swift on ${ nonDarwinPlatform } ` , async ( t ) =>
@@ -35,7 +56,7 @@ for (const nonDarwinPlatform of nonDarwinPlatforms) {
3556 const env = getTestEnv ( ) ;
3657 env . set ( ActionsEnvVars . RUNNER_TEMP , tmpDir ) ;
3758
38- const codeql = await getCodeQLForTesting (
59+ const codeql = await getCodeQLWithTracedStub (
3960 "codeql-for-testing" ,
4061 logger ,
4162 env ,
@@ -52,13 +73,78 @@ for (const nonDarwinPlatform of nonDarwinPlatforms) {
5273 } ) ) ;
5374}
5475
76+ test ( `checkRunnerSupportsTracedAnalysis doesn't throw for BMN` , async ( t ) =>
77+ withTmpDir ( async ( tmpDir ) => {
78+ const logger = new RecordingLogger ( ) ;
79+ const env = getTestEnv ( ) ;
80+ env . set ( ActionsEnvVars . RUNNER_TEMP , tmpDir ) ;
81+
82+ const codeql = await getCodeQLWithTracedStub (
83+ "codeql-for-testing" ,
84+ logger ,
85+ env ,
86+ ) ;
87+ sinon . stub ( codeql , "getVersion" ) . resolves ( makeVersionInfo ( "2.27.0" ) ) ;
88+
89+ await t . notThrowsAsync (
90+ checkRunnerSupportsTracedAnalysis (
91+ initAllState ( {
92+ platform : "darwin" ,
93+ osRelease : "27.0.0" ,
94+ env,
95+ logger,
96+ } ) ,
97+ createTestConfig ( { buildMode : BuildMode . None } ) ,
98+ codeql ,
99+ ) ,
100+ ) ;
101+ } ) ) ;
102+
103+ // Some languages not in `TEST_DEFAULT_TRACED_LANGUAGES`.
104+ const nonTracedLanguages : BuiltInLanguage [ ] = [
105+ BuiltInLanguage . javascript ,
106+ BuiltInLanguage . actions ,
107+ ] ;
108+ for ( const nonTracedLanguage of nonTracedLanguages ) {
109+ test ( `checkRunnerSupportsTracedAnalysis doesn't throw for ${ nonTracedLanguage } on unsupported macOS` , async ( t ) =>
110+ withTmpDir ( async ( tmpDir ) => {
111+ const logger = new RecordingLogger ( ) ;
112+ const env = getTestEnv ( ) ;
113+ env . set ( ActionsEnvVars . RUNNER_TEMP , tmpDir ) ;
114+
115+ const codeql = await getCodeQLWithTracedStub (
116+ "codeql-for-testing" ,
117+ logger ,
118+ env ,
119+ ) ;
120+ sinon . stub ( codeql , "getVersion" ) . resolves ( makeVersionInfo ( "2.27.0" ) ) ;
121+
122+ await t . notThrowsAsync (
123+ checkRunnerSupportsTracedAnalysis (
124+ initAllState ( {
125+ platform : "darwin" ,
126+ osRelease : "27.0.0" ,
127+ env,
128+ logger,
129+ } ) ,
130+ createTestConfig ( { languages : [ nonTracedLanguage ] } ) ,
131+ codeql ,
132+ ) ,
133+ ) ;
134+ } ) ) ;
135+ }
136+
55137test ( "checkRunnerSupportsTracedAnalysis warns if version string is not a semver" , async ( t ) =>
56138 withTmpDir ( async ( tmpDir ) => {
57139 const logger = new RecordingLogger ( ) ;
58140 const env = getTestEnv ( ) ;
59141 env . set ( ActionsEnvVars . RUNNER_TEMP , tmpDir ) ;
60142
61- const codeql = await getCodeQLForTesting ( "codeql-for-testing" , logger , env ) ;
143+ const codeql = await getCodeQLWithTracedStub (
144+ "codeql-for-testing" ,
145+ logger ,
146+ env ,
147+ ) ;
62148 sinon . stub ( codeql , "getVersion" ) . resolves ( makeVersionInfo ( "2.27.0" ) ) ;
63149
64150 await checkRunnerSupportsTracedAnalysis (
@@ -86,7 +172,7 @@ test.serial(
86172 const env = getTestEnv ( ) ;
87173 env . set ( ActionsEnvVars . RUNNER_TEMP , tmpDir ) ;
88174
89- const codeql = await getCodeQLForTesting (
175+ const codeql = await getCodeQLWithTracedStub (
90176 "codeql-for-testing" ,
91177 logger ,
92178 env ,
@@ -146,7 +232,7 @@ test.serial(
146232
147233 const features = createFeatures ( [ Feature . SkipUnsupportedTracedAnalysis ] ) ;
148234
149- const codeql = await getCodeQLForTesting (
235+ const codeql = await getCodeQLWithTracedStub (
150236 "codeql-for-testing" ,
151237 logger ,
152238 env ,
@@ -210,7 +296,7 @@ test.serial(
210296 . stub ( fs , "readlinkSync" )
211297 . returns ( "/Applications/Xcode_26.0.app/Contents/Developer" ) ;
212298
213- const codeql = await getCodeQLForTesting (
299+ const codeql = await getCodeQLWithTracedStub (
214300 "codeql-for-testing" ,
215301 logger ,
216302 env ,
@@ -260,7 +346,7 @@ test.serial(
260346 . stub ( fs , "readlinkSync" )
261347 . returns ( "/Applications/Xcode_27.0.app/Contents/Developer" ) ;
262348
263- const codeql = await getCodeQLForTesting (
349+ const codeql = await getCodeQLWithTracedStub (
264350 "codeql-for-testing" ,
265351 logger ,
266352 env ,
@@ -332,7 +418,7 @@ test.serial(
332418
333419 const features = createFeatures ( [ Feature . SkipUnsupportedTracedAnalysis ] ) ;
334420
335- const codeql = await getCodeQLForTesting (
421+ const codeql = await getCodeQLWithTracedStub (
336422 "codeql-for-testing" ,
337423 logger ,
338424 env ,
0 commit comments