mattermost-mobile-upstream/detox/maestro/scripts/reset_ios_app.sh
yasser khan cd1ee5322b
Some checks are pending
ci / lint-typecheck (push) Waiting to run
ci / detox-lint-typecheck (push) Waiting to run
ci / test (push) Waiting to run
E2E: CI flake fixes; bump Maestro 2.11.0 and Detox 20.51.4 (#10257)
* fix(maestro): reset the iOS app before each batch; wait for timed-out config writes

- iOS: clearState reinstalls and launches at once, and on a loaded runner FrontBoard
  may not know the app yet. reset_ios_app.sh reinstalls it and returns once it
  launches; flows then skip clearState. A failed reset fails the batch.
- A config/patch the client timed out on is usually still applied, since saves run one
  at a time. Wait for it to land instead of resending, which queued more saves.
- iOS merges the server URL field label with its inline error; match the merged text.

* chore(e2e): bump Maestro to 2.11.0

* ci(e2e): give the Android emulator working DNS before specs run

Start the emulator with explicit resolvers, wait for it to resolve SITE_1 before
installing the app, and cold-boot it once if it cannot.

* ci(e2e): re-run iOS specs that failed only because the runner lost its route

The runner Mac can lose its network route for ~2 s, failing every request with -1009.
After a failed shard, re-run once only the spec files whose every failing test shows that
signature in its own device.log, and merge the results. Any other failure stays red.

* chore(e2e): bump Detox to 20.51.4

Adds regex toHaveText and RegExp/array URL blacklists; existing string-array
setURLBlacklist calls are unchanged. The postinstall patches still apply.

* fix(e2e): keep failures red when an iOS re-run or app reset fails

- Clear a shard failure only when the route-loss re-run and the merge both succeed.
- Record a JUnit failure when an isolated Maestro step cannot reset the app.
- Use /etc/resolv.conf for emulator DNS when systemd-resolved is absent.
- Set the runner-reset flag only when there is a device to reset.

* fix(maestro): bound simctl launch and terminate in the iOS app reset

* fix(maestro): find the server URL field by id when scrolling back to it

* fix(maestro): stop the batches when the config baseline cannot be applied
2026-10-19 22:58:41 +05:30

56 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
# See LICENSE.txt for license information.
#
# Reinstall the iOS app on a simulator for a clean state, and return only once it launches.
#
# Maestro's launchApp clearState:true reinstalls the app and launches it at once. On a loaded
# runner FrontBoard can lag the install, so the launch fails with "unknown to FrontBoard" and
# Maestro's retry does not cover that error. Flows run with MAESTRO_APP_RESET_BY_RUNNER=true
# skip clearState and rely on this reset instead.
#
# Usage: reset_ios_app.sh <simulator-udid> <bundle-id>
set -euo pipefail
if [[ $# -ne 2 ]]; then
echo "usage: $0 <simulator-udid> <bundle-id>" >&2
exit 2
fi
udid="$1"
bundle_id="$2"
LAUNCH_READY_TIMEOUT_SECS="${LAUNCH_READY_TIMEOUT_SECS:-180}"
# simctl launch and terminate can hang on iOS 26.x, so bound each call.
bounded() {
local secs=$1
shift
if command -v timeout >/dev/null 2>&1; then
timeout "$secs" "$@"
else
perl -e 'alarm shift; exec @ARGV' "$secs" "$@"
fi
}
app_path="$(xcrun simctl get_app_container "$udid" "$bundle_id" app)"
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
cp -R "$app_path" "$tmp_dir/"
bounded 15 xcrun simctl terminate "$udid" "$bundle_id" 2>/dev/null || true
xcrun simctl uninstall "$udid" "$bundle_id"
xcrun simctl install "$udid" "$tmp_dir/$(basename "$app_path")"
# Launching is the only check that FrontBoard knows the app; listapps reads the install registry.
deadline=$((SECONDS + LAUNCH_READY_TIMEOUT_SECS))
attempts=0
until bounded 30 xcrun simctl launch "$udid" "$bundle_id" >/dev/null 2>&1; do
attempts=$((attempts + 1))
if ((SECONDS >= deadline)); then
echo "::error::$bundle_id was reinstalled but would not launch within ${LAUNCH_READY_TIMEOUT_SECS}s" >&2
exit 1
fi
sleep 2
done
bounded 15 xcrun simctl terminate "$udid" "$bundle_id" 2>/dev/null || true
echo "==> Reinstalled $bundle_id; it launched after $attempts failed attempt(s)"