@@ -473,6 +473,12 @@ const simpleConfigFileContents = `
473473 queries:
474474 - uses: ./foo_file` ;
475475
476+ /** The configuration in `simpleConfigFileContents`. */
477+ const simpleConfigInput : UserConfig = {
478+ name : "my config" ,
479+ queries : [ { uses : "./foo_file" } ] ,
480+ } ;
481+
476482/** A less minimal configuration file. */
477483const otherConfigFileContents = `
478484 name: my config
@@ -558,16 +564,14 @@ test.serial(
558564 tempDir ,
559565 ) ;
560566
561- const configInput = `
562- name: my config
563- queries:
564- - uses: ./foo
565- packs:
566- javascript:
567- - a/b@1.2.3
568- python:
569- - c/d@1.2.3
570- ` ;
567+ const configInput : UserConfig = {
568+ name : "my config" ,
569+ queries : [ { uses : "./foo" } ] ,
570+ packs : {
571+ javascript : [ "a/b@1.2.3" ] ,
572+ python : [ "c/d@1.2.3" ] ,
573+ } ,
574+ } ;
571575
572576 fs . mkdirSync ( path . join ( tempDir , "foo" ) ) ;
573577
@@ -598,7 +602,16 @@ test.serial(
598602 } ) ,
599603 ) ;
600604
601- t . deepEqual ( config . originalUserInput , yaml . load ( configInput ) ) ;
605+ // Compare with a separate object rather than `configInput` itself, so that the test catches
606+ // changes made to the input in place.
607+ t . deepEqual ( config . originalUserInput , {
608+ name : "my config" ,
609+ queries : [ { uses : "./foo" } ] ,
610+ packs : {
611+ javascript : [ "a/b@1.2.3" ] ,
612+ python : [ "c/d@1.2.3" ] ,
613+ } ,
614+ } ) ;
602615 } ) ;
603616 } ,
604617) ;
@@ -2413,7 +2426,7 @@ test("determineUserConfig - loads config input", async (t) => {
24132426 const expectedConfigPath = configUtils . userConfigFromActionPath ( tmpDir ) ;
24142427
24152428 const inputs = createTestInitConfigInputs ( {
2416- configInput : simpleConfigFileContents ,
2429+ configInput : simpleConfigInput ,
24172430 configFile : undefined ,
24182431 workspacePath : tmpDir ,
24192432 } ) ;
@@ -2423,17 +2436,15 @@ test("determineUserConfig - loads config input", async (t) => {
24232436
24242437 await target
24252438 // 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.
2439+ . logs ( t , `Using config from action input: ${ expectedConfigPath } ` )
2440+ // The message about no configuration input and the warning about both inputs should not have
2441+ // been logged. The generated config file isn't loaded, since the `config` input has already
2442+ // been parsed.
24332443 . notLogs (
24342444 t ,
24352445 "No configuration file was provided" ,
24362446 "Both a config file and config input were provided. Ignoring config file." ,
2447+ `Using configuration file: ${ expectedConfigPath } ` ,
24372448 )
24382449 // The loaded configuration should match `simpleConfigFileContents`.
24392450 . passes ( t . deepEqual , {
@@ -2452,7 +2463,7 @@ test("determineUserConfig - ignores config file input when both specified", asyn
24522463 const expectedConfigPath = configUtils . userConfigFromActionPath ( tmpDir ) ;
24532464
24542465 const inputs = createTestInitConfigInputs ( {
2455- configInput : simpleConfigFileContents ,
2466+ configInput : simpleConfigInput ,
24562467 configFile : configFilePath ,
24572468 workspacePath : tmpDir ,
24582469 } ) ;
@@ -2466,10 +2477,14 @@ test("determineUserConfig - ignores config file input when both specified", asyn
24662477 . logs (
24672478 t ,
24682479 `Using config from action input: ${ expectedConfigPath } ` ,
2469- `Using configuration file: ${ expectedConfigPath } ` ,
24702480 "Both a config file and config input were provided. Ignoring config file." ,
24712481 )
2472- . notLogs ( t , "No configuration file was provided" )
2482+ // The generated config file isn't loaded, since the `config` input has already been parsed.
2483+ . notLogs (
2484+ t ,
2485+ "No configuration file was provided" ,
2486+ `Using configuration file: ${ expectedConfigPath } ` ,
2487+ )
24732488 // The loaded configuration should match `simpleConfigFileContents`.
24742489 . passes ( t . deepEqual , {
24752490 name : "my config" ,
@@ -2482,11 +2497,14 @@ test("determineUserConfig - ignores config file input when both specified", asyn
24822497} ) ;
24832498
24842499/** A `config` input that we might get from Default Setup. */
2485- const defaultSetupConfigInput = `
2486- threat-models: [local, remote]
2487- default-setup:
2488- org:
2489- model-packs: [foo, bar]` ;
2500+ const defaultSetupConfigInput : UserConfig = {
2501+ "threat-models" : [ "local" , "remote" ] ,
2502+ "default-setup" : {
2503+ org : {
2504+ "model-packs" : [ "foo" , "bar" ] ,
2505+ } ,
2506+ } ,
2507+ } ;
24902508
24912509test ( "determineUserConfig - merges configs if FF is enabled in Default Setup" , async ( t ) => {
24922510 await withTmpDir ( async ( tmpDir ) => {
@@ -2555,7 +2573,7 @@ test("determineUserConfig - ignores config file input in Default Setup if FF is
25552573 . withArgs (
25562574 tmpDir ,
25572575 createTestInitConfigInputs ( {
2558- configInput : simpleConfigFileContents ,
2576+ configInput : simpleConfigInput ,
25592577 configFile : configFilePath ,
25602578 workspacePath : tmpDir ,
25612579 } ) ,
@@ -2565,10 +2583,14 @@ test("determineUserConfig - ignores config file input in Default Setup if FF is
25652583 . logs (
25662584 t ,
25672585 `Using config from action input: ${ expectedConfigPath } ` ,
2568- `Using configuration file: ${ expectedConfigPath } ` ,
25692586 "Both a config file and config input were provided. Ignoring config file." ,
25702587 )
2571- . notLogs ( t , "No configuration file was provided" )
2588+ // The generated config file isn't loaded, since the `config` input has already been parsed.
2589+ . notLogs (
2590+ t ,
2591+ "No configuration file was provided" ,
2592+ `Using configuration file: ${ expectedConfigPath } ` ,
2593+ )
25722594 . passes ( t . deepEqual , {
25732595 name : "my config" ,
25742596 queries : [ { uses : "./foo_file" } ] ,
@@ -2587,7 +2609,7 @@ test("determineUserConfig - ignores config file input outside Default Setup if F
25872609 . withArgs (
25882610 tmpDir ,
25892611 createTestInitConfigInputs ( {
2590- configInput : simpleConfigFileContents ,
2612+ configInput : simpleConfigInput ,
25912613 configFile : configFilePath ,
25922614 workspacePath : tmpDir ,
25932615 } ) ,
@@ -2597,10 +2619,14 @@ test("determineUserConfig - ignores config file input outside Default Setup if F
25972619 . logs (
25982620 t ,
25992621 `Using config from action input: ${ expectedConfigPath } ` ,
2600- `Using configuration file: ${ expectedConfigPath } ` ,
26012622 "Both a config file and config input were provided. Ignoring config file." ,
26022623 )
2603- . notLogs ( t , "No configuration file was provided" )
2624+ // The generated config file isn't loaded, since the `config` input has already been parsed.
2625+ . notLogs (
2626+ t ,
2627+ "No configuration file was provided" ,
2628+ `Using configuration file: ${ expectedConfigPath } ` ,
2629+ )
26042630 . passes ( t . deepEqual , {
26052631 name : "my config" ,
26062632 queries : [ { uses : "./foo_file" } ] ,
0 commit comments