-
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(3742): Feature Flag Values with Scope Based on threshold
- Loading branch information
1 parent
1fd0d3a
commit f9326fa
Showing
8 changed files
with
315 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |
|
||
## [Unreleased] | ||
|
||
## [1.2.0] | ||
|
||
### Added | ||
|
||
- Added support for threshold-based feature flag scoping ([#5051](https://github.com/MetaMask/core/pull/5051)) | ||
- Enables percentage-based feature flag distribution across user base | ||
- Uses deterministic random group assignment based on metaMetricsId | ||
|
||
## [1.1.0] | ||
|
||
### Added | ||
|
@@ -26,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |
- Initial release of the RemoteFeatureFlagController. ([#4931](https://github.com/MetaMask/core/pull/4931)) | ||
- This controller manages the retrieval and caching of remote feature flags. It fetches feature flags from a remote API, caches them, and provides methods to access and manage these flags. The controller ensures that feature flags are refreshed based on a specified interval and handles cases where the controller is disabled or the network is unavailable. | ||
|
||
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/[email protected] | ||
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/[email protected] | ||
[1.2.0]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected] | ||
[1.1.0]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected] | ||
[1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/[email protected] |
This file contains 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 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 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 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
103 changes: 103 additions & 0 deletions
103
packages/remote-feature-flag-controller/src/utils/user-segmentation-utils.test.ts
This file contains 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,103 @@ | ||
import { | ||
generateDeterministicRandomNumber, | ||
isFeatureFlagWithScopeValue, | ||
generateFallbackMetaMetricsId, | ||
} from './user-segmentation-utils'; | ||
import { webcrypto } from 'crypto'; | ||
|
||
const MOCK_METRICS_IDS = [ | ||
'0x1234567890abcdef', | ||
'0xdeadbeefdeadbeef', | ||
'0xabcdef0123456789', | ||
'0xfedcba9876543210', | ||
]; | ||
|
||
const MOCK_FEATURE_FLAGS = { | ||
VALID: { | ||
name: 'test-flag', | ||
value: true, | ||
scope: { | ||
type: 'threshold', | ||
value: 0.5, | ||
}, | ||
}, | ||
INVALID_NO_SCOPE: { | ||
name: 'test-flag', | ||
value: true, | ||
}, | ||
INVALID_VALUES: ['string', 123, true, null, []], | ||
}; | ||
|
||
describe('user-segmentation-utils', () => { | ||
beforeAll(() => { | ||
// Set up crypto for tests | ||
Object.defineProperty(global, 'crypto', { | ||
value: webcrypto, | ||
writable: true, | ||
configurable: true, | ||
}); | ||
}); | ||
|
||
describe('generateDeterministicRandomNumber', () => { | ||
it('generates consistent numbers for the same input', () => { | ||
const result1 = generateDeterministicRandomNumber(MOCK_METRICS_IDS[0]); | ||
const result2 = generateDeterministicRandomNumber(MOCK_METRICS_IDS[0]); | ||
|
||
expect(result1).toBe(result2); | ||
}); | ||
|
||
it('generates numbers between 0 and 1', () => { | ||
MOCK_METRICS_IDS.forEach((id) => { | ||
const result = generateDeterministicRandomNumber(id); | ||
expect(result).toBeGreaterThanOrEqual(0); | ||
expect(result).toBeLessThanOrEqual(1); | ||
}); | ||
}); | ||
|
||
it('generates different numbers for different inputs', () => { | ||
const result1 = generateDeterministicRandomNumber(MOCK_METRICS_IDS[0]); | ||
const result2 = generateDeterministicRandomNumber(MOCK_METRICS_IDS[1]); | ||
|
||
expect(result1).not.toBe(result2); | ||
}); | ||
}); | ||
|
||
describe('isFeatureFlagWithScopeValue', () => { | ||
it('returns true for valid feature flag with scope', () => { | ||
expect(isFeatureFlagWithScopeValue(MOCK_FEATURE_FLAGS.VALID)).toBe(true); | ||
}); | ||
|
||
it('returns false for null', () => { | ||
expect(isFeatureFlagWithScopeValue(null)).toBe(false); | ||
}); | ||
|
||
it('returns false for non-objects', () => { | ||
MOCK_FEATURE_FLAGS.INVALID_VALUES.forEach((value) => { | ||
expect(isFeatureFlagWithScopeValue(value)).toBe(false); | ||
}); | ||
}); | ||
|
||
it('returns false for objects without scope', () => { | ||
expect( | ||
isFeatureFlagWithScopeValue(MOCK_FEATURE_FLAGS.INVALID_NO_SCOPE), | ||
).toBe(false); | ||
}); | ||
}); | ||
|
||
// describe('generateFallbackMetaMetricsId', () => { | ||
Check warning on line 87 in packages/remote-feature-flag-controller/src/utils/user-segmentation-utils.test.ts GitHub Actions / Lint, build, and test / Lint (20.x)
|
||
// it('returns a properly formatted hex string', () => { | ||
Check warning on line 88 in packages/remote-feature-flag-controller/src/utils/user-segmentation-utils.test.ts GitHub Actions / Lint, build, and test / Lint (20.x)
|
||
// const result = generateFallbackMetaMetricsId(); | ||
// expect(typeof result).toBe('string'); | ||
// expect(result.startsWith('0x')).toBe(true); | ||
// expect(result).toHaveLength(66); | ||
// expect(result.slice(2)).toMatch(/^[0-9a-f]+$/u); | ||
// }); | ||
|
||
// it('generates unique values for each revoke', () => { | ||
// const result1 = generateFallbackMetaMetricsId(); | ||
// const result2 = generateFallbackMetaMetricsId(); | ||
|
||
// expect(result1).not.toBe(result2); | ||
// }); | ||
// }); | ||
}); |
Oops, something went wrong.