Skip to content

refactor(audience): sample-app reflection helpers and fixture extensions (SDK-277)#730

Open
ImmutableJeffrey wants to merge 9 commits intochore/sdk-272-pr-5-wire-format-pinningfrom
chore/sdk-272-pr-6-cleanup-and-reflection
Open

refactor(audience): sample-app reflection helpers and fixture extensions (SDK-277)#730
ImmutableJeffrey wants to merge 9 commits intochore/sdk-272-pr-5-wire-format-pinningfrom
chore/sdk-272-pr-6-cleanup-and-reflection

Conversation

@ImmutableJeffrey
Copy link
Copy Markdown
Collaborator

@ImmutableJeffrey ImmutableJeffrey commented May 3, 2026

Summary

  • Centralises sample-app reflection field names (LogEntry struct fields, UI Toolkit Clickable.clicked) in SampleAppTestHelpers; centralises the per-test panel-user prefix in SampleAppLiveFireTests.
  • Names the EventQueue background drain thread via a private const so the thread surfaces with a stable name in profilers, debuggers, and crash dumps.
  • Routes inline FlushIntervalSeconds and FlushSize test values through TestDefaults.
  • Centralises Progression and Resource numeric scenario fixtures in TestFixtures.
  • Centralises Purchase numeric fixtures and minimal one-character identifier placeholders in TestFixtures.
  • Cleans up missed Progression.Level and Gzip placeholder references.
  • Centralises the SessionTests fixed virtual-now fixture used as the starting point for every Session lifecycle test.
  • Centralises DiskStoreTests file body fixtures (stale, surviving, malformed).
  • Adds the missing .meta files Unity flags on first project open: README.md.meta, Tests/Editor.meta, DeviceCollectorTests.cs.meta, MessagesTests.cs.meta, WireFixture.cs.meta.
  • 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:18
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-5-wire-format-pinning branch from d5c1917 to 33aa3e6 Compare May 3, 2026 07:40
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-6-cleanup-and-reflection branch from e15f721 to 6a33ab0 Compare May 3, 2026 07:40
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-5-wire-format-pinning branch from 33aa3e6 to 01cc27c Compare May 3, 2026 07:43
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-6-cleanup-and-reflection branch from 6a33ab0 to 01c3993 Compare May 3, 2026 07:43
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-5-wire-format-pinning branch from 01cc27c to e513ad1 Compare May 3, 2026 07:54
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-6-cleanup-and-reflection branch from 01c3993 to fe8c352 Compare May 3, 2026 07:54
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-5-wire-format-pinning branch from e513ad1 to 1eb56dd Compare May 3, 2026 07:58
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-6-cleanup-and-reflection branch from fe8c352 to de9112d Compare May 3, 2026 07:59
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-5-wire-format-pinning branch from 1eb56dd to 1a3834e Compare May 3, 2026 12:39
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-6-cleanup-and-reflection branch from de9112d to 52ffbdd Compare May 3, 2026 12:39
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-5-wire-format-pinning branch from 1a3834e to 3bf92fe Compare May 3, 2026 14:14
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-6-cleanup-and-reflection branch from 52ffbdd to 20ee16c Compare May 3, 2026 14:14
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-5-wire-format-pinning branch from 3bf92fe to b05092a Compare May 3, 2026 19:06
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-6-cleanup-and-reflection branch from 20ee16c to 9404562 Compare May 3, 2026 19:07
… panel-user prefix

SampleAppTestHelpers reflects on AudienceSample.UI.cs's internal
LogEntry struct (Label / Body / Level) and on UI Toolkit's internal
Clickable.clicked field. The reflection design is deliberate: the
sample-app assembly does not grant InternalsVisibleTo to the test
assembly, so direct access (and nameof()) cannot reach LogEntry or
Clickable.clicked. Without consts, a struct-shape change has to
update three GetField call sites and the click extension separately.

Adds file-local consts (LogEntryLabelField / BodyField / LevelField)
inside SampleAppTestHelpers and an internal ClickableClickedField
const used by the ButtonTestExtensions reflection. Migrates four
GetField call sites.

SampleAppLiveFireTests also reflects on the internal
ImmutableAudience.ResetState method name and builds a unique userId
per test run from a "panel-user-" prefix concatenated with
DateTime.UtcNow.Ticks. Adds ResetStateMethodName and PanelUserPrefix
consts inside the fixture and migrates both sites.

Per the user's "everything random goes in a constant" stance.

Follow-up to SDK-272 (centralisation of duplicated literals).
…e const

EventQueue created its background drain thread with an inline
"imtbl-audience-drain" Name. The string surfaces in profilers,
debuggers, and crash dumps so on-call can identify SDK-owned
threads. Pinning it as a const keeps the name visible at the top
of the class and gives a rename one place to update.

Adds DrainThreadName private const to EventQueue and migrates the
single usage.

Per the user's "everything random goes in a constant" stance.

Follow-up to SDK-272 (centralisation of duplicated literals).
…and FlushSize

Four test files (DeleteDataTests, SessionTests, ConsentSyncTests,
ImmutableAudienceTests) had inline `FlushIntervalSeconds = 600` and
`FlushSize = 1000` in their MakeConfig fixture even though
TestDefaults already centralises both values for exactly this
purpose. The numbers had silently drifted into a duplicated
fixture across the four files.

Migrates eight inline references to TestDefaults.FlushIntervalSeconds
and TestDefaults.FlushSize.

Per the user's "everything random goes in a constant" stance.

Follow-up to SDK-272 (centralisation of duplicated literals).
…o fixtures

TypedEventTests' Progression_Complete fixture had four inline scenario
values ("1" Level, 1500 Score, 120.5f DurationSec) that paired across
input and assertion. The Score = 1500 was also reused by
JsonReaderTests' RoundTripViaSerializer with the same paired
shape. Resource.Amount = 100 / 100m similarly appeared three times
across TypedEventTests' Source / WithoutFlow / WithoutAmount tests
plus one cross-type assertion.

Adds to TestFixtures:
- ProgressionLevelFixture ("1")
- ProgressionScoreFixture (1500)
- ProgressionDurationSecFixture (120.5f)
- ResourceAmountFixture (100f)

Migrates eight references in TypedEventTests and two in
JsonReaderTests. The Resource.Amount cross-type assertion that read
"100m" (decimal) is now "TestFixtures.ResourceAmountFixture" (float);
NUnit's numeric AreEqual handles the cross-type comparison, and the
test now fails consistently if the fixture changes on either side.

Per the user's "everything random goes in a constant" stance.

Follow-up to SDK-272 (centralisation of duplicated literals).
…identifier placeholders

Two related rounds of inline fixtures rolled together:

Purchase numeric fixtures:
- 9.99m Value used four times across TypedEventTests' main Purchase
  fixture, the WithoutValue guard, the WithoutCurrency guard, and
  ImmutableAudienceTests' discardable-Purchase test
- 5.00m Value for TypedEventTests' optional-fields-omitted Purchase
- Quantity = 1 for the main Purchase fixture
Adds PurchaseValueFixture, PurchaseValueLowFixture,
PurchaseQuantityFixture to TestFixtures.

Minimal identifier placeholders:
- "a" / "u" appeared in DiskStoreTests as anonymousId / userId /
  fromId / toId placeholders (eight uses), and "a" was also a
  hand-rolled JSON value in the same file.
- "x" / "y" appeared as event-name placeholders in DiskStoreTests'
  ApplyAnonymousDowngrade fixture.
- "a" appeared as an event-name in EventQueueTests' message-builder
  test.
Adds MinimalIdentifierA / MinimalIdentifierU to TestFixtures and
PlaceholderX / PlaceholderY to TestEventNames. Migrates eleven
references across the three files.

The minimal-identifier consts are deliberately role-neutral
(MinimalIdentifierA / U rather than MinimalAnonymousId /
MinimalUserId) since the same one-char placeholder is reused across
anonymousId / fromId / userId / toId slots; binding the name to one
role would mislead at the other call sites.

Per the user's "everything random goes in a constant" stance.

Follow-up to SDK-272 (centralisation of duplicated literals).
…older references

Two inline references survived earlier sweeps:
- GzipTests:15 had `WireFixture.Track((MessageFields.EventName, "test"))`;
  the test exercises the gzip round trip and the event name is filler.
  Migrated to TestEventNames.PlaceholderTest, matching the
  HttpTransportTests pattern.
- ImmutableAudienceTests:585 had `Level = "1"` in a Progression Track
  fixture. Migrated to TestFixtures.ProgressionLevelFixture, paired
  with the existing TypedEventTests usage.

Per the user's "everything random goes in a constant" stance.

Follow-up to SDK-272 (centralisation of duplicated literals).
SessionTests had `new DateTime(2026, 4, 20, 12, 0, 0, DateTimeKind.Utc)`
inline eleven times, one per session lifecycle test that pins
behaviour to wall-clock time. The repetition meant a debugging
session that needed to sweep all clocks forward / back had to find
and update every call site individually.

Adds a static readonly FixedNowUtc field at the top of the fixture
(DateTime is not const-eligible) and migrates the eleven references.
A future bug investigation that needs to nudge the virtual now now
edits one line.

Per the user's "everything random goes in a constant" stance.

Follow-up to SDK-272 (centralisation of duplicated literals).
DiskStoreTests had three inline file body fixtures used as
File.WriteAllText payloads:
- "{\"stale\":true}" — older-than-purge-window file in the
  ApplyAnonymousDowngrade fixture
- "{\"survived\":true}" — non-stale file the same fixture must keep
- "{not valid json" — malformed file that exercises the
  malformed-input branch

Adds StaleFileBody / SurvivingFileBody / MalformedFileBody file-local
consts at the top of the fixture (matching the existing test-fixture
const block convention) and migrates the three call sites.

Per the user's "everything random goes in a constant" stance.

Follow-up to SDK-272 (centralisation of duplicated literals).
Adds the .meta files Unity flags on first project open so the test assets register
correctly: README.md, Tests/Editor and DeviceCollectorTests, MessagesTests, WireFixture,
and SampleAppUxmlAlignmentTests.
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-5-wire-format-pinning branch from b05092a to 9909f49 Compare May 3, 2026 19:15
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-6-cleanup-and-reflection branch from 9404562 to 687ccc3 Compare May 3, 2026 19:15
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