Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 89e1893

Browse files
committed
Forward file baseline information enablement to CLI
1 parent 5da50dc commit 89e1893

9 files changed

+114
-12
lines changed

lib/analyze.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.test.js

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyze.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ export async function runQueries(
389389
addSnippetsFlag,
390390
threadsFlag,
391391
enableDebugLogging ? "-vv" : "-v",
392-
automationDetailsId
392+
automationDetailsId,
393+
featureEnablement
393394
);
394395
}
395396

src/codeql.test.ts

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,16 @@ test("databaseInterpretResults() does not set --sarif-add-query-help for 2.7.0",
445445
const runnerConstructorStub = stubToolRunnerConstructor();
446446
const codeqlObject = await codeql.getCodeQLForTesting();
447447
sinon.stub(codeqlObject, "getVersion").resolves("2.7.0");
448-
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "");
448+
await codeqlObject.databaseInterpretResults(
449+
"",
450+
[],
451+
"",
452+
"",
453+
"",
454+
"-v",
455+
"",
456+
createFeatures([])
457+
);
449458
t.false(
450459
runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"),
451460
"--sarif-add-query-help should be absent, but it is present"
@@ -456,7 +465,16 @@ test("databaseInterpretResults() sets --sarif-add-query-help for 2.7.1", async (
456465
const runnerConstructorStub = stubToolRunnerConstructor();
457466
const codeqlObject = await codeql.getCodeQLForTesting();
458467
sinon.stub(codeqlObject, "getVersion").resolves("2.7.1");
459-
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "");
468+
await codeqlObject.databaseInterpretResults(
469+
"",
470+
[],
471+
"",
472+
"",
473+
"",
474+
"-v",
475+
"",
476+
createFeatures([])
477+
);
460478
t.true(
461479
runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"),
462480
"--sarif-add-query-help should be present, but it is absent"
@@ -846,6 +864,56 @@ test("does not use injected config", async (t: ExecutionContext<unknown>) => {
846864
}
847865
});
848866

867+
test("databaseInterpretResults() sets --sarif-add-baseline-file-info when feature enabled", async (t) => {
868+
const runnerConstructorStub = stubToolRunnerConstructor();
869+
const codeqlObject = await codeql.getCodeQLForTesting();
870+
// We need to set a CodeQL version such that running `databaseInterpretResults` does not crash.
871+
// The version of CodeQL is checked separately to determine feature enablement, and does not
872+
// otherwise impact this test, so set it to 0.0.0.
873+
sinon.stub(codeqlObject, "getVersion").resolves("0.0.0");
874+
await codeqlObject.databaseInterpretResults(
875+
"",
876+
[],
877+
"",
878+
"",
879+
"",
880+
"-v",
881+
"",
882+
createFeatures([Feature.FileBaselineInformationEnabled])
883+
);
884+
t.true(
885+
runnerConstructorStub.firstCall.args[1].includes(
886+
"--sarif-add-baseline-file-info"
887+
),
888+
"--sarif-add-baseline-file-info should be present, but it is absent"
889+
);
890+
});
891+
892+
test("databaseInterpretResults() does not set --sarif-add-baseline-file-info if feature disabled", async (t) => {
893+
const runnerConstructorStub = stubToolRunnerConstructor();
894+
const codeqlObject = await codeql.getCodeQLForTesting();
895+
// We need to set a CodeQL version such that running `databaseInterpretResults` does not crash.
896+
// The version of CodeQL is checked upstream to determine feature enablement, so it does not
897+
// affect this test.
898+
sinon.stub(codeqlObject, "getVersion").resolves("0.0.0");
899+
await codeqlObject.databaseInterpretResults(
900+
"",
901+
[],
902+
"",
903+
"",
904+
"",
905+
"-v",
906+
"",
907+
createFeatures([])
908+
);
909+
t.false(
910+
runnerConstructorStub.firstCall.args[1].includes(
911+
"--sarif-add-baseline-file-info"
912+
),
913+
"--sarif-add-baseline-file-info must be absent, but it is present"
914+
);
915+
});
916+
849917
export function stubToolRunnerConstructor(): sinon.SinonStub<
850918
any[],
851919
toolrunner.ToolRunner

src/codeql.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ export interface CodeQL {
173173
addSnippetsFlag: string,
174174
threadsFlag: string,
175175
verbosityFlag: string | undefined,
176-
automationDetailsId: string | undefined
176+
automationDetailsId: string | undefined,
177+
featureEnablement: FeatureEnablement
177178
): Promise<string>;
178179
/**
179180
* Run 'codeql database print-baseline'.
@@ -1066,7 +1067,8 @@ async function getCodeQLForCmd(
10661067
addSnippetsFlag: string,
10671068
threadsFlag: string,
10681069
verbosityFlag: string,
1069-
automationDetailsId: string | undefined
1070+
automationDetailsId: string | undefined,
1071+
featureEnablement: FeatureEnablement
10701072
): Promise<string> {
10711073
const codeqlArgs = [
10721074
"database",
@@ -1092,6 +1094,14 @@ async function getCodeQLForCmd(
10921094
) {
10931095
codeqlArgs.push("--sarif-category", automationDetailsId);
10941096
}
1097+
if (
1098+
await featureEnablement.getValue(
1099+
Feature.FileBaselineInformationEnabled,
1100+
this
1101+
)
1102+
) {
1103+
codeqlArgs.push("--sarif-add-baseline-file-info");
1104+
}
10951105
codeqlArgs.push(databasePath);
10961106
if (querySuitePaths) {
10971107
codeqlArgs.push(...querySuitePaths);

0 commit comments

Comments
 (0)