refactor: move endpoint host resolution to Swift - #874
nickolas-dimitrakas merged 1 commit into
Conversation
🐦 Swift Migration ProgressProduction implementation code at
Objective-C retained by design: Core SDK 5,855 · SDK kit infrastructure 385 · Standalone kits 0. This PR's code movement
How this is measured
Generated with |
📦 SDK Size Impact ReportMeasures how much the SDK adds to an app's size (with-SDK minus without-SDK).
➡️ SDK size impact change is minimal. Raw measurementsTarget branch (workstation/swift-migration): {"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":2320,"with_sdk_executable_size_bytes":76312,"sdk_impact_kb":2236,"sdk_executable_impact_bytes":848,"xcframework_size_kb":6852}This PR: {"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":2320,"with_sdk_executable_size_bytes":76312,"sdk_impact_kb":2236,"sdk_executable_impact_bytes":848,"xcframework_size_kb":6852} |
ef35d35 to
ebca24b
Compare
ebca24b to
fa85a2f
Compare
PR SummaryMedium Risk Overview
ObjC still owns warnings, network options, and upload settings at each call site; a private Reviewed by Cursor Bugbot for commit 14996c6. Bugbot is set up for automated code reviews on this repo. Configure here. |
fa85a2f to
3881dd5
Compare
Extracts pod routing and the host precedence ladder from MPNetworkCommunication into a Foundation-only Swift type, per docs/swift-migration/CONVERSION-RECIPE.md. MPEndpointHostResolver owns two things: - defaultHost(subdomain:apiKey:) parses the pod prefix out of the API key. A key with no hyphen, an empty key and a nil key all route to us1, matching componentsSeparatedByString: on nil returning nil and the original `count <= 1` test. - resolvedHost(...) is the one precedence ladder behind all five endpoint families: customBaseURL host, then the tracking host when ATT is authorized, then the configured host, then the default. Config and audience pass a nil tracking host, which is what the ObjC did by having no tracking branch at all. The .m keeps every read of MPStateMachine, MPNetworkOptions and MPUploadSettings, and every MPILogWarning, at the same call sites and with the same text. A new private -attAuthorized collapses the four copies of the ATT comparison; it is not declared in any header. Two behaviours worth naming, both preserved: - An empty-string host overrides the default rather than falling through, because ObjC's ?: treats @"" as a live object. Covered by a test so a future Swift rewrite cannot quietly "fix" it. - The audience endpoint ignores eventsTrackingHost entirely, unlike the events endpoint. That asymmetry is reproduced, not corrected. self.defaultEventHost / defaultIdentityHost are now evaluated eagerly as the defaultHost: argument instead of behind ?:. Both are pure functions of the ATT status and API key, and both were already called unconditionally on the following line to build defaultURL, so nothing observable changes. The alias endpoint's eventsOnly fallback stays a plain ?: -- it is a two-way default with no tracking or custom host, and the resolver would only add noise there. Include/ has a zero diff and abi-guard.sh check passes; the new resolver is not an exported declaration. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
3881dd5 to
14996c6
Compare
fdff960
into
workstation/swift-migration
The stack
Review bottom-up; merge top-down. This is #874.
Third of five, stacked on the previous.
What moves
MPEndpointHostResolverowns two things:defaultHost(subdomain:apiKey:)parses the pod prefix out of the API key. A key withno hyphen, an empty key and a nil key all route to
us1, matchingcomponentsSeparatedByString:on nil returning nil and the originalcount <= 1test.resolvedHost(...)is the one precedence ladder behind all five endpoint families:customBaseURLhost, then the tracking host when ATT is authorized, then the configuredhost, then the default. Config and audience pass a nil tracking host, which is what the
ObjC did by having no tracking branch at all.
The
.mkeeps every read ofMPStateMachine,MPNetworkOptionsandMPUploadSettings,and every
MPILogWarning, at the same call sites with the same text. A new private-attAuthorizedcollapses the four copies of the ATT comparison; it is not declared in anyheader.
Two behaviours worth naming, both preserved
ObjC's
?:treats@""as a live object. Covered by a test so a future Swift rewritecannot quietly "fix" it.
eventsTrackingHostentirely, unlike events — it onlypicks up the tracking subdomain indirectly through
defaultEventHost. Reproduced, notcorrected.
self.defaultEventHost/defaultIdentityHostare now evaluated eagerly as thedefaultHost:argument instead of behind?:. Both are pure functions of the ATT statusand API key, and both were already called unconditionally on the following line to build
defaultURL, so nothing observable changes.The alias endpoint's
eventsOnlyfallback stays a plain?:— a two-way default with notracking or custom host, where the resolver would only add noise.
Gate
abi-guard.sh checkclean,Include/diff emptypod lib lintx3 podspecstrunk checkThe first build of this slice left two
unused variable 'stateMachine'warnings behind inidentityURL:andmodifyURL; both locals are gone and the build is warning-clean.tvOS and test-flakiness caveats as in the first PR of the stack.
🤖 Generated with Claude Code