Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 69 additions & 19 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
name: E2E

# Maestro smoke e2e for the React Native wrapper, on the example app built from the local wrapper
# source (see TESTING.md):
# native-versions pinned native SDK versions vs the latest published (report-only for now)
# Maestro e2e for the React Native wrapper, on the example app built from the local wrapper source,
# with the same flows as the native SDK suites (see TESTING.md). GitHub-hosted runners only.
# config e2e/e2e-env.json + e2e/e2e-flows.json + the flow files agree; unit tests;
# shellcheck; Maestro syntax of every flow
# native-versions pinned native SDK versions vs the latest published
# android ubuntu + KVM emulator (API 35)
# ios self-hosted Mac simulator, serialised by e2e/sim-lock.sh
# ios macOS simulator
#
# Secrets: LINKTRAIL_KEY (workspace SDK key) and E2E_TOKEN (X-E2E-Token for the private backend
# check). Without both, only the offline flows run and the real ones are skipped with a notice.
# Pull requests from forks get no secrets, and never run on the self-hosted Mac.
# Environment: prod by default (LINKTRAIL_ENV); a manual run can pick dev and the link types.
# Secrets: LINKTRAIL_KEY (prod workspace SDK key), LINKTRAIL_TEST_KEY (dev workspace SDK key, dev
# runs only) and E2E_TOKEN (X-E2E-Token for the private backend check). Without the environment's
# key and E2E_TOKEN only the offline flow runs and the real ones are skipped with a notice (pull
# requests from forks get no secrets).
# Variables (optional):
# NATIVE_VERSION_STRICT 'false' to only warn on native SDK drift (default: fail)
# E2E_ENV the environment of pull request runs (default prod)

on:
pull_request:
workflow_dispatch:
inputs:
environment:
description: 'Backend + links (e2e/e2e-env.json)'
type: choice
options: [prod, dev]
default: prod
link_types:
description: 'Link-type rows: all, none, or a comma list (general,partner)'
type: string
default: all

permissions:
contents: read
Expand All @@ -23,7 +38,28 @@ concurrency:
group: e2e-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
LINKTRAIL_ENV: ${{ inputs.environment || vars.E2E_ENV || 'prod' }}
E2E_LINK_TYPES: ${{ inputs.link_types || 'all' }}

jobs:
config:
name: E2E config + scripts
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Validate the targets and the flow table
run: python3 -I e2e/targets.py validate
- name: Unit tests (e2e/targets.py, e2e/verify.py)
run: python3 -I -m unittest discover -s e2e/tests -v
- name: shellcheck
run: shellcheck -x e2e/*.sh
- name: Maestro syntax of every flow
run: |
curl -Ls https://get.maestro.mobile.dev | bash
for f in e2e/flows/*/*.yaml; do "$HOME/.maestro/bin/maestro" check-syntax "$f" >/dev/null || { echo "::error file=$f::Maestro syntax error"; exit 1; }; done

native-versions:
name: Native SDK versions
runs-on: ubuntu-latest
Expand All @@ -37,14 +73,10 @@ jobs:
android:
name: Android e2e (Maestro)
runs-on: ubuntu-latest
timeout-minutes: 75
timeout-minutes: 150
env:
API_LEVEL: 35
HAVE_SECRETS: ${{ secrets.LINKTRAIL_KEY != '' && secrets.E2E_TOKEN != '' }}
steps:
- name: Secrets notice
if: env.HAVE_SECRETS != 'true'
run: echo "::notice title=e2e::LINKTRAIL_KEY / E2E_TOKEN not available — only the offline flows run."

- uses: actions/checkout@v4

Expand Down Expand Up @@ -78,6 +110,7 @@ jobs:
- name: Build the example APK
env:
LINKTRAIL_KEY: ${{ secrets.LINKTRAIL_KEY }}
LINKTRAIL_TEST_KEY: ${{ secrets.LINKTRAIL_TEST_KEY }}
E2E_TOKEN: ${{ secrets.E2E_TOKEN }}
BUILD_ONLY: '1'
run: bash e2e/android.sh
Expand Down Expand Up @@ -119,9 +152,10 @@ jobs:
script: echo "Generated AVD snapshot for caching."

- name: E2E — Maestro
timeout-minutes: 30
timeout-minutes: 120
env:
LINKTRAIL_KEY: ${{ secrets.LINKTRAIL_KEY }}
LINKTRAIL_TEST_KEY: ${{ secrets.LINKTRAIL_TEST_KEY }}
E2E_TOKEN: ${{ secrets.E2E_TOKEN }}
SKIP_BUILD: '1'
uses: reactivecircus/android-emulator-runner@v2
Expand All @@ -138,6 +172,15 @@ jobs:
emulator-boot-timeout: 900
script: sleep 45 && bash e2e/android.sh

- name: Upload the e2e results
if: always()
uses: actions/upload-artifact@v4
with:
name: e2e-results-android
path: e2e/results-android.jsonl
retention-days: 14
if-no-files-found: ignore

- name: Upload Maestro debug output
if: failure()
uses: actions/upload-artifact@v4
Expand All @@ -153,15 +196,11 @@ jobs:
# manual runs only, because the job uses the repo's e2e secrets.
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository
runs-on: macos-latest
timeout-minutes: 120
timeout-minutes: 210
env:
LANG: en_US.UTF-8
LC_ALL: en_US.UTF-8
HAVE_SECRETS: ${{ secrets.LINKTRAIL_KEY != '' && secrets.E2E_TOKEN != '' }}
steps:
- name: Secrets notice
if: env.HAVE_SECRETS != 'true'
run: echo "::notice title=e2e::LINKTRAIL_KEY / E2E_TOKEN not available — only the offline flows run."

- uses: actions/checkout@v4

Expand Down Expand Up @@ -191,6 +230,7 @@ jobs:
- name: Build the example app
env:
LINKTRAIL_KEY: ${{ secrets.LINKTRAIL_KEY }}
LINKTRAIL_TEST_KEY: ${{ secrets.LINKTRAIL_TEST_KEY }}
E2E_TOKEN: ${{ secrets.E2E_TOKEN }}
run: |
set -euo pipefail
Expand All @@ -213,13 +253,23 @@ jobs:
xcrun simctl bootstatus "$UDID" -b >/dev/null 2>&1 || true

- name: E2E — Maestro
timeout-minutes: 45
timeout-minutes: 160
env:
LINKTRAIL_KEY: ${{ secrets.LINKTRAIL_KEY }}
LINKTRAIL_TEST_KEY: ${{ secrets.LINKTRAIL_TEST_KEY }}
E2E_TOKEN: ${{ secrets.E2E_TOKEN }}
SKIP_BUILD: '1'
run: DEVICE="$SIM_UDID" bash e2e/ios.sh

- name: Upload the e2e results
if: always()
uses: actions/upload-artifact@v4
with:
name: e2e-results-ios
path: e2e/results-ios.jsonl
retention-days: 14
if-no-files-found: ignore

- name: Upload Maestro debug output
if: failure()
uses: actions/upload-artifact@v4
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ coverage/
*.jks
example/android/upload-keystore.jks
example/ios/build-e2e/

# e2e run output
e2e/results-*.jsonl
__pycache__/
116 changes: 82 additions & 34 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,96 @@
`.github/workflows/ci.yml`, plus a JS bundle and an Android build of the example app;
`.github/workflows/ios.yml` builds the example for the iOS simulator.

## Smoke e2e (Maestro)
## E2E (Maestro)

`.github/workflows/e2e.yml` runs a small Maestro suite on the example app (`example/`), which uses
the wrapper from source (`"linktrail-react-native": "file:.."`) and the native SDKs it pins
(`LinkTrailSDK` from CocoaPods, `io.linktrail:sdk` from Maven Central). It runs on pull requests
and on manual dispatch.
`.github/workflows/e2e.yml` runs Maestro on the example app (`example/`), which uses the wrapper
from source (`"linktrail-react-native": "file:.."`) and the native SDKs it pins (`LinkTrailSDK`
from CocoaPods, `io.linktrail:sdk` from Maven Central). It runs the same flows as the native SDK
suites, through the wrapper, on GitHub-hosted runners, on pull requests and on manual dispatch.

App ids: Android `io.linktrail.demo.store` (the `applicationId`; the Kotlin namespace stays
`com.kickflip`), iOS `io.linktrail.kickflipdemo`. Both must be in the backend's
`E2E_APP_IDENTIFIERS` for the verify check.

| Flow | Android | iOS | Needs secrets |
| --- | --- | --- | --- |
| `consent_prompt` | consent gate shows; Deny persists across a relaunch | gate shows; Skip stays undecided; a grant persists | no |
| `deferred_allow` | real click, fake Play referrer, Allow | Safari stages the click token on the clipboard, Allow + Paste | yes |
| `deferred_deny` | the same with Deny | the same with Deny | yes |
| `reengagement` | https App Link while installed | `kickflip://e2e/open?url=<link>` → `handleDeepLink` | yes |
| `track_event` | `trackEvent("e2e_purchase", { value: 9.99, currency: "USD" })` | the same | yes |

The deferred and re-engagement flows assert that the JS `onLink` listener fired **exactly once**,
with the linked `path` (`/products/aj1`), `source` and `customData` (`voucher=SUMMER25`). The
values are read off an on-screen diagnostics panel (testIDs `e2e-link-count`, `e2e-link-path`,
`e2e-link-source`, `e2e-link-custom-data`, `e2e-consent`, `e2e-attribution`, `e2e-event`) that
only e2e builds show.
### Data-driven, like the native suites

After each deferred flow the runner asks the backend what it recorded for that flow's own click
token (`GET /v1/e2e/clicks/<token>`, header `X-E2E-Token`):
- `e2e/e2e-env.json`: the one place for backend URLs, hosts and slugs per environment (`prod`, the
default, and `dev`), the link-type links, the reward links and which newer backend checks each
environment has deployed (`backend_checks`). A link type or reward link with no entry for the
run's environment is **skipped with a notice**, never failed (prod has no `e2e-event` link yet).
- `e2e/e2e-flows.json`: the one table of rows (run order, kind, link slot, consent, link-type
matrix, what each asserts). Each row runs on both platforms from `e2e/flows/<platform>/<yaml>.yaml`.
- `e2e/targets.py` resolves both for the runners (`resolve`, `jobs`) and checks they agree with the
flow files (`validate`); `e2e/verify.py` holds the backend rules (same as the native
`scripts/e2e-verify.py`). The `config` job runs `validate`, `e2e/tests`, shellcheck and `maestro check-syntax` on every flow.

- allow: `installRecorded`, `attributed`, `matchType == "click_token"`, `installCount == 1`;
- deny: `installRecorded == false`, `installCount == 0`, held for the whole polling window.
### Rows

### Secrets and variables
| Row | Kind | Link (prod) | Asserts |
| --- | --- | --- | --- |
| `consent_prompt` | offline | none | consent gate; the decision persists across a relaunch |
| `reengagement_allow` / `_deny` | open | subdomain | onLink once (reengagement) with path + voucher; deny is route-only |
| `track_event` | event | none | `trackEvent("e2e_purchase", { value: 9.99, currency: "USD" })` is acknowledged |
| `deferred_custom_allow` / `_deny` | click | custom domain (`summer-sale`) | allow: onLink once (deferred), path + voucher, 1 counted `click_token` install, not fraud; deny: nothing recorded |
| `deferred_subdomain_allow` / `_deny` | click | subdomain (`discounted-product`) | the same |
| `deferred_{custom,subdomain}_{allow,deny}_problistic` | problistic | `custom-problistic`, `ios-problistic` | a real click but no token: the install is answered (allow: attributed or organic; deny: never attributed) |
| `deferred_custom_{allow,deny}__<type>` | click | `e2e-general`, `e2e-campaign`, `e2e-influencer`, `e2e-partner` | as `deferred_custom_*`, plus `linkType` / `source` in customData; the backend's `linkType`, and the reward: per_install earned on `influencer` / `partner` allow, nothing on deny, `reward: null` on the others |
| `reengagement_type_{allow,deny}__<type>` | reopen | the type's link | installed through the link, then opened again: `openCount` +1 (allow) / unchanged (deny), `installCount` and earning unchanged |
| `deferred_event_allow` / `_deny` | reward | `e2e-event` (dev only; skipped on prod) | per_event: the reward's event x2 + one other event; earning 2 x `reward.amountMinor`; deny earns 0 |
| `deferred_revshare_allow` / `_deny` | reward | `e2e-revshare` | rev_share: one revenue event (+ the same in another currency); earning `floor(revenue x rateBps / 10000)`; deny earns 0 |

Left out on purpose: the Android Play Store install-referrer flows (they stay in the private Android
SDK repo) and the native suites' simulated / custom-scheme flows (they test the native example app's
own simulator, not the SDK). The wrapper exposes no SDK device id, so the probabilistic rows can't
run the native device lookup: they assert the install's answer only (the report says so).

How the rows stage their click:

- Android: a real click with an Android Chrome UA; its `lt_click` (from the Play Store redirect) is
staged through the SDK's debug-only fake referrer (`setprop debug.linktrail.referrer`, a
debuggable app). Probabilistic rows stage nothing. Re-engagement opens the https App Link when the
manifest claims the host, else `kickflip://e2e/open?url=<link>`.
- iOS: Safari opens the link (`_stage_click.yaml`) and the interstitial stages the token on the
clipboard, which the consent prompt's Paste control reads. Probabilistic rows clear the clipboard
and call `trackInstall()` from the e2e panel. Re-engagement uses `kickflip://e2e/open?url=<link>`
(an unsigned simulator build has no Associated Domains).
- Reward rows send their events through `kickflip://e2e/events?list=<JSON>`, which the example app
sends with `trackEvent` and counts on the panel (`e2e-events`).

All values are read off an on-screen diagnostics panel that only e2e builds show (testIDs
`e2e-link-count`, `e2e-link-path`, `e2e-link-source`, `e2e-link-custom-data`, `e2e-consent`,
`e2e-attribution`, `e2e-event`, `e2e-install`, `e2e-events`; buttons `e2e-grant-consent`,
`e2e-deny-consent`, `e2e-track-event`, `e2e-track-install`).

After a click row the runner asks the backend what it recorded for that row's own click token
(`GET /v1/e2e/clicks/<token>`, header `X-E2E-Token`): allow polls until it matches; deny holds the
whole window, so a late install shows. A check an environment hasn't deployed
(`backend_checks: false`) is noted as skipped on the row, never passed or failed. Each run writes
`e2e/results-<platform>.jsonl` and a table in the job summary.

### Environments, secrets and variables

| Name | Kind | Purpose |
| --- | --- | --- |
| `LINKTRAIL_KEY` | secret | Workspace SDK key, bundled into the e2e build only |
| `LINKTRAIL_KEY` | secret | SDK key of the prod workspace, bundled into the e2e build only |
| `LINKTRAIL_TEST_KEY` | secret | SDK key of the dev workspace (dev runs only) |
| `E2E_TOKEN` | secret | `X-E2E-Token` for the backend check |
| `E2E_ENV` | variable | environment of pull request runs (default `prod`) |
| `NATIVE_VERSION_STRICT` | variable | `false` to only warn on native SDK drift (the CI check fails on drift by default) |

Without both secrets (for example on a pull request from a fork) only `consent_prompt` runs and the
other flows are skipped with a notice. Fork pull requests never run on the self-hosted Mac.
A manual run picks the environment (`prod` | `dev`) and the link types (`all`, `none` or a comma
list). Without the environment's key and `E2E_TOKEN` (for example on a pull request from a fork)
only `consent_prompt` runs and the other rows are skipped with a notice. `dev` points the Android
debug app at the dev backend (`setprop debug.linktrail.base`); the iOS wrapper ships the binary SDK,
which has no backend override, so iOS skips the real rows on `dev` with a notice.

### How the key reaches the build

The runners write the key to `example/e2e.config.local.json` (gitignored, removed when the run
ends). `example/metro.config.js` resolves the `kickflip-e2e-config` module to that file when it
exists and to `example/src/e2e/config.default.json` (e2e off, placeholder key) otherwise. The key is
never passed on a command line or printed; curl reads the secret headers from stdin.
The runners write the key and the environment's link hosts to `example/e2e.config.local.json`
(gitignored, removed when the run ends). `example/metro.config.js` resolves the
`kickflip-e2e-config` module to that file when it exists and to
`example/src/e2e/config.default.json` (e2e off, placeholder key) otherwise. The key is never passed
on a command line or printed; curl reads the secret headers from stdin.

The Android build bundles the JS into the **debug** APK (`-PbundleDebugJs`) so it runs without
Metro and stays debuggable, which the SDK's fake referrer requires. iOS builds **Release** for the
Expand All @@ -63,18 +105,24 @@ simulator, which bundles the JS.

```sh
npm ci && (cd example && npm install && bundle install)
python3 -I e2e/targets.py validate # config + flow table + flow files
python3 -I -m unittest discover -s e2e/tests # the runners' rules
python3 -I e2e/targets.py jobs --platform ios # what a run would do

# Android: a booted emulator (e.g. LinkTrail_API35)
bash e2e/android.sh # all flows; real ones only with the secrets set
bash e2e/android.sh consent_prompt # one flow
bash e2e/android.sh # all rows; real ones only with the secrets set
bash e2e/android.sh consent_prompt # one row
bash e2e/android.sh deferred_custom_allow__partner # one link-type row
bash e2e/android.sh reward # one kind

# iOS: a booted simulator
bash e2e/ios.sh
DEVICE=<udid> bash e2e/ios.sh consent_prompt
```

`LINKTRAIL_KEY=… E2E_TOKEN=… bash e2e/android.sh` runs the real flows. They make real clicks on
production links, so prefer CI for them. `SKIP_BUILD=1` reuses the last build.
`LINKTRAIL_KEY=… E2E_TOKEN=… bash e2e/android.sh` runs the real rows (`LINKTRAIL_ENV=dev` with
`LINKTRAIL_TEST_KEY` for dev). They make real clicks on real links, so prefer CI for them.
`SKIP_BUILD=1` reuses the last build; `E2E_LINK_TYPES=none` skips the link-type rows.

On a Mac shared with other simulator jobs, take the lock first:
`pid="$(bash e2e/sim-lock.sh acquire)"; …; bash e2e/sim-lock.sh release "$pid"`.
Expand Down
Loading
Loading