Cleanup automodel temporary pack after use
This commit is contained in:
@@ -63,10 +63,8 @@ export async function runAutoModelQueries({
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Generate a pack containing the candidate filters
|
// Generate a pack containing the candidate filters
|
||||||
const filterPackDir = await generateCandidateFilterPack(
|
const { packDir: filterPackDir, cleanup: cleanupFilterPack } =
|
||||||
databaseItem.language,
|
await generateCandidateFilterPack(databaseItem.language, candidateMethods);
|
||||||
candidateMethods,
|
|
||||||
);
|
|
||||||
|
|
||||||
const additionalPacks = [...getOnDiskWorkspaceFolders(), filterPackDir];
|
const additionalPacks = [...getOnDiskWorkspaceFolders(), filterPackDir];
|
||||||
const extensionPacks = Object.keys(
|
const extensionPacks = Object.keys(
|
||||||
@@ -85,6 +83,8 @@ export async function runAutoModelQueries({
|
|||||||
token: cancellationTokenSource.token,
|
token: cancellationTokenSource.token,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await cleanupFilterPack();
|
||||||
|
|
||||||
if (!completedQuery) {
|
if (!completedQuery) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -155,6 +155,11 @@ async function resolveAutomodelQuery(
|
|||||||
return queries[0];
|
return queries[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CandidateFilterPackResult = {
|
||||||
|
packDir: string;
|
||||||
|
cleanup: () => Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generateCandidateFilterPack will create a temporary extension pack.
|
* generateCandidateFilterPack will create a temporary extension pack.
|
||||||
* This pack will contain a filter that will restrict the automodel queries
|
* This pack will contain a filter that will restrict the automodel queries
|
||||||
@@ -167,9 +172,9 @@ async function resolveAutomodelQuery(
|
|||||||
export async function generateCandidateFilterPack(
|
export async function generateCandidateFilterPack(
|
||||||
language: string,
|
language: string,
|
||||||
candidateMethods: MethodSignature[],
|
candidateMethods: MethodSignature[],
|
||||||
): Promise<string> {
|
): Promise<CandidateFilterPackResult> {
|
||||||
// Pack resides in a temporary directory, to not pollute the workspace.
|
// Pack resides in a temporary directory, to not pollute the workspace.
|
||||||
const packDir = (await dir({ unsafeCleanup: true })).path;
|
const { path: packDir, cleanup } = await dir({ unsafeCleanup: true });
|
||||||
|
|
||||||
const syntheticConfigPack = {
|
const syntheticConfigPack = {
|
||||||
name: "codeql/automodel-filter",
|
name: "codeql/automodel-filter",
|
||||||
@@ -208,7 +213,10 @@ export async function generateCandidateFilterPack(
|
|||||||
const filterFile = join(packDir, "filter.yml");
|
const filterFile = join(packDir, "filter.yml");
|
||||||
await writeFile(filterFile, dumpYaml(filter), "utf8");
|
await writeFile(filterFile, dumpYaml(filter), "utf8");
|
||||||
|
|
||||||
return packDir;
|
return {
|
||||||
|
packDir,
|
||||||
|
cleanup,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function interpretAutomodelResults(
|
async function interpretAutomodelResults(
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import { QueryRunner } from "../../../../src/query-server";
|
|||||||
import * as queryResolver from "../../../../src/local-queries/query-resolver";
|
import * as queryResolver from "../../../../src/local-queries/query-resolver";
|
||||||
import { MethodSignature } from "../../../../src/model-editor/method";
|
import { MethodSignature } from "../../../../src/model-editor/method";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { exists, readFile } from "fs-extra";
|
import { pathExists, readFile } from "fs-extra";
|
||||||
import { load as loadYaml } from "js-yaml";
|
import { load as loadYaml } from "js-yaml";
|
||||||
import { CancellationTokenSource } from "vscode-jsonrpc";
|
import { CancellationTokenSource } from "vscode-jsonrpc";
|
||||||
import { QueryOutputDir } from "../../../../src/run-queries-shared";
|
import { QueryOutputDir } from "../../../../src/run-queries-shared";
|
||||||
@@ -176,12 +176,15 @@ describe("generateCandidateFilterPack", () => {
|
|||||||
methodParameters: "()",
|
methodParameters: "()",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const packDir = await generateCandidateFilterPack("java", candidateMethods);
|
const { packDir, cleanup } = await generateCandidateFilterPack(
|
||||||
|
"java",
|
||||||
|
candidateMethods,
|
||||||
|
);
|
||||||
expect(packDir).not.toBeUndefined();
|
expect(packDir).not.toBeUndefined();
|
||||||
const qlpackFile = join(packDir, "codeql-pack.yml");
|
const qlpackFile = join(packDir, "codeql-pack.yml");
|
||||||
expect(await exists(qlpackFile)).toBe(true);
|
expect(await pathExists(qlpackFile)).toBe(true);
|
||||||
const filterFile = join(packDir, "filter.yml");
|
const filterFile = join(packDir, "filter.yml");
|
||||||
expect(await exists(filterFile)).toBe(true);
|
expect(await pathExists(filterFile)).toBe(true);
|
||||||
// Read the contents of filterFile and parse as yaml
|
// Read the contents of filterFile and parse as yaml
|
||||||
const yaml = await loadYaml(await readFile(filterFile, "utf8"));
|
const yaml = await loadYaml(await readFile(filterFile, "utf8"));
|
||||||
const extensions = yaml.extensions;
|
const extensions = yaml.extensions;
|
||||||
@@ -193,5 +196,8 @@ describe("generateCandidateFilterPack", () => {
|
|||||||
expect(extension.data).toBeInstanceOf(Array);
|
expect(extension.data).toBeInstanceOf(Array);
|
||||||
expect(extension.data).toHaveLength(1);
|
expect(extension.data).toHaveLength(1);
|
||||||
expect(extension.data[0]).toEqual(["org.my", "A", "x", "()"]);
|
expect(extension.data[0]).toEqual(["org.my", "A", "x", "()"]);
|
||||||
|
|
||||||
|
await cleanup();
|
||||||
|
expect(await pathExists(packDir)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user