From 0d49c28436e92806527f1987c047f70b7882fe26 Mon Sep 17 00:00:00 2001 From: bymyself Date: Tue, 3 Feb 2026 01:08:33 +0000 Subject: [PATCH] feat: enable linear mode toggle for nightly builds - Add isNightly import to useFeatureFlags composable - Short-circuit linearToggleEnabled getter to return true for nightly builds - Add unit tests for the new isNightly behavior --- src/composables/useFeatureFlags.test.ts | 44 +++++++++++++++++++++++++ src/composables/useFeatureFlags.ts | 4 ++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/composables/useFeatureFlags.test.ts b/src/composables/useFeatureFlags.test.ts index c2b3634f785..c1caea6cf38 100644 --- a/src/composables/useFeatureFlags.test.ts +++ b/src/composables/useFeatureFlags.test.ts @@ -5,6 +5,7 @@ import { ServerFeatureFlag, useFeatureFlags } from '@/composables/useFeatureFlags' +import * as distributionTypes from '@/platform/distribution/types' import { api } from '@/scripts/api' // Mock the API module @@ -14,6 +15,12 @@ vi.mock('@/scripts/api', () => ({ } })) +// Mock the distribution types module +vi.mock('@/platform/distribution/types', () => ({ + isCloud: false, + isNightly: false +})) + describe('useFeatureFlags', () => { beforeEach(() => { vi.clearAllMocks() @@ -131,4 +138,41 @@ describe('useFeatureFlags', () => { expect(maxUploadSize.value).toBe(104857600) }) }) + + describe('linearToggleEnabled', () => { + it('should return true when isNightly is true', () => { + vi.mocked(distributionTypes).isNightly = true + + const { flags } = useFeatureFlags() + expect(flags.linearToggleEnabled).toBe(true) + expect(api.getServerFeature).not.toHaveBeenCalled() + }) + + it('should check remote config and server feature when isNightly is false', () => { + vi.mocked(distributionTypes).isNightly = false + vi.mocked(api.getServerFeature).mockImplementation( + (path, defaultValue) => { + if (path === ServerFeatureFlag.LINEAR_TOGGLE_ENABLED) return true + return defaultValue + } + ) + + const { flags } = useFeatureFlags() + expect(flags.linearToggleEnabled).toBe(true) + expect(api.getServerFeature).toHaveBeenCalledWith( + ServerFeatureFlag.LINEAR_TOGGLE_ENABLED, + false + ) + }) + + it('should return false when isNightly is false and flag is disabled', () => { + vi.mocked(distributionTypes).isNightly = false + vi.mocked(api.getServerFeature).mockImplementation( + (_path, defaultValue) => defaultValue + ) + + const { flags } = useFeatureFlags() + expect(flags.linearToggleEnabled).toBe(false) + }) + }) }) diff --git a/src/composables/useFeatureFlags.ts b/src/composables/useFeatureFlags.ts index e0e69b4c9cc..48747c7a9e9 100644 --- a/src/composables/useFeatureFlags.ts +++ b/src/composables/useFeatureFlags.ts @@ -1,6 +1,6 @@ import { computed, reactive, readonly } from 'vue' -import { isCloud } from '@/platform/distribution/types' +import { isCloud, isNightly } from '@/platform/distribution/types' import { isAuthenticatedConfigLoaded, remoteConfig @@ -84,6 +84,8 @@ export function useFeatureFlags() { ) }, get linearToggleEnabled() { + if (isNightly) return true + return ( remoteConfig.value.linear_toggle_enabled ?? api.getServerFeature(ServerFeatureFlag.LINEAR_TOGGLE_ENABLED, false)