Working-tree content. Subject to change and not yet released. Commit: e3d4530507.
Maestro E2E Testing
End-to-end flows for Magic Piano's logic, run against the Release simulator app (JS bundled) — the same
artifact CI builds on every merge to dev and publishes to the package registry. One runner for everything:
run-release.sh (bun run e2e:release). Full guide: docs/runtime-provider.md.
Flows are run by a developer or CI. AI agents run them only when the user asks (see testing-and-quality.mdc).
Layout
Running
Every run writes build/e2e/: report.xml (JUnit), artifacts/ (a screenshot + command log of a failing flow) and, with
RECORD_VIDEO=1 / on CI, video/e2e-run.mp4 — the whole run at a constant 60 fps (the raw simulator recording is
variable-frame-rate: it only writes frames when the screen changes, so static screens look "low fps" until it is re-encoded).
The folder is git-ignored. On merge requests the suite (e2e_mr) is a manual job: play it on the MR pipeline to run the flows and link the video from the MR. It does not start on its own.
Prerequisites: Maestro CLI (curl -fsSL https://get.maestro.mobile.dev | bash), Xcode with an iOS simulator, and
for the registry path a GITLAB_TOKEN (read_package_registry). Building your own app: see the docs link above.
Per-variant runs (monetization arms): subscriptions/<arm>/
You start Metro; the scripts only run the flows. The arm is whatever the Metro you run carries, so one arm at a time:
All arms, one after the other: bun run e2e:subscriptions (writes each arm's env file, runs its flows, and when Metro does not
serve the new arm yet it stops and asks you to restart Metro with --clear; it removes the env file at the end, KEEP_ENV=1 keeps it).
Per arm: e2e:subscriptions:friendly | :balance | :aggressive | :very-aggressive. To switch arm: bun run e2e:env <arm>, restart
Metro with --clear. Extra knobs: RETRIES (a flow that ends on the XCTest 500 runs again, default 3), METRO_PORT, UDID,
SKIP_ARM_CHECK=1. Reports: build/e2e/report-subscriptions-<arm>-<flow>.xml.
Each arm has its own folder and several flows. A flow file is a thin wrapper: it calls a shared subflow
(subflows/post-onboarding-paywall, user-opened-paywall, launch-paywall) with what THIS arm shows
(EXPECT_TRIAL / EXPECT_PAYWALL: "1" or "0"), so reading one arm's folder tells what it promises.
src/domain/__tests__/e2e-subscription-expectations.test.ts checks every value against the arm's real
config. A new topic for the same arms is a new numbered flow per folder (plus its subflow); a new arm is a folder.
Balance's paywall counts (subscriptions/balance/04–09, QC checklist G1–G8). Balance alone also walks the counts behind
each automatic offer: 04 launches 1–4 (paywall from launch 2, the 50%-off offer at launch 3, the paywall again at 4), 05 the offer
at exactly the 15th paywall closed, 06 the VIP press offer (2nd press of a session, once a session; the mock catalog's VIP row
e2e-vip), 07 the default paywall at the 6th song start, 08 the home-return paywall after 3 songs, 09 the replay paywall at the 3rd
replay. Every offer looks the same, so the screen names what opened it: paywall-screen-<screen> (selectPaywallMarker) and
sale-off-50-screen-<screen> (selectDiscountMarker). Each flow's header states the counts it walks; the expectations test checks
them against the arm. 07–09 play the mock song several times: about 3–6 minutes each. noads/balance/04-banner-placements checks
the banner on the pause panel and in Free Mode (Learn's banners stay a device check).
Why .env.development.local: in a development bundle Expo merges the .env* files OVER the shell's env, so your own
.env.local (APP_VARIANT=store, a MON_PKG) beats anything exported before expo start: the app would run real ads and the
wrong arm. .env.development.local is merged last (git-ignored). It holds EXPO_PUBLIC_RC_MON_PKG (the arm; a development-build
switch, hence the dev client), EXPO_PUBLIC_E2E_IAP=1 (the e2e IAP backend, src/core/iap/adapters/e2e-iap-service.ts: a free
player, only the default offering has the 3-day trial; the ordinary sim build is AlwaysPremium and keeps every paywall shut),
EXPO_PUBLIC_RC_ONBOARDING_SCRIPT=1 (the console deals scripts at random; 3 and 4 have no post-onboarding paywall), the sim
switches of e2e.env, and EXPO_PUBLIC_ADS_DEBUG=1 (the app's [ads:paywall] line in Metro shows the offering and armTrial).
Ads are NoAds in this area; noads/ and console/ turn on the e2e ads (below).
Flaky by nature: right after the app starts, iOS UI automation can fail to read the screen (a 500, kAXErrorInvalidUIElement);
Maestro ends the flow as Unknown error and does not retry it, so the runner runs such a flow again. Any other failure (an
assertion) is not repeated. The pauses right after launch use subflows/pause.yaml (no screen read), not sleep.yaml.
Release build: one app, any arm (MODE=release)
No Metro: the script starts a headless DevTool relay (tools/piano-devtool-desktop/scripts/web.ts) whose launch default is the
arm (PIANO_DEVTOOL_LAUNCH_VARIANT). The relay pushes it (set_monetization) to every app that connects, i.e. on each launch, so
a flow's cold restarts keep the arm. The desktop DevTool does the same by hand: Apply in the Monetization tab becomes the
default for that phone until you Clear it (or restart the relay).
The Release app for it is built with .maestro/e2e.env plus EXPO_PUBLIC_ENABLE_DESKTOP_TOOLS=1 (joins the relay),
EXPO_PUBLIC_E2E_IAP=1 (a free player: the ordinary e2e build is premium and keeps every paywall shut, so this is a separate build
from the one the other flows use) and EXPO_PUBLIC_RC_FORCE_ONBOARDING_SCRIPT=1 (scripts 3 and 4 open no paywall).
Monetization areas: Shop, No Ads, tutorial, Console
The same runner, for more areas: AREA=<area> picks the folder under .maestro/. As for subscriptions, you start Metro;
e2e:env writes the folder's env (its area's area.env / app.env, a console scenario's mon-pkg.json).
MODE=release carries the arm only (the relay's launch default): the e2e ads, an area's onboarding script, its app.env and
a console scenario's extra fields need the dev client + Metro.
What each arm must show, per the arm table (src/domain/policies/mon-arms/):
Every flow file is a thin wrapper that hands a shared subflow its arm's KEY: "value" expectations, and
src/data/__tests__/e2e-monetization-flows.test.ts checks
each value against the real config, and which files an arm must or must not have (no 02-shop-screen without a Shop).
A changed arm or mapper fails bun test before it fails a device run.
Per-area env (read by set-variant-env.sh): <area>/area.env — AREA_E2E_ADS=1 (noads/, console/) and
AREA_ONBOARDING_SCRIPT=2 (tutorial/); a caller's E2E_ADS= / ONBOARDING_SCRIPT= wins — and <area>/app.env
(EXPO_PUBLIC_* lines added as they are). The env file also blanks every other EXPO_PUBLIC_* switch of your .env.local
(a tutorial_song, a test pass length, the DevTool): they reach the device the same way, and an empty value reads as unset.
run-variants.sh checks the bundle carries the folder's arm, the e2e IAP and, for an area with ads, EXPO_PUBLIC_E2E_ADS=1.
The app also logs [ads:e2e] build appVariant=… ads=… iap=… arm=… at boot (in your Metro terminal).
E2E ads (EXPO_PUBLIC_E2E_ADS=1)
The e2e ads backend (src/core/ads/adapters/e2e-ads-service.ts) draws ads as plain app views a flow can see, count and close —
no SDK, no network, always filled, so a flow tests the app's own ad rules, never an ad network's fill:
The entitlement gate applies as in production: a No Ads player gets no interstitial and no banner, and keeps rewarded
(only VIP drops it). App Open and the FSN stay off. Off unless the area turns it on, so the subscriptions/ flows, written
for an ad-free build, never meet an ad they do not close.
How the popup is proven (subflows/noads-popup.yaml): the install starts with 5 finished songs
(launchApp argument e2eSongEnds, src/bootstrap/e2e-song-ends.ts), so the first-interstitial gate is open (and
"Learn Mode unlocked!" opens at launch: to-song-list.yaml keeps closing it). Songs are played until the popup is up (at most
8); every interstitial before its turn (E2E interstitial #1, #2) must close without it. An arm without the popup plays
until the 3rd interstitial and asserts it never opened. Aggressive also shows an interstitial on a song-row tap
(fs.home_song_click), and a song-end interstitial opens before the result; the cycle handles both. With the popup up (its
inside fades in: the flow waits for the buy button), the button must show the pack's price in the arm's tier; the flow buys
it (the e2e store's No Ads purchase succeeds) and checks that no interstitial, no banner and no promo row follow.
The e2e store (src/core/iap/adapters/e2e-iap-service.ts) sells the six No Ads products under noads_low
(t1: $1.99 / $4.99 / $9.99) and noads_high (t2: $2.99 / $6.99 / $14.99). A No Ads purchase succeeds (owned, dated);
a subscription purchase is still cancelled. In memory only: a fresh install is a free player again.
Console layer (console/)
The three layers a running arm's config comes from: the baseline (mon-arm.ts), the arm's overrides
(mon-arms/*.ts) and the console's mon_pkg fields on top (src/data/mappers/mon-pkg-mapper.ts). A console
scenario is a folder with a mon-pkg.json — sent as EXPO_PUBLIC_RC_MON_PKG, which replaces the console's mon_pkg
in a development build and goes through the same mapper — and the shop / noads flows of what it gives. No real
Firebase console is used: it is shared, throttled and not the same from one run to the next.
The full matrix (each field, each arm, both ways, invalid values, the fields the console cannot change:
tutorial.free_songs, the Shop's trial text) is unit-tested in
src/data/__tests__/mon-pkg-console-layer.test.ts.
Tutorial (tutorial/)
Onboarding script 2 (a choosing run) with its own console tutorial_song (tutorial/app.env): a slot plays its song only
when the song is in the catalog and its MIDI is a shipped excerpt, else the Twinkle stand-in — and three stand-ins are one card,
so every arm would end "single", without the picker. The value names the three mock songs on the bundled Twinkle excerpt;
src/features/tutorial/__tests__/e2e-tutorial-offer.test.ts proves it offers three. The drills wait for their own prompts
("Tap / Long press the highlighted key"). The mock songs are all free, so the flow checks the reward picker (2 free songs) or
its absence (3: the full result, left by "Open songs list"), not locked songs.
The mock catalog and how a song is played for real
In an e2e build (e2e.env) the catalog is src/core/e2e/e2e-mock-catalog.pure.ts: E2E Play Song (easy), E2E Hard
Song and Twinkle Twinkle Little Star (the tutorial's song), all on one hand-authored chart at 60 BPM:
C4 single, E4 single, G4 hold (2 s), D4 single. No remote catalog can override it, and the tutorial's own excerpt
chart is replaced by it. There is no "finish" shortcut: a flow plays the song with real taps.
The game waits on the hit line for each tile (auto-pause), and a tap within 2 s of the tile freezing there is Perfect+,
so a flow needs no clock sync (subflows/play-mock-song.yaml): wait for the first tile, then tap the keys in order,
long-pressing the hold. A clean run is 4 x Perfect+ (12) + the hold bonus = Score 58, 3 stars. Keys sit at fixed
positions in landscape percentages (A3..C5 at 5%, 15% ... 95% of the width, white-key faces at ~92% of the height).
How the flows cope with iOS UI automation (read before writing a flow)
- Build switches (
e2e.env):EXPO_PUBLIC_E2E=1(no intro film, which would redraw every frame),EXPO_PUBLIC_E2E_MOCK_CATALOG=1. A flow launches witharguments: { e2eSkipFtue: "1" }to start past onboarding + tutorial (subflows/launch-app.yaml; every flow but the first-run one), or without it to walk the first run. - Reduce Motion:
run-release.shboots the simulator with iOS Reduce Motion on (sim:prepare) so looping animations settle. - Orientation (the big one): the intro is portrait, everything after it landscape. On a headless simulator iOS UI
automation takes the device for whatever orientation was last set, so with the wrong one the tree is empty (portrait
screen, landscape device) or taps land at rotated positions (landscape screen, portrait device). The setting persists
across runs: every flow sets it explicitly (
setOrientation: LANDSCAPE_LEFTinlaunch-app.yaml;PORTRAITfor the intro in00-first-run.yaml, thenLANDSCAPE_LEFT). - Not exposed to automation: some modal controls (name dialog field, settings close X) have no accessibility id.
Flows type into the focused field + press Enter, or tap by position (
point: "96%,9%", landscape percentages). - Waits: always
extendedWaitUntilafter navigation;subflows/sleep.yamlfor a fixed delay (Maestro has no sleep).
📦 Automated CI/CD iOS Simulator Builds & Artifacts
1. Build Pipeline (currently disabled)
The simulator build workflow was already disabled on GitHub Actions and was not ported when CI moved to GitLab (
.gitlab-ci.yml, see docs/ci-cd.md). Build the simulator.applocally (xcodebuild -sdk iphonesimulator) until a GitLab job (e.g.artifacts:+expire_in: 7 days) is added;bun run e2e:downloadstill targets the old GitHub artifact and will not work.
1b. Release simulator app from the GitLab registry (current)
CI job
sim_release_publishbuilds the Release simulator app (JS bundled) when run manually (Run pipeline →PIPELINE_TARGET=sim-release) and publishes it to the package registry.bun run e2e:release(.maestro/run-release.sh) downloads the newest one, boots a simulator, installs it clean and runs.maestro/flowswith a JUnit report inbuild/e2e/; CI jobe2e_maestrodoes the same only when you Run pipeline →PIPELINE_TARGET=e2e, against the newest published build. A push todevdoes not start it. Details and Maestro MCP setup: docs/runtime-provider.md.
2. Downloading & Installing Artifacts Locally
Legacy flow (needs a pipeline that publishes the ios-simulator-app-* GitHub artifact; not available after the GitLab migration):
🎵 Song catalog end-to-end (.maestro/catalog/)
Drives the real app on a simulator against a local CDN: bundled catalog by default, a newer remote catalog overrides it, a song with no bundled chart downloads its MIDI on demand, and a cold restart (server up or down) serves everything from disk.
run.sh starts the CDN (scripts/catalog-e2e-server.ts) and its own Metro (port 8097, EXPO_PUBLIC_CATALOG_URL pointing at the CDN), wipes the catalog's MMKV/media state between scenarios, runs the five flows and asserts what the server saw (request counts). Notes: the sidebar mounts under the loading splash, so launch.yaml waits for the splash to disappear; Maestro env defaults (${APP_ID:-…}) are not supported by Maestro — pass -e APP_ID=….