diff --git a/ui/src/lib/variants.test.ts b/ui/src/lib/variants.test.ts index e8a208d..9558a62 100644 --- a/ui/src/lib/variants.test.ts +++ b/ui/src/lib/variants.test.ts @@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest'; import { ALL_VARIANTS, + DEFAULT_VARIANTS, availableVariants, supportsMultipleWordsToggle, multipleWordsForRequest, @@ -16,9 +17,11 @@ describe('ALL_VARIANTS', () => { }); describe('availableVariants', () => { - it('is ungated (all variants) for an empty or absent preference set', () => { - expect(availableVariants([])).toEqual(ALL_VARIANTS); - expect(availableVariants(undefined)).toEqual(ALL_VARIANTS); + it('falls back to the Erudit-only default for an empty or absent preference set', () => { + const fallback = ALL_VARIANTS.filter((v) => DEFAULT_VARIANTS.includes(v.id)); + expect(fallback.map((v) => v.id)).toEqual(['erudit_ru']); + expect(availableVariants([])).toEqual(fallback); + expect(availableVariants(undefined)).toEqual(fallback); }); it('offers only the preferred variants', () => { diff --git a/ui/src/lib/variants.ts b/ui/src/lib/variants.ts index 5981007..b520082 100644 --- a/ui/src/lib/variants.ts +++ b/ui/src/lib/variants.ts @@ -62,13 +62,23 @@ export function usesStarBlank(v: Variant): boolean { return v === 'erudit_ru'; } -// availableVariants gates ALL_VARIANTS by the player's variant preferences (the set -// they enabled in Settings). An empty or absent set is ungated (returns every variant) -// — a safety fallback; a real profile always carries at least one preference. +// DEFAULT_VARIANTS is the variant set a player sees before any preference is stored — a fresh +// or offline native client whose profile has not been synced yet (the device-local guest boots +// with no profile at all). It mirrors the backend's new-account default (the account service +// seeds Erudit only), so the local guest and a later synced account agree on what is enabled. +// Every dictionary is still bundled; the other variants are simply off until the player turns +// them on in Settings. +export const DEFAULT_VARIANTS: Variant[] = ['erudit_ru']; + +// availableVariants gates ALL_VARIANTS by the player's variant preferences (the set they +// enabled in Settings). An empty or absent set falls back to DEFAULT_VARIANTS rather than every +// variant: a real profile always carries at least one preference, and a profileless client (a +// fresh offline native launch) must match the server's Erudit-only default instead of exposing +// the English game before the player opts in. export function availableVariants(preferences: Variant[] | undefined): VariantOption[] { const prefs = preferences ?? []; - if (prefs.length === 0) return ALL_VARIANTS; - return ALL_VARIANTS.filter((v) => prefs.includes(v.id)); + const effective = prefs.length === 0 ? DEFAULT_VARIANTS : prefs; + return ALL_VARIANTS.filter((v) => effective.includes(v.id)); } // supportsMultipleWordsToggle reports whether the New Game "multiple words per turn" toggle