Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: github/remote-query-pack
version: 0.0.0
dependencies:
codeql/javascript-all: "*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import javascript

from File f
select f, "This is a file"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import javascript

from Stmt s
select s, "This is a statement"
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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] }),
}),
);

Expand Down