-
Notifications
You must be signed in to change notification settings - Fork 53
Add experimentalFeatures to initialization options #287
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
4 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import {FeatureFlags} from "./features.js"; | ||
|
|
||
| describe("FeatureFlags", () => { | ||
| describe("isEnabled", () => { | ||
| it("returns false by default when no options provided", () => { | ||
| const flags = new FeatureFlags(); | ||
| expect(flags.isEnabled("missingInputsQuickfix")).toBe(false); | ||
| }); | ||
|
|
||
| it("returns false by default when empty options provided", () => { | ||
| const flags = new FeatureFlags({}); | ||
| expect(flags.isEnabled("missingInputsQuickfix")).toBe(false); | ||
| }); | ||
|
|
||
| it("returns true when feature is explicitly enabled", () => { | ||
| const flags = new FeatureFlags({missingInputsQuickfix: true}); | ||
| expect(flags.isEnabled("missingInputsQuickfix")).toBe(true); | ||
| }); | ||
|
|
||
| it("returns false when feature is explicitly disabled", () => { | ||
| const flags = new FeatureFlags({missingInputsQuickfix: false}); | ||
| expect(flags.isEnabled("missingInputsQuickfix")).toBe(false); | ||
| }); | ||
|
|
||
| it("returns true when all is enabled", () => { | ||
| const flags = new FeatureFlags({all: true}); | ||
| expect(flags.isEnabled("missingInputsQuickfix")).toBe(true); | ||
| }); | ||
|
|
||
| it("explicit feature flag takes precedence over all:true", () => { | ||
| const flags = new FeatureFlags({all: true, missingInputsQuickfix: false}); | ||
| expect(flags.isEnabled("missingInputsQuickfix")).toBe(false); | ||
| }); | ||
|
|
||
| it("explicit feature flag takes precedence over all:false", () => { | ||
| const flags = new FeatureFlags({all: false, missingInputsQuickfix: true}); | ||
| expect(flags.isEnabled("missingInputsQuickfix")).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getEnabledFeatures", () => { | ||
| it("returns empty array when no features enabled", () => { | ||
| const flags = new FeatureFlags(); | ||
| expect(flags.getEnabledFeatures()).toEqual([]); | ||
| }); | ||
|
|
||
| it("returns enabled features", () => { | ||
| const flags = new FeatureFlags({missingInputsQuickfix: true}); | ||
| expect(flags.getEnabledFeatures()).toEqual(["missingInputsQuickfix"]); | ||
| }); | ||
|
|
||
| it("returns all features when all is enabled", () => { | ||
| const flags = new FeatureFlags({all: true}); | ||
| expect(flags.getEnabledFeatures()).toEqual(["missingInputsQuickfix"]); | ||
| }); | ||
| }); | ||
| }); |
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,66 @@ | ||
| /** | ||
| * Experimental feature flags. | ||
| * | ||
| * Individual feature flags take precedence over `all`. | ||
| * Example: { all: true, missingInputsQuickfix: false } enables all | ||
| * experimental features EXCEPT missingInputsQuickfix. | ||
| * | ||
| * When a feature graduates to stable, its flag becomes a no-op | ||
| * (the feature will be enabled regardless of the configuration value). | ||
| */ | ||
| export interface ExperimentalFeatures { | ||
| /** | ||
| * Enable all experimental features. | ||
| * Individual feature flags take precedence over this setting. | ||
| * @default false | ||
| */ | ||
| all?: boolean; | ||
|
|
||
| /** | ||
| * Enable quickfix code action for missing required action inputs. | ||
| * @default false | ||
| */ | ||
| missingInputsQuickfix?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Keys of ExperimentalFeatures that represent actual features (excludes 'all') | ||
| */ | ||
| export type ExperimentalFeatureKey = Exclude<keyof ExperimentalFeatures, "all">; | ||
|
|
||
| /** | ||
| * All known experimental feature keys. | ||
| * This list must be kept in sync with the ExperimentalFeatures interface. | ||
| */ | ||
| const allFeatureKeys: ExperimentalFeatureKey[] = ["missingInputsQuickfix"]; | ||
|
|
||
| export class FeatureFlags { | ||
| private readonly features: ExperimentalFeatures; | ||
|
|
||
| constructor(features?: ExperimentalFeatures) { | ||
| this.features = features ?? {}; | ||
| } | ||
|
|
||
| /** | ||
| * Check if an experimental feature is enabled. | ||
| * | ||
| * Resolution order: | ||
| * 1. Explicit feature flag (if set) | ||
| * 2. `all` flag (if set) | ||
| * 3. false (default) | ||
| */ | ||
| isEnabled(feature: ExperimentalFeatureKey): boolean { | ||
| const explicit = this.features[feature]; | ||
| if (explicit !== undefined) { | ||
| return explicit; | ||
| } | ||
| return this.features.all ?? false; | ||
| } | ||
|
|
||
| /** | ||
| * Returns list of all enabled experimental features. | ||
| */ | ||
| getEnabledFeatures(): ExperimentalFeatureKey[] { | ||
| return allFeatureKeys.filter(key => this.isEnabled(key)); | ||
| } | ||
| } |
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
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.