11import test from "ava" ;
22
3- import { resolveToolsInput } from "../config/resolve-tools-input" ;
3+ import {
4+ EffectiveToolsInputSource ,
5+ resolveToolsInput ,
6+ resolveToolsInputWithMetadata ,
7+ } from "../config/resolve-tools-input" ;
48import {
59 RepositoryPropertyName ,
610 ToolsModeRepositoryPropertyValue ,
@@ -56,7 +60,7 @@ test("resolveToolsInput returns repository property when only repository propert
5660 t . is ( loggedMessages . length , 1 ) ;
5761 t . is (
5862 loggedMessages [ 0 ] . message ,
59- "Setting tools: toolcache based on the 'github-codeql-tools' repository property." ,
63+ "Setting tools: toolcache based on the 'github-codeql-tools' repository property (mode: 'enforce') ." ,
6064 ) ;
6165} ) ;
6266
@@ -95,7 +99,7 @@ test("resolveToolsInput treats empty string workflow input as not set", (t) => {
9599 t . is ( loggedMessages . length , 1 ) ;
96100 t . is (
97101 loggedMessages [ 0 ] . message ,
98- "Setting tools: toolcache based on the 'github-codeql-tools' repository property." ,
102+ "Setting tools: toolcache based on the 'github-codeql-tools' repository property (mode: 'enforce') ." ,
99103 ) ;
100104} ) ;
101105
@@ -135,7 +139,7 @@ test("resolveToolsInput returns repository property when workflow input is not s
135139 t . is ( loggedMessages . length , 1 ) ;
136140 t . is (
137141 loggedMessages [ 0 ] . message ,
138- "Setting tools: toolcache based on the 'github-codeql-tools' repository property." ,
142+ "Setting tools: toolcache based on the 'github-codeql-tools' repository property (mode: 'enforce') ." ,
139143 ) ;
140144} ) ;
141145
@@ -169,7 +173,7 @@ test("resolveToolsInput applies tools property in enforce mode for static workfl
169173 t . is ( loggedMessages . length , 1 ) ;
170174 t . is (
171175 loggedMessages [ 0 ] . message ,
172- "Setting tools: toolcache based on the 'github-codeql-tools' repository property." ,
176+ "Setting tools: toolcache based on the 'github-codeql-tools' repository property (mode: 'enforce') ." ,
173177 ) ;
174178} ) ;
175179
@@ -188,7 +192,7 @@ test("resolveToolsInput applies tools property in dynamic mode for dynamic workf
188192 t . is ( loggedMessages . length , 1 ) ;
189193 t . is (
190194 loggedMessages [ 0 ] . message ,
191- "Setting tools: toolcache based on the 'github-codeql-tools' repository property." ,
195+ "Setting tools: toolcache based on the 'github-codeql-tools' repository property (mode: 'dynamic') ." ,
192196 ) ;
193197} ) ;
194198
@@ -215,3 +219,54 @@ test("resolveToolsInput ignores tools property in dynamic mode for static workfl
215219 "Ignoring 'github-codeql-tools' repository property because 'github-codeql-tools-mode' is set to 'dynamic' and this is not a dynamic workflow." ,
216220 ) ;
217221} ) ;
222+
223+ test ( "resolveToolsInputWithMetadata reports workflow input source" , ( t ) => {
224+ const logger = getRecordingLogger ( [ ] ) ;
225+
226+ const result = resolveToolsInputWithMetadata ( "latest" , false , { } , logger ) ;
227+
228+ t . is ( result . effectiveToolsInput , "latest" ) ;
229+ t . is ( result . effectiveToolsInputSource , EffectiveToolsInputSource . WorkflowInput ) ;
230+ t . is ( result . toolsRepoPropertyMode , undefined ) ;
231+ } ) ;
232+
233+ test ( "resolveToolsInputWithMetadata reports repository property source and mode" , ( t ) => {
234+ const logger = getRecordingLogger ( [ ] ) ;
235+
236+ const result = resolveToolsInputWithMetadata (
237+ undefined ,
238+ false ,
239+ {
240+ [ RepositoryPropertyName . TOOLS ] : "toolcache" ,
241+ [ RepositoryPropertyName . TOOLS_MODE ] :
242+ ToolsModeRepositoryPropertyValue . Enforce ,
243+ } ,
244+ logger ,
245+ ) ;
246+
247+ t . is ( result . effectiveToolsInput , "toolcache" ) ;
248+ t . is (
249+ result . effectiveToolsInputSource ,
250+ EffectiveToolsInputSource . RepositoryProperty ,
251+ ) ;
252+ t . is ( result . toolsRepoPropertyMode , ToolsModeRepositoryPropertyValue . Enforce ) ;
253+ } ) ;
254+
255+ test ( "resolveToolsInputWithMetadata reports dynamic-mode skip on static workflows" , ( t ) => {
256+ const logger = getRecordingLogger ( [ ] ) ;
257+
258+ const result = resolveToolsInputWithMetadata (
259+ undefined ,
260+ false ,
261+ {
262+ [ RepositoryPropertyName . TOOLS ] : "toolcache" ,
263+ [ RepositoryPropertyName . TOOLS_MODE ] :
264+ ToolsModeRepositoryPropertyValue . Dynamic ,
265+ } ,
266+ logger ,
267+ ) ;
268+
269+ t . is ( result . effectiveToolsInput , undefined ) ;
270+ t . is ( result . effectiveToolsInputSource , EffectiveToolsInputSource . None ) ;
271+ t . is ( result . toolsRepoPropertyMode , ToolsModeRepositoryPropertyValue . Dynamic ) ;
272+ } ) ;
0 commit comments