mirror of
https://github.com/github/codeql-action.git
synced 2026-01-05 06:00:32 +08:00
Merge pull request #1244 from github/criemen/remove-lua-tracer-ff
Remove the lua tracer feature flag check from the codeql-action.
This commit is contained in:
@@ -1,23 +1,19 @@
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
import { ExecOptions } from "@actions/exec";
|
||||
import * as toolrunner from "@actions/exec/lib/toolrunner";
|
||||
import test, { ExecutionContext } from "ava";
|
||||
import * as yaml from "js-yaml";
|
||||
import * as sinon from "sinon";
|
||||
|
||||
import {
|
||||
convertPackToQuerySuiteEntry,
|
||||
createdDBForScannedLanguages,
|
||||
createQuerySuiteContents,
|
||||
runQueries,
|
||||
validateQueryFilters,
|
||||
} from "./analyze";
|
||||
import { setCodeQL, getCodeQLForTesting } from "./codeql";
|
||||
import { setCodeQL } from "./codeql";
|
||||
import { Config } from "./config-utils";
|
||||
import * as count from "./count-loc";
|
||||
import { createFeatureFlags, FeatureFlag } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import { setupTests, setupActionsVars } from "./testing-utils";
|
||||
@@ -431,114 +427,3 @@ test("createQuerySuiteContents", (t) => {
|
||||
|
||||
t.deepEqual(yamlResult, expected);
|
||||
});
|
||||
|
||||
const stubConfig: Config = {
|
||||
languages: [Language.cpp, Language.go],
|
||||
queries: {},
|
||||
pathsIgnore: [],
|
||||
paths: [],
|
||||
originalUserInput: {},
|
||||
tempDir: "",
|
||||
codeQLCmd: "",
|
||||
gitHubVersion: {
|
||||
type: util.GitHubVariant.DOTCOM,
|
||||
} as util.GitHubVersion,
|
||||
dbLocation: "",
|
||||
packs: {},
|
||||
debugMode: false,
|
||||
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
|
||||
augmentationProperties: {
|
||||
injectedMlQueries: false,
|
||||
packsInputCombines: false,
|
||||
queriesInputCombines: false,
|
||||
},
|
||||
trapCaches: {},
|
||||
trapCacheDownloadTime: 0,
|
||||
};
|
||||
|
||||
for (const options of [
|
||||
{
|
||||
name: "Lua feature flag enabled, but old CLI",
|
||||
version: "2.9.0",
|
||||
featureFlags: [FeatureFlag.LuaTracerConfigEnabled],
|
||||
yesFlagSet: false,
|
||||
noFlagSet: false,
|
||||
},
|
||||
{
|
||||
name: "Lua feature flag disabled, with old CLI",
|
||||
version: "2.9.0",
|
||||
featureFlags: [],
|
||||
yesFlagSet: false,
|
||||
noFlagSet: false,
|
||||
},
|
||||
{
|
||||
name: "Lua feature flag enabled, with new CLI",
|
||||
version: "2.10.0",
|
||||
featureFlags: [FeatureFlag.LuaTracerConfigEnabled],
|
||||
yesFlagSet: true,
|
||||
noFlagSet: false,
|
||||
},
|
||||
{
|
||||
name: "Lua feature flag disabled, with new CLI",
|
||||
version: "2.10.0",
|
||||
featureFlags: [],
|
||||
yesFlagSet: false,
|
||||
noFlagSet: true,
|
||||
},
|
||||
]) {
|
||||
test(`createdDBForScannedLanguages() ${options.name}`, async (t) => {
|
||||
const runnerObjectStub = sinon.createStubInstance(toolrunner.ToolRunner);
|
||||
runnerObjectStub.exec.resolves(0);
|
||||
const runnerConstructorStub = sinon.stub(toolrunner, "ToolRunner");
|
||||
runnerConstructorStub.callsFake(
|
||||
(_toolPath, args, execOptions: ExecOptions) => {
|
||||
// Call listener on `codeql resolve extractor`
|
||||
if (args[0] === "resolve" && args[1] === "extractor") {
|
||||
const func = execOptions.listeners!.stdout as (data: Buffer) => void;
|
||||
t.truthy(func, "stdout listener is defined");
|
||||
func(Buffer.from('"/path/to/extractor"'));
|
||||
}
|
||||
return runnerObjectStub;
|
||||
}
|
||||
);
|
||||
|
||||
const codeqlObject = await getCodeQLForTesting("codeql/for-testing");
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(options.version);
|
||||
|
||||
await createdDBForScannedLanguages(
|
||||
codeqlObject,
|
||||
stubConfig,
|
||||
getRunnerLogger(true),
|
||||
createFeatureFlags(options.featureFlags)
|
||||
);
|
||||
if (options.yesFlagSet)
|
||||
t.true(
|
||||
runnerConstructorStub.secondCall.args[1].includes(
|
||||
"--internal-use-lua-tracing"
|
||||
),
|
||||
"--internal-use-lua-tracing should be present, but it is absent"
|
||||
);
|
||||
else
|
||||
t.false(
|
||||
runnerConstructorStub.secondCall.args[1].includes(
|
||||
"--internal-use-lua-tracing"
|
||||
),
|
||||
"--internal-use-lua-tracing should be absent, but it is present"
|
||||
);
|
||||
if (options.noFlagSet)
|
||||
t.true(
|
||||
runnerConstructorStub.secondCall.args[1].includes(
|
||||
"--no-internal-use-lua-tracing"
|
||||
),
|
||||
"--no-internal-use-lua-tracing should be present, but it is absent"
|
||||
);
|
||||
else
|
||||
t.false(
|
||||
runnerConstructorStub.secondCall.args[1].includes(
|
||||
"--no-internal-use-lua-tracing"
|
||||
),
|
||||
"--no-internal-use-lua-tracing should be absent, but it is present"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ export async function createdDBForScannedLanguages(
|
||||
await setupPythonExtractor(logger);
|
||||
}
|
||||
|
||||
await codeql.extractScannedLanguage(config, language, featureFlags);
|
||||
await codeql.extractScannedLanguage(config, language);
|
||||
logger.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,102 +442,6 @@ test("databaseInterpretResults() sets --sarif-add-query-help for 2.7.1", async (
|
||||
);
|
||||
});
|
||||
|
||||
test("databaseInitCluster() Lua feature flag enabled, but old CLI", async (t) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves("2.9.0");
|
||||
|
||||
await codeqlObject.databaseInitCluster(
|
||||
stubConfig,
|
||||
"",
|
||||
undefined,
|
||||
undefined,
|
||||
createFeatureFlags([FeatureFlag.LuaTracerConfigEnabled]),
|
||||
getRunnerLogger(true)
|
||||
);
|
||||
t.false(
|
||||
runnerConstructorStub.firstCall.args[1].includes(
|
||||
"--internal-use-lua-tracing"
|
||||
),
|
||||
"--internal-use-lua-tracing should be absent, but it is present"
|
||||
);
|
||||
t.false(
|
||||
runnerConstructorStub.firstCall.args[1].includes(
|
||||
"--no-internal-use-lua-tracing"
|
||||
),
|
||||
"--no-internal-use-lua-tracing should be absent, but it is present"
|
||||
);
|
||||
});
|
||||
|
||||
test("databaseInitCluster() Lua feature flag disabled, with old CLI", async (t) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves("2.9.0");
|
||||
|
||||
await codeqlObject.databaseInitCluster(
|
||||
stubConfig,
|
||||
"",
|
||||
undefined,
|
||||
undefined,
|
||||
createFeatureFlags([]),
|
||||
getRunnerLogger(true)
|
||||
);
|
||||
t.false(
|
||||
runnerConstructorStub.firstCall.args[1].includes(
|
||||
"--internal-use-lua-tracing"
|
||||
),
|
||||
"--internal-use-lua-tracing should be absent, but it is present"
|
||||
);
|
||||
t.false(
|
||||
runnerConstructorStub.firstCall.args[1].includes(
|
||||
"--no-internal-use-lua-tracing"
|
||||
),
|
||||
"--no-internal-use-lua-tracing should be absent, but it is present"
|
||||
);
|
||||
});
|
||||
|
||||
test("databaseInitCluster() Lua feature flag enabled, compatible CLI", async (t) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves("2.10.0");
|
||||
|
||||
await codeqlObject.databaseInitCluster(
|
||||
stubConfig,
|
||||
"",
|
||||
undefined,
|
||||
undefined,
|
||||
createFeatureFlags([FeatureFlag.LuaTracerConfigEnabled]),
|
||||
getRunnerLogger(true)
|
||||
);
|
||||
t.true(
|
||||
runnerConstructorStub.firstCall.args[1].includes(
|
||||
"--internal-use-lua-tracing"
|
||||
),
|
||||
"--internal-use-lua-tracing should be present, but it is absent"
|
||||
);
|
||||
});
|
||||
|
||||
test("databaseInitCluster() Lua feature flag disabled, compatible CLI", async (t) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves("2.10.0");
|
||||
|
||||
await codeqlObject.databaseInitCluster(
|
||||
stubConfig,
|
||||
"",
|
||||
undefined,
|
||||
undefined,
|
||||
createFeatureFlags([]),
|
||||
getRunnerLogger(true)
|
||||
);
|
||||
t.true(
|
||||
runnerConstructorStub.firstCall.args[1].includes(
|
||||
"--no-internal-use-lua-tracing"
|
||||
),
|
||||
"--no-internal-use-lua-tracing should be present, but it is absent"
|
||||
);
|
||||
});
|
||||
|
||||
test("databaseInitCluster() without injected codescanning config", async (t) => {
|
||||
await util.withTmpDir(async (tempDir) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
|
||||
@@ -102,11 +102,7 @@ export interface CodeQL {
|
||||
* Extract code for a scanned language using 'codeql database trace-command'
|
||||
* and running the language extractor.
|
||||
*/
|
||||
extractScannedLanguage(
|
||||
config: Config,
|
||||
language: Language,
|
||||
featureFlags: FeatureFlags
|
||||
): Promise<void>;
|
||||
extractScannedLanguage(config: Config, language: Language): Promise<void>;
|
||||
/**
|
||||
* Finalize a database using 'codeql database finalize'.
|
||||
*/
|
||||
@@ -800,29 +796,26 @@ async function getCodeQLForCmd(
|
||||
extraArgs.push(`--trace-process-level=${processLevel || 3}`);
|
||||
}
|
||||
if (
|
||||
await util.codeQlVersionAbove(this, CODEQL_VERSION_LUA_TRACER_CONFIG)
|
||||
// There's a bug in Lua tracing for Go on Windows in versions earlier than
|
||||
// `CODEQL_VERSION_LUA_TRACING_GO_WINDOWS_FIXED`, so don't use Lua tracing
|
||||
// when tracing Go on Windows on these CodeQL versions.
|
||||
(await util.codeQlVersionAbove(
|
||||
this,
|
||||
CODEQL_VERSION_LUA_TRACER_CONFIG
|
||||
)) &&
|
||||
config.languages.includes(Language.go) &&
|
||||
isTracedLanguage(
|
||||
Language.go,
|
||||
isGoExtractionReconciliationEnabled,
|
||||
logger
|
||||
) &&
|
||||
process.platform === "win32" &&
|
||||
!(await util.codeQlVersionAbove(
|
||||
this,
|
||||
CODEQL_VERSION_LUA_TRACING_GO_WINDOWS_FIXED
|
||||
))
|
||||
) {
|
||||
if (
|
||||
(await featureFlags.getValue(FeatureFlag.LuaTracerConfigEnabled)) &&
|
||||
// There's a bug in Lua tracing for Go on Windows in versions earlier than
|
||||
// `CODEQL_VERSION_LUA_TRACING_GO_WINDOWS_FIXED`, so don't use Lua tracing
|
||||
// when tracing Go on Windows on these CodeQL versions.
|
||||
(!config.languages.includes(Language.go) ||
|
||||
!isTracedLanguage(
|
||||
Language.go,
|
||||
isGoExtractionReconciliationEnabled,
|
||||
logger
|
||||
) ||
|
||||
process.platform !== "win32" ||
|
||||
(await util.codeQlVersionAbove(
|
||||
this,
|
||||
CODEQL_VERSION_LUA_TRACING_GO_WINDOWS_FIXED
|
||||
)))
|
||||
) {
|
||||
extraArgs.push("--internal-use-lua-tracing");
|
||||
} else {
|
||||
extraArgs.push("--no-internal-use-lua-tracing");
|
||||
}
|
||||
extraArgs.push("--no-internal-use-lua-tracing");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -879,11 +872,7 @@ async function getCodeQLForCmd(
|
||||
// (https://github.com/actions/runner/pull/416).
|
||||
await runTool(autobuildCmd);
|
||||
},
|
||||
async extractScannedLanguage(
|
||||
config: Config,
|
||||
language: Language,
|
||||
featureFlags: FeatureFlags
|
||||
) {
|
||||
async extractScannedLanguage(config: Config, language: Language) {
|
||||
const databasePath = util.getCodeQLDatabasePath(config, language);
|
||||
// Get extractor location
|
||||
let extractorPath = "";
|
||||
@@ -916,24 +905,12 @@ async function getCodeQLForCmd(
|
||||
"tools",
|
||||
`autobuild${ext}`
|
||||
);
|
||||
const extraArgs: string[] = [];
|
||||
if (
|
||||
await util.codeQlVersionAbove(this, CODEQL_VERSION_LUA_TRACER_CONFIG)
|
||||
) {
|
||||
if (await featureFlags.getValue(FeatureFlag.LuaTracerConfigEnabled)) {
|
||||
extraArgs.push("--internal-use-lua-tracing");
|
||||
} else {
|
||||
extraArgs.push("--no-internal-use-lua-tracing");
|
||||
}
|
||||
}
|
||||
|
||||
// Run trace command
|
||||
await toolrunnerErrorCatcher(
|
||||
cmd,
|
||||
[
|
||||
"database",
|
||||
"trace-command",
|
||||
...extraArgs,
|
||||
...(await getTrapCachingExtractorConfigArgsForLang(config, language)),
|
||||
...getExtraOptionsFromEnv(["database", "trace-command"]),
|
||||
databasePath,
|
||||
|
||||
@@ -153,10 +153,7 @@ test("Feature flags exception is propagated if the API request errors", async (t
|
||||
});
|
||||
});
|
||||
|
||||
const FEATURE_FLAGS = [
|
||||
"ml_powered_queries_enabled",
|
||||
"lua_tracer_config_enabled",
|
||||
];
|
||||
const FEATURE_FLAGS = ["ml_powered_queries_enabled"];
|
||||
|
||||
for (const featureFlag of FEATURE_FLAGS) {
|
||||
test(`Feature flag '${featureFlag}' is enabled if enabled in the API response`, async (t) => {
|
||||
@@ -181,9 +178,6 @@ for (const featureFlag of FEATURE_FLAGS) {
|
||||
ml_powered_queries_enabled: await featureFlags.getValue(
|
||||
FeatureFlag.MlPoweredQueriesEnabled
|
||||
),
|
||||
lua_tracer_config_enabled: await featureFlags.getValue(
|
||||
FeatureFlag.LuaTracerConfigEnabled
|
||||
),
|
||||
};
|
||||
|
||||
t.deepEqual(actualFeatureFlags, expectedFeatureFlags);
|
||||
|
||||
@@ -9,7 +9,6 @@ export interface FeatureFlags {
|
||||
|
||||
export enum FeatureFlag {
|
||||
BypassToolcacheEnabled = "bypass_toolcache_enabled",
|
||||
LuaTracerConfigEnabled = "lua_tracer_config_enabled",
|
||||
MlPoweredQueriesEnabled = "ml_powered_queries_enabled",
|
||||
TrapCachingEnabled = "trap_caching_enabled",
|
||||
GolangExtractionReconciliationEnabled = "golang_extraction_reconciliation_enabled",
|
||||
|
||||
Reference in New Issue
Block a user