Forward file baseline information enablement to CLI
This commit is contained in:
parent
5da50dc362
commit
89e18934d3
9 changed files with 114 additions and 12 deletions
2
lib/analyze.js
generated
2
lib/analyze.js
generated
|
|
@ -227,7 +227,7 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
|
||||||
return statusReport;
|
return statusReport;
|
||||||
async function runInterpretResults(language, queries, sarifFile, enableDebugLogging) {
|
async function runInterpretResults(language, queries, sarifFile, enableDebugLogging) {
|
||||||
const databasePath = util.getCodeQLDatabasePath(config, language);
|
const databasePath = util.getCodeQLDatabasePath(config, language);
|
||||||
return await codeql.databaseInterpretResults(databasePath, queries, sarifFile, addSnippetsFlag, threadsFlag, enableDebugLogging ? "-vv" : "-v", automationDetailsId);
|
return await codeql.databaseInterpretResults(databasePath, queries, sarifFile, addSnippetsFlag, threadsFlag, enableDebugLogging ? "-vv" : "-v", automationDetailsId, featureEnablement);
|
||||||
}
|
}
|
||||||
async function cliCanCountLoC() {
|
async function cliCanCountLoC() {
|
||||||
return await util.codeQlVersionAbove(await (0, codeql_1.getCodeQL)(config.codeQLCmd), codeql_1.CODEQL_VERSION_COUNTS_LINES);
|
return await util.codeQlVersionAbove(await (0, codeql_1.getCodeQL)(config.codeQLCmd), codeql_1.CODEQL_VERSION_COUNTS_LINES);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
5
lib/codeql.js
generated
5
lib/codeql.js
generated
|
|
@ -698,7 +698,7 @@ async function getCodeQLForCmd(cmd, checkVersion) {
|
||||||
}
|
}
|
||||||
await runTool(cmd, codeqlArgs);
|
await runTool(cmd, codeqlArgs);
|
||||||
},
|
},
|
||||||
async databaseInterpretResults(databasePath, querySuitePaths, sarifFile, addSnippetsFlag, threadsFlag, verbosityFlag, automationDetailsId) {
|
async databaseInterpretResults(databasePath, querySuitePaths, sarifFile, addSnippetsFlag, threadsFlag, verbosityFlag, automationDetailsId, featureEnablement) {
|
||||||
const codeqlArgs = [
|
const codeqlArgs = [
|
||||||
"database",
|
"database",
|
||||||
"interpret-results",
|
"interpret-results",
|
||||||
|
|
@ -721,6 +721,9 @@ async function getCodeQLForCmd(cmd, checkVersion) {
|
||||||
(await util.codeQlVersionAbove(this, CODEQL_VERSION_SARIF_GROUP))) {
|
(await util.codeQlVersionAbove(this, CODEQL_VERSION_SARIF_GROUP))) {
|
||||||
codeqlArgs.push("--sarif-category", automationDetailsId);
|
codeqlArgs.push("--sarif-category", automationDetailsId);
|
||||||
}
|
}
|
||||||
|
if (await featureEnablement.getValue(feature_flags_1.Feature.FileBaselineInformationEnabled, this)) {
|
||||||
|
codeqlArgs.push("--sarif-add-baseline-file-info");
|
||||||
|
}
|
||||||
codeqlArgs.push(databasePath);
|
codeqlArgs.push(databasePath);
|
||||||
if (querySuitePaths) {
|
if (querySuitePaths) {
|
||||||
codeqlArgs.push(...querySuitePaths);
|
codeqlArgs.push(...querySuitePaths);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
24
lib/codeql.test.js
generated
24
lib/codeql.test.js
generated
|
|
@ -308,14 +308,14 @@ for (const [isFeatureEnabled, toolsInput, shouldToolcacheBeBypassed,] of TOOLCAC
|
||||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
sinon.stub(codeqlObject, "getVersion").resolves("2.7.0");
|
sinon.stub(codeqlObject, "getVersion").resolves("2.7.0");
|
||||||
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "");
|
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "", (0, testing_utils_1.createFeatures)([]));
|
||||||
t.false(runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"), "--sarif-add-query-help should be absent, but it is present");
|
t.false(runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"), "--sarif-add-query-help should be absent, but it is present");
|
||||||
});
|
});
|
||||||
(0, ava_1.default)("databaseInterpretResults() sets --sarif-add-query-help for 2.7.1", async (t) => {
|
(0, ava_1.default)("databaseInterpretResults() sets --sarif-add-query-help for 2.7.1", async (t) => {
|
||||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
sinon.stub(codeqlObject, "getVersion").resolves("2.7.1");
|
sinon.stub(codeqlObject, "getVersion").resolves("2.7.1");
|
||||||
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "");
|
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "", (0, testing_utils_1.createFeatures)([]));
|
||||||
t.true(runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"), "--sarif-add-query-help should be present, but it is absent");
|
t.true(runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"), "--sarif-add-query-help should be present, but it is absent");
|
||||||
});
|
});
|
||||||
(0, ava_1.default)("databaseInitCluster() without injected codescanning config", async (t) => {
|
(0, ava_1.default)("databaseInitCluster() without injected codescanning config", async (t) => {
|
||||||
|
|
@ -564,6 +564,26 @@ const injectedConfigMacro = ava_1.default.macro({
|
||||||
process.env["CODEQL_PASS_CONFIG_TO_CLI"] = origCODEQL_PASS_CONFIG_TO_CLI;
|
process.env["CODEQL_PASS_CONFIG_TO_CLI"] = origCODEQL_PASS_CONFIG_TO_CLI;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
(0, ava_1.default)("databaseInterpretResults() sets --sarif-add-baseline-file-info when feature enabled", async (t) => {
|
||||||
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
|
// We need to set a CodeQL version such that running `databaseInterpretResults` does not crash.
|
||||||
|
// The version of CodeQL is checked separately to determine feature enablement, and does not
|
||||||
|
// otherwise impact this test, so set it to 0.0.0.
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("0.0.0");
|
||||||
|
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "", (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.FileBaselineInformationEnabled]));
|
||||||
|
t.true(runnerConstructorStub.firstCall.args[1].includes("--sarif-add-baseline-file-info"), "--sarif-add-baseline-file-info should be present, but it is absent");
|
||||||
|
});
|
||||||
|
(0, ava_1.default)("databaseInterpretResults() does not set --sarif-add-baseline-file-info if feature disabled", async (t) => {
|
||||||
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
|
// We need to set a CodeQL version such that running `databaseInterpretResults` does not crash.
|
||||||
|
// The version of CodeQL is checked upstream to determine feature enablement, so it does not
|
||||||
|
// affect this test.
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("0.0.0");
|
||||||
|
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "", (0, testing_utils_1.createFeatures)([]));
|
||||||
|
t.false(runnerConstructorStub.firstCall.args[1].includes("--sarif-add-baseline-file-info"), "--sarif-add-baseline-file-info must be absent, but it is present");
|
||||||
|
});
|
||||||
function stubToolRunnerConstructor() {
|
function stubToolRunnerConstructor() {
|
||||||
const runnerObjectStub = sinon.createStubInstance(toolrunner.ToolRunner);
|
const runnerObjectStub = sinon.createStubInstance(toolrunner.ToolRunner);
|
||||||
runnerObjectStub.exec.resolves(0);
|
runnerObjectStub.exec.resolves(0);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -389,7 +389,8 @@ export async function runQueries(
|
||||||
addSnippetsFlag,
|
addSnippetsFlag,
|
||||||
threadsFlag,
|
threadsFlag,
|
||||||
enableDebugLogging ? "-vv" : "-v",
|
enableDebugLogging ? "-vv" : "-v",
|
||||||
automationDetailsId
|
automationDetailsId,
|
||||||
|
featureEnablement
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -445,7 +445,16 @@ test("databaseInterpretResults() does not set --sarif-add-query-help for 2.7.0",
|
||||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
sinon.stub(codeqlObject, "getVersion").resolves("2.7.0");
|
sinon.stub(codeqlObject, "getVersion").resolves("2.7.0");
|
||||||
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "");
|
await codeqlObject.databaseInterpretResults(
|
||||||
|
"",
|
||||||
|
[],
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"-v",
|
||||||
|
"",
|
||||||
|
createFeatures([])
|
||||||
|
);
|
||||||
t.false(
|
t.false(
|
||||||
runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"),
|
runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"),
|
||||||
"--sarif-add-query-help should be absent, but it is present"
|
"--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 (
|
||||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
sinon.stub(codeqlObject, "getVersion").resolves("2.7.1");
|
sinon.stub(codeqlObject, "getVersion").resolves("2.7.1");
|
||||||
await codeqlObject.databaseInterpretResults("", [], "", "", "", "-v", "");
|
await codeqlObject.databaseInterpretResults(
|
||||||
|
"",
|
||||||
|
[],
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"-v",
|
||||||
|
"",
|
||||||
|
createFeatures([])
|
||||||
|
);
|
||||||
t.true(
|
t.true(
|
||||||
runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"),
|
runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"),
|
||||||
"--sarif-add-query-help should be present, but it is absent"
|
"--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>) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("databaseInterpretResults() sets --sarif-add-baseline-file-info when feature enabled", async (t) => {
|
||||||
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
|
// We need to set a CodeQL version such that running `databaseInterpretResults` does not crash.
|
||||||
|
// The version of CodeQL is checked separately to determine feature enablement, and does not
|
||||||
|
// otherwise impact this test, so set it to 0.0.0.
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("0.0.0");
|
||||||
|
await codeqlObject.databaseInterpretResults(
|
||||||
|
"",
|
||||||
|
[],
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"-v",
|
||||||
|
"",
|
||||||
|
createFeatures([Feature.FileBaselineInformationEnabled])
|
||||||
|
);
|
||||||
|
t.true(
|
||||||
|
runnerConstructorStub.firstCall.args[1].includes(
|
||||||
|
"--sarif-add-baseline-file-info"
|
||||||
|
),
|
||||||
|
"--sarif-add-baseline-file-info should be present, but it is absent"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("databaseInterpretResults() does not set --sarif-add-baseline-file-info if feature disabled", async (t) => {
|
||||||
|
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||||
|
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||||
|
// We need to set a CodeQL version such that running `databaseInterpretResults` does not crash.
|
||||||
|
// The version of CodeQL is checked upstream to determine feature enablement, so it does not
|
||||||
|
// affect this test.
|
||||||
|
sinon.stub(codeqlObject, "getVersion").resolves("0.0.0");
|
||||||
|
await codeqlObject.databaseInterpretResults(
|
||||||
|
"",
|
||||||
|
[],
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"-v",
|
||||||
|
"",
|
||||||
|
createFeatures([])
|
||||||
|
);
|
||||||
|
t.false(
|
||||||
|
runnerConstructorStub.firstCall.args[1].includes(
|
||||||
|
"--sarif-add-baseline-file-info"
|
||||||
|
),
|
||||||
|
"--sarif-add-baseline-file-info must be absent, but it is present"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
export function stubToolRunnerConstructor(): sinon.SinonStub<
|
export function stubToolRunnerConstructor(): sinon.SinonStub<
|
||||||
any[],
|
any[],
|
||||||
toolrunner.ToolRunner
|
toolrunner.ToolRunner
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,8 @@ export interface CodeQL {
|
||||||
addSnippetsFlag: string,
|
addSnippetsFlag: string,
|
||||||
threadsFlag: string,
|
threadsFlag: string,
|
||||||
verbosityFlag: string | undefined,
|
verbosityFlag: string | undefined,
|
||||||
automationDetailsId: string | undefined
|
automationDetailsId: string | undefined,
|
||||||
|
featureEnablement: FeatureEnablement
|
||||||
): Promise<string>;
|
): Promise<string>;
|
||||||
/**
|
/**
|
||||||
* Run 'codeql database print-baseline'.
|
* Run 'codeql database print-baseline'.
|
||||||
|
|
@ -1066,7 +1067,8 @@ async function getCodeQLForCmd(
|
||||||
addSnippetsFlag: string,
|
addSnippetsFlag: string,
|
||||||
threadsFlag: string,
|
threadsFlag: string,
|
||||||
verbosityFlag: string,
|
verbosityFlag: string,
|
||||||
automationDetailsId: string | undefined
|
automationDetailsId: string | undefined,
|
||||||
|
featureEnablement: FeatureEnablement
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const codeqlArgs = [
|
const codeqlArgs = [
|
||||||
"database",
|
"database",
|
||||||
|
|
@ -1092,6 +1094,14 @@ async function getCodeQLForCmd(
|
||||||
) {
|
) {
|
||||||
codeqlArgs.push("--sarif-category", automationDetailsId);
|
codeqlArgs.push("--sarif-category", automationDetailsId);
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
await featureEnablement.getValue(
|
||||||
|
Feature.FileBaselineInformationEnabled,
|
||||||
|
this
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
codeqlArgs.push("--sarif-add-baseline-file-info");
|
||||||
|
}
|
||||||
codeqlArgs.push(databasePath);
|
codeqlArgs.push(databasePath);
|
||||||
if (querySuitePaths) {
|
if (querySuitePaths) {
|
||||||
codeqlArgs.push(...querySuitePaths);
|
codeqlArgs.push(...querySuitePaths);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue