chore: Support flag change listeners in contract tests#368
Merged
Conversation
Co-Authored-By: mkeeler@launchdarkly.com <keelerm84@gmail.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
keelerm84
reviewed
Mar 3, 2026
Co-Authored-By: mkeeler@launchdarkly.com <keelerm84@gmail.com>
…t-manager.devin.ai/proxy/github.com/launchdarkly/ruby-server-sdk into mk/sdk-1967/flag-change-listener-support
keelerm84
approved these changes
Mar 3, 2026
jsonbailey
approved these changes
Mar 4, 2026
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
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.
Requirements
Related issues
Describe the solution you've provided
Implements test service support for the new flag change listener contract tests. No changes to the SDK itself — only the contract test service (
contract-tests/) is modified.New file:
flag_change_listener.rbIntroduces a
ListenerRegistrythat manages active listener subscriptions for an SDK client entity. Two callback listener classes (FlagChangeCallbackListenerandFlagValueChangeCallbackListener) implement the#updatemethod expected by the SDK'sFlagTrackerand POSTListenerNotificationJSON payloads to the callback URI provided by the test harness.The registry handles:
FlagTracker#add_listenerFlagTracker#add_flag_value_change_listener, which handles context-specific evaluation and old/new value tracking internallyclose_allis called when the client entity shuts downCapabilities advertised:
flag-change-listenersandflag-value-change-listenersCommands handled:
registerFlagChangeListener,registerFlagValueChangeListener,unregisterListenerHuman review checklist — items worth close attention:
client_entity.rb:236): UsesLDContext.create(params[:context])on the symbolized-key hash from JSON parsing. Other commands passparams[:context]directly to SDK methods that internally callmake_context, butadd_flag_value_change_listenerexpects anLDContextso explicit creation is needed. Verify this produces a valid context from the test harness payload format.flag_change_listener.rb:93): For value change listeners, the registry stores the adapter returned byadd_flag_value_change_listener(not the inner callback listener). This is intentional — the adapter is what must be passed toremove_listenerper the SDK API.flag_change_listener.rb:75-77): The listener is stored in the map before calling@tracker.add_listener. If an unregister command races in, it might callremove_listeneron a not-yet-registered listener. This should be benign but worth noting.Devin session: https://app.devin.ai/sessions/5a3ff6991d1147f5b56df8c048b8dcc2
Requested by: @keelerm84
Note
Medium Risk
Limited to the contract test service, but introduces new listener lifecycle/concurrency and outbound callback POSTs that could cause flaky tests or resource leaks if mis-registered or not cleaned up correctly.
Overview
Adds contract-test-service support for flag change listener contract tests by introducing a
ListenerRegistrythat registers/unregisters SDKflag_trackerlisteners and posts change notifications to a harness-provided callback URI.The service now advertises
flag-change-listeners/flag-value-change-listeners, handles new commands (registerFlagChangeListener,registerFlagValueChangeListener,unregisterListener), and ensures listeners are removed on client shutdown. CI is updated to run contract testsv3.0.0-alpha.4.Written by Cursor Bugbot for commit 1b84760. This will update automatically on new commits. Configure here.