-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add local override functionality #184
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
20 commits
Select commit
Hold shift + click to select a range
ec87564
Add local override functionality
yfrancis 272c3ab
Hash flag keys before looking up
yfrancis 37d20e1
Re-use flag evaluation details builder
yfrancis 7f423b7
Revert "Hash flag keys before looking up"
yfrancis 398e802
Remove unused constant
yfrancis 2f3865d
Add test coverage for override functionality
yfrancis 2c2db42
change overrides store type to ISyncStore
yfrancis 1c9697a
Better test for assignment cache behavior with overrides
yfrancis 458bc0e
Add unsetOverridesStore method
yfrancis 9c5581c
Add a test for unsetting overrides store
yfrancis 8d74403
Move overridesStore param and decl closer to other stores
yfrancis c23636b
Add prefix to allocation key for overrides for clarity
yfrancis 2309ba9
Move evaluation details construction into helper
yfrancis f860c88
style: move overrides store param next to other stores
yfrancis b5cf5b3
Add overrides to precomputed client
yfrancis 20ed6c7
Add test coverage for overrides with the precomputed client
yfrancis 4979b7d
Fix type of overridesStore in the client constructor, should be ISync…
yfrancis a9780be
Add getter for all active override keys
yfrancis a24f4a9
Rename overridesStore to overrideStore
yfrancis f7da0e4
bump SDK version to 4.10.0
greghuels 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import { | |
validateTestAssignments, | ||
} from '../../test/testHelpers'; | ||
import { IAssignmentLogger } from '../assignment-logger'; | ||
import { AssignmentCache } from '../cache/abstract-assignment-cache'; | ||
import { | ||
IConfigurationWire, | ||
IObfuscatedPrecomputedConfigurationResponse, | ||
|
@@ -23,7 +24,7 @@ import { IConfigurationStore } from '../configuration-store/configuration-store' | |
import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store'; | ||
import { MAX_EVENT_QUEUE_SIZE, DEFAULT_POLL_INTERVAL_MS, POLL_JITTER_PCT } from '../constants'; | ||
import { decodePrecomputedFlag } from '../decoding'; | ||
import { Flag, ObfuscatedFlag, VariationType } from '../interfaces'; | ||
import { Flag, ObfuscatedFlag, Variation, VariationType } from '../interfaces'; | ||
import { getMD5Hash } from '../obfuscation'; | ||
import { AttributeType } from '../types'; | ||
|
||
|
@@ -945,4 +946,225 @@ describe('EppoClient E2E test', () => { | |
); | ||
}); | ||
}); | ||
|
||
describe('flag overrides', () => { | ||
let client: EppoClient; | ||
let mockLogger: IAssignmentLogger; | ||
let overrideStore: IConfigurationStore<Variation>; | ||
|
||
beforeEach(() => { | ||
storage.setEntries({ [flagKey]: mockFlag }); | ||
mockLogger = td.object<IAssignmentLogger>(); | ||
overrideStore = new MemoryOnlyConfigurationStore<Variation>(); | ||
client = new EppoClient({ | ||
flagConfigurationStore: storage, | ||
overrideStore: overrideStore, | ||
}); | ||
client.setAssignmentLogger(mockLogger); | ||
client.useNonExpiringInMemoryAssignmentCache(); | ||
}); | ||
|
||
it('returns override values for all supported types', () => { | ||
overrideStore.setEntries({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Upstream |
||
'string-flag': { | ||
key: 'override-variation', | ||
value: 'override-string', | ||
}, | ||
'boolean-flag': { | ||
key: 'override-variation', | ||
value: true, | ||
}, | ||
'numeric-flag': { | ||
key: 'override-variation', | ||
value: 42.5, | ||
}, | ||
'json-flag': { | ||
key: 'override-variation', | ||
value: '{"foo": "bar"}', | ||
}, | ||
}); | ||
|
||
expect(client.getStringAssignment('string-flag', 'subject-10', {}, 'default')).toBe( | ||
'override-string', | ||
); | ||
expect(client.getBooleanAssignment('boolean-flag', 'subject-10', {}, false)).toBe(true); | ||
expect(client.getNumericAssignment('numeric-flag', 'subject-10', {}, 0)).toBe(42.5); | ||
expect(client.getJSONAssignment('json-flag', 'subject-10', {}, {})).toEqual({ foo: 'bar' }); | ||
yfrancis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('does not log assignments when override is applied', () => { | ||
overrideStore.setEntries({ | ||
[flagKey]: { | ||
key: 'override-variation', | ||
value: 'override-value', | ||
}, | ||
}); | ||
|
||
client.getStringAssignment(flagKey, 'subject-10', {}, 'default'); | ||
|
||
expect(td.explain(mockLogger.logAssignment).callCount).toBe(0); | ||
}); | ||
|
||
it('includes override details in assignment details', () => { | ||
overrideStore.setEntries({ | ||
[flagKey]: { | ||
key: 'override-variation', | ||
value: 'override-value', | ||
}, | ||
}); | ||
|
||
const result = client.getStringAssignmentDetails( | ||
flagKey, | ||
'subject-10', | ||
{ foo: 3 }, | ||
'default', | ||
); | ||
|
||
expect(result).toMatchObject({ | ||
variation: 'override-value', | ||
evaluationDetails: { | ||
flagEvaluationCode: 'MATCH', | ||
flagEvaluationDescription: 'Flag override applied', | ||
}, | ||
}); | ||
}); | ||
|
||
it('does not update assignment cache when override is applied', () => { | ||
const mockAssignmentCache = td.object<AssignmentCache>(); | ||
td.when(mockAssignmentCache.has(td.matchers.anything())).thenReturn(false); | ||
td.when(mockAssignmentCache.set(td.matchers.anything())).thenReturn(); | ||
client.useCustomAssignmentCache(mockAssignmentCache); | ||
|
||
overrideStore.setEntries({ | ||
[flagKey]: { | ||
key: 'override-variation', | ||
value: 'override-value', | ||
}, | ||
}); | ||
|
||
// First call with override | ||
client.getStringAssignment(flagKey, 'subject-10', {}, 'default'); | ||
|
||
// Verify cache was not used at all | ||
expect(td.explain(mockAssignmentCache.set).callCount).toBe(0); | ||
|
||
// Remove override | ||
overrideStore.setEntries({}); | ||
|
||
// Second call without override | ||
client.getStringAssignment(flagKey, 'subject-10', {}, 'default'); | ||
|
||
// Now cache should be used | ||
expect(td.explain(mockAssignmentCache.set).callCount).toBe(1); | ||
}); | ||
|
||
it('uses normal assignment when no override exists for flag', () => { | ||
// Set override for a different flag | ||
overrideStore.setEntries({ | ||
'other-flag': { | ||
key: 'override-variation', | ||
value: 'override-value', | ||
}, | ||
}); | ||
|
||
const result = client.getStringAssignment(flagKey, 'subject-10', {}, 'default'); | ||
|
||
// Should get the normal assignment value from mockFlag | ||
expect(result).toBe(variationA.value); | ||
expect(td.explain(mockLogger.logAssignment).callCount).toBe(1); | ||
}); | ||
|
||
it('uses normal assignment when no overrides store is configured', () => { | ||
// Create client without overrides store | ||
const clientWithoutOverrides = new EppoClient({ | ||
flagConfigurationStore: storage, | ||
}); | ||
clientWithoutOverrides.setAssignmentLogger(mockLogger); | ||
|
||
const result = clientWithoutOverrides.getStringAssignment( | ||
flagKey, | ||
'subject-10', | ||
{}, | ||
'default', | ||
); | ||
|
||
// Should get the normal assignment value from mockFlag | ||
expect(result).toBe(variationA.value); | ||
expect(td.explain(mockLogger.logAssignment).callCount).toBe(1); | ||
}); | ||
|
||
it('respects override after initial assignment without override', () => { | ||
// First call without override | ||
const initialAssignment = client.getStringAssignment(flagKey, 'subject-10', {}, 'default'); | ||
expect(initialAssignment).toBe(variationA.value); | ||
expect(td.explain(mockLogger.logAssignment).callCount).toBe(1); | ||
|
||
// Set override and make second call | ||
overrideStore.setEntries({ | ||
[flagKey]: { | ||
key: 'override-variation', | ||
value: 'override-value', | ||
}, | ||
}); | ||
|
||
const overriddenAssignment = client.getStringAssignment(flagKey, 'subject-10', {}, 'default'); | ||
expect(overriddenAssignment).toBe('override-value'); | ||
// No additional logging should occur when using override | ||
expect(td.explain(mockLogger.logAssignment).callCount).toBe(1); | ||
}); | ||
|
||
it('reverts to normal assignment after removing override', () => { | ||
// Set initial override | ||
overrideStore.setEntries({ | ||
[flagKey]: { | ||
key: 'override-variation', | ||
value: 'override-value', | ||
}, | ||
}); | ||
|
||
const overriddenAssignment = client.getStringAssignment(flagKey, 'subject-10', {}, 'default'); | ||
expect(overriddenAssignment).toBe('override-value'); | ||
expect(td.explain(mockLogger.logAssignment).callCount).toBe(0); | ||
|
||
// Remove override and make second call | ||
overrideStore.setEntries({}); | ||
|
||
const normalAssignment = client.getStringAssignment(flagKey, 'subject-10', {}, 'default'); | ||
expect(normalAssignment).toBe(variationA.value); | ||
// Should log the normal assignment | ||
expect(td.explain(mockLogger.logAssignment).callCount).toBe(1); | ||
}); | ||
|
||
it('reverts to normal assignment after unsetting overrides store', () => { | ||
overrideStore.setEntries({ | ||
[flagKey]: { | ||
key: 'override-variation', | ||
value: 'override-value', | ||
}, | ||
}); | ||
|
||
client.unsetOverrideStore(); | ||
|
||
const normalAssignment = client.getStringAssignment(flagKey, 'subject-10', {}, 'default'); | ||
expect(normalAssignment).toBe(variationA.value); | ||
}); | ||
|
||
it('returns a mapping of flag key to variation key for all active overrides', () => { | ||
overrideStore.setEntries({ | ||
[flagKey]: { | ||
key: 'override-variation', | ||
value: 'override-value', | ||
}, | ||
'other-flag': { | ||
key: 'other-variation', | ||
value: 'other-value', | ||
}, | ||
}); | ||
|
||
expect(client.getOverrideVariationKeys()).toEqual({ | ||
[flagKey]: 'override-variation', | ||
'other-flag': 'other-variation', | ||
}); | ||
}); | ||
}); | ||
}); |
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.