Skip to content

fix: implement identity overrides merging logic#268

Open
xolott-ark wants to merge 1 commit intoFlagsmith:mainfrom
xolott-ark:fix/merge-duplicate-identity-overrides
Open

fix: implement identity overrides merging logic#268
xolott-ark wants to merge 1 commit intoFlagsmith:mainfrom
xolott-ark:fix/merge-duplicate-identity-overrides

Conversation

@xolott-ark
Copy link
Copy Markdown

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #267

When an environment document contained multiple identity override entries for the same identifier, the SDK only kept the last one because it built identitiesWithOverridesByIdentifier with new Map(...entries). Later entries overwrote earlier ones, so feature overrides set on previous entries silently disappeared during local evaluation.

This PR replaces that map construction with a parseIdentityOverrides helper that:

  • Iterates over environment.identityOverrides and groups entries by identifier.
  • For the first entry of an identifier, clones the IdentityModel (preserving its prototype) and wraps identityFeatures in an IdentityFeaturesList so subsequent pushes go through the engine's collection.
  • For each additional entry sharing the same identifier, merges its identityFeatures into the existing clone instead of replacing it.

The original IdentityModel instances on environment.identityOverrides are left untouched, so engine code that re-reads the environment still sees the raw API payload.

How did you test this code?

  • Added tests/engine/unit/mappers.test.ts coverage that asserts each unique feature-set hash produces its own identity override segment, including two entries for multi-override-id.
  • Added tests/sdk/flagsmith.test.ts › test_localEvaluation_true__multiple_identity_overrides_for_same_identifier_merged, which calls getIdentityFlags('multi-override-id') against a local-evaluation client and verifies both some_feature (from the first entry) and mv_feature (from the second entry) resolve to their overridden values and enabled states.
  • Extended tests/sdk/data/environment.json with two multi-override-id entries covering different features so the new tests exercise the merge path.
  • Ran npm test locally; all suites pass.

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.

[sdk/local-evaluation] Duplicate identity override entries silently drop feature overrides

1 participant