More renaming

This commit is contained in:
Andrew Eisenberg 2022-10-11 10:39:40 -07:00
parent 6c869f8b03
commit 701cea34ba
45 changed files with 356 additions and 358 deletions

View file

@ -140,13 +140,13 @@ function doesGoExtractionOutputExist(config: Config): boolean {
*/
async function runAutobuildIfLegacyGoWorkflow(
config: Config,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
logger: Logger
) {
if (!config.languages.includes(Language.go)) {
return;
}
if (!(await util.isGoExtractionReconciliationEnabled(featureFlags))) {
if (!(await util.isGoExtractionReconciliationEnabled(featureEnablement))) {
logger.debug(
"Won't run Go autobuild since Go extraction reconciliation is not enabled."
);
@ -228,14 +228,14 @@ async function run() {
const gitHubVersion = await getGitHubVersionActionsOnly();
const featureFlags = new Features(
const features = new Features(
gitHubVersion,
apiDetails,
repositoryNwo,
logger
);
await runAutobuildIfLegacyGoWorkflow(config, featureFlags, logger);
await runAutobuildIfLegacyGoWorkflow(config, features, logger);
dbCreationTimings = await runFinalize(
outputDir,
@ -243,7 +243,7 @@ async function run() {
memory,
config,
logger,
featureFlags
features
);
if (actionsUtil.getRequiredInput("skip-queries") !== "true") {
@ -255,7 +255,7 @@ async function run() {
actionsUtil.getOptionalInput("category"),
config,
logger,
featureFlags
features
);
}

View file

@ -16,11 +16,7 @@ import { Config } from "./config-utils";
import * as count from "./count-loc";
import { Language } from "./languages";
import { getRunnerLogger } from "./logging";
import {
setupTests,
setupActionsVars,
createFeatureFlags,
} from "./testing-utils";
import { setupTests, setupActionsVars, createFeatures } from "./testing-utils";
import * as util from "./util";
setupTests(test);
@ -143,7 +139,7 @@ test("status report fields and search path setting", async (t) => {
undefined,
config,
getRunnerLogger(true),
createFeatureFlags([])
createFeatures([])
);
const hasPacks = language in packs;
const statusReportKeys = Object.keys(builtinStatusReport).sort();
@ -193,7 +189,7 @@ test("status report fields and search path setting", async (t) => {
undefined,
config,
getRunnerLogger(true),
createFeatureFlags([])
createFeatures([])
);
t.deepEqual(Object.keys(customStatusReport).length, 2);
t.true(

View file

@ -122,7 +122,7 @@ export async function createdDBForScannedLanguages(
codeql: CodeQL,
config: configUtils.Config,
logger: Logger,
featureFlags: FeatureEnablement
featureEnablement: FeatureEnablement
) {
// Insert the LGTM_INDEX_X env vars at this point so they are set when
// we extract any scanned languages.
@ -132,7 +132,7 @@ export async function createdDBForScannedLanguages(
if (
isScannedLanguage(
language,
await util.isGoExtractionReconciliationEnabled(featureFlags),
await util.isGoExtractionReconciliationEnabled(featureEnablement),
logger
) &&
!dbIsFinalized(config, language, logger)
@ -173,12 +173,12 @@ async function finalizeDatabaseCreation(
threadsFlag: string,
memoryFlag: string,
logger: Logger,
featureFlags: FeatureEnablement
featureEnablement: FeatureEnablement
): Promise<DatabaseCreationTimings> {
const codeql = await getCodeQL(config.codeQLCmd);
const extractionStart = performance.now();
await createdDBForScannedLanguages(codeql, config, logger, featureFlags);
await createdDBForScannedLanguages(codeql, config, logger, featureEnablement);
const extractionTime = performance.now() - extractionStart;
const trapImportStart = performance.now();
@ -214,7 +214,7 @@ export async function runQueries(
automationDetailsId: string | undefined,
config: configUtils.Config,
logger: Logger,
featureFlags: FeatureEnablement
featureEnablement: FeatureEnablement
): Promise<QueriesStatusReport> {
const statusReport: QueriesStatusReport = {};
@ -240,7 +240,7 @@ export async function runQueries(
const codeql = await getCodeQL(config.codeQLCmd);
await util.logCodeScanningConfigInCli(codeql, featureFlags, logger);
await util.logCodeScanningConfigInCli(codeql, featureEnablement, logger);
for (const language of config.languages) {
const queries = config.queries[language];
@ -260,7 +260,7 @@ export async function runQueries(
}
try {
if (await util.useCodeScanningConfigInCli(codeql, featureFlags)) {
if (await util.useCodeScanningConfigInCli(codeql, featureEnablement)) {
// If we are using the codescanning config in the CLI,
// much of the work needed to generate the query suites
// is done in the CLI. We just need to make a single
@ -500,7 +500,7 @@ export async function runFinalize(
memoryFlag: string,
config: configUtils.Config,
logger: Logger,
featureFlags: FeatureEnablement
featureEnablement: FeatureEnablement
): Promise<DatabaseCreationTimings> {
try {
await del(outputDir, { force: true });
@ -516,7 +516,7 @@ export async function runFinalize(
threadsFlag,
memoryFlag,
logger,
featureFlags
featureEnablement
);
const codeql = await getCodeQL(config.codeQLCmd);
@ -529,7 +529,7 @@ export async function runFinalize(
// Delete variables as specified by the end-tracing script
await endTracingForCluster(
config,
await util.isGoExtractionReconciliationEnabled(featureFlags),
await util.isGoExtractionReconciliationEnabled(featureEnablement),
logger
);
} else {

View file

@ -76,7 +76,7 @@ async function run() {
const gitHubVersion = await getGitHubVersionActionsOnly();
checkGitHubVersionInRange(gitHubVersion, logger, Mode.actions);
const featureFlags = new Features(
const features = new Features(
gitHubVersion,
getApiDetails(),
parseRepositoryNwo(getRequiredEnvParam("GITHUB_REPOSITORY")),
@ -90,7 +90,7 @@ async function run() {
);
}
languages = await determineAutobuildLanguages(config, featureFlags, logger);
languages = await determineAutobuildLanguages(config, features, logger);
if (languages !== undefined) {
const workingDirectory = getOptionalInput("working-directory");
if (workingDirectory) {

View file

@ -7,11 +7,11 @@ import * as util from "./util";
export async function determineAutobuildLanguages(
config: configUtils.Config,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
logger: Logger
): Promise<Language[] | undefined> {
const isGoExtractionReconciliationEnabled =
await util.isGoExtractionReconciliationEnabled(featureFlags);
await util.isGoExtractionReconciliationEnabled(featureEnablement);
// Attempt to find a language to autobuild
// We want pick the dominant language in the repo from the ones we're able to build
// The languages are sorted in order specified by user or by lines of code if we got

View file

@ -16,11 +16,7 @@ import * as defaults from "./defaults.json";
import { Feature, FeatureEnablement } from "./feature-flags";
import { Language } from "./languages";
import { getRunnerLogger } from "./logging";
import {
setupTests,
setupActionsVars,
createFeatureFlags,
} from "./testing-utils";
import { setupTests, setupActionsVars, createFeatures } from "./testing-utils";
import * as util from "./util";
import { Mode, initializeEnvironment } from "./util";
@ -73,14 +69,14 @@ test.beforeEach(() => {
async function mockApiAndSetupCodeQL({
apiDetails,
featureFlags,
featureEnablement,
isPinned,
tmpDir,
toolsInput,
version,
}: {
apiDetails?: GitHubApiDetails;
featureFlags?: FeatureEnablement;
featureEnablement?: FeatureEnablement;
isPinned?: boolean;
tmpDir: string;
toolsInput?: { input?: string };
@ -113,7 +109,7 @@ async function mockApiAndSetupCodeQL({
apiDetails ?? sampleApiDetails,
tmpDir,
util.GitHubVariant.DOTCOM,
featureFlags ?? createFeatureFlags([]),
featureEnablement ?? createFeatures([]),
getRunnerLogger(true),
false
);
@ -176,7 +172,7 @@ test("don't download codeql bundle cache with pinned different version cached",
sampleApiDetails,
tmpDir,
util.GitHubVariant.DOTCOM,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true),
false
);
@ -260,14 +256,14 @@ const TOOLCACHE_BYPASS_TEST_CASES: Array<
];
for (const [
isFeatureFlagEnabled,
isFeatureEnabled,
toolsInput,
shouldToolcacheBeBypassed,
] of TOOLCACHE_BYPASS_TEST_CASES) {
test(`download codeql bundle ${
shouldToolcacheBeBypassed ? "bypasses" : "does not bypass"
} toolcache when feature flag ${
isFeatureFlagEnabled ? "enabled" : "disabled"
isFeatureEnabled ? "enabled" : "disabled"
} and tools: ${toolsInput} passed`, async (t) => {
await util.withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);
@ -284,8 +280,8 @@ for (const [
await mockApiAndSetupCodeQL({
version: defaults.bundleVersion,
apiDetails: sampleApiDetails,
featureFlags: createFeatureFlags(
isFeatureFlagEnabled ? [Feature.BypassToolcacheEnabled] : []
featureEnablement: createFeatures(
isFeatureEnabled ? [Feature.BypassToolcacheEnabled] : []
),
toolsInput: { input: toolsInput },
tmpDir,
@ -342,7 +338,7 @@ test("download codeql bundle from github ae endpoint", async (t) => {
sampleGHAEApiDetails,
tmpDir,
util.GitHubVariant.GHAE,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true),
false
);
@ -488,7 +484,7 @@ test("databaseInitCluster() without injected codescanning config", async (t) =>
"",
undefined,
undefined,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
@ -528,7 +524,7 @@ const injectedConfigMacro = test.macro({
"",
undefined,
undefined,
createFeatureFlags([Feature.CliConfigFileEnabled]),
createFeatures([Feature.CliConfigFileEnabled]),
getRunnerLogger(true)
);
@ -835,7 +831,7 @@ test("does not use injected config", async (t: ExecutionContext<unknown>) => {
"",
undefined,
undefined,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);

View file

@ -91,7 +91,7 @@ export interface CodeQL {
sourceRoot: string,
processName: string | undefined,
processLevel: number | undefined,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
logger: Logger
): Promise<void>;
/**
@ -772,14 +772,14 @@ async function getCodeQLForCmd(
sourceRoot: string,
processName: string | undefined,
processLevel: number | undefined,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
logger: Logger
) {
const extraArgs = config.languages.map(
(language) => `--language=${language}`
);
const isGoExtractionReconciliationEnabled =
await util.isGoExtractionReconciliationEnabled(featureFlags);
await util.isGoExtractionReconciliationEnabled(featureEnablement);
if (
config.languages.filter((l) =>
isTracedLanguage(l, isGoExtractionReconciliationEnabled, logger)
@ -822,7 +822,7 @@ async function getCodeQLForCmd(
const configLocation = await generateCodescanningConfig(
codeql,
config,
featureFlags
featureEnablement
);
if (configLocation) {
extraArgs.push(`--codescanning-config=${configLocation}`);
@ -1274,9 +1274,9 @@ async function runTool(cmd: string, args: string[] = []) {
async function generateCodescanningConfig(
codeql: CodeQL,
config: Config,
featureFlags: FeatureEnablement
featureEnablement: FeatureEnablement
): Promise<string | undefined> {
if (!(await util.useCodeScanningConfigInCli(codeql, featureFlags))) {
if (!(await util.useCodeScanningConfigInCli(codeql, featureEnablement))) {
return;
}
const configLocation = path.resolve(config.tempDir, "user-config.yaml");

View file

@ -12,7 +12,7 @@ import * as configUtils from "./config-utils";
import { Feature } from "./feature-flags";
import { Language } from "./languages";
import { getRunnerLogger, Logger } from "./logging";
import { setupTests, createFeatureFlags } from "./testing-utils";
import { setupTests, createFeatures } from "./testing-utils";
import * as util from "./util";
setupTests(test);
@ -102,7 +102,7 @@ test("load empty config", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
logger
);
@ -123,7 +123,7 @@ test("load empty config", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
logger
)
);
@ -173,7 +173,7 @@ test("loading config saves config", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
logger
);
@ -211,7 +211,7 @@ test("load input outside of workspace", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
throw new Error("initConfig did not throw error");
@ -251,7 +251,7 @@ test("load non-local input with invalid repo syntax", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
throw new Error("initConfig did not throw error");
@ -292,7 +292,7 @@ test("load non-existent input", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
throw new Error("initConfig did not throw error");
@ -399,7 +399,7 @@ test("load non-empty input", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
@ -470,7 +470,7 @@ test("Default queries are used", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
@ -549,7 +549,7 @@ test("Queries can be specified in config file", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
@ -627,7 +627,7 @@ test("Queries from config file can be overridden in workflow file", async (t) =>
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
@ -703,7 +703,7 @@ test("Queries in workflow file can be used in tandem with the 'disable default q
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
@ -770,7 +770,7 @@ test("Multiple queries can be specified in workflow file, no config file require
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
@ -858,7 +858,7 @@ test("Queries in workflow file can be added to the set of queries without overri
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
@ -940,7 +940,7 @@ test("Invalid queries in workflow file handled correctly", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
t.fail("initConfig did not throw error");
@ -1012,7 +1012,7 @@ test("API client used when reading remote config", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
t.assert(spyGetContents.called);
@ -1043,7 +1043,7 @@ test("Remote config handles the case where a directory is provided", async (t) =
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
throw new Error("initConfig did not throw error");
@ -1082,7 +1082,7 @@ test("Invalid format of remote config handled correctly", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
throw new Error("initConfig did not throw error");
@ -1125,7 +1125,7 @@ test("No detected languages", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
throw new Error("initConfig did not throw error");
@ -1157,7 +1157,7 @@ test("Unknown languages", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
throw new Error("initConfig did not throw error");
@ -1214,7 +1214,7 @@ test("Config specifies packages", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
t.deepEqual(packs as unknown, {
@ -1275,7 +1275,7 @@ test("Config specifies packages for multiple languages", async (t) => {
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
t.deepEqual(packs as unknown, {
@ -1347,7 +1347,7 @@ function doInvalidInputTest(
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags([]),
createFeatures([]),
getRunnerLogger(true)
);
throw new Error("initConfig did not throw error");
@ -1935,7 +1935,7 @@ const mlPoweredQueriesMacro = test.macro({
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags(
createFeatures(
isMlPoweredQueriesFlagEnabled ? [Feature.MlPoweredQueriesEnabled] : []
),
getRunnerLogger(true)

View file

@ -389,7 +389,7 @@ async function addBuiltinSuiteQueries(
resultMap: Queries,
packs: Packs,
suiteName: string,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
configFile?: string
): Promise<boolean> {
let injectedMlQueries = false;
@ -411,7 +411,7 @@ async function addBuiltinSuiteQueries(
languages.includes("javascript") &&
(found === "security-extended" || found === "security-and-quality") &&
!packs.javascript?.some(isMlPoweredJsQueriesPack) &&
(await featureFlags.getValue(Feature.MlPoweredQueriesEnabled, codeQL))
(await featureEnablement.getValue(Feature.MlPoweredQueriesEnabled, codeQL))
) {
if (!packs.javascript) {
packs.javascript = [];
@ -543,7 +543,7 @@ async function parseQueryUses(
tempDir: string,
workspacePath: string,
apiDetails: api.GitHubApiExternalRepoDetails,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
logger: Logger,
configFile?: string
): Promise<boolean> {
@ -572,7 +572,7 @@ async function parseQueryUses(
resultMap,
packs,
queryUses,
featureFlags,
featureEnablement,
configFile
);
}
@ -948,7 +948,7 @@ async function addQueriesAndPacksFromWorkflow(
tempDir: string,
workspacePath: string,
apiDetails: api.GitHubApiExternalRepoDetails,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
logger: Logger
): Promise<boolean> {
let injectedMlQueries = false;
@ -966,7 +966,7 @@ async function addQueriesAndPacksFromWorkflow(
tempDir,
workspacePath,
apiDetails,
featureFlags,
featureEnablement,
logger
);
injectedMlQueries = injectedMlQueries || didInject;
@ -1005,7 +1005,7 @@ export async function getDefaultConfig(
workspacePath: string,
gitHubVersion: GitHubVersion,
apiDetails: api.GitHubApiCombinedDetails,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
logger: Logger
): Promise<Config> {
const languages = await getLanguages(
@ -1044,7 +1044,7 @@ export async function getDefaultConfig(
tempDir,
workspacePath,
apiDetails,
featureFlags,
featureEnablement,
logger
);
}
@ -1114,7 +1114,7 @@ async function loadConfig(
workspacePath: string,
gitHubVersion: GitHubVersion,
apiDetails: api.GitHubApiCombinedDetails,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
logger: Logger
): Promise<Config> {
let parsedYAML: UserConfig;
@ -1195,7 +1195,7 @@ async function loadConfig(
tempDir,
workspacePath,
apiDetails,
featureFlags,
featureEnablement,
logger
);
}
@ -1220,7 +1220,7 @@ async function loadConfig(
tempDir,
workspacePath,
apiDetails,
featureFlags,
featureEnablement,
logger,
configFile
);
@ -1638,7 +1638,7 @@ export async function initConfig(
workspacePath: string,
gitHubVersion: GitHubVersion,
apiDetails: api.GitHubApiCombinedDetails,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
logger: Logger
): Promise<Config> {
let config: Config;
@ -1661,7 +1661,7 @@ export async function initConfig(
workspacePath,
gitHubVersion,
apiDetails,
featureFlags,
featureEnablement,
logger
);
} else {
@ -1681,7 +1681,7 @@ export async function initConfig(
workspacePath,
gitHubVersion,
apiDetails,
featureFlags,
featureEnablement,
logger
);
}
@ -1703,9 +1703,9 @@ export async function initConfig(
// When using the codescanning config in the CLI, pack downloads
// happen in the CLI during the `database init` command, so no need
// to download them here.
await logCodeScanningConfigInCli(codeQL, featureFlags, logger);
await logCodeScanningConfigInCli(codeQL, featureEnablement, logger);
if (!(await useCodeScanningConfigInCli(codeQL, featureFlags))) {
if (!(await useCodeScanningConfigInCli(codeQL, featureEnablement))) {
const registries = parseRegistries(registriesInput);
await downloadPacks(
codeQL,

View file

@ -49,7 +49,7 @@ for (const variant of ALL_FEATURE_FLAGS_DISABLED_VARIANTS) {
test(`All feature flags are disabled if running against ${variant.description}`, async (t) => {
await withTmpDir(async (tmpDir) => {
const loggedMessages = [];
const featureFlags = setUpTests(
const featureEnablement = setUpTests(
tmpDir,
getRecordingLogger(loggedMessages),
variant.gitHubVersion
@ -57,7 +57,7 @@ for (const variant of ALL_FEATURE_FLAGS_DISABLED_VARIANTS) {
for (const flag of Object.values(Feature)) {
t.false(
await featureFlags.getValue(flag, includeCodeQlIfRequired(flag))
await featureEnablement.getValue(flag, includeCodeQlIfRequired(flag))
);
}
@ -76,14 +76,19 @@ for (const variant of ALL_FEATURE_FLAGS_DISABLED_VARIANTS) {
test("API response missing", async (t) => {
await withTmpDir(async (tmpDir) => {
const loggedMessages: LoggedMessage[] = [];
const featureFlags = setUpTests(tmpDir, getRecordingLogger(loggedMessages));
const featureEnablement = setUpTests(
tmpDir,
getRecordingLogger(loggedMessages)
);
mockFeatureFlagApiEndpoint(403, {});
for (const flag of Object.values(Feature)) {
t.assert(
(await featureFlags.getValue(flag, includeCodeQlIfRequired(flag))) ===
false
(await featureEnablement.getValue(
flag,
includeCodeQlIfRequired(flag)
)) === false
);
}
assertAllFeaturesUndefinedInApi(t, loggedMessages);
@ -93,14 +98,19 @@ test("API response missing", async (t) => {
test("Feature flags are disabled if they're not returned in API response", async (t) => {
await withTmpDir(async (tmpDir) => {
const loggedMessages: LoggedMessage[] = [];
const featureFlags = setUpTests(tmpDir, getRecordingLogger(loggedMessages));
const featureEnablement = setUpTests(
tmpDir,
getRecordingLogger(loggedMessages)
);
mockFeatureFlagApiEndpoint(200, {});
for (const flag of Object.values(Feature)) {
t.assert(
(await featureFlags.getValue(flag, includeCodeQlIfRequired(flag))) ===
false
(await featureEnablement.getValue(
flag,
includeCodeQlIfRequired(flag)
)) === false
);
}
@ -110,13 +120,13 @@ test("Feature flags are disabled if they're not returned in API response", async
test("Feature flags exception is propagated if the API request errors", async (t) => {
await withTmpDir(async (tmpDir) => {
const featureFlags = setUpTests(tmpDir);
const featureEnablement = setUpTests(tmpDir);
mockFeatureFlagApiEndpoint(500, {});
await t.throwsAsync(
async () =>
featureFlags.getValue(
featureEnablement.getValue(
Feature.MlPoweredQueriesEnabled,
includeCodeQlIfRequired(Feature.MlPoweredQueriesEnabled)
),
@ -128,133 +138,133 @@ test("Feature flags exception is propagated if the API request errors", async (t
});
});
for (const featureFlag of Object.keys(featureConfig)) {
test(`Only feature flag '${featureFlag}' is enabled if enabled in the API response. Other flags disabled`, async (t) => {
for (const feature of Object.keys(featureConfig)) {
test(`Only feature flag '${feature}' is enabled if enabled in the API response. Other flags disabled`, async (t) => {
await withTmpDir(async (tmpDir) => {
const featureFlags = setUpTests(tmpDir);
const featureEnablement = setUpTests(tmpDir);
// set all feature flags to false except the one we're testing
const expectedFeatureFlags: { [flag: string]: boolean } = {};
const expectedFeatureEnablement: { [flag: string]: boolean } = {};
for (const f of Object.keys(featureConfig)) {
expectedFeatureFlags[f] = f === featureFlag;
expectedFeatureEnablement[f] = f === feature;
}
mockFeatureFlagApiEndpoint(200, expectedFeatureFlags);
mockFeatureFlagApiEndpoint(200, expectedFeatureEnablement);
// retrieve the values of the actual feature flags
const actualFeatureFlags: { [flag: string]: boolean } = {};
const actualFeatureEnablement: { [flag: string]: boolean } = {};
for (const f of Object.keys(featureConfig)) {
actualFeatureFlags[f] = await featureFlags.getValue(
actualFeatureEnablement[f] = await featureEnablement.getValue(
f as Feature,
includeCodeQlIfRequired(f)
);
}
// Alls flags should be false except the one we're testing
t.deepEqual(actualFeatureFlags, expectedFeatureFlags);
t.deepEqual(actualFeatureEnablement, expectedFeatureEnablement);
});
});
test(`Only feature flag '${featureFlag}' is enabled if the associated environment variable is true. Others disabled.`, async (t) => {
test(`Only feature flag '${feature}' is enabled if the associated environment variable is true. Others disabled.`, async (t) => {
await withTmpDir(async (tmpDir) => {
const featureFlags = setUpTests(tmpDir);
const featureEnablement = setUpTests(tmpDir);
const expectedFeatureFlags = initializeFeatures(false);
mockFeatureFlagApiEndpoint(200, expectedFeatureFlags);
const expectedFeatureEnablement = initializeFeatures(false);
mockFeatureFlagApiEndpoint(200, expectedFeatureEnablement);
// feature flag should be disabled initially
t.assert(
!(await featureFlags.getValue(
featureFlag as Feature,
includeCodeQlIfRequired(featureFlag)
!(await featureEnablement.getValue(
feature as Feature,
includeCodeQlIfRequired(feature)
))
);
// set env var to true and check that the feature flag is now enabled
process.env[featureConfig[featureFlag].envVar] = "true";
process.env[featureConfig[feature].envVar] = "true";
t.assert(
await featureFlags.getValue(
featureFlag as Feature,
includeCodeQlIfRequired(featureFlag)
await featureEnablement.getValue(
feature as Feature,
includeCodeQlIfRequired(feature)
)
);
});
});
test(`Feature flag '${featureFlag}' is disabled if the associated environment variable is false, even if enabled in API`, async (t) => {
test(`Feature flag '${feature}' is disabled if the associated environment variable is false, even if enabled in API`, async (t) => {
await withTmpDir(async (tmpDir) => {
const featureFlags = setUpTests(tmpDir);
const featureEnablement = setUpTests(tmpDir);
const expectedFeatureFlags = initializeFeatures(true);
mockFeatureFlagApiEndpoint(200, expectedFeatureFlags);
const expectedFeatureEnablement = initializeFeatures(true);
mockFeatureFlagApiEndpoint(200, expectedFeatureEnablement);
// feature flag should be enabled initially
t.assert(
await featureFlags.getValue(
featureFlag as Feature,
includeCodeQlIfRequired(featureFlag)
await featureEnablement.getValue(
feature as Feature,
includeCodeQlIfRequired(feature)
)
);
// set env var to false and check that the feature flag is now disabled
process.env[featureConfig[featureFlag].envVar] = "false";
process.env[featureConfig[feature].envVar] = "false";
t.assert(
!(await featureFlags.getValue(
featureFlag as Feature,
includeCodeQlIfRequired(featureFlag)
!(await featureEnablement.getValue(
feature as Feature,
includeCodeQlIfRequired(feature)
))
);
});
});
if (featureConfig[featureFlag].minimumVersion !== undefined) {
test(`Getting Feature Flag '${featureFlag} should throw if no codeql is provided`, async (t) => {
if (featureConfig[feature].minimumVersion !== undefined) {
test(`Getting Feature Flag '${feature} should throw if no codeql is provided`, async (t) => {
await withTmpDir(async (tmpDir) => {
const featureFlags = setUpTests(tmpDir);
const featureEnablement = setUpTests(tmpDir);
const expectedFeatureFlags = initializeFeatures(true);
mockFeatureFlagApiEndpoint(200, expectedFeatureFlags);
const expectedFeatureEnablement = initializeFeatures(true);
mockFeatureFlagApiEndpoint(200, expectedFeatureEnablement);
await t.throwsAsync(
async () => featureFlags.getValue(featureFlag as Feature),
async () => featureEnablement.getValue(feature as Feature),
{
message: `Internal error: A minimum version is specified for feature ${featureFlag}, but no instance of CodeQL was provided.`,
message: `Internal error: A minimum version is specified for feature ${feature}, but no instance of CodeQL was provided.`,
}
);
});
});
}
if (featureConfig[featureFlag].minimumVersion !== undefined) {
test(`Feature flag '${featureFlag}' is disabled if the minimum CLI version is below ${featureConfig[featureFlag].minimumVersion}`, async (t) => {
if (featureConfig[feature].minimumVersion !== undefined) {
test(`Feature flag '${feature}' is disabled if the minimum CLI version is below ${featureConfig[feature].minimumVersion}`, async (t) => {
await withTmpDir(async (tmpDir) => {
const featureFlags = setUpTests(tmpDir);
const featureEnablement = setUpTests(tmpDir);
const expectedFeatureFlags = initializeFeatures(true);
mockFeatureFlagApiEndpoint(200, expectedFeatureFlags);
const expectedFeatureEnablement = initializeFeatures(true);
mockFeatureFlagApiEndpoint(200, expectedFeatureEnablement);
// feature flag should be disabled when an old CLI version is set
let codeql = mockCodeQLVersion("2.0.0");
t.assert(
!(await featureFlags.getValue(featureFlag as Feature, codeql))
!(await featureEnablement.getValue(feature as Feature, codeql))
);
// even setting the env var to true should not enable the feature flag if
// the minimum CLI version is not met
process.env[featureConfig[featureFlag].envVar] = "true";
process.env[featureConfig[feature].envVar] = "true";
t.assert(
!(await featureFlags.getValue(featureFlag as Feature, codeql))
!(await featureEnablement.getValue(feature as Feature, codeql))
);
// feature flag should be enabled when a new CLI version is set
// and env var is not set
process.env[featureConfig[featureFlag].envVar] = "";
codeql = mockCodeQLVersion(featureConfig[featureFlag].minimumVersion);
t.assert(await featureFlags.getValue(featureFlag as Feature, codeql));
process.env[featureConfig[feature].envVar] = "";
codeql = mockCodeQLVersion(featureConfig[feature].minimumVersion);
t.assert(await featureEnablement.getValue(feature as Feature, codeql));
// set env var to false and check that the feature flag is now disabled
process.env[featureConfig[featureFlag].envVar] = "false";
process.env[featureConfig[feature].envVar] = "false";
t.assert(
!(await featureFlags.getValue(featureFlag as Feature, codeql))
!(await featureEnablement.getValue(feature as Feature, codeql))
);
});
});
@ -280,12 +290,12 @@ test("At least one feature has a minimum version specified", (t) => {
});
function assertAllFeaturesUndefinedInApi(t, loggedMessages: LoggedMessage[]) {
for (const featureFlag of Object.keys(featureConfig)) {
for (const feature of Object.keys(featureConfig)) {
t.assert(
loggedMessages.find(
(v) =>
v.type === "debug" &&
(v.message as string).includes(featureFlag) &&
(v.message as string).includes(feature) &&
(v.message as string).includes("considering it disabled")
) !== undefined
);

View file

@ -157,7 +157,7 @@ async function run() {
getRequiredEnvParam("GITHUB_REPOSITORY")
);
const featureFlags = new Features(
const features = new Features(
gitHubVersion,
apiDetails,
repositoryNwo,
@ -185,7 +185,7 @@ async function run() {
apiDetails,
getTemporaryDirectory(),
gitHubVersion.type,
featureFlags,
features,
logger
);
codeql = initCodeQLResult.codeql;
@ -199,7 +199,7 @@ async function run() {
getOptionalInput("registries"),
getOptionalInput("config-file"),
getOptionalInput("db-location"),
await getTrapCachingEnabled(featureFlags),
await getTrapCachingEnabled(features),
// Debug mode is enabled if:
// - The `init` Action is passed `debug: true`.
// - Actions step debugging is enabled (e.g. by [enabling debug logging for a rerun](https://docs.github.com/en/actions/managing-workflow-runs/re-running-workflows-and-jobs#re-running-all-the-jobs-in-a-workflow),
@ -213,7 +213,7 @@ async function run() {
getRequiredEnvParam("GITHUB_WORKSPACE"),
gitHubVersion,
apiDetails,
featureFlags,
features,
logger
);
@ -276,7 +276,7 @@ async function run() {
sourceRoot,
"Runner.Worker.exe",
undefined,
featureFlags,
features,
logger
);
if (tracerConfig !== undefined) {
@ -318,13 +318,13 @@ async function run() {
}
async function getTrapCachingEnabled(
featureFlags: FeatureEnablement
featureEnablement: FeatureEnablement
): Promise<boolean> {
const trapCaching = getOptionalInput("trap-caching");
if (trapCaching !== undefined) {
return trapCaching === "true";
}
return await featureFlags.getValue(Feature.TrapCachingEnabled);
return await featureEnablement.getValue(Feature.TrapCachingEnabled);
}
async function runWrapper() {

View file

@ -20,7 +20,7 @@ export async function initCodeQL(
apiDetails: GitHubApiDetails,
tempDir: string,
variant: util.GitHubVariant,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
logger: Logger
): Promise<{ codeql: CodeQL; toolsVersion: string }> {
logger.startGroup("Setup CodeQL tools");
@ -29,7 +29,7 @@ export async function initCodeQL(
apiDetails,
tempDir,
variant,
featureFlags,
featureEnablement,
logger,
true
);
@ -55,7 +55,7 @@ export async function initConfig(
workspacePath: string,
gitHubVersion: util.GitHubVersion,
apiDetails: GitHubApiCombinedDetails,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
logger: Logger
): Promise<configUtils.Config> {
logger.startGroup("Load language configuration");
@ -76,7 +76,7 @@ export async function initConfig(
workspacePath,
gitHubVersion,
apiDetails,
featureFlags,
featureEnablement,
logger
);
analysisPaths.printPathFiltersWarning(config, logger);
@ -90,7 +90,7 @@ export async function runInit(
sourceRoot: string,
processName: string | undefined,
processLevel: number | undefined,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
logger: Logger
): Promise<TracerConfig | undefined> {
fs.mkdirSync(config.dbLocation, { recursive: true });
@ -103,7 +103,7 @@ export async function runInit(
sourceRoot,
processName,
processLevel,
featureFlags,
featureEnablement,
logger
);
} else {
@ -122,7 +122,7 @@ export async function runInit(
return await getCombinedTracerConfig(
config,
codeql,
await util.isGoExtractionReconciliationEnabled(featureFlags),
await util.isGoExtractionReconciliationEnabled(featureEnablement),
logger
);
}

View file

@ -12,7 +12,7 @@ import { initCodeQL, initConfig, injectWindowsTracer, runInit } from "./init";
import { Language, parseLanguage } from "./languages";
import { getRunnerLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import { createFeatureFlags } from "./testing-utils";
import { createFeatures } from "./testing-utils";
import * as upload_lib from "./upload-lib";
import {
checkGitHubVersionInRange,
@ -229,7 +229,7 @@ program
apiDetails,
tempDir,
gitHubVersion.type,
createFeatureFlags([]),
createFeatures([]),
logger
)
).codeql;
@ -253,7 +253,7 @@ program
workspacePath,
gitHubVersion,
apiDetails,
createFeatureFlags([]),
createFeatures([]),
logger
);
@ -264,7 +264,7 @@ program
sourceRoot,
parseTraceProcessName(),
parseTraceProcessLevel(),
createFeatureFlags([]),
createFeatures([]),
logger
);
if (tracerConfig === undefined) {
@ -377,7 +377,7 @@ program
} else {
languages = await determineAutobuildLanguages(
config,
createFeatureFlags([]),
createFeatures([]),
logger
);
}
@ -508,7 +508,7 @@ program
memory,
config,
logger,
createFeatureFlags([])
createFeatures([])
);
await runQueries(
outputDir,
@ -518,7 +518,7 @@ program
cmd.category,
config,
logger,
createFeatureFlags([])
createFeatures([])
);
if (!cmd.upload) {

View file

@ -175,9 +175,7 @@ export function mockCodeQLVersion(version) {
*
* This should be only used within tests.
*/
export function createFeatureFlags(
enabledFeatures: Feature[]
): FeatureEnablement {
export function createFeatures(enabledFeatures: Feature[]): FeatureEnablement {
return {
getValue: async (feature) => {
return enabledFeatures.includes(feature);

View file

@ -779,17 +779,17 @@ export function isInTestMode(): boolean {
*/
export async function useCodeScanningConfigInCli(
codeql: CodeQL,
featureFlags: FeatureEnablement
featureEnablement: FeatureEnablement
): Promise<boolean> {
return await featureFlags.getValue(Feature.CliConfigFileEnabled, codeql);
return await featureEnablement.getValue(Feature.CliConfigFileEnabled, codeql);
}
export async function logCodeScanningConfigInCli(
codeql: CodeQL,
featureFlags: FeatureEnablement,
featureEnablement: FeatureEnablement,
logger: Logger
) {
if (await useCodeScanningConfigInCli(codeql, featureFlags)) {
if (await useCodeScanningConfigInCli(codeql, featureEnablement)) {
logger.info(
"Code Scanning configuration file being processed in the codeql CLI."
);
@ -832,9 +832,9 @@ export function listFolder(dir: string): string[] {
}
export async function isGoExtractionReconciliationEnabled(
featureFlags: FeatureEnablement
featureEnablement: FeatureEnablement
): Promise<boolean> {
return await featureFlags.getValue(
return await featureEnablement.getValue(
Feature.GolangExtractionReconciliationEnabled
);
}