fix(onboarding): preserve system language in both experiment cohorts (#31810)

This commit is contained in:
Jinjing
2026-10-21 21:02:25 -07:00
committed by GitHub
parent 307f0cdaee
commit 301059fb77
3 changed files with 10 additions and 10 deletions
@@ -32,9 +32,9 @@ afterEach(async () => {
describe('persisted onboarding language cohorts', () => {
it.each([
{ draw: 0, cohort: 'control', language: 'en' },
{ draw: 1, cohort: 'treatment', language: 'system' }
])('retains $cohort through settings changes and restart', async ({ draw, cohort, language }) => {
{ draw: 0, cohort: 'control' },
{ draw: 1, cohort: 'treatment' }
])('retains $cohort through settings changes and restart', async ({ draw, cohort }) => {
vi.mocked(crypto.randomInt).mockImplementation(() => draw)
const store = createStore()
const telemetry = store.getSettings().telemetry
@@ -42,9 +42,10 @@ describe('persisted onboarding language cohorts', () => {
throw new Error('Fresh profile has no telemetry settings')
}
expect(telemetry.onboardingLanguageCohort).toBe(cohort)
expect(store.getSettings().uiLanguage).toBe(language)
expect(store.getSettings().uiLanguage).toBe('system')
store.flush()
expect(readDataFile()).toHaveProperty('settings.telemetry.onboardingLanguageCohort', cohort)
expect(readDataFile()).toHaveProperty('settings.uiLanguage', 'system')
store.updateSettings({ uiLanguage: 'fr' })
store.updateSettings({ telemetry: { ...telemetry, optedIn: false } })
@@ -12,17 +12,17 @@ afterEach(() => vi.resetAllMocks())
describe('onboarding language experiment', () => {
it.each([
{ draw: 0, cohort: 'control', language: 'en' },
{ draw: 1, cohort: 'treatment', language: 'system' }
{ draw: 0, cohort: 'control' },
{ draw: 1, cohort: 'treatment' }
])(
'assigns and freezes the $cohort experience for a new install',
({ draw, cohort, language }) => {
'assigns and freezes the $cohort experience with the system language for a new install',
({ draw, cohort }) => {
vi.mocked(crypto.randomInt).mockImplementation(() => draw)
const runtime = { loadNeedsSave: false }
const migration = new LoadedCohortMigrationOperations(runtime)
const fresh = migration.migrateTelemetry(getDefaultPersistedState('/test'), false)
expect(fresh.settings.telemetry?.onboardingLanguageCohort).toBe(cohort)
expect(fresh.settings.uiLanguage).toBe(language)
expect(fresh.settings.uiLanguage).toBe('system')
expect(runtime.loadNeedsSave).toBe(true)
const reopened = migration.migrateTelemetry(JSON.parse(JSON.stringify(fresh)), true)
expect(reopened).toEqual(fresh)
@@ -96,7 +96,6 @@ export class LoadedCohortMigrationOperations {
...state,
settings: {
...state.settings,
...(onboardingLanguageCohort === 'control' ? { uiLanguage: 'en' as const } : {}),
telemetry: {
...existing,
...(onboardingLanguageCohort ? { onboardingLanguageCohort } : {}),