feat: add InMemoryProvider context callbacks and event emission#224
feat: add InMemoryProvider context callbacks and event emission#224josecolella merged 3 commits intomainfrom
Conversation
…vents - Support callable (Proc/lambda) flag values that receive evaluation context, enabling dynamic flag resolution (Appendix A) - Include Provider::EventEmitter in InMemoryProvider for event emission - add_flag now emits PROVIDER_CONFIGURATION_CHANGED when attached to configuration - Add update_flags method to replace entire flag set with event emission - Remove TODO comments for completed features - Update provider compatibility tests to reflect EventEmitter inclusion Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Jose Colella <jose.colella@gusto.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request enhances the InMemoryProvider by adding support for context-aware dynamic flag evaluation and event emission for flag changes, aligning it with the OpenFeature specification. The changes are well-structured and include comprehensive tests. I've identified a potential issue with state mutation in the new update_flags method and suggested a minor improvement to test robustness. Overall, great work on implementing these features.
| end | ||
|
|
||
| def update_flags(new_flags) | ||
| @flags = new_flags |
There was a problem hiding this comment.
The new_flags hash is assigned by reference, which could lead to unintended mutations of the provider's state if the original hash is modified after this call. This would happen without triggering change events, causing inconsistencies. Storing a shallow copy of the hash will prevent this.
@flags = new_flags.dup| expect(config).to have_received(:dispatch_provider_event).with( | ||
| provider, | ||
| OpenFeature::SDK::ProviderEvent::PROVIDER_CONFIGURATION_CHANGED, | ||
| flags_changed: ["flag_a", "flag_b"] |
There was a problem hiding this comment.
- update_flags now stores a shallow copy to prevent external mutation without triggering change events - Use contain_exactly for flags_changed assertion to avoid order dependency Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Jose Colella <jose.colella@gusto.com>
|
Both review comments addressed in ed2b2dc:
🤖 Jose's AI agent |
Summary
Provider::EventEmitterin InMemoryProvider for lifecycle event emissionadd_flagnow emitsPROVIDER_CONFIGURATION_CHANGEDwhen attached to configurationupdate_flagsmethod to replace entire flag set with event emissionSpec References
Part of the spec compliance roadmap: #220
Test plan
bundle exec rspec spec/open_feature/sdk/provider/in_memory_provider_spec.rb— all passbundle exec rspec spec/open_feature/sdk/provider_compatibility_spec.rb— all passbundle exec standardrb— no offenses🤖 Jose's AI agent