Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

ci(phones): every phone build is started on an emulator or simulator before it can ship

Jareer76ee4233475d
diff --git a/.github/workflows/mobile.yml b/.github/workflows/mobile.yml
index e36d2cac..a41cb061 100644
--- a/.github/workflows/mobile.yml
+++ b/.github/workflows/mobile.yml
@@ -29,6 +29,23 @@ name: Build for phones
# scripts it runs, and a pull request's run never sees it at all. The .ipa
# is ad-hoc signed: a tester signs it with their own Apple ID on the way
# onto a phone (AltStore, Sideloadly, Xcode's Devices window all do this).
+#
+# No phone build passes unless it starts on a phone. The APK the Android
+# job uploads, the very file a release ships, is installed on an emulator
+# of Android 11 (API 30, where #312's preview failed) and of Android 15
+# (API 35, the SDK the app targets) and started there
+# (scripts/ci/smoke-android.sh). The APK is arm64 only, and the emulators
+# are x86_64 ones on Linux with KVM, which run arm64 code through the ARM
+# translation Google's x86_64 images carry from API 30 on: GitHub's arm64
+# Macs cannot run the emulator at all (no nested virtualisation, so HVF
+# fails with HV_UNSUPPORTED), and an x86_64 APK would be a different build
+# from the one that ships. The iPhone is tested the same way through the
+# iOS Simulator, which needs a build of its own for aarch64-apple-ios-sim,
+# made beside the device build and never shipped
+# (scripts/ci/smoke-ios.sh). release.yml waits on every job here, so a
+# release with a phone that does not start is never published; what the
+# smokes leave behind (logs, screenshots) is uploaded under smoke-*, a
+# name the release does not pick up.
on:
workflow_call:
inputs:
@@ -232,6 +249,70 @@ jobs:
path: stage/*
if-no-files-found: error
+ # The APK the job above uploaded, installed and started on an emulator;
+ # see the top of this file for why an x86_64 one. A release's run tests
+ # the APK signed with the repository's key, which is the one it ships.
+ android-smoke:
+ name: Android smoke (API ${{ matrix.api }})
+ needs: android
+ runs-on: ubuntu-latest
+ timeout-minutes: 45
+ strategy:
+ fail-fast: false
+ matrix:
+ api: [30, 35]
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ ref: ${{ inputs.ref }}
+ sparse-checkout: scripts/ci
+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
+ timeout-minutes: 10
+ with:
+ name: Concat-android-arm64
+ path: apk
+
+ # The emulator needs KVM, which the runner has but only root may
+ # open until a udev rule says otherwise.
+ - name: KVM for the emulator
+ timeout-minutes: 2
+ 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
+
+ # A Google APIs image, which has the ARM translation (the ATD images
+ # leave it out), on a phone-sized screen with SwiftShader standing in
+ # for the GPU. The emulator keeps its sound device, as a phone does:
+ # the engine opens an audio stream as it starts. The SDK pieces the
+ # action downloads are checked by sdkmanager against Google's own
+ # repository digests, not through scripts/ci/deps.lock.
+ - name: Start the APK on an emulator
+ timeout-minutes: 30
+ uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # v2.38.0
+ with:
+ api-level: ${{ matrix.api }}
+ target: google_apis
+ arch: x86_64
+ profile: pixel_6
+ cores: 4
+ ram-size: 4096M
+ disk-size: 6G
+ emulator-boot-timeout: 900
+ emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -no-boot-anim -camera-back none -camera-front none
+ disable-animations: true
+ script: scripts/ci/smoke-android.sh --out smoke-android --wait 60 apk/Concat-*.apk
+
+ # The log, the screenshot and the rest, pass or fail.
+ - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
+ if: always()
+ timeout-minutes: 10
+ with:
+ name: smoke-android-api${{ matrix.api }}
+ path: smoke-android/
+ if-no-files-found: warn
+
ios:
name: iOS arm64
runs-on: macos-15
@@ -328,3 +409,119 @@ jobs:
name: Concat-ios-arm64
path: stage/*
if-no-files-found: error
+
+ # The iPhone build again, for the iOS Simulator on this Mac, bundled the
+ # way the device build is and started there; it is never shipped. The
+ # same FFmpeg and sherpa-onnx, for the simulator: ffmpeg-mobile.sh and
+ # ios-app.sh take aarch64-apple-ios-sim, and the xcframework
+ # sherpa-mobile.sh fetches for iOS carries a simulator slice beside the
+ # device one. mobile-env.sh does not know the simulator yet, so the
+ # build's environment is written out in the build step below.
+ ios-simulator:
+ name: iOS simulator smoke
+ runs-on: macos-15
+ timeout-minutes: 90
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ ref: ${{ inputs.ref }}
+ - name: The pinned toolchain
+ id: toolchain
+ timeout-minutes: 1
+ run: echo "channel=$(sed -n 's/^channel = "\(.*\)"/\1/p' src/rust-toolchain.toml)" >> "$GITHUB_OUTPUT"
+ - uses: dtolnay/rust-toolchain@e2a55d2ffb04f378e9626c28d38b36d230d1e12f # master (v1), 2026-10-09
+ timeout-minutes: 10
+ with:
+ toolchain: ${{ steps.toolchain.outputs.channel }}
+ targets: aarch64-apple-ios-sim
+
+ - run: brew install cmake
+ timeout-minutes: 10
+
+ - name: FFmpeg for the iOS Simulator (cached)
+ id: ffmpeg
+ timeout-minutes: 10
+ uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
+ with:
+ path: src/vendor/ffmpeg/aarch64-apple-ios-sim
+ key: ffmpeg-aarch64-apple-ios-sim-${{ hashFiles('src/scripts/ffmpeg-mobile.sh') }}
+ - name: FFmpeg for the iOS Simulator
+ if: steps.ffmpeg.outputs.cache-hit != 'true'
+ timeout-minutes: 45
+ run: src/scripts/ffmpeg-mobile.sh aarch64-apple-ios-sim
+ - name: FFmpeg for the iOS Simulator (save)
+ if: steps.ffmpeg.outputs.cache-hit != 'true'
+ timeout-minutes: 10
+ uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
+ with:
+ path: src/vendor/ffmpeg/aarch64-apple-ios-sim
+ key: ${{ steps.ffmpeg.outputs.cache-primary-key }}
+
+ # The device's fetch, which brings the whole xcframework; the binary
+ # links against the simulator's slice of it, under the name the
+ # linker looks for, as mobile-env.sh does with the device's slice.
+ - name: sherpa-onnx for the iOS Simulator
+ timeout-minutes: 10
+ run: |
+ set -euo pipefail
+ src/scripts/sherpa-mobile.sh aarch64-apple-ios
+ framework=$(find src/vendor/sherpa-onnx/ios -maxdepth 2 -name '*.xcframework' | head -1)
+ binary=$PWD/$framework/ios-arm64_x86_64-simulator/SherpaOnnxC.framework/SherpaOnnxC
+ [ -f "$binary" ] || { echo "::error::no simulator slice in $framework"; exit 1; }
+ mkdir -p src/vendor/sherpa-onnx/ios/lib-sim
+ ln -sf "$binary" src/vendor/sherpa-onnx/ios/lib-sim/libsherpa-onnx-c-api.dylib
+
+ - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
+ timeout-minutes: 10
+ with:
+ workspaces: src
+ key: aarch64-apple-ios-sim
+
+ # What `scripts/mobile-env.sh aarch64-apple-ios` exports, for the
+ # simulator: its FFmpeg, its slice of sherpa-onnx, and the same
+ # oldest iOS. whisper.cpp's CMake build is told the simulator's SDK
+ # outright (whisper-rs-sys hands it every CMAKE_ variable): left to
+ # itself, CMake's iOS platform takes the device's.
+ - name: Build
+ working-directory: src
+ timeout-minutes: 75
+ run: |
+ set -o pipefail
+ export FFMPEG_DIR="$PWD/vendor/ffmpeg/aarch64-apple-ios-sim"
+ export SHERPA_ONNX_LIB_DIR="$PWD/vendor/sherpa-onnx/ios/lib-sim"
+ export IPHONEOS_DEPLOYMENT_TARGET=15.0
+ export CMAKE_OSX_SYSROOT=iphonesimulator
+ cargo build --release -p concat --target aarch64-apple-ios-sim 2>&1 | tee build.log
+
+ - name: Build log to the summary (failure only)
+ if: failure()
+ timeout-minutes: 1
+ run: |
+ if [ -f src/build.log ]; then
+ {
+ echo "### Build failed: iOS Simulator"
+ echo '```'
+ tail -n 150 src/build.log
+ echo '```'
+ } >> "$GITHUB_STEP_SUMMARY"
+ fi
+
+ - name: Bundle
+ timeout-minutes: 5
+ run: src/scripts/ios-app.sh aarch64-apple-ios-sim release
+
+ # A fresh iPhone simulator: `--smoke` through the first publish, then
+ # a launch as from the home screen, watched for a minute.
+ - name: Start the app on a simulator
+ timeout-minutes: 25
+ run: scripts/ci/smoke-ios.sh --out smoke-ios --wait 60 src/target/aarch64-apple-ios-sim/release/Concat.app
+
+ # The app's output, the system log, the screenshot and any crash
+ # report, pass or fail.
+ - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
+ if: always()
+ timeout-minutes: 10
+ with:
+ name: smoke-ios-simulator
+ path: smoke-ios/
+ if-no-files-found: warn
diff --git a/scripts/ci/smoke-android.sh b/scripts/ci/smoke-android.sh
new file mode 100755
index 00000000..1894abd1
--- /dev/null
+++ b/scripts/ci/smoke-android.sh
@@ -0,0 +1,272 @@
+#!/usr/bin/env bash
+# Installs the built APK on an Android device or emulator, starts it the
+# way the launcher does, and fails if it does not stay up: nothing else in
+# the phone build ever runs what it packages.
+#
+# smoke-android.sh [--out DIR] [--wait SECS] [--ready REGEX] [--no-install]
+# [--package NAME] APK
+#
+# On whatever device adb talks to (ANDROID_SERIAL picks one of several):
+# waits for it to finish booting; checks the device can run one of the
+# ABIs the APK carries (an x86_64 emulator image runs an arm64-only APK
+# through its ARM translation, and says so in ro.product.cpu.abilist);
+# installs the APK; starts its launcher activity with `am start -W`; and
+# then watches for WAIT seconds (45 by default). It fails as soon as
+#
+# - the process is gone,
+# - logcat has, from the app, a Java crash (FATAL EXCEPTION), a native
+# one (Fatal signal), a Rust panic (panicked at), an ANR (ANR in), or
+# one of the app's own start-up failures (could not start, an event
+# loop that ended in an error, or a preview that failed: the window's
+# "Preview failed" notice, which the log carries as `preview: ...`,
+# #312),
+#
+# and passes if none of that has happened by the end of the wait, with the
+# app's own first line ("Concat <version> starting") in the log, so a pass
+# means its native code ran. With --ready, it also requires a line matching
+# REGEX (an extended regular expression) by the end of the wait, and stops
+# waiting once it appears.
+#
+# Whatever the outcome it leaves in DIR (smoke-android by default): the
+# whole logcat from before the launch to the end, the app's lines alone,
+# a screenshot of the screen at the end, the window focus, and the
+# device's properties. CI uploads that folder. The package is
+# app.concat.editor unless --package names another.
+#
+# --no-install starts what is already installed, which leaves a device
+# somebody is using as it was apart from the restart of the app. Runs in
+# CI (mobile.yml) and locally against any device adb can see. Needs adb,
+# unzip and perl.
+set -euo pipefail
+
+out=smoke-android
+wait_secs=45
+ready=""
+install=1
+package=app.concat.editor
+
+usage() {
+ echo "usage: $0 [--out DIR] [--wait SECS] [--ready REGEX] [--no-install] [--package NAME] APK" >&2
+ exit 2
+}
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+ --out) out=${2:?}; shift 2 ;;
+ --wait) wait_secs=${2:?}; shift 2 ;;
+ --ready) ready=${2:?}; shift 2 ;;
+ --no-install) install=0; shift ;;
+ --package) package=${2:?}; shift 2 ;;
+ -h|--help) usage ;;
+ --*) usage ;;
+ *) break ;;
+ esac
+done
+[ $# -eq 1 ] || usage
+apk=$1
+[ -f "$apk" ] || { echo "smoke: no APK at $apk" >&2; exit 2; }
+
+say() { printf '\n== %s\n' "$*"; }
+note() {
+ if [ -n "${GITHUB_ACTIONS:-}" ]; then echo "::warning::$*"; else echo "smoke: $*"; fi
+}
+
+mkdir -p "$out"
+logcat_file=$out/logcat.txt
+logcat_pid=""
+collected=""
+
+# Everything the folder should hold, gathered on the way out whatever the
+# outcome: a failure is exactly when the screenshot and the log are wanted.
+collect() {
+ collected=1
+ set +e
+ if [ -n "$logcat_pid" ]; then
+ kill "$logcat_pid" 2>/dev/null
+ wait "$logcat_pid" 2>/dev/null
+ logcat_pid=""
+ fi
+ adb exec-out screencap -p > "$out/screen.png" 2>/dev/null || rm -f "$out/screen.png"
+ {
+ adb shell dumpsys activity activities 2>/dev/null | grep -i 'ResumedActivity'
+ adb shell dumpsys window 2>/dev/null | grep -E 'mCurrentFocus|mFocusedApp'
+ } | tr -d '\r' > "$out/focus.txt"
+ adb shell getprop > "$out/getprop.txt" 2>/dev/null
+ # Tombstones for a native crash, where the device lets them be read.
+ adb logcat -d -b crash -v threadtime > "$out/logcat-crash.txt" 2>/dev/null
+ if [ -f "$logcat_file" ]; then
+ grep -E ' concat +:' "$logcat_file" > "$out/concat.txt" || true
+ fi
+ set -e
+}
+# And on a way out nobody wrote a `fail` for - a command that `set -e`
+# ends the script on - so the background logcat is stopped and the folder
+# still holds what the failure left.
+trap '[ -n "$collected" ] || collect' EXIT
+
+fail() {
+ collect
+ if [ -s "$out/concat.txt" ]; then
+ echo "-- the app's last lines --"
+ tail -n 60 "$out/concat.txt"
+ fi
+ if [ -n "${GITHUB_ACTIONS:-}" ]; then echo "::error::$*"; else echo "smoke: $*" >&2; fi
+ exit 1
+}
+
+# A time limit without coreutils, so this runs on a Mac too: perl's alarm,
+# which the exec keeps. A command that overstays it dies of SIGALRM, 142.
+limit() {
+ local secs=$1
+ shift
+ perl -e 'alarm shift; exec @ARGV or die "exec: $!"' "$secs" "$@"
+}
+
+say "the device"
+limit 300 adb wait-for-device || fail "no device came up for adb within 300s"
+booted=""
+for _ in $(seq 1 150); do
+ booted=$(adb shell getprop sys.boot_completed 2>/dev/null | tr -d '\r' || true)
+ [ "$booted" = 1 ] && break
+ sleep 2
+done
+[ "$booted" = 1 ] || fail "the device did not finish booting within 300s"
+sdk=$(adb shell getprop ro.build.version.sdk | tr -d '\r')
+release=$(adb shell getprop ro.build.version.release | tr -d '\r')
+abilist=$(adb shell getprop ro.product.cpu.abilist | tr -d '\r')
+model=$(adb shell getprop ro.product.model | tr -d '\r')
+echo "$model, Android $release (API $sdk), ABIs $abilist"
+
+# The ABIs the APK carries native code for, from its lib/ folders. One the
+# device lists is one it can load, natively or through its translation.
+apk_abis=$(unzip -Z1 "$apk" | sed -n 's#^lib/\([^/]*\)/.*#\1#p' | sort -u | tr '\n' ' ')
+echo "the APK carries: ${apk_abis:-no native code}"
+runnable=""
+for abi in $apk_abis; do
+ case ",$abilist," in *",$abi,"*) runnable=$abi; break ;; esac
+done
+[ -n "$runnable" ] || [ -z "$apk_abis" ] || fail "the device runs $abilist and the APK carries only $apk_abis: an x86_64 emulator image needs ARM translation (API 30+ google_apis or default images have it, ATD images do not)"
+primary=${abilist%%,*}
+if [ -n "$runnable" ] && [ "$runnable" != "$primary" ]; then
+ echo "the app runs as $runnable through the device's translation for $primary"
+fi
+
+if [ "$install" = 1 ]; then
+ say "install"
+ # -g grants every runtime permission the manifest asks for, so no
+ # permission prompt stands between the launch and the window.
+ limit 300 adb install -r -g "$apk" < /dev/null \
+ || fail "adb install failed (an installed build signed with another key has to be uninstalled first)"
+fi
+adb shell pm path "$package" > /dev/null 2>&1 || fail "$package is not installed"
+
+# The activity the launcher would start, asked of the package manager
+# rather than written down: cargo-apk names it, not this script.
+activity=$(adb shell cmd package resolve-activity --brief -c android.intent.category.LAUNCHER "$package" 2>/dev/null \
+ | tr -d '\r' | tail -n 1)
+case "$activity" in
+ "$package"/*) ;;
+ *) fail "no launcher activity for $package (resolve-activity said: $activity)" ;;
+esac
+
+say "start $activity"
+# A cold start: the app stopped, the log emptied and made big enough to
+# hold the whole run, and read into a file from before the launch on, so
+# the app's first line cannot have scrolled out of the device's buffer by
+# the time it is looked for.
+adb shell am force-stop "$package" || true
+adb logcat -G 16M > /dev/null 2>&1 || true
+adb logcat -c || true
+adb logcat -v threadtime > "$logcat_file" 2>&1 &
+logcat_pid=$!
+started=$(limit 180 adb shell am start -W -n "$activity" 2>&1 | tr -d '\r') \
+ || fail "am start did not return within 180s"
+printf '%s\n' "$started"
+grep -q '^Status: ok' <<< "$started" || fail "am start did not report the launch as ok"
+
+# The lines that mean the start-up failed, wherever they come from: the
+# runtime's crash report, the C library's on a fatal signal, Rust's on a
+# panic (the app's hook writes the standard message into its own line),
+# the system's on an ANR, and the app's own on a start-up it gave up on or
+# a window whose event loop ended in an error.
+# Only the app's count: a line written by one of its processes, or one
+# that names it (the system's ANR report does). An emulator's own services
+# crash now and then while it settles, and that is not this app failing.
+# The app's lines read "concat : <module>: <message>".
+fatal='FATAL EXCEPTION|Fatal signal [0-9]+|panicked at|ANR in |Preview failed'
+fatal+='| concat +: ([A-Za-z0-9_:]+: )?(preview: |could not start|close: event loop exited [(]ok=false[)])'
+
+# Every process the app has had since the launch: the ones the activity
+# manager reports starting, which a process that dies at once still has,
+# and the one running now.
+# Sets `running` to the process there is now, empty when there is none,
+# and adds it to `pids`. Called in this shell, not in $( ): it sets both.
+pids=""
+running=""
+app_pids() {
+ running=$(adb shell pidof "$package" 2>/dev/null | tr -d '\r' || true)
+ pids=$(
+ {
+ sed -n "s/.*Start proc \([0-9][0-9]*\):$package\/.*/\1/p" "$logcat_file"
+ printf '%s %s\n' "$running" "$pids" | tr ' ' '\n'
+ } | grep -E '^[0-9]+$' | sort -u | tr '\n' ' '
+ )
+}
+
+# The fatal lines that are the app's, from the log so far. threadtime puts
+# the writing process's id in the third column.
+fatal_lines() {
+ awk -v re="$fatal" -v pids=" $pids " -v pkg="$package" '
+ $0 ~ re && (index(pids, " " $3 " ") || index($0, pkg)) { print; if (++n == 5) exit }
+ ' "$logcat_file"
+}
+
+say "watch for ${wait_secs}s"
+seen_ready=""
+deadline=$((SECONDS + wait_secs))
+while [ "$SECONDS" -lt "$deadline" ]; do
+ sleep 2
+ app_pids
+ found=$(fatal_lines)
+ if [ -n "$found" ]; then
+ printf '%s\n' "$found"
+ fail "the app failed on start: $(head -n 1 <<< "$found")"
+ fi
+ if [ -z "$running" ]; then
+ # The log can trail the death by a moment; the reason is worth the wait.
+ gone=$((wait_secs - deadline + SECONDS))
+ sleep 3
+ found=$(fatal_lines)
+ [ -z "$found" ] || printf '%s\n' "$found"
+ fail "the app's process is gone ${gone}s after the launch${found:+: $(head -n 1 <<< "$found")}"
+ fi
+ if [ -n "$ready" ] && grep -E -q -- "$ready" "$logcat_file"; then
+ seen_ready=1
+ echo "the ready line is in the log: $(grep -E -m 1 -- "$ready" "$logcat_file")"
+ break
+ fi
+done
+
+say "the outcome"
+collect
+cat "$out/focus.txt" || true
+# A process can outlive its window: an android_main that returns, on an
+# error it logged as anything else, finishes the activity and leaves the
+# process cached. The activity in front is the app's, or it did not start.
+grep -i 'ResumedActivity' "$out/focus.txt" | grep -q "$package/" \
+ || fail "the app's activity is not the one in front after ${wait_secs}s"
+# The app's own first line, from android_main: proof its native code ran,
+# and not only that a process by its name exists.
+grep -E -q ' concat +: ([A-Za-z0-9_:]+: )?Concat .* starting' "$logcat_file" \
+ || fail "the app's first line (\"Concat <version> starting\") never reached logcat"
+if [ -n "$ready" ] && [ -z "$seen_ready" ]; then
+ fail "no line matching '$ready' within ${wait_secs}s"
+fi
+if ! grep -E 'mCurrentFocus' "$out/focus.txt" | grep -q "$package"; then
+ note "the window in focus is not the app's: $(grep -E 'mCurrentFocus' "$out/focus.txt" | tr -s ' ')"
+fi
+echo "-- the app's lines --"
+head -n 40 "$out/concat.txt" || true
+echo
+echo "the app is up after ${wait_secs}s with nothing fatal in the log; see $out/"
+say "ok"
diff --git a/scripts/ci/smoke-ios.sh b/scripts/ci/smoke-ios.sh
new file mode 100755
index 00000000..11a00248
--- /dev/null
+++ b/scripts/ci/smoke-ios.sh
@@ -0,0 +1,224 @@
+#!/usr/bin/env bash
+# Installs the simulator build of the iOS app on an iOS Simulator, starts
+# it, and fails if it does not come up and stay up: nothing else in the
+# phone build ever runs what it packages.
+#
+# smoke-ios.sh [--out DIR] [--wait SECS] [--device UDID] [--no-smoke] Concat.app
+#
+# Concat.app is the bundle scripts/ios-app.sh lays out for
+# aarch64-apple-ios-sim; a device build cannot run on a simulator, and the
+# script says so rather than failing at the install. On a fresh iPhone
+# simulator of the newest iOS runtime Xcode has (or on UDID, which is left
+# booted and kept), it
+#
+# 1. starts the app with `--smoke`, which runs the whole start-up - the
+# GPU, the engine, the window's component and every model handed to
+# it - as far as the window's first publish, logs "smoke: ok" and
+# exits 0; and fails unless that line comes back within 180s;
+# 2. starts the app as the home screen would and watches it for WAIT
+# seconds (45 by default), failing as soon as its process is gone or
+# its output or the system log has a Rust panic (panicked at), an
+# uncaught Objective-C exception, one of the app's own start-up
+# failures (could not start, an event loop that ended in an error),
+# or a preview that failed ("Preview failed", logged as
+# `preview: ...`, #312); and failing at the end unless the app's
+# first log line (the logger's "Concat <version> · ios ...") is there.
+#
+# --no-smoke leaves out the first part. Whatever the outcome it leaves in
+# DIR (smoke-ios by default): the app's own output from both runs, the
+# system log of its process, a screenshot at the end, and any crash report
+# the run left. CI uploads that folder. Runs in CI (mobile.yml) and locally
+# on a Mac with Xcode; needs python3 to read simctl's lists.
+set -euo pipefail
+
+out="smoke-ios"
+wait_secs=45
+device=""
+smoke=1
+
+usage() {
+ echo "usage: $0 [--out DIR] [--wait SECS] [--device UDID] [--no-smoke] Concat.app" >&2
+ exit 2
+}
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+ --out) out=${2:?}; shift 2 ;;
+ --wait) wait_secs=${2:?}; shift 2 ;;
+ --device) device=${2:?}; shift 2 ;;
+ --no-smoke) smoke=0; shift ;;
+ -h|--help) usage ;;
+ --*) usage ;;
+ *) break ;;
+ esac
+done
+[ $# -eq 1 ] || usage
+app=${1%/}
+[ -d "$app" ] || { echo "smoke: no app bundle at $app" >&2; exit 2; }
+
+say() { printf '\n== %s\n' "$*"; }
+
+mkdir -p "$out"
+created=""
+launch_pid=""
+log_pid=""
+# Older than anything the run writes, so a crash report can be told apart
+# from the ones already there.
+mark=$(mktemp)
+
+# A time limit without coreutils: perl's alarm, which the exec keeps. A
+# command that overstays it dies of SIGALRM, status 142.
+limit() {
+ local secs=$1
+ shift
+ perl -e 'alarm shift; exec @ARGV or die "exec: $!"' "$secs" "$@"
+}
+
+# Everything the folder should hold, gathered on the way out whatever the
+# outcome, and the simulator put back the way it was found.
+cleanup() {
+ set +e
+ if [ -n "$device" ]; then
+ xcrun simctl io "$device" screenshot "$out/screen.png" > /dev/null 2>&1 || rm -f "$out/screen.png"
+ [ -z "${bundle_id:-}" ] || xcrun simctl terminate "$device" "$bundle_id" > /dev/null 2>&1
+ fi
+ for pid in $launch_pid $log_pid; do
+ kill "$pid" 2>/dev/null
+ wait "$pid" 2>/dev/null
+ done
+ # A crash report written since the run started, by the app's process.
+ find "$HOME/Library/Logs/DiagnosticReports" -maxdepth 1 -name 'Concat*' -newer "$mark" \
+ -exec cp {} "$out/" \; 2>/dev/null
+ rm -f "$mark"
+ if [ -n "$created" ]; then
+ xcrun simctl shutdown "$created" > /dev/null 2>&1
+ xcrun simctl delete "$created" > /dev/null 2>&1
+ fi
+ set -e
+}
+trap cleanup EXIT
+
+fail() {
+ for f in "$out/smoke-run.txt" "$out/console.txt"; do
+ if [ -s "$f" ]; then
+ echo "-- the last lines of $(basename "$f") --"
+ tail -n 60 "$f"
+ fi
+ done
+ if [ -n "${GITHUB_ACTIONS:-}" ]; then echo "::error::$*"; else echo "smoke: $*" >&2; fi
+ exit 1
+}
+
+say "the bundle"
+plist=$app/Info.plist
+[ -f "$plist" ] || fail "no Info.plist in $app"
+bundle_id=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$plist")
+executable=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleExecutable' "$plist")
+[ -x "$app/$executable" ] || fail "no executable $executable in $app"
+# The platform the binary was linked for, from its load commands: 7 is the
+# iOS Simulator, 2 a phone.
+platform=$(otool -l "$app/$executable" | awk '/LC_BUILD_VERSION/ { found = 1 } found && $1 == "platform" { print $2; exit }')
+case "$platform" in
+ 7|IOSSIMULATOR) ;;
+ *) fail "$app/$executable is built for platform ${platform:-unknown}, not the iOS Simulator (7): build for aarch64-apple-ios-sim" ;;
+esac
+codesign --verify --deep --strict "$app" || fail "the bundle's signature does not verify"
+echo "$bundle_id, $executable, built for the iOS Simulator"
+
+say "the simulator"
+if [ -z "$device" ]; then
+ # A fresh iPhone on the newest iOS runtime there is, so the run starts
+ # from nothing a run before left behind.
+ pick=$(python3 -I -c '
+import json, subprocess, sys
+def simctl(*what):
+ return json.loads(subprocess.run(["xcrun", "simctl", "list", "-j", *what],
+ check=True, capture_output=True, text=True).stdout)
+runtimes = [r for r in simctl("runtimes", "available")["runtimes"]
+ if r.get("platform", r["name"].split()[0]) == "iOS"]
+if not runtimes:
+ sys.exit("no iOS simulator runtime is installed")
+runtime = max(runtimes, key=lambda r: [int(p) for p in r["version"].split(".")])
+# The newest iPhone the runtime runs, and of those the plain model.
+newness = {t["identifier"]: t.get("minRuntimeVersion", 0) for t in simctl("devicetypes")["devicetypes"]}
+phones = [t for t in runtime.get("supportedDeviceTypes", []) if t.get("productFamily") == "iPhone"]
+if not phones:
+ sys.exit("the runtime " + runtime["name"] + " runs no iPhone")
+phone = max(phones, key=lambda t: (newness.get(t["identifier"], 0), -len(t["name"])))
+print(runtime["identifier"], phone["identifier"], runtime["name"] + ", " + phone["name"])
+') || fail "could not choose a simulator"
+ read -r runtime type name <<< "$pick"
+ echo "a new $name"
+ created=$(xcrun simctl create concat-smoke "$type" "$runtime")
+ device=$created
+fi
+echo "device $device"
+state=$(xcrun simctl list devices | grep -F "$device" || true)
+case "$state" in
+ *"(Booted)"*) ;;
+ *) xcrun simctl boot "$device" || fail "the simulator did not boot" ;;
+esac
+limit 600 xcrun simctl bootstatus "$device" -b > /dev/null || fail "the simulator did not finish booting within 600s"
+
+say "install"
+limit 300 xcrun simctl install "$device" "$app" || fail "simctl install failed"
+
+# The system's log of the app's process, for what never reaches its own
+# output: UIKit's complaints, an uncaught exception, the reason it died.
+xcrun simctl spawn "$device" log stream --level debug --style compact \
+ --predicate "process == \"$executable\"" > "$out/oslog.txt" 2>&1 &
+log_pid=$!
+
+# The lines that mean the start-up failed: Rust's on a panic (the app's
+# hook writes the standard message into its own line), Objective-C's on an
+# uncaught exception, and the app's own on a start-up it gave up on, on a
+# window whose event loop ended in an error, or on a preview that failed.
+fatal='panicked at|Terminating app due to uncaught exception|Preview failed|(^|: )(preview: |could not start|close: event loop exited [(]ok=false[)])'
+
+if [ "$smoke" = 1 ]; then
+ say "$executable --smoke"
+ status=0
+ limit 180 xcrun simctl launch --console-pty --terminate-running-process "$device" "$bundle_id" --smoke \
+ > "$out/smoke-run.txt" 2>&1 || status=$?
+ tail -n 40 "$out/smoke-run.txt"
+ [ "$status" -ne 142 ] || fail "--smoke was still running after 180s"
+ if found=$(grep -E -m 5 "$fatal" "$out/smoke-run.txt"); then
+ fail "--smoke failed: $(head -n 1 <<< "$found")"
+ fi
+ grep -q 'smoke: ok' "$out/smoke-run.txt" || fail "--smoke ended without \"smoke: ok\" (simctl exited $status)"
+ # "smoke: ok" and then a crash on the way out is still a crash: v0.2.7-rc.2's
+ # Linux arm64 bundle did exactly that. simctl's --console-pty ends with
+ # the app's process; whether its status is the app's own is for the first
+ # run to show, and anything but 0 fails either way.
+ [ "$status" -eq 0 ] || fail "--smoke said \"smoke: ok\" and then simctl exited with $status"
+fi
+
+say "start $bundle_id, and watch it for ${wait_secs}s"
+xcrun simctl launch --console-pty --terminate-running-process "$device" "$bundle_id" \
+ > "$out/console.txt" 2>&1 &
+launch_pid=$!
+deadline=$((SECONDS + wait_secs))
+while [ "$SECONDS" -lt "$deadline" ]; do
+ sleep 2
+ if found=$(cat "$out/console.txt" "$out/oslog.txt" | grep -E -m 5 "$fatal"); then
+ printf '%s\n' "$found"
+ fail "the app failed on start: $(head -n 1 <<< "$found")"
+ fi
+ # simctl's --console-pty lasts exactly as long as the app's process does.
+ if ! kill -0 "$launch_pid" 2>/dev/null; then
+ status=0
+ wait "$launch_pid" || status=$?
+ launch_pid=""
+ fail "the app's process is gone $((wait_secs - deadline + SECONDS))s after the launch (simctl exited $status)"
+ fi
+done
+
+say "the outcome"
+# The logger's first line, written once the app's own code is running.
+grep -E -q 'Concat [0-9][^ ]* · ios' "$out/console.txt" \
+ || fail "the app's first log line (\"Concat <version> · ios ...\") never reached its output"
+echo "-- the app's output --"
+head -n 40 "$out/console.txt"
+echo
+echo "the app is up after ${wait_secs}s with nothing fatal in its output; see $out/"
+say "ok"