Merge pull request #3354 from github/robertbrignull/multi-mrva-test

Add a CLI test for MRVA with multiple queries
This commit is contained in:
Robert
2024-02-14 12:23:56 +00:00
committed by GitHub
4 changed files with 45 additions and 10 deletions

View File

@@ -0,0 +1,4 @@
name: github/remote-query-pack
version: 0.0.0
dependencies:
codeql/javascript-all: "*"

View File

@@ -0,0 +1,4 @@
import javascript
from File f
select f, "This is a file"

View File

@@ -0,0 +1,4 @@
import javascript
from Stmt s
select s, "This is a statement"

View File

@@ -236,7 +236,7 @@ describe("Variant Analysis Manager", () => {
it("should run a remote query that is part of a qlpack", async () => {
await doVariantAnalysisTest({
queryPath: "data-remote-qlpack/in-pack.ql",
queryPaths: ["data-remote-qlpack/in-pack.ql"],
qlPackRootPath: "data-remote-qlpack",
qlPackFilePath: "data-remote-qlpack/qlpack.yml",
expectedPackName: "github/remote-query-pack",
@@ -248,7 +248,7 @@ describe("Variant Analysis Manager", () => {
it("should run a remote query that is not part of a qlpack", async () => {
await doVariantAnalysisTest({
queryPath: "data-remote-no-qlpack/in-pack.ql",
queryPaths: ["data-remote-no-qlpack/in-pack.ql"],
qlPackRootPath: "data-remote-no-qlpack",
qlPackFilePath: undefined,
expectedPackName: "codeql-remote/query",
@@ -260,7 +260,7 @@ describe("Variant Analysis Manager", () => {
it("should run a remote query that is nested inside a qlpack", async () => {
await doVariantAnalysisTest({
queryPath: "data-remote-qlpack-nested/subfolder/in-pack.ql",
queryPaths: ["data-remote-qlpack-nested/subfolder/in-pack.ql"],
qlPackRootPath: "data-remote-qlpack-nested",
qlPackFilePath: "data-remote-qlpack-nested/codeql-pack.yml",
expectedPackName: "github/remote-query-pack",
@@ -279,7 +279,7 @@ describe("Variant Analysis Manager", () => {
}
await cli.setUseExtensionPacks(true);
await doVariantAnalysisTest({
queryPath: "data-remote-qlpack-nested/subfolder/in-pack.ql",
queryPaths: ["data-remote-qlpack-nested/subfolder/in-pack.ql"],
qlPackRootPath: "data-remote-qlpack-nested",
qlPackFilePath: "data-remote-qlpack-nested/codeql-pack.yml",
expectedPackName: "github/remote-query-pack",
@@ -330,7 +330,7 @@ describe("Variant Analysis Manager", () => {
const queryPath = join(qlPackRootPath, queryToRun);
const qlPackFilePath = join(qlPackRootPath, "qlpack.yml");
await doVariantAnalysisTest({
queryPath,
queryPaths: [queryPath],
qlPackRootPath,
qlPackFilePath,
expectedPackName: "codeql/java-queries",
@@ -343,8 +343,31 @@ describe("Variant Analysis Manager", () => {
});
});
it("should run multiple queries that are part of the same pack", async () => {
if (!(await cli.cliConstraints.supportsPackCreateWithMultipleQueries())) {
console.log(
`Skipping test because MRVA with multiple queries is only suppported in CLI version ${CliVersionConstraint.CLI_VERSION_WITH_MULTI_QUERY_PACK_CREATE} or later.`,
);
return;
}
await doVariantAnalysisTest({
queryPaths: [
"data-qlpack-multiple-queries/query1.ql",
"data-qlpack-multiple-queries/query2.ql",
],
qlPackRootPath: "data-qlpack-multiple-queries",
qlPackFilePath: "data-qlpack-multiple-queries/codeql-pack.yml",
expectedPackName: "github/remote-query-pack",
filesThatExist: ["query1.ql", "query2.ql"],
filesThatDoNotExist: [],
qlxFilesThatExist: ["query1.qlx", "query2.qlx"],
dependenciesToCheck: ["codeql/javascript-all"],
});
});
async function doVariantAnalysisTest({
queryPath,
queryPaths,
qlPackRootPath,
qlPackFilePath,
expectedPackName,
@@ -357,7 +380,7 @@ describe("Variant Analysis Manager", () => {
dependenciesToCheck = ["codeql/javascript-all"],
checkVersion = true,
}: {
queryPath: string;
queryPaths: string[];
qlPackRootPath: string;
qlPackFilePath: string | undefined;
expectedPackName: string;
@@ -367,9 +390,9 @@ describe("Variant Analysis Manager", () => {
dependenciesToCheck?: string[];
checkVersion?: boolean;
}) {
const filePath = getFileOrDir(queryPath);
const filePaths = queryPaths.map(getFileOrDir);
const qlPackDetails: QlPackDetails = {
queryFiles: [filePath],
queryFiles: filePaths,
qlPackRootPath: getFileOrDir(qlPackRootPath),
qlPackFilePath: qlPackFilePath && getFileOrDir(qlPackFilePath),
language: QueryLanguage.Javascript,
@@ -385,7 +408,7 @@ describe("Variant Analysis Manager", () => {
expect(executeCommandSpy).toHaveBeenCalledWith(
"codeQL.monitorNewVariantAnalysis",
expect.objectContaining({
query: expect.objectContaining({ filePath }),
query: expect.objectContaining({ filePath: filePaths[0] }),
}),
);