Ensure remote queries can handle codeql-pack.yml files
This updates one of our integration tests so that it uses `codeql-pack.yml` instead of `qlpack.yml`.
This commit is contained in:
@@ -34,6 +34,7 @@ import { DbManager } from "../databases/db-manager";
|
||||
export interface QlPack {
|
||||
name: string;
|
||||
version: string;
|
||||
library?: boolean;
|
||||
dependencies: { [key: string]: string };
|
||||
defaultSuite?: Array<Record<string, unknown>>;
|
||||
defaultSuiteFile?: string;
|
||||
@@ -66,7 +67,7 @@ async function generateQueryPack(
|
||||
const targetQueryFileName = join(queryPackDir, packRelativePath);
|
||||
|
||||
let language: string | undefined;
|
||||
if (await pathExists(join(originalPackRoot, "qlpack.yml"))) {
|
||||
if (await getExistingPackFile(originalPackRoot)) {
|
||||
// don't include ql files. We only want the queryFile to be copied.
|
||||
const toCopy = await cliServer.packPacklist(originalPackRoot, false);
|
||||
|
||||
@@ -162,7 +163,7 @@ async function generateQueryPack(
|
||||
async function findPackRoot(queryFile: string): Promise<string> {
|
||||
// recursively find the directory containing qlpack.yml
|
||||
let dir = dirname(queryFile);
|
||||
while (!(await pathExists(join(dir, "qlpack.yml")))) {
|
||||
while (!(await getExistingPackFile(dir))) {
|
||||
dir = dirname(dir);
|
||||
if (isFileSystemRoot(dir)) {
|
||||
// there is no qlpack.yml in this directory or any parent directory.
|
||||
@@ -174,6 +175,16 @@ async function findPackRoot(queryFile: string): Promise<string> {
|
||||
return dir;
|
||||
}
|
||||
|
||||
async function getExistingPackFile(dir: string) {
|
||||
if (await pathExists(join(dir, "qlpack.yml"))) {
|
||||
return join(dir, "qlpack.yml");
|
||||
}
|
||||
if (await pathExists(join(dir, "codeql-pack.yml"))) {
|
||||
return join(dir, "codeql-pack.yml");
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isFileSystemRoot(dir: string): boolean {
|
||||
const pathObj = parse(dir);
|
||||
return pathObj.root === dir && pathObj.base === "";
|
||||
@@ -314,7 +325,14 @@ async function fixPackFile(
|
||||
queryPackDir: string,
|
||||
packRelativePath: string,
|
||||
): Promise<void> {
|
||||
const packPath = join(queryPackDir, "qlpack.yml");
|
||||
const packPath = await getExistingPackFile(queryPackDir);
|
||||
|
||||
// This should not happen since we create the pack ourselves.
|
||||
if (!packPath) {
|
||||
throw new Error(
|
||||
`Could not find qlpack.yml or codeql-pack.yml file in '${queryPackDir}'`,
|
||||
);
|
||||
}
|
||||
const qlpack = load(await readFile(packPath, "utf8")) as QlPack;
|
||||
|
||||
// update pack name
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
name: github/remote-query-pack
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
# The workspace reference will be removed before creating the MRVA pack.
|
||||
codeql/javascript-all: '*'
|
||||
@@ -1,4 +1,4 @@
|
||||
name: github/remote-query-pack
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
codeql/javascript-all: '${workspace}'
|
||||
codeql/javascript-all: ${workspace}
|
||||
|
||||
@@ -277,7 +277,7 @@ describe("Remote queries", () => {
|
||||
|
||||
// check a few files that we know should exist and others that we know should not
|
||||
expect(packFS.fileExists("subfolder/in-pack.ql")).toBe(true);
|
||||
expect(packFS.fileExists("qlpack.yml")).toBe(true);
|
||||
expect(packFS.fileExists("codeql-pack.yml")).toBe(true);
|
||||
// depending on the cli version, we should have one of these files
|
||||
expect(
|
||||
packFS.fileExists("qlpack.lock.yml") ||
|
||||
@@ -289,13 +289,13 @@ describe("Remote queries", () => {
|
||||
// the compiled pack
|
||||
verifyQlPack(
|
||||
"subfolder/in-pack.ql",
|
||||
packFS.fileContents("qlpack.yml"),
|
||||
packFS.fileContents("codeql-pack.yml"),
|
||||
"0.0.0",
|
||||
);
|
||||
|
||||
// should have generated a correct qlpack file
|
||||
const qlpackContents: any = load(
|
||||
packFS.fileContents("qlpack.yml").toString("utf-8"),
|
||||
packFS.fileContents("codeql-pack.yml").toString("utf-8"),
|
||||
);
|
||||
expect(qlpackContents.name).toBe("codeql-remote/query");
|
||||
expect(qlpackContents.version).toBe("0.0.0");
|
||||
@@ -333,22 +333,27 @@ describe("Remote queries", () => {
|
||||
// don't check the build metadata since it is variable
|
||||
delete (qlPack as any).buildMetadata;
|
||||
|
||||
expect(qlPack).toEqual({
|
||||
name: "codeql-remote/query",
|
||||
version: packVersion,
|
||||
dependencies: {
|
||||
"codeql/javascript-all": "*",
|
||||
},
|
||||
library: false,
|
||||
defaultSuite: [
|
||||
{
|
||||
description: "Query suite for variant analysis",
|
||||
expect(qlPack).toEqual(
|
||||
expect.objectContaining({
|
||||
name: "codeql-remote/query",
|
||||
version: packVersion,
|
||||
dependencies: {
|
||||
"codeql/javascript-all": "*",
|
||||
},
|
||||
{
|
||||
query: queryPath,
|
||||
},
|
||||
],
|
||||
});
|
||||
defaultSuite: [
|
||||
{
|
||||
description: "Query suite for variant analysis",
|
||||
},
|
||||
{
|
||||
query: queryPath,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
// v2.11.6 and later set this to false.
|
||||
// Earlier versions don't set it at all.
|
||||
expect(qlPack.library).toBeFalsy();
|
||||
}
|
||||
|
||||
function getFile(file: string): Uri {
|
||||
|
||||
Reference in New Issue
Block a user