Skip to content

Ruby: Add OpenFeature provider#132

Open
msiebert wants to merge 11 commits intomasterfrom
msiebert-openfeature-provider
Open

Ruby: Add OpenFeature provider#132
msiebert wants to merge 11 commits intomasterfrom
msiebert-openfeature-provider

Conversation

@msiebert
Copy link
Copy Markdown

Summary

  • Adds an OpenFeature-compatible provider as a separate gem (mixpanel-openfeature) in the openfeature-provider/ directory
  • Wraps either LocalFlagsProvider or RemoteFlagsProvider via a single Mixpanel::OpenFeature::Provider class
  • Implements the OpenFeature Ruby SDK duck-type interface: fetch_boolean_value, fetch_string_value, fetch_number_value, fetch_integer_value, fetch_float_value, fetch_object_value

Design decisions

  • Identity check for flag-not-found detection: passes a fallback SelectedVariant to get_variant and uses equal? (object identity) to detect when the flag was not found
  • Reason codes: STATIC for successful evaluations, ERROR for all failure cases
  • Error codes: PROVIDER_NOT_READY, FLAG_NOT_FOUND, TYPE_MISMATCH
  • Variant key passthrough: successful resolutions include variant: result.variant_key in ResolutionDetails
  • Context forwarding: evaluation_context is converted and forwarded to get_variant
  • Provider readiness: uses respond_to?(:are_flags_ready) so remote providers are treated as always ready
  • Type coercion: float-to-int when no fractional part, int-to-float promotion
  • shutdown is a no-op: Mixpanel SDK manages its own lifecycle
  • targetingKey has no special meaning: included in context as a regular property

Test coverage

37 RSpec tests covering all 6 flag types, type coercion, all 3 error codes, variant key passthrough, context forwarding, remote provider readiness, lifecycle, and metadata.

Test plan

  • bundle exec rspec spec/ — 37 examples, 0 failures

Generated with Claude Code

Implement an OpenFeature-compatible provider as a separate gem
(mixpanel-openfeature) that wraps the existing Mixpanel flags providers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@msiebert msiebert self-assigned this Mar 19, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 94.89796% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.09%. Comparing base (a3020d2) to head (c952e30).

Files with missing lines Patch % Lines
...ture-provider/lib/mixpanel/openfeature/provider.rb 95.94% 3 Missing ⚠️
lib/mixpanel-ruby/flags/flags_provider.rb 83.33% 1 Missing ⚠️
lib/mixpanel-ruby/flags/local_flags_provider.rb 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #132      +/-   ##
==========================================
- Coverage   96.29%   96.09%   -0.20%     
==========================================
  Files          12       14       +2     
  Lines         567      641      +74     
==========================================
+ Hits          546      616      +70     
- Misses         21       25       +4     
Flag Coverage Δ
openfeature 96.00% <96.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

msiebert and others added 3 commits March 20, 2026 11:05
Adds begin/rescue for SDK exceptions in provider, plus tests for
exception handling and null variant key behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use camelCase 'targetingKey' instead of snake_case 'targeting_key' to
match the key name Java and Go SDKs receive from their OpenFeature
SDKs' built-in flattening.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- shutdown now delegates to underlying flags provider
- Add shutdown to FlagsProvider (no-op) and LocalFlagsProvider (stops polling)
- Explicitly pass report_exposure: true to get_variant
- Add context value unwrapping with whole-number float→int conversion

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@msiebert msiebert changed the title Add OpenFeature provider Ruby: Add OpenFeature provider Mar 31, 2026
msiebert and others added 4 commits April 1, 2026 12:49
Fix bug where ServerError was incorrectly caught and re-raised as
ConnectionError in call_flags_endpoint. Use dig for nested hash
access, each_with_object for hash construction, map(&:dup), and
simplified conditionals throughout. Simplify boolean type check
and make number case consistent in provider.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add nil guard for typed resolutions to return TYPE_MISMATCH instead of
passing nil through. Update mock signatures to capture report_exposure
keyword arg. Add exposure reporting verification test. Strengthen
shutdown test to verify delegation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Required by repo policy — all actions must use full-length commit SHAs
instead of version tags.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Aligns with the convention used by other SDKs (e.g. mixpanel-java-openfeature-provider)
where the language name is included in the package name.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@msiebert msiebert requested a review from efahk April 2, 2026 22:25
@msiebert msiebert marked this pull request as ready for review April 2, 2026 22:25
@msiebert msiebert requested review from a team and jaredmixpanel April 2, 2026 22:25
msiebert and others added 3 commits April 2, 2026 15:34
Runs the openfeature-provider test suite as a separate job across all
Ruby versions to ensure the provider is tested in CI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
openfeature-sdk 0.5.1 requires Ruby >= 3.1, so Ruby 3.0 is no longer
compatible. Update the gemspec and remove 3.0 from the CI matrix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add SimpleCov with Cobertura output to the openfeature-provider test
suite and upload coverage from the test-openfeature CI job. This lets
Codecov merge coverage from both test suites, fixing the patch/project
coverage check failures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant