diff --git a/packages/create-nx-workspace/src/utils/nx/ab-testing.spec.ts b/packages/create-nx-workspace/src/utils/nx/ab-testing.spec.ts index c09e97c0928..b78d6e56e99 100644 --- a/packages/create-nx-workspace/src/utils/nx/ab-testing.spec.ts +++ b/packages/create-nx-workspace/src/utils/nx/ab-testing.spec.ts @@ -1,8 +1,8 @@ import { isEnterpriseCloudUrl, getBannerVariant, - shouldShowCloudPrompt, getFlowVariant, + PromptMessages, } from './ab-testing'; describe('ab-testing', () => { @@ -104,9 +104,40 @@ describe('ab-testing', () => { }); }); - describe('shouldShowCloudPrompt', () => { - it('should always return false (variant 2 locked in CLOUD-4255)', () => { - expect(shouldShowCloudPrompt()).toBe(false); + describe('setupNxCloudV2 prompt variants', () => { + const originalEnv = process.env; + + beforeEach(() => { + jest.resetModules(); + process.env = { ...originalEnv }; + }); + + afterEach(() => { + process.env = originalEnv; + }); + + it.each([ + { flowVariant: '0', expectedCode: 'connect-to-cloud' }, + { flowVariant: '1', expectedCode: 'cloud-ab-remote-cache-speed' }, + { flowVariant: '2', expectedCode: 'cloud-ab-fast-ci-setup' }, + ])( + 'should select $expectedCode for flow variant $flowVariant', + ({ flowVariant, expectedCode }) => { + jest.resetModules(); + process.env.NX_CNW_FLOW_VARIANT = flowVariant; + const { PromptMessages: FreshPromptMessages } = require('./ab-testing'); + const pm = new FreshPromptMessages(); + expect(pm.getPrompt('setupNxCloudV2').code).toBe(expectedCode); + } + ); + + it('should select variant 0 for docs generation', () => { + process.env.NX_GENERATE_DOCS_PROCESS = 'true'; + const { PromptMessages: FreshPromptMessages } = jest.requireActual( + './ab-testing' + ) as typeof import('./ab-testing'); + const pm = new FreshPromptMessages(); + expect(pm.getPrompt('setupNxCloudV2').code).toBe('connect-to-cloud'); }); }); }); diff --git a/packages/create-nx-workspace/src/utils/nx/ab-testing.ts b/packages/create-nx-workspace/src/utils/nx/ab-testing.ts index 3f6b5e8d040..6cb2e10aca2 100644 --- a/packages/create-nx-workspace/src/utils/nx/ab-testing.ts +++ b/packages/create-nx-workspace/src/utils/nx/ab-testing.ts @@ -8,6 +8,7 @@ import { } from 'node:fs'; import { join } from 'node:path'; import { tmpdir } from 'node:os'; +import chalk from 'chalk'; import { isCI } from '../ci/is-ci'; import type { BannerVariant, CompletionMessageKey } from './messages'; @@ -98,12 +99,6 @@ export function getCompletionMessageKeyForVariant(): CompletionMessageKey { return 'platform-setup'; } -export function shouldShowCloudPrompt(): boolean { - // CLOUD-4255: Lock to variant 2 behavior (no prompt) - // To re-enable A/B testing: return getFlowVariant() !== '2'; - return false; -} - // ============================================================================ // Banner Variant A/B Testing (CLOUD-4235) // ============================================================================ @@ -220,13 +215,41 @@ const messageOptions: Record = { choices: [ { value: 'yes', name: 'Yes' }, { value: 'skip', name: 'Skip for now' }, - { value: 'never', name: "No, don't ask again" }, + { value: 'never', name: chalk.dim("No, don't ask again") }, ], footer: '\nAutomatically fix broken PRs, 70% faster CI: https://nx.dev/nx-cloud', fallback: undefined, completionMessage: 'platform-setup', }, + { + code: 'cloud-ab-remote-cache-speed', + message: 'Enable remote caching to speed up builds with Nx Cloud?', + initial: 0, + choices: [ + { value: 'yes', name: 'Yes' }, + { value: 'skip', name: 'Skip for now' }, + { value: 'never', name: chalk.dim("No, don't ask again") }, + ], + footer: + '\nFree for small teams. 2-minute setup with GitHub — cache locally and in CI: https://nx.dev/nx-cloud', + fallback: undefined, + completionMessage: 'platform-setup', + }, + { + code: 'cloud-ab-fast-ci-setup', + message: 'Speed up your CI with Nx Cloud?', + initial: 0, + choices: [ + { value: 'yes', name: 'Yes' }, + { value: 'skip', name: 'Skip for now' }, + { value: 'never', name: chalk.dim("No, don't ask again") }, + ], + footer: + '\n70% faster CI on GitHub, GitLab, and more. Free tier, 2-minute setup: https://nx.dev/nx-cloud', + fallback: undefined, + completionMessage: 'platform-setup', + }, ], }; @@ -250,9 +273,9 @@ export class PromptMessages { if (process.env.NX_GENERATE_DOCS_PROCESS === 'true') { this.selectedMessages[key] = 0; } else { - this.selectedMessages[key] = Math.floor( - Math.random() * messageOptions[key].length - ); + const variant = Number(getFlowVariant()); + this.selectedMessages[key] = + variant < messageOptions[key].length ? variant : 0; } } return messageOptions[key][this.selectedMessages[key]!];