Skip to content

Commit 528abfd

Browse files
jbowesShawkyZ
authored andcommitted
fix: ignore the cli checksum when looking for clis without auto-downloads (#726)
If our plugin isn't managing the cli, then we never set use or compare the checksum. However, when the downloader looked for the cli, it checked for a state-stored checksum as well, and showed an error dialog if either were missing. This error doesn't stop the CLI from loading, nor does it compare the checksum (which happens elsewhere for auto-downloads). If the plugin never downloaded the cli, there's no checksum, and you get an error no matter what. Change the logic to only look for the cli existing when auto-downloads are disabled.
1 parent bb78d6a commit 528abfd

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/snyk/common/services/downloadService.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ export class DownloadService {
4343
'Automatic dependency management is disabled — skipping CLI download/update. ' +
4444
'Enable "Automatic Dependency Management" in Snyk settings to allow automatic CLI updates.',
4545
);
46-
if (!cliInstalled) {
46+
// Check for a configured CLI path. We don't examine checksum here, as we aren't auto-downloading.
47+
const cliPath = await this.configuration.getCliPath();
48+
const cliExecutableExists = await CliExecutable.exists(cliPath);
49+
if (!cliExecutableExists) {
4750
throw new Error(
4851
'The Snyk CLI is not installed. Please download it manually or enable "Automatic Dependency Management" in Snyk settings.',
4952
);

src/test/unit/common/services/downloadService.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ suite('DownloadService', () => {
106106
getCliPath: () => Promise.resolve('path/to/cli'),
107107
} as IConfiguration;
108108
const service = new DownloadService(context, configuration, cliApi, windowMock, logger, downloader);
109-
stub(service, 'isCliInstalled').resolves(true);
109+
stub(CliExecutable, 'exists').resolves(true);
110110
const downloadSpy = stub(service, 'download');
111111
const updateSpy = stub(service, 'update');
112112

@@ -193,7 +193,7 @@ suite('DownloadService', () => {
193193
getCliPath: () => Promise.resolve('path/to/cli'),
194194
} as IConfiguration;
195195
const service = new DownloadService(context, configuration, cliApi, windowMock, logger, downloader);
196-
stub(service, 'isCliInstalled').resolves(true);
196+
stub(CliExecutable, 'exists').resolves(true);
197197

198198
await service.downloadOrUpdate();
199199

@@ -210,7 +210,7 @@ suite('DownloadService', () => {
210210
getCliPath: () => Promise.resolve('path/to/cli'),
211211
} as IConfiguration;
212212
const service = new DownloadService(context, configuration, cliApi, windowMock, logger, downloader);
213-
stub(service, 'isCliInstalled').resolves(false);
213+
stub(CliExecutable, 'exists').resolves(false);
214214

215215
let thrownError: Error | undefined;
216216
try {
@@ -234,7 +234,7 @@ suite('DownloadService', () => {
234234
getCliPath: () => Promise.resolve('path/to/cli'),
235235
} as IConfiguration;
236236
const service = new DownloadService(context, configuration, cliApi, windowMock, logger, downloader);
237-
stub(service, 'isCliInstalled').resolves(true);
237+
stub(CliExecutable, 'exists').resolves(true);
238238

239239
const result = await service.downloadOrUpdate();
240240

0 commit comments

Comments
 (0)