Skip to content

Add the native graph the iOS app creates on first use (RND-2355) - #3418

Draft
StylianosGakis wants to merge 13 commits into
eng/ios-network-clients-and-readsfrom
eng/ios-native-graph
Draft

StylianosGakis wants to merge 13 commits into
eng/ios-network-clients-and-readsfrom
eng/ios-native-graph

Conversation

@StylianosGakis

Copy link
Copy Markdown
Member
🤖 AI description

Sits on #3417. The graph the iOS app creates once, with its flavor, two fetchers, a language source and a log policy. Creating the holder builds nothing; the graph is built on first use, and a feature adds reads with a contributed component and an extension on the holder, without editing the graph. A simulator test hook (canned HTTP backend, an example member and logged-out read) is compiled into a framework only with -Phedvig.ios.testHook=true, so no published framework carries it. CI: a Linux job on every PR compiles the iOS source sets to klibs, and a macOS workflow runs the simulator tests, links the release device framework and checks it for the hook and a size budget, daily and as a required step before each umbrella release. None of these workflows has run on GitHub yet.

Framework size

Release iosArm64 framework, shipped bytes (__TEXT plus non-zerofill __DATA): develop 3,593,170, this stack 4,624,217.

IosGraph is the AppScope graph of every module the framework links. The
iOS app passes only what Kotlin cannot know: the flavor (typed, required,
no default), the token and device id fetchers, the language source and the
network log policy. The rest of the build (bundle id, versions, OS version,
device model) is read from the bundle and the device, and platformName
keeps Kotlin's native default.

createIosGraphHolder only keeps those inputs: the graph is built, and the
NSLog and RUM fallback loggers installed, on the first call that needs it,
which logs the build time. A second holder in the process is a mistake: a
debug framework fails it with an IllegalStateException, a release one logs
it at ERROR and returns the first holder.

The graph leaves out the DataStore the native datastore module offers,
since no read stores anything, and takes no demo mode: demo mode is the
iOS app's own. No AuthEvent is published on iOS, so no AuthEventListener
can read a token it was never given. A production flavor never logs bodies
or GraphQL data, whatever policy the iOS app passes; error text follows
the policy.

Written for this series after the integration branch's native graph
(4152719, 8b7c0e7, 35a377e, 70206b7), without the claim
history screen model, the ViewModel factory, initializables, auth events
or demo mode.
MockedNetworkIosGraph has every IosGraph binding with one difference: the
Ktor engine is a MockEngine. The base client comes from the app's own
buildKtorClient, now public for this, and the token plugin and both
Apollo clients from the app's own providers, so a request goes through
the iOS app's inputs and the real interceptors and never reaches the
network.

It lives in src/iosTestHook, which the umbrella's tests always compile and
a simulator framework carries only when built with
-Phedvig.ios.testHook=true, so no published framework contains it.

The tests send a real operation from data-paying-member, from a
background thread as reads do, and check the token and the iOS headers,
that a public request sends no token and asks for none while a member is
logged in, that a cache-first request still goes to the network, that a
failing token fetch sends nothing, that UNAUTHENTICATED is an ordinary
error, and what the iOS app's sink receives with the policy off, on and in
production.

(the graph is adapted from commits 20af0318a6 and a354e933e2: it reads the
smaller accessor set, both clients and the base HTTP client)
The iOS app's tests and the Kotlin tests need to drive the real graph,
network clients and read helper without a backend. CannedBackend answers,
fails or holds GraphQL operations by name and records what was sent;
TestGraphs.create builds the real bindings over it, optionally with a
token fetch that never answers, and returns the holder.

ExampleReads is written the way a feature writes its reads: an @Inject
facade over SessionReads, an accessor interface contributed to the app
scope, and an extension on IosGraphHolder that Swift sees as a method. It
proves a feature adds reads without touching the holder or the graph. It
has a member read and a logged-out read of data-conversations'
operation, which links no compose resources, so checkUmbrellaClasspath
holds with the hook in the framework too.

Like the test graph, the hook is compiled into a simulator framework only
with -Phedvig.ios.testHook=true, for the iOS app's tests in local umbrella
mode; the published framework never has it.

The tests drive the hook the way the iOS app's tests would: a canned
answer with the member's token, an HTTP failure with the names the iOS
app logs, a login or logout while a member read is held, a token fetch
that never answers (TIMEOUT, then STUCK, one fetch), a logged-out read
that sends no token while a member is logged in and is not ended by a
login or logout, and a cancel that reads as no failure.

(adapted from the reads experiment's hook in dcb65db4a0)
…snapshot

HeaderSnapshotTest reads the simulator debug framework's header and
compares the declarations of the holder, its inputs, the log sink and the
read failures with a snapshot in the test. A boxed primitive, a renamed or
removed member, or a new type reached from the API then shows in the
Android pull request that causes it, where the iOS reviewer sees it. Two
more checks fail on any reached framework type outside the API and on any
boxed primitive.

The test hook has its own snapshot when the framework is built with it,
and without it the test checks that no line of it is in the header.

(adapted from the reads experiment's ReadsHeaderTest and the header parser
of TravelCertificateDataHeaderTest; this parser also reads protocols and
drops multi-line comments)
…nd before releases

pr.yml runs on Linux and compiled nothing for iOS, so a commonMain or
nativeMain change that breaks the iOS compile was only found by the
nightly umbrella release. Kotlin/Native compiles iOS klibs on Linux, so a
new ios_klibs job in pr.yml compiles every module's iOS source sets, main
and test, next to the other Linux jobs.

What needs macOS stays off normal PRs. ios-shared.yml runs every module's
iOS simulator tests, the umbrella's tests with the test hook in the
framework, the release device framework link, a check that the hook is
not in it and a 20 MB size budget, once a day and as a required job of
umbrella.yml, which also checks every slice of the XCFramework it
publishes for the hook. A failed scheduled run is emailed by GitHub to
whoever last changed its schedule, as for the repo's other scheduled
workflows.

To confirm before merging: the ios_klibs job's time on the runner, the
macOS runner's time for the daily job, and that its Xcode has a simulator
the Kotlin test task can boot.
@notion-workspace

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant