Skip to content

Commit

Permalink
Fix tests with workspaceContains:.git activation event
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
koesie10 committed Nov 23, 2023
1 parent 560008c commit 27bd419
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
3 changes: 2 additions & 1 deletion extensions/ql-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
6 changes: 2 additions & 4 deletions extensions/ql-vscode/src/codeql-cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
}
Expand Down Expand Up @@ -290,6 +286,8 @@ export class CodeQLCliServer implements Disposable {
const callback = (): void => {
try {
this.killProcessIfRunning();
this._version = undefined;
this._supportedLanguages = undefined;
} finally {
this.runNext();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,6 +42,8 @@ describe("database-fetcher", () => {

afterEach(async () => {
await cleanDatabases(databaseManager);
await remove(storagePath);
await ensureDir(storagePath);
});

describe("importArchiveDatabase", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down

0 comments on commit 27bd419

Please sign in to comment.