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
Conversation
d5c1917 to
33aa3e6
Compare
e15f721 to
6a33ab0
Compare
33aa3e6 to
01cc27c
Compare
6a33ab0 to
01c3993
Compare
01cc27c to
e513ad1
Compare
01c3993 to
fe8c352
Compare
e513ad1 to
1eb56dd
Compare
fe8c352 to
de9112d
Compare
1eb56dd to
1a3834e
Compare
de9112d to
52ffbdd
Compare
1a3834e to
3bf92fe
Compare
52ffbdd to
20ee16c
Compare
3bf92fe to
b05092a
Compare
20ee16c to
9404562
Compare
… 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.
b05092a to
9909f49
Compare
9404562 to
687ccc3
Compare
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
Clickable.clicked) inSampleAppTestHelpers; centralises the per-test panel-user prefix inSampleAppLiveFireTests.EventQueuebackground drain thread via a private const so the thread surfaces with a stable name in profilers, debuggers, and crash dumps.FlushIntervalSecondsandFlushSizetest values throughTestDefaults.ProgressionandResourcenumeric scenario fixtures inTestFixtures.Purchasenumeric fixtures and minimal one-character identifier placeholders inTestFixtures.Progression.LevelandGzipplaceholder references.SessionTestsfixed virtual-now fixture used as the starting point for every Session lifecycle test.DiskStoreTestsfile body fixtures (stale, surviving, malformed)..metafiles Unity flags on first project open:README.md.meta,Tests/Editor.meta,DeviceCollectorTests.cs.meta,MessagesTests.cs.meta,WireFixture.cs.meta.OnErrorcallback contract unchanged.Linear: SDK-277