Skip to content

Commit 54be065

Browse files
committed
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.
1 parent c3425b5 commit 54be065

File tree

5 files changed

+36
-20
lines changed

5 files changed

+36
-20
lines changed

extensions/ql-vscode/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"onWebviewPanel:resultsView",
4040
"onWebviewPanel:codeQL.variantAnalysis",
4141
"onWebviewPanel:codeQL.dataFlowPaths",
42-
"onFileSystem:codeql-zip-archive"
42+
"onFileSystem:codeql-zip-archive",
43+
"workspaceContains:.git"
4344
],
4445
"main": "./out/extension",
4546
"files": [

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,11 @@ export class CodeQLCliServer implements Disposable {
241241
if (this.distributionProvider.onDidChangeDistribution) {
242242
this.distributionProvider.onDidChangeDistribution(() => {
243243
this.restartCliServer();
244-
this._version = undefined;
245-
this._supportedLanguages = undefined;
246244
});
247245
}
248246
if (this.cliConfig.onDidChangeConfiguration) {
249247
this.cliConfig.onDidChangeConfiguration(() => {
250248
this.restartCliServer();
251-
this._version = undefined;
252-
this._supportedLanguages = undefined;
253249
});
254250
}
255251
}
@@ -290,6 +286,8 @@ export class CodeQLCliServer implements Disposable {
290286
const callback = (): void => {
291287
try {
292288
this.killProcessIfRunning();
289+
this._version = undefined;
290+
this._supportedLanguages = undefined;
293291
} finally {
294292
this.runNext();
295293
}

extensions/ql-vscode/test/vscode-tests/cli-integration/databases/database-fetcher.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
storagePath,
1616
} from "../../global.helper";
1717
import { createMockCommandManager } from "../../../__mocks__/commandsMock";
18+
import { ensureDir, remove } from "fs-extra";
1819

1920
/**
2021
* Run various integration tests for databases
@@ -41,6 +42,8 @@ describe("database-fetcher", () => {
4142

4243
afterEach(async () => {
4344
await cleanDatabases(databaseManager);
45+
await remove(storagePath);
46+
await ensureDir(storagePath);
4447
});
4548

4649
describe("importArchiveDatabase", () => {

extensions/ql-vscode/test/vscode-tests/cli-integration/jest.setup.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "../jest.activated-extension.setup";
88
import { createWriteStream, existsSync, mkdirpSync } from "fs-extra";
99
import { dirname } from "path";
10-
import { DB_URL, dbLoc } from "../global.helper";
10+
import { DB_URL, dbLoc, getActivatedExtension } from "../global.helper";
1111
import fetch from "node-fetch";
1212

1313
beforeAll(async () => {
@@ -31,6 +31,25 @@ beforeAll(async () => {
3131
}
3232

3333
await beforeAllAction();
34+
35+
// Activate the extension
36+
const extension = await getActivatedExtension();
37+
38+
if (process.env.CLI_VERSION && process.env.CLI_VERSION !== "nightly") {
39+
const cliVersion = await extension.cliServer.getVersion();
40+
41+
if (cliVersion.compare(process.env.CLI_VERSION) !== 0) {
42+
// This calls the private `updateConfiguration` method in the `ConfigListener`
43+
// It seems like the CUSTOM_CODEQL_PATH_SETTING.updateValue() call in
44+
// `beforeAllAction` doesn't fire the event that the config has changed.
45+
// This is a hacky workaround.
46+
(
47+
extension.distributionManager.config as unknown as {
48+
updateConfiguration: () => void;
49+
}
50+
).updateConfiguration();
51+
}
52+
}
3453
});
3554

3655
beforeEach(async () => {

extensions/ql-vscode/test/vscode-tests/cli-integration/model-editor/modeled-method-fs.test.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,6 @@ describe("modeled-method-fs", () => {
5353
let workspacePath: string;
5454
let cli: CodeQLCliServer;
5555

56-
beforeAll(async () => {
57-
const extension = await getActivatedExtension();
58-
cli = extension.cliServer;
59-
60-
// All transitive dependencies must be available for resolve extensions to succeed.
61-
const packUsingExtensionsPath = join(
62-
__dirname,
63-
"../../..",
64-
"data-extensions",
65-
"pack-using-extensions",
66-
);
67-
await cli.packInstall(packUsingExtensionsPath);
68-
});
69-
7056
beforeEach(async () => {
7157
// On windows, make sure to use a temp directory that isn't an alias and therefore won't be canonicalised by CodeQL.
7258
// See https://github.com/github/vscode-codeql/pull/2605 for more context.
@@ -92,6 +78,15 @@ describe("modeled-method-fs", () => {
9278

9379
const extension = await getActivatedExtension();
9480
cli = extension.cliServer;
81+
82+
// All transitive dependencies must be available for resolve extensions to succeed.
83+
const packUsingExtensionsPath = join(
84+
__dirname,
85+
"../../..",
86+
"data-extensions",
87+
"pack-using-extensions",
88+
);
89+
await cli.packInstall(packUsingExtensionsPath);
9590
});
9691

9792
afterEach(() => {

0 commit comments

Comments
 (0)