Skip to content

Commit

Permalink
chore: hide oss quickfixes behind a preview flag (#504)
Browse files Browse the repository at this point in the history
* chore: hide oss quickfixes behind a preview flag

* fix: add missing prop in tests

* fix: add getPreviewFeatures mock for settings test

* refactor: move getpreview call to configuration

---------

Co-authored-by: Abdelrahman Shawki Hassan <shawki.hassan@snyk.io>
  • Loading branch information
bastiandoetsch and ShawkyZ committed Jul 26, 2024
1 parent 468444e commit f6a758e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/snyk/common/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface SeverityFilter {

export type PreviewFeatures = {
advisor: boolean | undefined;
ossQuickfixes: boolean | undefined;
};

export interface IConfiguration {
Expand Down Expand Up @@ -132,6 +133,8 @@ export interface IConfiguration {

getDeltaFindingsEnabled(): boolean;

getOssQuickFixCodeActionsEnabled(): boolean;

getFolderConfigs(): FolderConfig[];

setFolderConfigs(folderConfig: FolderConfig[]): Promise<void>;
Expand All @@ -147,6 +150,10 @@ export class Configuration implements IConfiguration {

constructor(private processEnv: NodeJS.ProcessEnv = process.env, private workspace: IVSCodeWorkspace) {}

getOssQuickFixCodeActionsEnabled(): boolean {
return this.getPreviewFeatures().ossQuickfixes ?? false;
}

getInsecure(): boolean {
const strictSSL = this.workspace.getConfiguration<boolean>('http', 'proxyStrictSSL') ?? true;
return !strictSSL;
Expand Down Expand Up @@ -449,6 +456,7 @@ export class Configuration implements IConfiguration {
getPreviewFeatures(): PreviewFeatures {
const defaultSetting: PreviewFeatures = {
advisor: false,
ossQuickfixes: false,
};

const userSetting =
Expand Down
2 changes: 2 additions & 0 deletions src/snyk/common/languageServer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type ServerSettings = {
requiredProtocolVersion?: string;
enableDeltaFindings?: string;
folderConfigs: FolderConfig[];
enableSnykOSSQuickFixCodeActions: string;
};

export class LanguageServerSettings {
Expand Down Expand Up @@ -84,6 +85,7 @@ export class LanguageServerSettings {
deviceId: user.anonymousId,
requiredProtocolVersion: `${PROTOCOL_VERSION}`,
folderConfigs: configuration.getFolderConfigs(),
enableSnykOSSQuickFixCodeActions: `${configuration.getOssQuickFixCodeActionsEnabled()}`,
};
}
}
2 changes: 2 additions & 0 deletions src/test/unit/common/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ suite('Configuration', () => {

deepStrictEqual(configuration.getPreviewFeatures(), {
advisor: false,
ossQuickfixes: false,
} as PreviewFeatures);
});

test('Preview features: some features enabled', () => {
const previewFeatures = {
advisor: false,
ossQuickfixes: false,
} as PreviewFeatures;
const workspace = stubWorkspaceConfiguration(FEATURES_PREVIEW_SETTING, previewFeatures);

Expand Down
11 changes: 8 additions & 3 deletions src/test/unit/common/languageServer/languageServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@ suite('Language Server', () => {
isAutomaticDependencyManagementEnabled() {
return true;
},
getOssQuickFixCodeActionsEnabled() {
return false;
},
getFeaturesConfiguration() {
return defaultFeaturesConfigurationStub;
},
getPreviewFeatures() {
return {
advisor: false,
ossQuickfixes: false,
};
},
getFeaturesConfiguration() {
return defaultFeaturesConfigurationStub;
},
severityFilter: {
critical: true,
high: true,
Expand Down Expand Up @@ -231,6 +235,7 @@ suite('Language Server', () => {
scanningMode: 'auto',
folderConfigs: [],
authenticationMethod: 'oauth',
enableSnykOSSQuickFixCodeActions: 'false',
};

deepStrictEqual(await languageServer.getInitializationOptions(), expectedInitializationOptions);
Expand Down
9 changes: 5 additions & 4 deletions src/test/unit/common/languageServer/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ suite('Language Server: Middleware', () => {
getDeltaFindingsEnabled(): boolean {
return false;
},
getPreviewFeatures: () => {
return {
advisor: false,
};
getPreviewFeatures() {
return { advisor: false, ossQuickfixes: false };
},
getOssQuickFixCodeActionsEnabled(): boolean {
return false;
},
getFeaturesConfiguration() {
return defaultFeaturesConfigurationStub;
Expand Down
8 changes: 7 additions & 1 deletion src/test/unit/common/languageServer/settings.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert';
import { FolderConfig, IConfiguration } from '../../../../snyk/common/configuration/configuration';
import { FolderConfig, IConfiguration, PreviewFeatures } from '../../../../snyk/common/configuration/configuration';
import { LanguageServerSettings } from '../../../../snyk/common/languageServer/settings';
import { User } from '../../../../snyk/common/user';

Expand All @@ -23,6 +23,12 @@ suite('LanguageServerSettings', () => {
getFolderConfigs(): FolderConfig[] {
return [];
},
getPreviewFeatures(): PreviewFeatures {
return { advisor: false, ossQuickfixes: false };
},
getOssQuickFixCodeActionsEnabled(): boolean {
return false;
},
getAuthenticationMethod(): string {
return 'oauth';
},
Expand Down

0 comments on commit f6a758e

Please sign in to comment.