[AI-FSSDK] [FSSDK-12813] Relax campaign_id/entity_id validation to non-empty string per updated spec#645
Closed
jaeopt wants to merge 1 commit into
Closed
[AI-FSSDK] [FSSDK-12813] Relax campaign_id/entity_id validation to non-empty string per updated spec#645jaeopt wants to merge 1 commit into
jaeopt wants to merge 1 commit into
Conversation
…ing per updated spec The updated spec (2026-06-24) relaxes the validation contract for `decisions[].campaign_id` and `events[].entity_id`: any non-empty string is now valid, including opaque IDs like "layer_abc" or "default-12345". The fallback to `experiment_id` now fires only when the source value is the empty string (previously fired on any non-numeric input). `decisions[].variation_id` is unchanged: it keeps the stricter numeric-string-only contract and still falls back to nil (JSON null) for empty / whitespace / non-numeric values. Changes: - BatchEventBuilder.normalizeDecisionIds now uses isNonEmptyString (new helper) for the campaign_id branch. - isValidNumericIdString is retained and still gates variation_id. - Tests flipped: whitespace and non-numeric campaign_id now assert passthrough (was: fallback). Added explicit opaque-ID passthrough test as proof of the relaxation. Added isNonEmptyString unit tests. variation_id tests unchanged.
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
Follow-up to the merged #642 (released as 5.4.1), which normalized
decisions[].campaign_id,decisions[].variation_id, andevents[].entity_idon outgoing decision impression events.The FSSDK-12813 spec was updated on 2026-06-24 to relax the validation contract for
campaign_idandentity_idonly. This PR brings the Swift SDK in line with the relaxed contract.What the spec relaxed
decisions[].campaign_idandevents[].entity_idMUST be non-empty strings. IDs may be opaque (e.g."layer_abc","default-12345") — any non-empty string is valid regardless of character content.experiment_idnow fires only when the source value is the empty string""(or nil / missing). Previously it fired on any non-numeric input.What is unchanged
decisions[].variation_idkeeps the stricter numeric-string-only contract per spec FR-003. Empty, whitespace, or non-numericvariation_idvalues still normalize tonil(JSONnull).Sources/Data Model/DispatchEvents/BatchEvent.swift—Decision.variationID: String?and its explicit-nullencoder from [AI-FSSDK] [FSSDK-12813] normalize campaign_id, variation_id, and entity_id on decision events #642 remain correct.Changes
Sources/Implementation/Events/BatchEventBuilder.swiftnormalizeDecisionIds(...)now gatescampaign_idwith a newisNonEmptyString(_:)helper instead ofisValidNumericIdString(_:). Thevariation_idbranch is untouched.isNonEmptyString(_:) -> Bool(returns!value.isEmpty).isValidNumericIdString(_:)— still used by thevariation_idbranch per spec FR-003.Tests/OptimizelyTests-Common/BatchEventBuilderTests_HoldoutIds.swifttestNormalize_whitespaceCampaignFallsBackToExperimentId→testNormalize_whitespaceCampaignPassesThrough(whitespace is non-empty, so it passes through unchanged).testNormalize_nonNumericCampaignFallsBackToExperimentId→testNormalize_nonNumericCampaignPassesThrough(non-numeric is non-empty, so it passes through unchanged).testNormalize_opaqueCampaignPassesThrough_FSSDK12813_relaxation— direct proof that an opaque ID"layer_abc"passes throughcampaign_idunchanged with no fallback toexperiment_id.testIsNonEmptyString_acceptsAnyNonEmptyContentandtestIsNonEmptyString_rejectsEmptyOnly— unit coverage for the new helper.variation_idtests unchanged.isValidNumericIdStringtests unchanged (still used byvariation_id).Verification
xcodebuild -workspace OptimizelySwiftSDK.xcworkspace -scheme OptimizelySwiftSDK-iOS -destination 'platform=iOS Simulator,name=iPhone 17' test— not executed in this run; CoreSimulator was unavailable in the sandboxed environment. Local reviewers should run the command above. The change is mechanical: one validator swap on one branch ofnormalizeDecisionIds, plus tests flipped/added in lockstep.BatchEventBuilderTests_Events,BatchEventBuilderTests_Attributes,BatchEventBuilderTests_EventTags,BatchEventBuilderTests_Region,DecisionServiceTests_Holdouts) all used non-empty placeholders forcampaign_idand so are unaffected by this relaxation (FR-011 audit).Jira Ticket
FSSDK-12813
Related