Skip to content

Commit b3ad1d6

Browse files
committed
fix: Avoid warning user if no new launcher exists
Allow extension to remain on the deprecated launcher.
1 parent 130d3c0 commit b3ad1d6

File tree

2 files changed

+75
-12
lines changed

2 files changed

+75
-12
lines changed

extensions/ql-vscode/src/distribution.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ export class DistributionManager implements DistributionProvider {
112112
"that a CodeQL executable exists at the specified path or remove the setting.");
113113
return undefined;
114114
}
115-
if (deprecatedCodeQlLauncherName() && this._config.customCodeQlPath.endsWith(deprecatedCodeQlLauncherName()!)) {
115+
116+
// emit a warning if using a deprecated launcher and a non-deprecated launcher exists
117+
if (
118+
deprecatedCodeQlLauncherName() &&
119+
this._config.customCodeQlPath.endsWith(deprecatedCodeQlLauncherName()!) &&
120+
await this.hasNewLauncherName()
121+
) {
116122
warnDeprecatedLauncher();
117123
}
118124
return this._config.customCodeQlPath;
@@ -173,6 +179,21 @@ export class DistributionManager implements DistributionProvider {
173179
return this._onDidChangeDistribution;
174180
}
175181

182+
/**
183+
* @return true if the non-deprecated launcher name exists on the file system
184+
* in the same directory as the specified launcher only if using an external
185+
* installation. False otherwise.
186+
*/
187+
private async hasNewLauncherName(): Promise<boolean> {
188+
if (!this._config.customCodeQlPath) {
189+
// not managed externally
190+
return false;
191+
}
192+
const dir = path.dirname(this._config.customCodeQlPath);
193+
const newLaunderPath = path.join(dir, codeQlLauncherName());
194+
return await fs.pathExists(newLaunderPath);
195+
}
196+
176197
private readonly _config: DistributionConfig;
177198
private readonly _extensionSpecificDistributionManager: ExtensionSpecificDistributionManager;
178199
private readonly _updateCheckRateLimiter: InvocationRateLimiter<DistributionUpdateCheckResult>;

extensions/ql-vscode/src/vscode-tests/no-workspace/distribution.test.ts

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,12 @@ describe("Release version ordering", () => {
188188
});
189189

190190
describe('Launcher path', () => {
191+
const pathToCmd = `abc${path.sep}codeql.cmd`;
192+
const pathToExe = `abc${path.sep}codeql.exe`;
193+
191194
let sandbox: sinon.SinonSandbox;
192195
let warnSpy: sinon.SinonSpy;
196+
let errorSpy: sinon.SinonSpy;
193197
let logSpy: sinon.SinonSpy;
194198
let fsSpy: sinon.SinonSpy;
195199
let platformSpy: sinon.SinonSpy;
@@ -209,37 +213,37 @@ describe('Launcher path', () => {
209213
it('should not warn with proper launcher name', async () => {
210214
launcherThatExists = 'codeql.exe';
211215
const result = await getExecutableFromDirectory('abc');
212-
expect(fsSpy).to.have.been.calledWith(`abc${path.sep}codeql.exe`);
216+
expect(fsSpy).to.have.been.calledWith(pathToExe);
213217

214218
// correct launcher has been found, so alternate one not looked for
215-
expect(fsSpy).not.to.have.been.calledWith(`abc${path.sep}codeql.cmd`);
219+
expect(fsSpy).not.to.have.been.calledWith(pathToCmd);
216220

217221
// no warning message
218222
expect(warnSpy).not.to.have.been.calledWith(sinon.match.string);
219223
// No log message
220224
expect(logSpy).not.to.have.been.calledWith(sinon.match.string);
221-
expect(result).to.equal(`abc${path.sep}codeql.exe`);
225+
expect(result).to.equal(pathToExe);
222226
});
223227

224228
it('should warn when using a hard-coded deprecated launcher name', async () => {
225229
launcherThatExists = 'codeql.cmd';
226230
path.sep;
227231
const result = await getExecutableFromDirectory('abc');
228-
expect(fsSpy).to.have.been.calledWith(`abc${path.sep}codeql.exe`);
229-
expect(fsSpy).to.have.been.calledWith(`abc${path.sep}codeql.cmd`);
232+
expect(fsSpy).to.have.been.calledWith(pathToExe);
233+
expect(fsSpy).to.have.been.calledWith(pathToCmd);
230234

231235
// Should have opened a warning message
232236
expect(warnSpy).to.have.been.calledWith(sinon.match.string);
233237
// No log message
234238
expect(logSpy).not.to.have.been.calledWith(sinon.match.string);
235-
expect(result).to.equal(`abc${path.sep}codeql.cmd`);
239+
expect(result).to.equal(pathToCmd);
236240
});
237241

238242
it('should avoid warn when no launcher is found', async () => {
239243
launcherThatExists = 'xxx';
240244
const result = await getExecutableFromDirectory('abc', false);
241-
expect(fsSpy).to.have.been.calledWith(`abc${path.sep}codeql.exe`);
242-
expect(fsSpy).to.have.been.calledWith(`abc${path.sep}codeql.cmd`);
245+
expect(fsSpy).to.have.been.calledWith(pathToExe);
246+
expect(fsSpy).to.have.been.calledWith(pathToCmd);
243247

244248
// no warning message
245249
expect(warnSpy).not.to.have.been.calledWith(sinon.match.string);
@@ -251,8 +255,8 @@ describe('Launcher path', () => {
251255
it('should warn when no launcher is found', async () => {
252256
launcherThatExists = 'xxx';
253257
const result = await getExecutableFromDirectory('abc', true);
254-
expect(fsSpy).to.have.been.calledWith(`abc${path.sep}codeql.exe`);
255-
expect(fsSpy).to.have.been.calledWith(`abc${path.sep}codeql.cmd`);
258+
expect(fsSpy).to.have.been.calledWith(pathToExe);
259+
expect(fsSpy).to.have.been.calledWith(pathToCmd);
256260

257261
// no warning message
258262
expect(warnSpy).not.to.have.been.calledWith(sinon.match.string);
@@ -261,17 +265,55 @@ describe('Launcher path', () => {
261265
expect(result).to.equal(undefined);
262266
});
263267

268+
it('should not warn when deprecated launcher is used, but no new launcher is available', async () => {
269+
const manager = new (createModule().DistributionManager)(undefined as any, { customCodeQlPath: pathToCmd } as any, undefined as any);
270+
launcherThatExists = 'codeql.cmd';
271+
272+
const result = await manager.getCodeQlPathWithoutVersionCheck();
273+
expect(result).to.equal(pathToCmd);
274+
275+
// no warning or error message
276+
expect(warnSpy).to.have.callCount(0);
277+
expect(errorSpy).to.have.callCount(0);
278+
});
279+
280+
it('should warn when deprecated launcher is used, and new launcher is available', async () => {
281+
const manager = new (createModule().DistributionManager)(undefined as any, { customCodeQlPath: pathToCmd } as any, undefined as any);
282+
launcherThatExists = ''; // pretend both launchers exist
283+
284+
const result = await manager.getCodeQlPathWithoutVersionCheck();
285+
expect(result).to.equal(pathToCmd);
286+
287+
// has warning message
288+
expect(warnSpy).to.have.callCount(1);
289+
expect(errorSpy).to.have.callCount(0);
290+
});
291+
292+
it('should warn when launcher path is incorrect', async () => {
293+
const manager = new (createModule().DistributionManager)(undefined as any, { customCodeQlPath: pathToCmd } as any, undefined as any);
294+
launcherThatExists = 'xxx'; // pretend neither launcher exists
295+
296+
const result = await manager.getCodeQlPathWithoutVersionCheck();
297+
expect(result).to.equal(undefined);
298+
299+
// no error message
300+
expect(warnSpy).to.have.callCount(0);
301+
expect(errorSpy).to.have.callCount(1);
302+
});
303+
264304
function createModule() {
265305
sandbox = sinon.createSandbox();
266306
warnSpy = sandbox.spy();
307+
errorSpy = sandbox.spy();
267308
logSpy = sandbox.spy();
268309
// pretend that only the .cmd file exists
269310
fsSpy = sandbox.stub().callsFake(arg => arg.endsWith(launcherThatExists) ? true : false);
270311
platformSpy = sandbox.stub().returns('win32');
271312

272313
return proxyquire('../../distribution', {
273314
'./helpers': {
274-
showAndLogWarningMessage: warnSpy
315+
showAndLogWarningMessage: warnSpy,
316+
showAndLogErrorMessage: errorSpy
275317
},
276318
'./logging': {
277319
'logger': {

0 commit comments

Comments
 (0)