@@ -12,7 +12,7 @@ import { AnalysisKind, supportedAnalysisKinds } from "./analyses";
1212import * as api from "./api-client" ;
1313import { CachingKind } from "./caching-utils" ;
1414import { createStubCodeQL } from "./codeql" ;
15- import { UserConfig } from "./config/db-config" ;
15+ import { UserConfig , UserConfigWithActionExtensions } from "./config/db-config" ;
1616import * as file from "./config/file" ;
1717import * as configUtils from "./config-utils" ;
1818import * as errorMessages from "./error-messages" ;
@@ -2544,6 +2544,7 @@ test("loadUserConfig - loads local configuration files", async (t) => {
25442544 ) =>
25452545 configUtils . loadUserConfig (
25462546 actionState ,
2547+ [ AnalysisKind . CodeScanning ] ,
25472548 filePath ,
25482549 workspaceDir ,
25492550 SAMPLE_DOTCOM_API_DETAILS ,
@@ -2587,7 +2588,13 @@ test.serial("loadUserConfig - loads remote configuration files", async (t) => {
25872588
25882589 const remoteAddress = "owner/repo/file@ref" ;
25892590 await callee ( configUtils . loadUserConfig )
2590- . withArgs ( remoteAddress , tmpDir , SAMPLE_DOTCOM_API_DETAILS , tmpDir )
2591+ . withArgs (
2592+ [ AnalysisKind . CodeScanning ] ,
2593+ remoteAddress ,
2594+ tmpDir ,
2595+ SAMPLE_DOTCOM_API_DETAILS ,
2596+ tmpDir ,
2597+ )
25912598 . passes ( t . deepEqual , { } ) ;
25922599
25932600 t . true (
@@ -2665,6 +2672,7 @@ test.serial(
26652672
26662673 // Prepare the test call to `loadUserConfig`.
26672674 const targetWithArgs = target . withArgs (
2675+ [ AnalysisKind . CodeScanning ] ,
26682676 address ,
26692677 tmpDir ,
26702678 SAMPLE_DOTCOM_API_DETAILS ,
@@ -2705,3 +2713,57 @@ test.serial(
27052713 } ) ;
27062714 } ,
27072715) ;
2716+
2717+ test ( "loadUserConfig - applies analysis-specific settings" , async ( t ) => {
2718+ await withTmpDir ( async ( workspaceDir ) => {
2719+ await withTmpDir ( async ( tmpDir ) => {
2720+ // Construct the test target.
2721+ const loadUserConfig = (
2722+ actionState : ActionState < [ "Logger" , "Env" , "FeatureFlags" ] > ,
2723+ filePath : string ,
2724+ analysisKind : AnalysisKind ,
2725+ ) =>
2726+ configUtils . loadUserConfig (
2727+ actionState ,
2728+ [ analysisKind ] ,
2729+ filePath ,
2730+ workspaceDir ,
2731+ SAMPLE_DOTCOM_API_DETAILS ,
2732+ tmpDir ,
2733+ ) ;
2734+ const target = callee ( loadUserConfig ) ;
2735+
2736+ for ( const analysisKind of Object . values ( AnalysisKind ) ) {
2737+ const analysisSpecificConfig : UserConfig = {
2738+ paths : [ "custom" ] ,
2739+ queries : [ { uses : "foo" } ] ,
2740+ } ;
2741+ const baseConfig : UserConfig = { "threat-models" : [ "remote" ] } ;
2742+
2743+ // Write a local configuration file with an `analysisKind`-specific section.
2744+ const configPath = path . join ( workspaceDir , "codeql.yml" ) ;
2745+ fs . writeFileSync (
2746+ configPath ,
2747+ JSON . stringify ( {
2748+ ...baseConfig ,
2749+ [ analysisKind ] : analysisSpecificConfig ,
2750+ } satisfies UserConfigWithActionExtensions ) ,
2751+ "utf8" ,
2752+ ) ;
2753+
2754+ // The resulting configuration should be the `baseConfig` with the `analysisSpecificConfig`
2755+ // merged into it if the FF is enabled.
2756+ await target
2757+ . withArgs ( configPath , analysisKind )
2758+ . withFeatures ( [ Feature . ScopedConfigurations ] )
2759+ . passes ( t . deepEqual , { ...baseConfig , ...analysisSpecificConfig } ) ;
2760+
2761+ // Without the FF, it should be the `baseConfig`. This also validates that the
2762+ // `AnalysisKind`-specific sections are removed even if the FF is off.
2763+ await target
2764+ . withArgs ( configPath , analysisKind )
2765+ . passes ( t . deepEqual , baseConfig ) ;
2766+ }
2767+ } ) ;
2768+ } ) ;
2769+ } ) ;
0 commit comments