feat: add registerPlugin so a plugin can be added after the client starts - #393
Open
abelonogov-ld wants to merge 2 commits into
Open
feat: add registerPlugin so a plugin can be added after the client starts#393abelonogov-ld wants to merge 2 commits into
abelonogov-ld wants to merge 2 commits into
Conversation
…arts Plugins could only be supplied through LDConfig, so an integration that learns about a plugin later — or that wants to instrument a client it did not configure — had no way in. Hooks go live only once register succeeds, matching the .NET ordering, so a plugin whose registration failed never contributes hooks and a plugin's own hooks do not observe its register call. Retaining EnvironmentMetadata on the instance lets a plugin registered later be handed the same environment description as one configured up front. Co-authored-by: Cursor <cursoragent@cursor.com>
6 tasks
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.
Summary
Plugins could only be supplied through
LDConfig, so an integration that learns about a plugin later — or that wants to instrument a client it did not configure — had no way in. This addsLDClient.registerPlugin(Plugin), mirroring the method the .NET and Flutter SDKs already expose.registersucceeds. This follows the .NET ordering, and it differs from configuration-time registration, where a plugin's hooks are active beforeregisteris called. The consequence is that a plugin whose registration failed never contributes hooks, and a plugin's own hooks do not observe the evaluations or identify calls itsregistermakes.EnvironmentMetadatais now retained on the instance rather than living in a local map duringinit, so a plugin registered later is handed the same environment description as one configured up front. Theinitloop switches from aMap<LDClient, EnvironmentMetadata>to aList<LDClient>accordingly.getHooksleaves the plugin unregistered; a throwingregisteryields a failure result passed toonPluginsReady. Neither propagates to the caller. Reading the plugin's name for the log message tolerates metadata that itself throws, so reporting one failure cannot raise another out of the handler reporting it.Registration applies to the one client it is called on, so a multi-environment setup means calling it per environment.
Test plan
Eight cases added to
LDClientPluginsTest, all passing on an API 36 emulator alongside the three pre-existing plugin tests (11 total):registerPluginPassesClientAndEnvironmentMetadataregisterPluginActivatesBundledHooksregisterPluginDoesNotRunTheRegisteringPluginsOwnHooksregisterPluginReportsSuccessToOnPluginsReadyregisterPluginDoesNotRegisterPluginWhoseGetHooksThrowsregisterPluginToleratesRegisterThrowingregisterPluginRejectsNullPluginregisterPluginAppliesOnlyToTheClientItIsCalledOntestDebugUnitTestgreenNote
Overview
Adds
LDClient.registerPluginso a plugin can be attached after init, not only viaLDConfig. Registration is per client (one environment).Hooks are installed only after
registersucceeds, so they never observe the plugin’s ownregisterwork and a failed plugin contributes none.getHooks/register/onPluginsReadyexceptions are logged, not thrown.EnvironmentMetadatais kept on the instance so late registration gets the same metadata as config-time plugins.Reviewed by Cursor Bugbot for commit f556929. Bugbot is set up for automated code reviews on this repo. Configure here.