Skip to content

Commit d5e7e54

Browse files
authored
Merge pull request #3086 from github/koesie10/fix-cli-tests
Fix tests with `workspaceContains:.git` activation event
2 parents d0d12b7 + 2e06fa3 commit d5e7e54

File tree

6 files changed

+43
-20
lines changed

6 files changed

+43
-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/src/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ export interface DistributionConfig {
119119
ownerName?: string;
120120
repositoryName?: string;
121121
onDidChangeConfiguration?: Event<void>;
122+
123+
/**
124+
* This forces an update of the distribution, even if the settings haven't changed.
125+
*
126+
* This should only be used when the distribution has been updated outside of the extension
127+
* and only in tests. It should not be called in production code.
128+
*/
129+
forceUpdateConfiguration(): void;
122130
}
123131

124132
// Query server configuration
@@ -275,6 +283,10 @@ export class DistributionConfigListener
275283
);
276284
}
277285

286+
public forceUpdateConfiguration() {
287+
this._onDidChangeConfiguration.fire(undefined);
288+
}
289+
278290
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
279291
this.handleDidChangeConfigurationForRelevantSettings(
280292
DISTRIBUTION_CHANGE_SETTINGS,

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

Lines changed: 2 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 { remove } from "fs-extra";
1819

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

4243
afterEach(async () => {
4344
await cleanDatabases(databaseManager);
45+
await remove(storagePath);
4446
});
4547

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

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

Lines changed: 16 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,21 @@ 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+
// It seems like the CUSTOM_CODEQL_PATH_SETTING.updateValue() call in
43+
// `beforeAllAction` doesn't fire the event that the config has changed.
44+
// `forceUpdateConfiguration` will fire the event manually.
45+
// This is a hacky workaround.
46+
extension.distributionManager.config.forceUpdateConfiguration();
47+
}
48+
}
3449
});
3550

3651
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)