From c7eb488f8f5715587be486eb3391796a0aeea8dd Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Sat, 20 Sep 2025 14:06:20 +0100 Subject: [PATCH] Add tests --- src/codeql.test.ts | 78 ++++++++++++++++++++++++++++++++++++ src/config/db-config.test.ts | 48 ++++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/src/codeql.test.ts b/src/codeql.test.ts index 91cb2a453..b80b29725 100644 --- a/src/codeql.test.ts +++ b/src/codeql.test.ts @@ -713,6 +713,84 @@ test( {}, ); +test( + "repo property queries have the highest precedence", + injectedConfigMacro, + { + ...defaultAugmentationProperties, + queriesInputCombines: true, + queriesInput: [{ uses: "xxx" }, { uses: "yyy" }], + repoPropertyQueries: { + combines: false, + input: [{ uses: "zzz" }, { uses: "aaa" }], + }, + }, + { + originalUserInput: { + queries: [{ uses: "uu" }, { uses: "vv" }], + }, + }, + { + queries: [{ uses: "zzz" }, { uses: "aaa" }], + }, +); + +test( + "repo property queries combines with queries input", + injectedConfigMacro, + { + ...defaultAugmentationProperties, + queriesInputCombines: false, + queriesInput: [{ uses: "xxx" }, { uses: "yyy" }], + repoPropertyQueries: { + combines: true, + input: [{ uses: "zzz" }, { uses: "aaa" }], + }, + }, + { + originalUserInput: { + queries: [{ uses: "uu" }, { uses: "vv" }], + }, + }, + { + queries: [ + { uses: "zzz" }, + { uses: "aaa" }, + { uses: "xxx" }, + { uses: "yyy" }, + ], + }, +); + +test( + "repo property queries combines everything else", + injectedConfigMacro, + { + ...defaultAugmentationProperties, + queriesInputCombines: true, + queriesInput: [{ uses: "xxx" }, { uses: "yyy" }], + repoPropertyQueries: { + combines: true, + input: [{ uses: "zzz" }, { uses: "aaa" }], + }, + }, + { + originalUserInput: { + queries: [{ uses: "uu" }, { uses: "vv" }], + }, + }, + { + queries: [ + { uses: "zzz" }, + { uses: "aaa" }, + { uses: "xxx" }, + { uses: "yyy" }, + { uses: "uu" }, + { uses: "vv" }, + ], + }, +); + test("passes a code scanning config AND qlconfig to the CLI", async (t: ExecutionContext) => { await util.withTmpDir(async (tempDir) => { const runnerConstructorStub = stubToolRunnerConstructor(); diff --git a/src/config/db-config.test.ts b/src/config/db-config.test.ts index a5778088f..b22503475 100644 --- a/src/config/db-config.test.ts +++ b/src/config/db-config.test.ts @@ -271,6 +271,42 @@ test( }, ); +test( + calculateAugmentationMacro, + "With repo property queries", + undefined, + undefined, + [KnownLanguage.javascript], + { + "github-codeql-extra-queries": "a, b, c, d", + }, + { + ...dbConfig.defaultAugmentationProperties, + repoPropertyQueries: { + combines: false, + input: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }], + }, + }, +); + +test( + calculateAugmentationMacro, + "With repo property queries combining", + undefined, + undefined, + [KnownLanguage.javascript], + { + "github-codeql-extra-queries": "+ a, b, c, d", + }, + { + ...dbConfig.defaultAugmentationProperties, + repoPropertyQueries: { + combines: true, + input: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }], + }, + }, +); + const calculateAugmentationErrorMacro = test.macro({ exec: async ( t: ExecutionContext, @@ -315,6 +351,18 @@ test( /The workflow property "packs" is invalid/, ); +test( + calculateAugmentationErrorMacro, + "Plus (+) with nothing else (repo property queries)", + undefined, + undefined, + [KnownLanguage.javascript], + { + "github-codeql-extra-queries": " + ", + }, + /The repository property "github-codeql-extra-queries" is invalid/, +); + test( calculateAugmentationErrorMacro, "Packs input with multiple languages",