Skip to content

refactor(audience): catalogues, identity helpers, sample-app strings, and test infrastructure (SDK-277)#726

Open
ImmutableJeffrey wants to merge 9 commits intochore/sdk-272-pr-1-sdk-runtime-constantsfrom
chore/sdk-272-pr-2-catalogues-and-test-infra
Open

refactor(audience): catalogues, identity helpers, sample-app strings, and test infrastructure (SDK-277)#726
ImmutableJeffrey wants to merge 9 commits intochore/sdk-272-pr-1-sdk-runtime-constantsfrom
chore/sdk-272-pr-2-catalogues-and-test-infra

Conversation

@ImmutableJeffrey
Copy link
Copy Markdown
Collaborator

Summary

  • Adds AudienceErrorMessages catalogue for runtime error messages.
  • Adds AudienceArgumentMessages catalogue for argument-validation messages.
  • Promotes Log.Prefix to internal and adds Log.WarnPrefix.
  • Adds IdentityTypeExtensions.ParseLowercaseString for case-insensitive wire-string parsing with Custom fallback for unknown / null / empty inputs.
  • Centralises sample-app UXML element names, CSS class names, and message strings into SampleAppUi.
  • Introduces TestDefaults.PublishableKey for the test publishable-key default.
  • Introduces WireFixture and migrates mock-store JSON fixtures so test envelopes are built from MessageFields and MessageTypes.
  • Replaces hard-coded test wire strings with values derived from IdentityType.ToLowercaseString() / ConsentLevel.ToLowercaseString().
  • Consolidates twelve timing and retry constants into Constants.cs with module-prefixed names: MessagesRequestTimeoutSeconds, HttpBackoff{1st,2nd,3rd,4th,Cap}Ms, SessionHeartbeatIntervalMs, SessionPauseTimeoutMs, SessionHeartbeatDrainTimeoutMs, SessionStartDrainTimeoutMs, ConsentSyncMaxAttempts, ConsentSyncBaseRetryMs. Migrates runtime call sites in HttpTransport, Session, ImmutableAudience, plus SessionTests.
  • No behaviour change. Wire format and OnError callback contract unchanged.

Linear: SDK-277

@ImmutableJeffrey ImmutableJeffrey requested review from a team as code owners May 3, 2026 07:17
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-1-sdk-runtime-constants branch from fba80b5 to 34d4050 Compare May 3, 2026 07:40
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-2-catalogues-and-test-infra branch 2 times, most recently from 9c7496b to 91f1783 Compare May 3, 2026 07:53
Names the message strings routed through AudienceConfig.OnError so a wording tweak touches one file
and runtime emit / test assert read from the same constants.

- Log.cs: adds AudienceErrorMessages with the LocalStorageReadFailed / BatchPartiallyRejected
  formatters and the BatchRejectedPrefix / ServerErrorWillRetryPrefix / ConsentSyncFailedWithStatus
  / ConsentSyncThrew entries.
- HttpTransport.cs: flush onError messages route through AudienceErrorMessages.
- ImmutableAudience.cs: consent-sync onError messages route through AudienceErrorMessages.
Names the ArgumentException strings thrown from public SDK surfaces so user-code that reads .Message
stays in sync if a wording is tweaked in one site but not another.

- Log.cs: adds AudienceArgumentMessages with the Init / config validation entries
  (PublishableKeyRequired, PersistentDataPathRequired) and the typed-event ToProperties entries
  (ProgressionStatusRequired, ResourceFlow / Currency / AmountRequired, PurchaseValue /
  CurrencyInvalid, MilestoneReachedNameRequired).
- TypedEvents.cs: Progression / Resource / Purchase / MilestoneReached ArgumentException messages
  route through AudienceArgumentMessages.
- ImmutableAudience.cs: Init validation ArgumentException messages route through
  AudienceArgumentMessages.
…rnPrefix

Hoists the SDK stamp into named constants so the sample-app log adapter can strip it back off
without hardcoding the same string.

- Log.cs: promotes Prefix from private to internal and adds WarnPrefix following the "{Prefix}
  WARN:" shape Log.Warn emits.
- Log.cs: Warn now reads its prefix from WarnPrefix instead of inlining the format.
…seString

Adds the inverse of ToLowercaseString so callers reading user-supplied or wire-format identity
strings can round-trip back into the enum without hand-rolling another switch.

- IdentityType.cs: adds IdentityTypeExtensions.ParseLowercaseString, the case-insensitive inverse of
  ToLowercaseString. Falls back to Custom for unknown / empty values; never throws.
- AudienceSample.cs: ParseIdentityType reverse mapper delegates to
  IdentityTypeExtensions.ParseLowercaseString instead of hand-rolling its own switch.
…to SampleAppUi

Moves the SampleAppUi catalogue from Tests/Runtime to Scripts so non-test code can reference it, and
expands it to cover every UXML element name, CSS class, button caption, resource path, and side
string the sample manipulates.

- Moves SampleAppUi.cs from Tests/Runtime to Scripts so AudienceSample.cs / .UI.cs / .Events.cs can
  reference it.
- SampleAppUi gains AliasFromType / AliasToType identity-field names.
- SampleAppUi.Layout names the layout-internal elements (sdk-version, tab-bar, typed-events-host,
  log-resize-handle, page-scroll, controls-column, log-column, sample-app-grid, log-count,
  accordion-{item, title, content}).
- SampleAppUi.Css names every CSS class the sample manipulates (state-*, accordion-*, log-*,
  badge-*, status-value, field-*, etc.).
- SampleAppUi.ButtonText (Send / Copy / Copied) names dynamically-built button captions.
- SampleAppUi.Resources names the four Resources.Load asset paths.
- SampleAppUi.Messages holds six human-readable side strings used in consent / identity flows.
- SampleAppUi.LogLabels gains Ready / Sdk / OnError / Init / Shutdown / Reset / Flush / DeleteData /
  Page / Track / SetConsent.
- SampleAppUi.LogBadgeText names the two-letter SDK / APP pill text.
- SampleAppUi.StatusBar.EmptyText replaces six hardcoded em-dash placeholder glyphs.
- AudienceSample.cs / .UI.cs / .Events.cs read UXML element names, CSS classes, dynamic button
  captions, resource paths, and log labels from SampleAppUi.
- SampleAppLiveFireTests.cs reads UXML element names, log labels, and the env-var key from
  SampleAppUi.
Names the sandbox-shaped publishable-key fixture so the same string doesn't have to live in 28
separate test files.

- TestDefaults.cs: new internal helper with PublishableKey ("pk_imapik-test-key1") plus the
  FlushIntervalSeconds and FlushSize defaults shared across the test fixture.
- HttpTransportTests, ImmutableAudienceTests, ConsentSyncTests, DeleteDataTests, SessionTests: 28
  inline copies of the publishable-key string read from TestDefaults.PublishableKey.
…ures

Names a small builder for wire-format envelope JSON so tests stop hand-rolling escape-laden strings,
and a rename on MessageFields lights up runtime emit and test fixtures together.

- WireFixture.cs: new internal helper with Track / Identify / Alias overloads that build envelopes
  from MessageFields and MessageTypes constants.
- DiskStoreTests.cs, GzipTests.cs, HttpTransportTests.cs, EventQueueTests.cs: hand-rolled
  "{type:track,...}" mock-store fixtures read from WireFixture; envelope key access uses
  MessageFields.
…rcaseString

Final test sweep: tests asserting on enum-derived wire strings stop hardcoding the lowercase forms
and read them from the matching ToLowercaseString extension instead, so a wire-rename on an enum
member touches one place.

- MessageBuilderTests, ImmutableAudienceTests, JsonReaderTests, JsonTests, TypedEventTests,
  ConsentSyncTests, SessionTests, OfflineResilienceTests: ConsentLevel / IdentityType /
  ProgressionStatus / ResourceFlow assertions read via ToLowercaseString.
- SessionTests pause-rollover thresholds derive from Session.PauseTimeoutMs.
- DeleteDataTests query-string asserts use the constants introduced in earlier slices.
…ts.cs

The previous SSOT pass left twelve timing / retry constants co-located
with their owning module: HttpTransport.RequestTimeoutSeconds and
five Backoff*Ms constants, Session.HeartbeatIntervalMs / PauseTimeoutMs
/ HeartbeatDrainTimeoutMs / StartDrainTimeoutMs, and ImmutableAudience.
ConsentSyncMaxAttempts / ConsentSyncBaseRetryMs. Constants.cs already
held analogous timing / sizing knobs (DefaultFlushIntervalSeconds,
MaxBatchSize, ControlPlaneRequestTimeoutSeconds), so the split was
inconsistent.

Move all twelve into Constants.cs with module-prefixed names
(MessagesRequestTimeoutSeconds, HttpBackoff{1st,2nd,3rd,4th,Cap}Ms,
SessionHeartbeatIntervalMs, SessionPauseTimeoutMs,
SessionHeartbeatDrainTimeoutMs, SessionStartDrainTimeoutMs,
ConsentSyncMaxAttempts, ConsentSyncBaseRetryMs). Migrate runtime call
sites in HttpTransport, Session, and ImmutableAudience plus the one
test reference in SessionTests. Behaviour unchanged.

Follow-up to SDK-272 (centralisation of duplicated literals).
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-1-sdk-runtime-constants branch from 34d4050 to 994279f Compare May 3, 2026 07:58
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-2-catalogues-and-test-infra branch from 91f1783 to 427f963 Compare May 3, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant