Bug 2040784 - Introduce AIFeatureState to handle the "Unknown" states of AI controls - #273
Closed
segunfamisa wants to merge 1 commit into
Closed
Bug 2040784 - Introduce AIFeatureState to handle the "Unknown" states of AI controls#273segunfamisa wants to merge 1 commit into
segunfamisa wants to merge 1 commit into
Conversation
… of AI controls This fixes the issue in bug 2040784 by ensuring that we have an unknown state where we don't know yet if the feature is enabled or not. This becomes important when we need to know if the user turned a feature on explicitly, or it was on by default, or they just never never interacted with the feature.
Contributor
Author
Contributor
|
View this pull request in Lando to land it once approved. |
MatthewTighe
approved these changes
May 29, 2026
MatthewTighe
left a comment
Contributor
There was a problem hiding this comment.
few small things, but this otherwise LGTM. thanks for taking this one
Comment on lines
+21
to
+24
| context: Context, | ||
| ): AIFeatureRegistry = | ||
| DefaultAIFeatureRegistry(scope, AIFeatureBlockStorage.dataStore(context)) | ||
|
|
Contributor
There was a problem hiding this comment.
Can we swap the context dependency for an AIFeatureBlockStorage dependency?
Contributor
There was a problem hiding this comment.
Ah, I see why this was chosen now - we didn't want to expose the internal type. Carry on
| assertFalse(block.isBlocked.first()) | ||
| } | ||
|
|
||
| private class FakeAIFeatureRegistry : AIFeatureRegistry { |
Contributor
There was a problem hiding this comment.
I think we could just reuse AIFeatureRegistry.inMemory for this
Comment on lines
+97
to
+106
| private class TestAIFeatureBlockStorage(initialBlocked: Boolean) : AIFeatureBlockStorage { | ||
| val blockedFlow = MutableStateFlow(initialBlocked) | ||
| override val isBlocked: Flow<Boolean> = blockedFlow | ||
|
|
||
| override suspend fun setBlocked(isBlocked: Boolean) { | ||
| blockedFlow.value = isBlocked | ||
| } | ||
| } | ||
|
|
||
| private class TestAIControllableFeature( |
Contributor
There was a problem hiding this comment.
These could also use the .inMemory factories I believe
Comment on lines
+41
to
+47
| scope.launch { | ||
| if (feature.featureState.first() is AIFeatureState.Unknown) { | ||
| val aiFeaturesBlocked = storage.isBlocked.first() | ||
| feature.set(!aiFeaturesBlocked) | ||
| } | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
We should move to the IO dispatcher here since we are using the MainScope
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This fixes the issue in bug 2040784 by ensuring that we have an unknown state where we don't know yet if the feature is enabled or not. This becomes important when we need to know if the user turned a feature on explicitly, or it was on by default, or they just never never interacted with the feature.