feat: support rule-based segments in local evaluation - #225
Merged
Conversation
Bucketeer server 2.3.0 added rule-based segments: a segment carries attribute-based rules in addition to its included-user list, and a user belongs to the segment if they are in the list OR match any rule. The rules are delivered inside the SegmentUsers message returned by the gateway's GetSegmentUsers endpoint. - Bump @bucketeer/evaluation to 0.0.9, which evaluates segment rules (AND across clauses in a rule, OR across rules) - Carry the rules from the GetSegmentUsers response through the cache processor into the segment users cache - Rebuild the Segment messages from the cached rules and pass them to the evaluator in the local evaluation path Segments without rules and servers older than 2.3.0 are unaffected. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
Adds support for Bucketeer server 2.3.0+ rule-based segments in the Node server SDK’s local evaluation path by propagating segment rules from the API response into the cache and then into the evaluator inputs (alongside the existing included-user list behavior).
Changes:
- Bump
@bucketeer/evaluationto0.0.9to obtain proto + evaluation support for segmentrules. - Extend the SegmentUsers model + cache converter to carry
rulesthrough full/diff cache updates. - Update local evaluator wiring to pass reconstructed
Segmentrule data to the evaluation engine; add unit/integration/e2e coverage for rule AND/OR semantics and backward compatibility.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
package.json |
Bumps @bucketeer/evaluation dependency to 0.0.9. |
yarn.lock |
Locks @bucketeer/evaluation@0.0.9 resolution/integrity. |
src/objects/segment.ts |
Adds optional rules to the SegmentUsers response model. |
src/cache/processor/converter.ts |
Carries SegmentUsers.rules into the cached proto via setRulesList. |
src/evaluator/local.ts |
Rebuilds Segment from cached rules and passes a segmentsMap into evaluateFeatures. |
src/__tests__/utils/feature.ts |
Adds createSegmentUsers helper to build ProtoSegmentUsers via the converter. |
src/__tests__/evaluator/evaluator.ts |
Adds unit tests for rule-based segment matching + list-only backward compatibility. |
src/__tests__/cache/segements_user.ts |
Adds cache put/get test ensuring proto rules survive round-trip. |
src/__tests__/cache/processor/segementUsersCache/rules.ts |
Adds integration test covering API parse → processor → cache → evaluator rule propagation. |
src/__tests__/cache/processor/converter.ts |
Adds converter tests validating proto rulesList output + missing-rules behavior. |
e2e/local_evaluation/evaluation_rule_based_segment.ts |
Adds e2e scenarios for multi-rule/multi-clause rule-based segments in local evaluation. |
e2e/constants/constants.ts |
Adds constants used by the new rule-based segment e2e tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove the redundant null check after getSegmentUsers, which throws when the segment is not found in the cache - Document why Segment is imported from the generated proto module and add a TODO to switch to the package root export once available Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 12 changed files in this pull request and generated no new comments.
Suppressed comments (1)
e2e/local_evaluation/evaluation_rule_based_segment.ts:67
- Grammar: this comment reads awkwardly. Consider rephrasing to “Wait for the cache to become available” so it’s clear what the await is doing.
// Waiting for the cache available
await t.context.bktClient.waitForInitialization({ timeout: 5000 });
Use the same segment rules, flags, users, and test scenarios as go-server-sdk#194, replacing only "go" with "nodejs" in the fixture names, so both SDKs can share the same test environment configuration. Co-authored-by: Cursor <cursoragent@cursor.com>
duyhungtnn
approved these changes
Aug 7, 2026
duyhungtnn
left a comment
Collaborator
There was a problem hiding this comment.
Nice works.
This PR LGTM
Merged
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.
Part of bucketeer-io/bucketeer#2722
Summary
Bucketeer server 2.3.0 introduced rule-based segments: a segment can define attribute-based rules in addition to its uploaded included-user list. A user belongs to the segment if they are in the list OR match any rule. Within a rule, clauses are AND-ed; across rules, OR. The backend delivers the rules to server SDKs inside the
SegmentUsersmessage returned by the gateway'sGetSegmentUsersendpoint.This PR makes the Node server SDK's local evaluation honor those rules. It requires
@bucketeer/evaluation0.0.9 and a Bucketeer server 2.3.0+ to take effect.Changes
package.json/yarn.lock: bump@bucketeer/evaluation0.0.8 → 0.0.9, which addsrulesto theSegmentUsersproto and evaluates segment rules.src/objects/segment.ts: add the optionalrulesfield to theSegmentUsersresponse model.src/cache/processor/converter.ts:toProtoSegmentUserscarries the rules into the cached proto, so both full-state and diff cache updates preserve them.src/evaluator/local.ts: rebuildSegmentmessages from the cached rules and pass them to the evaluator, so a flag rule with a SEGMENT clause matches users by rules as well as by user-ID list.Evaluation semantics
Backward compatibility
Tests
e2e/local_evaluation/evaluation_rule_based_segment.ts(multi-rule/multi-clause segments with varied operators, mixed list+rules segments, SEGMENT clause AND attribute clause, missing attributes, backward compat). Note: these require new fixtures in the e2e environment; the required configuration is documented at the top of the test file.E2E tests: https://github.com/bucketeer-io/node-server-sdk/actions/runs/31152495702/job/92784909315