Make automodel and flow queries work without submodule.
This commit is contained in:
@@ -3,7 +3,6 @@ import { CoreCompletedQuery, QueryRunner } from "../query-server";
|
||||
import { DatabaseItem } from "../databases/local-databases";
|
||||
import { ProgressCallback } from "../common/vscode/progress";
|
||||
import * as Sarif from "sarif";
|
||||
import { qlpackOfDatabase, resolveQueries } from "../local-queries";
|
||||
import { Mode } from "./shared/mode";
|
||||
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
|
||||
import { interpretResultsSarif } from "../query-results";
|
||||
@@ -16,6 +15,7 @@ import { MethodSignature } from "./external-api-usage";
|
||||
import { runQuery } from "../local-queries/run-query";
|
||||
import { QueryMetadata } from "../common/interface-types";
|
||||
import { CancellationTokenSource } from "vscode";
|
||||
import { resolveQueries } from "../local-queries";
|
||||
|
||||
function modeTag(mode: Mode): string {
|
||||
switch (mode) {
|
||||
@@ -127,7 +127,7 @@ async function resolveAutomodelQuery(
|
||||
queryTag: string,
|
||||
mode: Mode,
|
||||
): Promise<string> {
|
||||
const qlpack = await qlpackOfDatabase(cliServer, databaseItem);
|
||||
const packsToSearch = [`codeql/${databaseItem.language}-queries`];
|
||||
|
||||
// First, resolve the query that we want to run.
|
||||
// All queries are tagged like this:
|
||||
@@ -135,7 +135,7 @@ async function resolveAutomodelQuery(
|
||||
// Example: internal extract automodel framework-mode candidates
|
||||
const queries = await resolveQueries(
|
||||
cliServer,
|
||||
qlpack,
|
||||
packsToSearch,
|
||||
`Extract automodel ${queryTag}`,
|
||||
{
|
||||
kind: "problem",
|
||||
|
||||
@@ -10,9 +10,9 @@ import { ProgressCallback } from "../common/vscode/progress";
|
||||
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
|
||||
import { ModeledMethod, ModeledMethodType } from "./modeled-method";
|
||||
import { redactableError } from "../common/errors";
|
||||
import { qlpackOfDatabase, resolveQueries } from "../local-queries";
|
||||
import { telemetryListener } from "../common/vscode/telemetry";
|
||||
import { runQuery } from "../local-queries/run-query";
|
||||
import { resolveQueries } from "../local-queries";
|
||||
|
||||
type FlowModelOptions = {
|
||||
cliServer: CodeQLCliServer;
|
||||
@@ -83,11 +83,16 @@ async function resolveFlowQueries(
|
||||
cliServer: CodeQLCliServer,
|
||||
databaseItem: DatabaseItem,
|
||||
): Promise<string[]> {
|
||||
const qlpacks = await qlpackOfDatabase(cliServer, databaseItem);
|
||||
const packsToSearch = [`codeql/${databaseItem.language}-queries`];
|
||||
|
||||
return await resolveQueries(cliServer, qlpacks, "flow model generator", {
|
||||
"tags contain": ["modelgenerator"],
|
||||
});
|
||||
return await resolveQueries(
|
||||
cliServer,
|
||||
packsToSearch,
|
||||
"flow model generator",
|
||||
{
|
||||
"tags contain": ["modelgenerator"],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async function runSingleFlowQuery(
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from "./key-type";
|
||||
import { CodeQLCliServer } from "../../codeql-cli/cli";
|
||||
import { DatabaseItem } from "../../databases/local-databases";
|
||||
import { resolveQueries as resolveLocalQueries } from "../../local-queries/query-resolver";
|
||||
import { resolveQueriesByLanguagePack as resolveLocalQueries } from "../../local-queries/query-resolver";
|
||||
import { extLogger } from "../../common/logging/vscode";
|
||||
import { TeeLogger } from "../../common/logging";
|
||||
import { CancellationToken } from "vscode";
|
||||
|
||||
@@ -72,16 +72,7 @@ async function resolveQueriesFromPacks(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the queries with the specified kind and tags in a QLPack.
|
||||
*
|
||||
* @param cli The CLI instance to use.
|
||||
* @param qlpacks The list of packs to search.
|
||||
* @param name The name of the query to use in error messages.
|
||||
* @param constraints Constraints on the queries to search for.
|
||||
* @returns The found queries from the first pack in which any matching queries were found.
|
||||
*/
|
||||
export async function resolveQueries(
|
||||
export async function resolveQueriesByLanguagePack(
|
||||
cli: CodeQLCliServer,
|
||||
qlpacks: QlPacksForLanguage,
|
||||
name: string,
|
||||
@@ -95,6 +86,24 @@ export async function resolveQueries(
|
||||
packsToSearch.push(qlpacks.queryPack);
|
||||
}
|
||||
|
||||
return resolveQueries(cli, packsToSearch, name, constraints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the queries with the specified kind and tags in a QLPack.
|
||||
*
|
||||
* @param cli The CLI instance to use.
|
||||
* @param packsToSearch The list of packs to search.
|
||||
* @param name The name of the query to use in error messages.
|
||||
* @param constraints Constraints on the queries to search for.
|
||||
* @returns The found queries from the first pack in which any matching queries were found.
|
||||
*/
|
||||
export async function resolveQueries(
|
||||
cli: CodeQLCliServer,
|
||||
packsToSearch: string[],
|
||||
name: string,
|
||||
constraints: QueryConstraints,
|
||||
): Promise<string[]> {
|
||||
const queries = await resolveQueriesFromPacks(
|
||||
cli,
|
||||
packsToSearch,
|
||||
|
||||
@@ -23,11 +23,6 @@ import { CancellationTokenSource } from "vscode-jsonrpc";
|
||||
import { QueryOutputDir } from "../../../../src/run-queries-shared";
|
||||
|
||||
describe("runAutoModelQueries", () => {
|
||||
const qlpack = {
|
||||
dbschemePack: "dbschemePack",
|
||||
dbschemePackIsLibraryPack: false,
|
||||
};
|
||||
|
||||
let resolveQueriesSpy: jest.SpiedFunction<
|
||||
typeof queryResolver.resolveQueries
|
||||
>;
|
||||
@@ -36,23 +31,23 @@ describe("runAutoModelQueries", () => {
|
||||
>;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(queryResolver, "qlpackOfDatabase").mockResolvedValue(qlpack);
|
||||
|
||||
resolveQueriesSpy = jest
|
||||
.spyOn(queryResolver, "resolveQueries")
|
||||
.mockImplementation(async (_cliServer, _qlPack, _name, constraints) => {
|
||||
if (constraints["tags contain all"]?.includes("candidates")) {
|
||||
return ["/a/b/c/ql/candidates.ql"];
|
||||
}
|
||||
if (constraints["tags contain all"]?.includes("positive")) {
|
||||
return ["/a/b/c/ql/positive-examples.ql"];
|
||||
}
|
||||
if (constraints["tags contain all"]?.includes("negative")) {
|
||||
return ["/a/b/c/ql/negative-examples.ql"];
|
||||
}
|
||||
.mockImplementation(
|
||||
async (_cliServer, _packsToSearch, _name, constraints) => {
|
||||
if (constraints["tags contain all"]?.includes("candidates")) {
|
||||
return ["/a/b/c/ql/candidates.ql"];
|
||||
}
|
||||
if (constraints["tags contain all"]?.includes("positive")) {
|
||||
return ["/a/b/c/ql/positive-examples.ql"];
|
||||
}
|
||||
if (constraints["tags contain all"]?.includes("negative")) {
|
||||
return ["/a/b/c/ql/negative-examples.ql"];
|
||||
}
|
||||
|
||||
return [];
|
||||
});
|
||||
return [];
|
||||
},
|
||||
);
|
||||
|
||||
createLockFileForStandardQuerySpy = jest
|
||||
.spyOn(standardQueries, "createLockFileForStandardQuery")
|
||||
@@ -154,7 +149,7 @@ describe("runAutoModelQueries", () => {
|
||||
expect(resolveQueriesSpy).toHaveBeenCalledTimes(1);
|
||||
expect(resolveQueriesSpy).toHaveBeenCalledWith(
|
||||
options.cliServer,
|
||||
qlpack,
|
||||
["codeql/java-queries"],
|
||||
"Extract automodel candidates",
|
||||
{
|
||||
kind: "problem",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
qlpackOfDatabase,
|
||||
resolveQueries,
|
||||
resolveQueriesByLanguagePack,
|
||||
} from "../../../../src/local-queries";
|
||||
import { mockDatabaseItem, mockedObject } from "../../utils/mocking.helpers";
|
||||
import { CodeQLCliServer } from "../../../../src/codeql-cli/cli";
|
||||
@@ -69,7 +69,7 @@ describe("resolveQueries", () => {
|
||||
|
||||
it("should resolve a query", async () => {
|
||||
resolveQueriesInSuite.mockReturnValue(["a", "b"]);
|
||||
const result = await resolveQueries(
|
||||
const result = await resolveQueriesByLanguagePack(
|
||||
mockCli,
|
||||
{ dbschemePack: "my-qlpack", dbschemePackIsLibraryPack: false },
|
||||
"my query",
|
||||
@@ -103,7 +103,7 @@ describe("resolveQueries", () => {
|
||||
resolveQueriesInSuite.mockReturnValue([]);
|
||||
|
||||
await expect(
|
||||
resolveQueries(
|
||||
resolveQueriesByLanguagePack(
|
||||
mockCli,
|
||||
{ dbschemePack: "my-qlpack", dbschemePackIsLibraryPack: false },
|
||||
"my query",
|
||||
|
||||
Reference in New Issue
Block a user