Skip to content

Commit

Permalink
chore(compass-preferences-model): remove bypass ai hello check prefer…
Browse files Browse the repository at this point in the history
…ence COMPASS-7226 (mongodb-js#5043)
  • Loading branch information
Anemy authored Oct 31, 2023
1 parent 090feab commit 6cc3d9a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
12 changes: 10 additions & 2 deletions packages/compass-e2e-tests/tests/atlas-login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import path from 'path';
import { expect } from 'chai';
import { createNumbersCollection } from '../helpers/insert-data';
import { AcceptTOSToggle } from '../helpers/selectors';
import { startMockAtlasServiceServer } from '../helpers/atlas-service';

const DEFAULT_TOKEN_PAYLOAD = {
expires_in: 3600,
Expand All @@ -37,11 +38,17 @@ describe('Atlas Login', function () {
let oidcMockProvider: OIDCMockProvider;
let originalDisableKeychainUsage: string | undefined;
let getTokenPayload: OIDCMockProviderConfig['getTokenPayload'];
let stopMockAtlasServer: () => Promise<void>;

before(async function () {
originalDisableKeychainUsage =
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE;

// Start a mock server to pass an ai response.
const { endpoint, stop } = await startMockAtlasServiceServer();
stopMockAtlasServer = stop;
process.env.COMPASS_ATLAS_SERVICE_UNAUTH_BASE_URL_OVERRIDE = endpoint;

function isAuthorised(req: { headers: { authorization?: string } }) {
const [, token] = req.headers.authorization?.split(' ') ?? [];
// We can't check that the issued token is the one received by oidc-plugin
Expand Down Expand Up @@ -108,12 +115,10 @@ describe('Atlas Login', function () {
'browserCommandForOIDCAuth',
getTestBrowserShellCommand()
);
await browser.setFeature('enableAIWithoutRolloutAccess', true);
});

afterEach(async function () {
await browser.setFeature('browserCommandForOIDCAuth', undefined);
await browser.setFeature('enableAIWithoutRolloutAccess', false);
await afterTest(compass, this.currentTest);
await afterTests(compass, this.currentTest);
});
Expand All @@ -125,6 +130,9 @@ describe('Atlas Login', function () {
delete process.env.COMPASS_ATLAS_AUTH_PORTAL_URL_OVERRIDE;
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE =
originalDisableKeychainUsage;

await stopMockAtlasServer();
delete process.env.COMPASS_ATLAS_SERVICE_UNAUTH_BASE_URL_OVERRIDE;
});

describe('in settings', function () {
Expand Down
13 changes: 0 additions & 13 deletions packages/compass-preferences-model/src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type FeatureFlagDefinition = {

export type FeatureFlags = {
enableGenAIExperience: boolean;
enableAIWithoutRolloutAccess: boolean;
enableLgDarkmode: boolean;
enableOidc: boolean; // Not capitalized "OIDC" for spawn arg casing.
enableStageWizard: boolean;
Expand All @@ -41,18 +40,6 @@ export const featureFlags: Required<{
},
},

/**
* Temporary feature flag for bypassing our incremental rollout for ai access.
* Ticket to remove: COMPASS-7226
*/
enableAIWithoutRolloutAccess: {
stage: 'development',
description: {
short: 'Enable AI Features Without Rollout Access',
long: 'Bypass the public preview rollout access for the AI features in Compass. Do not use this feature with sensitive data.',
},
},

/**
* Currently Compass uses `darkreader` to globally change the views of
* Compass to a dark theme. Turning on this feature flag stops darkreader
Expand Down
14 changes: 2 additions & 12 deletions packages/compass-preferences-model/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@ export function capMaxTimeMSAtPreferenceLimit<T>(value: T): T | number {
* feature is considered enabled if:
* - AI feature flag is enabled
* - config preference that controls AI is enabled
* - either mms backend rollout enabled feature for the compass user or special
* option to bypass the check is passed
* - mms backend rollout enabled feature for the compass user
*/
export function isAIFeatureEnabled(
preferences: Pick<
AllPreferences,
| 'enableGenAIFeatures'
| 'enableGenAIExperience'
| 'cloudFeatureRolloutAccess'
| 'enableAIWithoutRolloutAccess'
> = preferencesAccess.getPreferences()
) {
const {
Expand All @@ -66,14 +64,11 @@ export function isAIFeatureEnabled(
enableGenAIExperience,
// based on mms backend rollout response
cloudFeatureRolloutAccess,
// feature flag to bypass rollout access check
enableAIWithoutRolloutAccess,
} = preferences;
return (
enableGenAIFeatures &&
enableGenAIExperience &&
(!!cloudFeatureRolloutAccess?.GEN_AI_COMPASS ||
enableAIWithoutRolloutAccess)
!!cloudFeatureRolloutAccess?.GEN_AI_COMPASS
);
}

Expand All @@ -84,15 +79,10 @@ export function useIsAIFeatureEnabled(React: ReactHooks) {
'cloudFeatureRolloutAccess',
React
);
const enableAIWithoutRolloutAccess = usePreference(
'enableAIWithoutRolloutAccess',
React
);

return isAIFeatureEnabled({
enableGenAIFeatures,
enableGenAIExperience,
cloudFeatureRolloutAccess,
enableAIWithoutRolloutAccess,
});
}

0 comments on commit 6cc3d9a

Please sign in to comment.