@@ -98,53 +98,72 @@ test("getCodeQLSource sets CLI version for a semver tagged bundle", async (t) =>
9898} ) ;
9999
100100test ( "getCodeQLSource correctly returns bundled CLI version when tools == linked" , async ( t ) => {
101- const loggedMessages : LoggedMessage [ ] = [ ] ;
102- const logger = getRecordingLogger ( loggedMessages ) ;
103-
104101 await withTmpDir ( async ( tmpDir ) => {
105102 setupActionsVars ( tmpDir , tmpDir ) ;
106103 const source = await setupCodeql . getCodeQLSource (
107104 "linked" ,
108105 SAMPLE_DEFAULT_CLI_VERSION ,
109106 SAMPLE_DOTCOM_API_DETAILS ,
110107 GitHubVariant . DOTCOM ,
111- logger ,
108+ getRunnerLogger ( true ) ,
112109 ) ;
113110
114- // Assert first that we got the right version of the CodeQL CLI,
115- // and that we're sourcing it using the correct method for that.
116111 t . is ( source . toolsVersion , LINKED_CLI_VERSION . cliVersion ) ;
117112 t . is ( source . sourceType , "download" ) ;
118-
119- // Ensure that we're adequately notifying the user of the version we're using.
120- const expected_message : LoggedMessage = {
121- type : "info" ,
122- message : `Using CodeQL CLI version: ${ LINKED_CLI_VERSION . cliVersion } from download.` ,
123- } ;
124-
125- loggedMessages . forEach ( ( msg ) => {
126- console . log ( msg . message ) ;
127- } ) ;
128-
129- t . assert ( loggedMessages . includes ( expected_message ) ) ;
130113 } ) ;
131114} ) ;
132115
133116test ( "getCodeQLSource correctly returns bundled CLI version when tools == latest" , async ( t ) => {
134- const loggedMessages = [ ] ;
135- const logger = getRecordingLogger ( loggedMessages ) ;
136-
137117 await withTmpDir ( async ( tmpDir ) => {
138118 setupActionsVars ( tmpDir , tmpDir ) ;
139119 const source = await setupCodeql . getCodeQLSource (
140120 "latest" ,
141121 SAMPLE_DEFAULT_CLI_VERSION ,
142122 SAMPLE_DOTCOM_API_DETAILS ,
143123 GitHubVariant . DOTCOM ,
144- logger ,
124+ getRunnerLogger ( true ) ,
145125 ) ;
146126
147127 t . is ( source . toolsVersion , LINKED_CLI_VERSION . cliVersion ) ;
148128 t . is ( source . sourceType , "download" ) ;
149129 } ) ;
150130} ) ;
131+
132+ test ( "setupCodeQLBundle logs the CodeQL CLI version being used" , async ( t ) => {
133+ const loggedMessages : LoggedMessage [ ] = [ ] ;
134+ const logger = getRecordingLogger ( loggedMessages ) ;
135+
136+ // Stub the downloadCodeQL function to prevent downloading artefacts
137+ // during testing from being called.
138+ sinon . stub ( setupCodeql , "downloadCodeQL" ) . resolves ( {
139+ toolsVersion : LINKED_CLI_VERSION . cliVersion ,
140+ codeqlFolder : "codeql" ,
141+ toolsDownloadDurationMs : 200 ,
142+ } ) ;
143+
144+ await withTmpDir ( async ( tmpDir ) => {
145+ setupActionsVars ( tmpDir , tmpDir ) ;
146+ const result = await setupCodeql . setupCodeQLBundle (
147+ "linked" ,
148+ SAMPLE_DOTCOM_API_DETAILS ,
149+ "tmp/codeql_action_test/" ,
150+ GitHubVariant . DOTCOM ,
151+ SAMPLE_DEFAULT_CLI_VERSION ,
152+ logger ,
153+ ) ;
154+
155+ // Basic sanity check that the version we got back is indeed
156+ // the linked (default) CLI version.
157+ t . is ( result . toolsVersion , LINKED_CLI_VERSION . cliVersion ) ;
158+
159+ const expected_message : LoggedMessage = {
160+ type : "info" ,
161+ message : `Using CodeQL CLI version ${ LINKED_CLI_VERSION . cliVersion } from download.` ,
162+ } ;
163+
164+ // Ensure message logging CodeQL CLI version was present in user logs.
165+ t . assert (
166+ loggedMessages . some ( ( msg ) => msg . message === expected_message . message ) ,
167+ ) ;
168+ } ) ;
169+ } ) ;
0 commit comments