Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests with workspaceContains:.git activation event #3086

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 12 additions & 0 deletions extensions/ql-vscode/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ export interface DistributionConfig {
ownerName?: string;
repositoryName?: string;
onDidChangeConfiguration?: Event<void>;

/**
* This forces an update of the distribution, even if the settings haven't changed.
*
* This should only be used when the distribution has been updated outside of the extension
* and only in tests. It should not be called in production code.
*/
forceUpdateConfiguration(): void;
}

// Query server configuration
Expand Down Expand Up @@ -275,6 +283,10 @@ export class DistributionConfigListener
);
}

public forceUpdateConfiguration() {
this._onDidChangeConfiguration.fire(undefined);
}

protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
this.handleDidChangeConfigurationForRelevantSettings(
DISTRIBUTION_CHANGE_SETTINGS,
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 { remove } from "fs-extra";

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

afterEach(async () => {
await cleanDatabases(databaseManager);
await remove(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,21 @@ 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) {
// It seems like the CUSTOM_CODEQL_PATH_SETTING.updateValue() call in
charisk marked this conversation as resolved.
Show resolved Hide resolved
// `beforeAllAction` doesn't fire the event that the config has changed.
// `forceUpdateConfiguration` will fire the event manually.
// This is a hacky workaround.
extension.distributionManager.config.forceUpdateConfiguration();
}
}
});

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(() => {
Expand Down