-
Notifications
You must be signed in to change notification settings - Fork 673
feat(featureFlags): employee-gated session feature flag overrides via ?ff= #15033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
97b2a4b
feat(featureFlags): add employee-gated session flag overrides via ?ff=
Glary-Bot f9321e6
refactor(featureFlags): make override capture idempotent instead of m…
Glary-Bot 96f7042
feat(featureFlags): make every feature flag session-overridable
Glary-Bot 3a26b58
refactor(featureFlags): inline the employee check instead of an adapt…
Glary-Bot fd1c150
test(api): characterize getServerFeature resolution before the overri…
Glary-Bot 42e1041
fix(featureFlags): honour session overrides in serverSupportsFeature
Glary-Bot 9139fd3
test(api): isolate session override state and cover an explicit false…
Glary-Bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { api } from '@/scripts/api' | ||
|
|
||
| const mockDistribution = vi.hoisted(() => ({ | ||
| isCloud: true, | ||
| isNightly: false | ||
| })) | ||
| vi.mock('@/platform/distribution/types', () => mockDistribution) | ||
|
|
||
| const mockCurrentUser = vi.hoisted(() => ({ | ||
| value: null as { email: string | null; emailVerified: boolean } | null | ||
| })) | ||
| vi.mock('vuefire', () => ({ | ||
| useCurrentUser: vi.fn(() => mockCurrentUser) | ||
| })) | ||
|
|
||
| /** | ||
| * Every call here happens at plain module scope — no component, no `setup()`, | ||
| * no active Vue instance — which is how `api.getServerFeature` is reached from | ||
| * stores and utilities. Identity is stubbed at the `vuefire` boundary, so what | ||
| * these cases pin is the precedence and gating logic, not VueFire itself. | ||
| * | ||
| * That VueFire resolves the default Firebase app outside a component is a | ||
| * property of the real SDK and needs a real initialised app, so it is verified | ||
| * against a live Firebase app in the browser rather than here. | ||
| */ | ||
| describe('api.getServerFeature session override outside component setup', () => { | ||
| beforeEach(() => { | ||
| mockDistribution.isCloud = true | ||
| mockCurrentUser.value = { email: 'dev@comfy.org', emailVerified: true } | ||
| api.serverFeatureFlags.value = {} | ||
| sessionStorage.clear() | ||
| localStorage.clear() | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| window.history.replaceState({}, '', '/') | ||
| api.serverFeatureFlags.value = {} | ||
| sessionStorage.clear() | ||
| localStorage.clear() | ||
| vi.restoreAllMocks() | ||
| }) | ||
|
|
||
| it('applies a numeric override to a flag that never routes through resolveFlag', () => { | ||
| api.serverFeatureFlags.value = { max_upload_size: 100 } | ||
| window.history.replaceState({}, '', '/?ff=max_upload_size:209715200') | ||
|
|
||
| expect(api.getServerFeature('max_upload_size')).toBe(209715200) | ||
| }) | ||
|
|
||
| it('does not throw when no Vue instance is active', () => { | ||
| window.history.replaceState({}, '', '/?ff=some_flag:enforce') | ||
|
|
||
| expect(() => api.getServerFeature('some_flag')).not.toThrow() | ||
| expect(api.getServerFeature('some_flag')).toBe('enforce') | ||
| }) | ||
|
|
||
| it('beats the dev localStorage override', () => { | ||
| localStorage.setItem('ff:some_flag', '"from_local_storage"') | ||
| window.history.replaceState({}, '', '/?ff=some_flag:from_url') | ||
|
|
||
| expect(api.getServerFeature('some_flag')).toBe('from_url') | ||
| }) | ||
|
|
||
| it('withholds the override from a non-employee', () => { | ||
| mockCurrentUser.value = { email: 'someone@gmail.com', emailVerified: true } | ||
| api.serverFeatureFlags.value = { max_upload_size: 100 } | ||
| window.history.replaceState({}, '', '/?ff=max_upload_size:209715200') | ||
|
|
||
| expect(api.getServerFeature('max_upload_size')).toBe(100) | ||
| }) | ||
|
|
||
| it('leaves resolution untouched when no override is requested', () => { | ||
| api.serverFeatureFlags.value = { max_upload_size: 100 } | ||
|
|
||
| expect(api.getServerFeature('max_upload_size')).toBe(100) | ||
| expect(api.getServerFeature('missing', 'DEFAULT')).toBe('DEFAULT') | ||
| }) | ||
|
|
||
| it('reports the override through serverSupportsFeature too', () => { | ||
| api.serverFeatureFlags.value = { some_flag: false } | ||
| window.history.replaceState({}, '', '/?ff=some_flag') | ||
|
|
||
| expect(api.serverSupportsFeature('some_flag')).toBe(true) | ||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| it('turns a supported feature off through an explicit false override', () => { | ||
| api.serverFeatureFlags.value = { some_flag: true } | ||
| window.history.replaceState({}, '', '/?ff=some_flag:false') | ||
|
|
||
| expect(api.serverSupportsFeature('some_flag')).toBe(false) | ||
| expect(api.getServerFeature('some_flag')).toBe(false) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.