@@ -473,6 +473,9 @@ const simpleConfigFileContents = `
473473 queries:
474474 - uses: ./foo_file` ;
475475
476+ /** The configuration in `simpleConfigFileContents`, as parsed from the `config` input. */
477+ const simpleConfigInput = yaml . load ( simpleConfigFileContents ) as UserConfig ;
478+
476479/** A less minimal configuration file. */
477480const otherConfigFileContents = `
478481 name: my config
@@ -591,7 +594,7 @@ test.serial(
591594 createTestInitConfigInputs ( {
592595 languagesInput,
593596 configFile : configFilePath ,
594- configInput,
597+ configInput : yaml . load ( configInput ) as UserConfig ,
595598 tempDir,
596599 codeql,
597600 workspacePath : tempDir ,
@@ -2343,6 +2346,40 @@ test("applyIncrementalAnalysisSettings: adds exclusions for diff-informed-only r
23432346 ] ) ;
23442347} ) ;
23452348
2349+ test ( "parseConfigInput - returns undefined when the input isn't set" , async ( t ) => {
2350+ await callee ( configUtils . parseConfigInput )
2351+ . withArgs ( undefined )
2352+ . passes ( t . is , undefined ) ;
2353+ } ) ;
2354+
2355+ test ( "parseConfigInput - parses the input as YAML" , async ( t ) => {
2356+ await callee ( configUtils . parseConfigInput )
2357+ . withArgs ( simpleConfigFileContents )
2358+ . passes ( t . deepEqual , {
2359+ name : "my config" ,
2360+ queries : [ { uses : "./foo_file" } ] ,
2361+ } ) ;
2362+ } ) ;
2363+
2364+ test ( "parseConfigInput - throws a ConfigurationError naming the input if it isn't valid YAML" , async ( t ) => {
2365+ await callee ( configUtils . parseConfigInput )
2366+ . withArgs ( "queries: [" )
2367+ . throws ( t , {
2368+ instanceOf : ConfigurationError ,
2369+ message : / ^ C a n n o t p a r s e " ` c o n f i g ` i n p u t " / ,
2370+ } ) ;
2371+ } ) ;
2372+
2373+ test ( "parseConfigInput - throws a ConfigurationError naming the input if validation fails" , async ( t ) => {
2374+ await callee ( configUtils . parseConfigInput )
2375+ . withFeatures ( [ Feature . ValidateDbConfig ] )
2376+ . withArgs ( "queries: 1" )
2377+ . throws ( t , {
2378+ instanceOf : ConfigurationError ,
2379+ message : / ^ T h e c o n f i g u r a t i o n f i l e " ` c o n f i g ` i n p u t " i s i n v a l i d / ,
2380+ } ) ;
2381+ } ) ;
2382+
23462383test ( "determineUserConfig - empty config when neither input is specified" , async ( t ) => {
23472384 await withTmpDir ( async ( tmpDir ) => {
23482385 const target = callee ( configUtils . determineUserConfig )
@@ -2413,7 +2450,7 @@ test("determineUserConfig - loads config input", async (t) => {
24132450 const expectedConfigPath = configUtils . userConfigFromActionPath ( tmpDir ) ;
24142451
24152452 const inputs = createTestInitConfigInputs ( {
2416- configInput : simpleConfigFileContents ,
2453+ configInput : simpleConfigInput ,
24172454 configFile : undefined ,
24182455 workspacePath : tmpDir ,
24192456 } ) ;
@@ -2423,17 +2460,15 @@ test("determineUserConfig - loads config input", async (t) => {
24232460
24242461 await target
24252462 // The input source and path of the generated config file should have been logged.
2426- . logs (
2427- t ,
2428- "Using config from action input:" ,
2429- `Using configuration file: ${ expectedConfigPath } ` ,
2430- )
2431- // The message about no configuration input and
2432- // the warning about both inputs should not have been logged.
2463+ . logs ( t , `Using config from action input: ${ expectedConfigPath } ` )
2464+ // The message about no configuration input and the warning about both inputs should not have
2465+ // been logged. The generated config file isn't loaded, since the `config` input has already
2466+ // been parsed.
24332467 . notLogs (
24342468 t ,
24352469 "No configuration file was provided" ,
24362470 "Both a config file and config input were provided. Ignoring config file." ,
2471+ `Using configuration file: ${ expectedConfigPath } ` ,
24372472 )
24382473 // The loaded configuration should match `simpleConfigFileContents`.
24392474 . passes ( t . deepEqual , {
@@ -2452,7 +2487,7 @@ test("determineUserConfig - ignores config file input when both specified", asyn
24522487 const expectedConfigPath = configUtils . userConfigFromActionPath ( tmpDir ) ;
24532488
24542489 const inputs = createTestInitConfigInputs ( {
2455- configInput : simpleConfigFileContents ,
2490+ configInput : simpleConfigInput ,
24562491 configFile : configFilePath ,
24572492 workspacePath : tmpDir ,
24582493 } ) ;
@@ -2466,10 +2501,14 @@ test("determineUserConfig - ignores config file input when both specified", asyn
24662501 . logs (
24672502 t ,
24682503 `Using config from action input: ${ expectedConfigPath } ` ,
2469- `Using configuration file: ${ expectedConfigPath } ` ,
24702504 "Both a config file and config input were provided. Ignoring config file." ,
24712505 )
2472- . notLogs ( t , "No configuration file was provided" )
2506+ // The generated config file isn't loaded, since the `config` input has already been parsed.
2507+ . notLogs (
2508+ t ,
2509+ "No configuration file was provided" ,
2510+ `Using configuration file: ${ expectedConfigPath } ` ,
2511+ )
24732512 // The loaded configuration should match `simpleConfigFileContents`.
24742513 . passes ( t . deepEqual , {
24752514 name : "my config" ,
@@ -2481,12 +2520,12 @@ test("determineUserConfig - ignores config file input when both specified", asyn
24812520 } ) ;
24822521} ) ;
24832522
2484- /** A `config` input that we might get from Default Setup. */
2485- const defaultSetupConfigInput = `
2523+ /** The configuration from a `config` input that we might get from Default Setup. */
2524+ const defaultSetupConfigInput = yaml . load ( `
24862525 threat-models: [local, remote]
24872526 default-setup:
24882527 org:
2489- model-packs: [foo, bar]` ;
2528+ model-packs: [foo, bar]` ) as UserConfig ;
24902529
24912530test ( "determineUserConfig - merges configs if FF is enabled in Default Setup" , async ( t ) => {
24922531 await withTmpDir ( async ( tmpDir ) => {
@@ -2555,7 +2594,7 @@ test("determineUserConfig - ignores config file input in Default Setup if FF is
25552594 . withArgs (
25562595 tmpDir ,
25572596 createTestInitConfigInputs ( {
2558- configInput : simpleConfigFileContents ,
2597+ configInput : simpleConfigInput ,
25592598 configFile : configFilePath ,
25602599 workspacePath : tmpDir ,
25612600 } ) ,
@@ -2565,10 +2604,14 @@ test("determineUserConfig - ignores config file input in Default Setup if FF is
25652604 . logs (
25662605 t ,
25672606 `Using config from action input: ${ expectedConfigPath } ` ,
2568- `Using configuration file: ${ expectedConfigPath } ` ,
25692607 "Both a config file and config input were provided. Ignoring config file." ,
25702608 )
2571- . notLogs ( t , "No configuration file was provided" )
2609+ // The generated config file isn't loaded, since the `config` input has already been parsed.
2610+ . notLogs (
2611+ t ,
2612+ "No configuration file was provided" ,
2613+ `Using configuration file: ${ expectedConfigPath } ` ,
2614+ )
25722615 . passes ( t . deepEqual , {
25732616 name : "my config" ,
25742617 queries : [ { uses : "./foo_file" } ] ,
@@ -2587,7 +2630,7 @@ test("determineUserConfig - ignores config file input outside Default Setup if F
25872630 . withArgs (
25882631 tmpDir ,
25892632 createTestInitConfigInputs ( {
2590- configInput : simpleConfigFileContents ,
2633+ configInput : simpleConfigInput ,
25912634 configFile : configFilePath ,
25922635 workspacePath : tmpDir ,
25932636 } ) ,
@@ -2597,10 +2640,14 @@ test("determineUserConfig - ignores config file input outside Default Setup if F
25972640 . logs (
25982641 t ,
25992642 `Using config from action input: ${ expectedConfigPath } ` ,
2600- `Using configuration file: ${ expectedConfigPath } ` ,
26012643 "Both a config file and config input were provided. Ignoring config file." ,
26022644 )
2603- . notLogs ( t , "No configuration file was provided" )
2645+ // The generated config file isn't loaded, since the `config` input has already been parsed.
2646+ . notLogs (
2647+ t ,
2648+ "No configuration file was provided" ,
2649+ `Using configuration file: ${ expectedConfigPath } ` ,
2650+ )
26042651 . passes ( t . deepEqual , {
26052652 name : "my config" ,
26062653 queries : [ { uses : "./foo_file" } ] ,
0 commit comments