[AI-FSSDK] [FSSDK-12813] Normalize decision event campaign_id, variation_id, and entity_id#1158
Open
jaeopt wants to merge 2 commits into
Open
[AI-FSSDK] [FSSDK-12813] Normalize decision event campaign_id, variation_id, and entity_id#1158jaeopt wants to merge 2 commits into
jaeopt wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the event-builder layer to normalize decision-event identifier fields consistently across all impression decision types (experiment, feature-test, rollout, holdout), ensuring wire payloads use numeric-string IDs when valid, and deterministic fallbacks when invalid.
Changes:
- Added numeric-string validation plus normalization helpers for
decisions[].campaign_id/impressionevents[].entity_id(fallback toexperiment_idornull) anddecisions[].variation_id(fallback tonull). - Updated impression snapshot construction so
events[].entity_idis byte-identical todecisions[].campaign_id. - Updated/expanded tests to reflect the new normalization contract and adjusted fixtures to use numeric-string IDs for happy-path expectations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/optimizely/index.tests.js | Updates expected decision snapshot output so invalid/empty variation_id is asserted as null (normalized) rather than an empty string. |
| lib/event_processor/event_builder/log_event.ts | Implements normalization helpers and applies them in makeDecisionSnapshot, including ensuring entity_id matches normalized campaign_id. |
| lib/event_processor/event_builder/log_event.spec.ts | Updates existing fixtures to numeric-string IDs and adds comprehensive normalization contract tests across decision types and edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ing per updated spec
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
Normalize three decision-event ID fields uniformly across every decision type (experiment, feature test, rollout, holdout) in the event-builder layer.
decisions[].campaign_idand impressionevents[].entity_idaccept any non-empty string (IDs may be opaque, e.g."default-12345","layer_abc") and fall back toexperiment_idonly when empty, null, or missing;decisions[].variation_idretains the stricter numeric-string-only contract and falls back tonullfor any invalid input. The normalization path is silent and never drops or defers event dispatch.Changes
isNonEmptyString(used forcampaign_id/entity_id) andisNumericString(used forvariation_id) validators, plusnormalizeCampaignIdandnormalizeVariationIdhelpers in the event builder, applied uniformly inmakeDecisionSnapshotwith no per-type branching.normalizeCampaignIdreturns the provided id unchanged when it is a non-empty string of any character content; otherwise substitutesexperimentIdwhen that itself is a non-empty string; otherwise returnsnull.normalizeVariationIdreturns the provided id unchanged only when it is a non-empty decimal-digit string; otherwise returnsnull.entity_idreuses the normalizedcampaign_idvalue so the two fields are byte-identical on the wire.campaign_id/entity_idnow passes through unchanged; non-numericvariation_idstill normalizes tonull).Jira Ticket
FSSDK-12813