Rename VersionOutput to VersionInfo

This commit is contained in:
Michael B. Gale
2023-10-04 15:54:34 +01:00
parent 49b94f1a2d
commit bcbb900532
19 changed files with 60 additions and 68 deletions

View File

@@ -21,7 +21,7 @@ import {
setupTests,
setupActionsVars,
createFeatures,
makeVersionOutput,
makeVersionInfo,
} from "./testing-utils";
import * as uploadLib from "./upload-lib";
import * as util from "./util";
@@ -262,7 +262,7 @@ test("status report fields and search path setting", async (t) => {
function mockCodeQL(): Partial<CodeQL> {
return {
getVersion: async () => makeVersionOutput("1.0.0"),
getVersion: async () => makeVersionInfo("1.0.0"),
databaseRunQueries: sinon.spy(),
databaseInterpretResults: async () => "",
databasePrintBaseline: async () => "",

View File

@@ -27,7 +27,7 @@ import {
SAMPLE_DOTCOM_API_DETAILS,
SAMPLE_DEFAULT_CLI_VERSION,
mockBundleDownloadApi,
makeVersionOutput,
makeVersionInfo,
} from "./testing-utils";
import * as util from "./util";
import { initializeEnvironment } from "./util";
@@ -564,9 +564,7 @@ test("databaseInitCluster() without injected codescanning config", async (t) =>
await util.withTmpDir(async (tempDir) => {
const runnerConstructorStub = stubToolRunnerConstructor();
const codeqlObject = await codeql.getCodeQLForTesting();
sinon
.stub(codeqlObject, "getVersion")
.resolves(makeVersionOutput("2.10.5"));
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.10.5"));
// safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves("");
@@ -611,7 +609,7 @@ const injectedConfigMacro = test.macro({
sinon
.stub(codeqlObject, "getVersion")
.resolves(
makeVersionOutput(
makeVersionInfo(
featureConfig[Feature.CliConfigFileEnabled].minimumVersion ||
"1.0.0",
),
@@ -837,7 +835,7 @@ test("does not pass a code scanning config or qlconfig file to the CLI when CLI
const runnerConstructorStub = stubToolRunnerConstructor();
const codeqlObject = await codeql.getCodeQLForTesting();
// stubbed version doesn't matter. It just needs to be valid semver.
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("0.0.0"));
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("0.0.0"));
await codeqlObject.databaseInitCluster(
{ ...stubConfig, tempDir },
@@ -869,7 +867,7 @@ test("passes a code scanning config AND qlconfig to the CLI when CLI config pass
const codeqlObject = await codeql.getCodeQLForTesting();
sinon
.stub(codeqlObject, "getVersion")
.resolves(makeVersionOutput(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG));
.resolves(makeVersionInfo(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG));
await codeqlObject.databaseInitCluster(
{ ...stubConfig, tempDir },
@@ -899,9 +897,7 @@ test("passes a code scanning config BUT NOT a qlconfig to the CLI when CLI confi
await util.withTmpDir(async (tempDir) => {
const runnerConstructorStub = stubToolRunnerConstructor();
const codeqlObject = await codeql.getCodeQLForTesting();
sinon
.stub(codeqlObject, "getVersion")
.resolves(makeVersionOutput("2.12.2"));
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.12.2"));
await codeqlObject.databaseInitCluster(
{ ...stubConfig, tempDir },
@@ -936,7 +932,7 @@ test("does not pass a qlconfig to the CLI when it is undefined", async (t: Execu
const codeqlObject = await codeql.getCodeQLForTesting();
sinon
.stub(codeqlObject, "getVersion")
.resolves(makeVersionOutput(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG));
.resolves(makeVersionInfo(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG));
await codeqlObject.databaseInitCluster(
{ ...stubConfig, tempDir },
@@ -958,7 +954,7 @@ test("does not pass a qlconfig to the CLI when it is undefined", async (t: Execu
test("databaseInterpretResults() sets --sarif-add-baseline-file-info for 2.11.3", async (t) => {
const runnerConstructorStub = stubToolRunnerConstructor();
const codeqlObject = await codeql.getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("2.11.3"));
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.11.3"));
// safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves("");
await codeqlObject.databaseInterpretResults(
@@ -984,7 +980,7 @@ test("databaseInterpretResults() sets --sarif-add-baseline-file-info for 2.11.3"
test("databaseInterpretResults() does not set --sarif-add-baseline-file-info for 2.11.2", async (t) => {
const runnerConstructorStub = stubToolRunnerConstructor();
const codeqlObject = await codeql.getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("2.11.2"));
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.11.2"));
// safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves("");
await codeqlObject.databaseInterpretResults(
@@ -1047,7 +1043,7 @@ for (const {
const codeqlObject = await codeql.getCodeQLForTesting();
sinon
.stub(codeqlObject, "getVersion")
.resolves(makeVersionOutput(codeqlVersion));
.resolves(makeVersionInfo(codeqlVersion));
// safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves("");
await codeqlObject.databaseInterpretResults(
@@ -1090,7 +1086,7 @@ test("database finalize recognises JavaScript no code found error on CodeQL 2.11
2020-09-07T17:39:53.9251124Z [2020-09-07 17:39:53] [ERROR] Spawned process exited abnormally (code 255; tried to run: [/opt/hostedtoolcache/CodeQL/0.0.0-20200630/x64/codeql/javascript/tools/autobuild.sh])`,
);
const codeqlObject = await codeql.getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("2.11.6"));
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.11.6"));
// safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves("");
@@ -1107,7 +1103,7 @@ test("database finalize recognises JavaScript no code found error on CodeQL 2.11
test("database finalize overrides no code found error on CodeQL 2.11.6", async (t) => {
stubToolRunnerConstructor(32);
const codeqlObject = await codeql.getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("2.11.6"));
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.11.6"));
// safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves("");
@@ -1127,7 +1123,7 @@ test("database finalize does not override no code found error on CodeQL 2.12.4",
"https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build.";
stubToolRunnerConstructor(32, cliMessage);
const codeqlObject = await codeql.getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("2.12.4"));
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.12.4"));
// safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves("");
@@ -1152,7 +1148,7 @@ test("runTool summarizes several fatal errors", async (t) => {
`${heapError}\n${datasetImportError}.`;
stubToolRunnerConstructor(32, cliStderr);
const codeqlObject = await codeql.getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionOutput("2.12.4"));
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.12.4"));
// safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves("");

View File

@@ -75,7 +75,7 @@ export interface CodeQL {
/**
* Get a string containing the semver version of the CodeQL executable.
*/
getVersion(): Promise<VersionOutput>;
getVersion(): Promise<VersionInfo>;
/**
* Print version information about CodeQL.
*/
@@ -212,7 +212,7 @@ export interface CodeQL {
resolveExtractor(language: Language): Promise<string>;
}
export interface VersionOutput {
export interface VersionInfo {
version: string;
features?: { [name: string]: boolean };
}
@@ -540,7 +540,7 @@ export async function getCodeQLForCmd(
if (result === undefined) {
const output = await runTool(cmd, ["version", "--format=json"]);
try {
result = JSON.parse(output) as VersionOutput;
result = JSON.parse(output) as VersionInfo;
} catch (err) {
throw Error(
`Invalid JSON output from \`version --format=json\`: ${output}`,

View File

@@ -16,7 +16,7 @@ import {
setupTests,
createFeatures,
mockLanguagesInRepo as mockLanguagesInRepo,
makeVersionOutput,
makeVersionInfo,
} from "./testing-utils";
import {
GitHubVariant,
@@ -2353,7 +2353,7 @@ test("downloadPacks-with-registries", async (t) => {
const codeQL = setCodeQL({
packDownload: packDownloadStub,
getVersion: () => Promise.resolve(makeVersionOutput("2.10.5")),
getVersion: () => Promise.resolve(makeVersionInfo("2.10.5")),
});
// packs are supplied for go, java, and python
@@ -2411,7 +2411,7 @@ test("downloadPacks-with-registries fails with invalid registries block", async
]);
const codeQL = setCodeQL({
getVersion: () => Promise.resolve(makeVersionOutput("2.10.4")),
getVersion: () => Promise.resolve(makeVersionInfo("2.10.4")),
});
await t.throwsAsync(
async () => {

View File

@@ -209,16 +209,16 @@ export function mockLanguagesInRepo(languages: string[]) {
}
/**
* Constructs a `VersionOutput` object for testing purposes only.
* Constructs a `VersionInfo` object for testing purposes only.
*/
export const makeVersionOutput = (version: string): CodeQL.VersionOutput => ({
export const makeVersionInfo = (version: string): CodeQL.VersionInfo => ({
version,
});
export function mockCodeQLVersion(version: string) {
return {
async getVersion() {
return makeVersionOutput(version);
return makeVersionInfo(version);
},
} as CodeQL.CodeQL;
}

View File

@@ -16,7 +16,7 @@ import { Config } from "./config-utils";
import { Language } from "./languages";
import {
getRecordingLogger,
makeVersionOutput,
makeVersionInfo,
setupTests,
} from "./testing-utils";
import {
@@ -30,7 +30,7 @@ setupTests(test);
const stubCodeql = setCodeQL({
async getVersion() {
return makeVersionOutput("2.10.3");
return makeVersionInfo("2.10.3");
},
async betterResolveLanguages() {
return {

View File

@@ -10,7 +10,7 @@ import getFolderSize from "get-folder-size";
import * as semver from "semver";
import * as apiCompatibility from "./api-compatibility.json";
import type { CodeQL, VersionOutput } from "./codeql";
import type { CodeQL, VersionInfo } from "./codeql";
import type { Config, Pack } from "./config-utils";
import { EnvVar } from "./environment";
import { Language } from "./languages";
@@ -576,16 +576,16 @@ export function isHTTPError(arg: any): arg is HTTPError {
return arg?.status !== undefined && Number.isInteger(arg.status);
}
let cachedCodeQlVersion: undefined | VersionOutput = undefined;
let cachedCodeQlVersion: undefined | VersionInfo = undefined;
export function cacheCodeQlVersion(version: VersionOutput): void {
export function cacheCodeQlVersion(version: VersionInfo): void {
if (cachedCodeQlVersion !== undefined) {
throw new Error("cacheCodeQlVersion() should be called only once");
}
cachedCodeQlVersion = version;
}
export function getCachedCodeQlVersion(): undefined | VersionOutput {
export function getCachedCodeQlVersion(): undefined | VersionInfo {
return cachedCodeQlVersion;
}