Repository navigation
fix(cache): wait for late or hidden controls at cached points (ENG-1556) #7779
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
| name: mobile | |
| # The mobile benchmark on an iOS simulator and an Android emulator, on every | |
| # pull request and merge queue entry that can reach it (the `changes` job says | |
| # which): the second real engine the runner ships, gated the way the web | |
| # engine is by the testbed and the web benchmark. A push to main runs no suite: | |
| # the merge queue already ran them on the same tree. It only builds the Expo | |
| # app when the cache misses, since main's cache is the one every run restores. | |
| # | |
| # The Expo app is the expensive part (about twenty minutes of native build on | |
| # iOS). .github/actions/expo-app builds it once per native fingerprint and | |
| # otherwise refreshes the cached build's JS bundle, so only a native change | |
| # rebuilds. | |
| # | |
| # One job per platform and suite. Each runs `e2e run` for its target on the | |
| # booted device and, when a test fails, runs the failed tests once more with | |
| # `--last-failed` before the job goes red (agent-device's runtime has episodes | |
| # of its own on a shared machine, #502). The agentic suite replays the | |
| # recordings committed under .e2e/cache and calls the model for a step with | |
| # none, so on a pull request it runs for this repository's branches only, | |
| # and not for Dependabot's, whose runs get no secrets either. Android runs | |
| # it with `--strict-cache`, the way benchmark.yml runs the web one: a | |
| # committed recording that no longer replays fails the job as REPLAY_STALE | |
| # instead of spending model calls on every run. iOS replays leniently until | |
| # the three scenarios the README names replay on a simulator. | |
| # The merge queue runs with this repository's secrets, so it runs the agentic | |
| # suite for every pull request. Both platforms' entries are recorded on a Mac | |
| # (an iPhone 17 Pro simulator, a 1080x2400 emulator) and committed with the | |
| # scenario change. | |
| # | |
| # A job uploads its report from every run, and its artifacts (screens, | |
| # video) only when it fails: the quota is shared with every workflow | |
| # here, and the report alone says what the first attempt of a flaky test met. | |
| # | |
| # Each job posts its run to the pull request as one comment through | |
| # @e2e-dev/github (hence pull-requests: write), named `ios`, `ios agent`, | |
| # `android`, or `android agent` by E2E_MOBILE_BENCHMARK_COMMENT, the way | |
| # benchmark.yml names the web ones. The second pass over the failed tests | |
| # updates the same comment: the reporter folds the rerun into the first | |
| # pass, so a test the rerun recovered reads as flaky and the comment says | |
| # what the job's status says. | |
| # | |
| # The ruleset requires `mobile gate` alone, which passes when every other job | |
| # passed or was skipped, so the suites can be a matrix the `changes` job | |
| # plans: a suite that cannot run is left out instead of booting a device for | |
| # nothing. | |
| on: | |
| workflow_call: | |
| inputs: | |
| agent-device-version: | |
| description: Exact driver version for compatibility runs | |
| type: string | |
| default: '' | |
| pull_request: | |
| merge_group: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| env: | |
| # The repository's own runs are not usage: the CLI sends no telemetry from CI here. | |
| E2E_TELEMETRY_DISABLED: '1' | |
| # A pull request from a fork runs with no secrets and a read-only token, as | |
| # GitHub grants on `pull_request`: the agentic suite is skipped there and | |
| # shared caches are restore-only. Never switch this workflow to | |
| # `pull_request_target` to get the key onto fork branches: that hands the | |
| # secret to untrusted code. | |
| SAME_REPO: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }} | |
| permissions: | |
| contents: read | |
| # The suites post their comments; the `changes` job reads the pull request's files. | |
| pull-requests: write | |
| # The Expo app action deletes a cached build its repack step proved broken. | |
| actions: write | |
| concurrency: | |
| group: ${{ github.workflow }}-mobile-${{ github.ref }} | |
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
| jobs: | |
| # Plans the run. A pull request or a merge queue entry gets the suites when | |
| # the change reaches the runner, the engine, or the benchmark app | |
| # (.github/filters.yml says what does, and why a skip rather than a | |
| # workflow-level `paths:` filter); a manual dispatch always gets them. A | |
| # push to main gets the cache warm-up instead, on the same filter. | |
| changes: | |
| runs-on: blacksmith-4vcpu-ubuntu-2404 | |
| timeout-minutes: 5 | |
| outputs: | |
| suites: ${{ steps.plan.outputs.suites }} | |
| warm: ${{ steps.plan.outputs.warm }} | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| # A pull request's files come from the API; a merge queue entry is | |
| # diffed against its base, and a push to main against the commit | |
| # before it, which the action fetches itself. | |
| - uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3 | |
| id: filter | |
| if: ${{ github.event_name != 'workflow_dispatch' && inputs.agent-device-version == '' }} | |
| with: | |
| filters: .github/filters.yml | |
| predicate-quantifier: some-with-excludes | |
| - name: Plan | |
| id: plan | |
| env: | |
| EVENT: ${{ inputs.agent-device-version != '' && 'workflow_dispatch' || github.event_name }} | |
| MOBILE: ${{ steps.filter.outputs.mobile }} | |
| # Dependabot's pull requests come from this repository but run with | |
| # Dependabot's secrets, which hold no model key: the agentic suite | |
| # would fail every step without a recording. | |
| AGENTIC: ${{ github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') }} | |
| run: | | |
| suites='[]' | |
| warm=false | |
| if [ "$EVENT" = push ]; then | |
| [ "$MOBILE" = true ] && warm=true | |
| elif [ "$EVENT" = workflow_dispatch ] || [ "$MOBILE" = true ]; then | |
| if [ "$AGENTIC" = true ]; then | |
| suites='["deterministic","agentic"]' | |
| else | |
| suites='["deterministic"]' | |
| fi | |
| fi | |
| echo "suites=$suites" >> "$GITHUB_OUTPUT" | |
| echo "warm=$warm" >> "$GITHUB_OUTPUT" | |
| # One job per suite, each on its own Mac with two simulators: the | |
| # deterministic suite and the agentic one take about as long as each other, | |
| # so the gate's wall time is one of them, not their sum. | |
| ios: | |
| name: ios ${{ matrix.suite }} | |
| needs: changes | |
| if: ${{ needs.changes.outputs.suites != '[]' }} | |
| runs-on: blacksmith-6vcpu-macos-26 | |
| timeout-minutes: 60 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| suite: ${{ fromJSON(needs.changes.outputs.suites) }} | |
| defaults: | |
| run: | |
| working-directory: apps/mobile-benchmark | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - uses: pnpm/action-setup@9fd676a19091d4595eefd76e4bd31c97133911f1 # v4.2.0 | |
| - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 | |
| with: | |
| node-version: 26 | |
| cache: pnpm | |
| - uses: ./.github/actions/workspace-install | |
| with: | |
| agent-device-version: ${{ inputs.agent-device-version }} | |
| - name: Build | |
| run: pnpm run build | |
| working-directory: . | |
| - name: Toolchain | |
| run: | | |
| xcodebuild -version | |
| xcrun simctl list runtimes available | |
| - name: Expo app | |
| id: app | |
| uses: ./.github/actions/expo-app | |
| with: | |
| platform: ios | |
| # agent-device compiles its XCUITest runner on first use; keep it between | |
| # runs. Only the build: the rest of ~/.agent-device is the state of the | |
| # daemon that ran (its pid, lock, sessions, device claims), and a job | |
| # that restores it starts against a daemon record from another machine. | |
| - name: Restore the agent-device runner | |
| uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: ~/.agent-device/apple-runner/derived | |
| key: agent-device-runner-${{ inputs.agent-device-version }}-${{ runner.os }}-${{ hashFiles('packages/mobile/package.json') }} | |
| # `bootstatus -b` boots a device when it is not up yet and waits for it. | |
| # Two simulators, the picked one and a clone of it, so the run drives | |
| # two workers (e2e.config.ts reads the comma-separated UDIDs). The | |
| # runtime is pinned: the accessibility bridge reports control state | |
| # differently from one iOS release to the next (on 26.2 a selected tab | |
| # or radio carries no `selected`, and an empty field reports its | |
| # placeholder as its value), and the suites are verified on 26.5. Bump | |
| # IOS_RUNTIME on purpose, with a local run on that runtime first. | |
| - name: Boot two simulators | |
| env: | |
| IOS_RUNTIME: com.apple.CoreSimulator.SimRuntime.iOS-26-5 | |
| run: | | |
| set -euo pipefail | |
| PICK="$(xcrun simctl list devices available -j | node -e ' | |
| const payload = JSON.parse(require("node:fs").readFileSync(0, "utf8")); | |
| const wanted = process.env.IOS_RUNTIME; | |
| const major = wanted.replace(/-\d+$/, "-"); | |
| const rank = (runtime) => (runtime === wanted ? 0 : runtime.startsWith(major) ? 1 : 2); | |
| const runtimes = Object.entries(payload.devices) | |
| .filter(([runtime]) => runtime.includes("SimRuntime.iOS-")) | |
| .sort(([a], [b]) => rank(a) - rank(b) || b.localeCompare(a, undefined, { numeric: true })); | |
| for (const [runtime, list] of runtimes) { | |
| const pick = list.find((d) => d.name === "iPhone 17 Pro") ?? list.find((d) => d.name.startsWith("iPhone")); | |
| if (pick) { process.stdout.write(`${pick.udid} ${runtime} ${pick.name}`); process.exit(0); } | |
| } | |
| process.exit(1); | |
| ')" | |
| UDID="${PICK%% *}" | |
| SECOND="$(xcrun simctl clone "$UDID" "iPhone 17 Pro (2)")" | |
| echo "booting ${PICK#* } ($UDID) and its clone ($SECOND)" | |
| # Both boots start before either is waited on: one after the other | |
| # took about 130 s on this runner. | |
| xcrun simctl boot "$UDID" | |
| xcrun simctl boot "$SECOND" | |
| xcrun simctl bootstatus "$UDID" | |
| xcrun simctl bootstatus "$SECOND" | |
| echo "E2E_MOBILE_BENCHMARK_IOS_DEVICE=$UDID,$SECOND" >> "$GITHUB_ENV" | |
| # A test that fails gets a second pass, alone, with the tests that | |
| # passed left out (`--last-failed` reads the report the first pass | |
| # wrote). agent-device's runtime has episodes of its own on a shared CI | |
| # machine (#502: a daemon replaced as unreachable mid-run, a runner that | |
| # overruns its watchdog), and the same tests pass on a Mac every time. | |
| - name: Run the suite | |
| env: | |
| AI_GATEWAY_API_KEY: ${{ secrets.AI_GATEWAY_API_KEY }} | |
| GITHUB_TOKEN: ${{ inputs.agent-device-version == '' && github.token || '' }} | |
| E2E_MOBILE_BENCHMARK_IOS_APP: ${{ steps.app.outputs.app-path }} | |
| E2E_MOBILE_BENCHMARK_COMMENT: ios${{ matrix.suite == 'agentic' && ' agent' || '' }} | |
| E2E_RUN: node node_modules/e2e/dist/cli/bin.js run --target ios-simulator ${{ matrix.suite == 'agentic' && '--config e2e.agent.config.ts --output .e2e/agent' || '' }} | |
| run: $E2E_RUN || $E2E_RUN --last-failed | |
| # The artifact upload below fails whenever the repository's quota is | |
| # full, so the failure evidence goes into the log as well. | |
| - name: Failure screens | |
| if: ${{ failure() }} | |
| run: &failure-screens | | |
| find .e2e -name screen-at-failure.txt | sort | head -n 12 | while read -r screen; do | |
| echo "::group::$screen" | |
| head -c 8000 "$screen" | |
| echo | |
| echo "::endgroup::" | |
| done | |
| # The report is small and says what the first attempt of a flaky test | |
| # met, so it is kept from every run; the artifacts (screens, video) | |
| # only from a red one, since the quota is shared. | |
| - name: Upload report | |
| if: ${{ !cancelled() }} | |
| continue-on-error: true | |
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | |
| with: | |
| name: mobile-benchmark-ios-${{ matrix.suite }}-report | |
| path: &report-paths | | |
| apps/mobile-benchmark/.e2e/report.json | |
| apps/mobile-benchmark/.e2e/agent/report.json | |
| if-no-files-found: warn | |
| retention-days: 7 | |
| - name: Upload artifacts | |
| if: ${{ failure() }} | |
| continue-on-error: true | |
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | |
| with: | |
| name: mobile-benchmark-ios-${{ matrix.suite }} | |
| path: &artifact-paths | | |
| apps/mobile-benchmark/.e2e/results | |
| apps/mobile-benchmark/.e2e/agent/results | |
| if-no-files-found: warn | |
| retention-days: 7 | |
| # One job per suite here too, each with its own emulator, for the same | |
| # reason: the gate's wall time is the longer suite, not both. | |
| android: | |
| name: android ${{ matrix.suite }} | |
| needs: changes | |
| if: ${{ needs.changes.outputs.suites != '[]' }} | |
| # x64 Blacksmith runners expose KVM, which the emulator needs. | |
| runs-on: blacksmith-4vcpu-ubuntu-2404 | |
| timeout-minutes: 60 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| suite: ${{ fromJSON(needs.changes.outputs.suites) }} | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - uses: pnpm/action-setup@9fd676a19091d4595eefd76e4bd31c97133911f1 # v4.2.0 | |
| - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 | |
| with: | |
| node-version: 26 | |
| cache: pnpm | |
| - uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0 | |
| with: | |
| distribution: temurin | |
| java-version: 17 | |
| - name: Enable KVM for the emulator | |
| run: | | |
| echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | |
| sudo udevadm control --reload-rules | |
| sudo udevadm trigger --name-match=kvm | |
| - uses: ./.github/actions/workspace-install | |
| with: | |
| agent-device-version: ${{ inputs.agent-device-version }} | |
| - name: Build | |
| run: pnpm run build | |
| - name: Expo app | |
| id: app | |
| uses: ./.github/actions/expo-app | |
| with: | |
| platform: android | |
| gradle-cache-read-only: ${{ env.SAME_REPO != 'true' }} | |
| # The emulator lives for this step only (the action terminates it when | |
| # the step ends) and runs each `script` line in its own shell, so the | |
| # suite and its second pass over the failed tests are one line. Same | |
| # rerun as the iOS job. A new AVD's screen lock is None, which | |
| # device.lock() refuses, so the deterministic suite's first line sets | |
| # Swipe, a lock with no credential, for the lock test in | |
| # tests/device.e2e.ts. Swipe also shows its keyguard whenever the screen | |
| # turns off, which hid the app from every test of an agentic run, so the | |
| # same line keeps the screen on and the agentic suite keeps None. | |
| - name: Run the suite | |
| uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # v2.38.0 | |
| with: | |
| api-level: 36 | |
| arch: x86_64 | |
| target: google_apis | |
| profile: pixel_7 | |
| emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -no-metrics | |
| disable-animations: true | |
| working-directory: apps/mobile-benchmark | |
| script: | | |
| if [ "${{ matrix.suite }}" = deterministic ]; then adb shell svc power stayon true && adb shell locksettings set-disabled false; fi | |
| $E2E_RUN || $E2E_RUN --last-failed | |
| env: | |
| AI_GATEWAY_API_KEY: ${{ secrets.AI_GATEWAY_API_KEY }} | |
| GITHUB_TOKEN: ${{ inputs.agent-device-version == '' && github.token || '' }} | |
| E2E_MOBILE_BENCHMARK_ANDROID_APP: ${{ steps.app.outputs.app-path }} | |
| E2E_MOBILE_BENCHMARK_COMMENT: android${{ matrix.suite == 'agentic' && ' agent' || '' }} | |
| E2E_RUN: node node_modules/e2e/dist/cli/bin.js run --target android-emulator ${{ matrix.suite == 'agentic' && '--config e2e.agent.config.ts --output .e2e/agent --strict-cache' || '' }} | |
| - name: Failure screens | |
| if: ${{ failure() }} | |
| working-directory: apps/mobile-benchmark | |
| run: *failure-screens | |
| - name: Upload report | |
| if: ${{ !cancelled() }} | |
| continue-on-error: true | |
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | |
| with: | |
| name: mobile-benchmark-android-${{ matrix.suite }}-report | |
| path: *report-paths | |
| if-no-files-found: warn | |
| retention-days: 7 | |
| - name: Upload artifacts | |
| if: ${{ failure() }} | |
| continue-on-error: true | |
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | |
| with: | |
| name: mobile-benchmark-android-${{ matrix.suite }} | |
| path: *artifact-paths | |
| if-no-files-found: warn | |
| retention-days: 7 | |
| # A push to main saves the Expo app under main's scope, the one pull | |
| # requests and merge queue entries restore from, and boots no device. A hit | |
| # downloads nothing, so this is a fingerprint and a cache lookup. | |
| warm: | |
| name: ${{ matrix.platform }} app cache | |
| needs: changes | |
| if: ${{ needs.changes.outputs.warm == 'true' }} | |
| runs-on: ${{ matrix.runs-on }} | |
| timeout-minutes: 60 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - platform: ios | |
| runs-on: blacksmith-6vcpu-macos-26 | |
| - platform: android | |
| runs-on: blacksmith-4vcpu-ubuntu-2404 | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - uses: pnpm/action-setup@9fd676a19091d4595eefd76e4bd31c97133911f1 # v4.2.0 | |
| - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 | |
| with: | |
| node-version: 26 | |
| cache: pnpm | |
| - uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0 | |
| if: ${{ matrix.platform == 'android' }} | |
| with: | |
| distribution: temurin | |
| java-version: 17 | |
| - uses: ./.github/actions/workspace-install | |
| with: | |
| agent-device-version: ${{ inputs.agent-device-version }} | |
| - name: Expo app | |
| uses: ./.github/actions/expo-app | |
| with: | |
| platform: ${{ matrix.platform }} | |
| cache-only: 'true' | |
| # The one check the ruleset requires from this workflow. A skipped job | |
| # passes (the change cannot reach it); a failed or cancelled one fails it. | |
| gate: | |
| name: mobile gate | |
| needs: [changes, ios, android, warm] | |
| if: ${{ always() }} | |
| runs-on: blacksmith-4vcpu-ubuntu-2404 | |
| timeout-minutes: 5 | |
| steps: | |
| - name: Require every job to pass or skip | |
| env: | |
| RESULTS: ${{ toJSON(needs) }} | |
| run: | | |
| failed="$(jq -r '[to_entries[] | select(.value.result != "success" and .value.result != "skipped") | "\(.key) \(.value.result)"] | join(", ")' <<< "$RESULTS")" | |
| [ -z "$failed" ] || { echo "::error::$failed"; exit 1; } |