Fix tests with workspaceContains:.git activation event

It seems like changes to the CLI path setting are not picked up by the
extension when it is already activated. This is probably because the
`workspace.onDidChangeConfiguration` event is not fired when the update
is made programmatically.

This fixes it by manually firing the event so that all listeners (CLI
server, query server, IDE server) can pick up the change.
This commit is contained in:
Koen Vlaswinkel
2023-11-24 11:15:49 +01:00
parent c3425b5146
commit 54be065f3e
5 changed files with 36 additions and 20 deletions

View File

@@ -39,7 +39,8 @@
"onWebviewPanel:resultsView",
"onWebviewPanel:codeQL.variantAnalysis",
"onWebviewPanel:codeQL.dataFlowPaths",
"onFileSystem:codeql-zip-archive"
"onFileSystem:codeql-zip-archive",
"workspaceContains:.git"
],
"main": "./out/extension",
"files": [

View File

@@ -241,15 +241,11 @@ export class CodeQLCliServer implements Disposable {
if (this.distributionProvider.onDidChangeDistribution) {
this.distributionProvider.onDidChangeDistribution(() => {
this.restartCliServer();
this._version = undefined;
this._supportedLanguages = undefined;
});
}
if (this.cliConfig.onDidChangeConfiguration) {
this.cliConfig.onDidChangeConfiguration(() => {
this.restartCliServer();
this._version = undefined;
this._supportedLanguages = undefined;
});
}
}
@@ -290,6 +286,8 @@ export class CodeQLCliServer implements Disposable {
const callback = (): void => {
try {
this.killProcessIfRunning();
this._version = undefined;
this._supportedLanguages = undefined;
} finally {
this.runNext();
}

View File

@@ -15,6 +15,7 @@ import {
storagePath,
} from "../../global.helper";
import { createMockCommandManager } from "../../../__mocks__/commandsMock";
import { ensureDir, remove } from "fs-extra";
/**
* Run various integration tests for databases
@@ -41,6 +42,8 @@ describe("database-fetcher", () => {
afterEach(async () => {
await cleanDatabases(databaseManager);
await remove(storagePath);
await ensureDir(storagePath);
});
describe("importArchiveDatabase", () => {

View File

@@ -7,7 +7,7 @@ import {
} from "../jest.activated-extension.setup";
import { createWriteStream, existsSync, mkdirpSync } from "fs-extra";
import { dirname } from "path";
import { DB_URL, dbLoc } from "../global.helper";
import { DB_URL, dbLoc, getActivatedExtension } from "../global.helper";
import fetch from "node-fetch";
beforeAll(async () => {
@@ -31,6 +31,25 @@ beforeAll(async () => {
}
await beforeAllAction();
// Activate the extension
const extension = await getActivatedExtension();
if (process.env.CLI_VERSION && process.env.CLI_VERSION !== "nightly") {
const cliVersion = await extension.cliServer.getVersion();
if (cliVersion.compare(process.env.CLI_VERSION) !== 0) {
// This calls the private `updateConfiguration` method in the `ConfigListener`
// It seems like the CUSTOM_CODEQL_PATH_SETTING.updateValue() call in
// `beforeAllAction` doesn't fire the event that the config has changed.
// This is a hacky workaround.
(
extension.distributionManager.config as unknown as {
updateConfiguration: () => void;
}
).updateConfiguration();
}
}
});
beforeEach(async () => {

View File

@@ -53,20 +53,6 @@ describe("modeled-method-fs", () => {
let workspacePath: string;
let cli: CodeQLCliServer;
beforeAll(async () => {
const extension = await getActivatedExtension();
cli = extension.cliServer;
// All transitive dependencies must be available for resolve extensions to succeed.
const packUsingExtensionsPath = join(
__dirname,
"../../..",
"data-extensions",
"pack-using-extensions",
);
await cli.packInstall(packUsingExtensionsPath);
});
beforeEach(async () => {
// On windows, make sure to use a temp directory that isn't an alias and therefore won't be canonicalised by CodeQL.
// See https://github.com/github/vscode-codeql/pull/2605 for more context.
@@ -92,6 +78,15 @@ describe("modeled-method-fs", () => {
const extension = await getActivatedExtension();
cli = extension.cliServer;
// All transitive dependencies must be available for resolve extensions to succeed.
const packUsingExtensionsPath = join(
__dirname,
"../../..",
"data-extensions",
"pack-using-extensions",
);
await cli.packInstall(packUsingExtensionsPath);
});
afterEach(() => {