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
76 changes: 63 additions & 13 deletions .maestro/run_scene_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fi
export DEVELOPER_DIR
export MAESTRO_CLI_NO_ANALYTICS=1

for command in bundle jq maestro node npm npx ruby xcodebuild xcrun; do
for command in bundle jq maestro node npm npx python3 ruby xcodebuild xcrun; do
command -v "$command" >/dev/null 2>&1 || {
echo "error: required command '$command' is not installed" >&2
exit 2
Expand Down Expand Up @@ -77,8 +77,13 @@ package_dir=""
derived_data=""
flow_log=""
flow_pid=""
boot_pid=""
installed_app=false
current_phase="setup"
enter_phase() {
current_phase="$1"
echo "==> phase: $current_phase"
}
cleanup() {
local exit_code=$?
set +e
Expand All @@ -98,6 +103,10 @@ cleanup() {
if [[ -n "$flow_log" ]]; then
rm -f "$flow_log"
fi
if [[ -n "$boot_pid" ]]; then
kill "$boot_pid" >/dev/null 2>&1 || true
wait "$boot_pid" 2>/dev/null || true
fi
if [[ "$installed_app" == true ]]; then
xcrun simctl terminate "$device_id" "$APP_ID" >/dev/null 2>&1 || true
xcrun simctl uninstall "$device_id" "$APP_ID" >/dev/null 2>&1 || true
Expand Down Expand Up @@ -128,10 +137,13 @@ trap cleanup EXIT

if ! jq -e --arg id "$device_id" \
'any(.devices[][]; .udid == $id and .state == "Booted")' <<< "$simulator_devices" >/dev/null; then
xcrun simctl boot "$device_id"
# Boot in the background so it overlaps the package, pods and compile phases, none of which
# need the simulator; the app-install phase waits for it.
xcrun simctl boot "$device_id" &
boot_pid=$!
echo "Booting $device_id in the background (pid $boot_pid)"
simulator_started_by_runner=true
fi
xcrun simctl bootstatus "$device_id" -b

if [[ -n "${CIO_E2E_HOST_PARENT:-}" ]]; then
host_parent="$CIO_E2E_HOST_PARENT"
Expand Down Expand Up @@ -235,12 +247,12 @@ run_ordinary_url_flow() {
}

cd "$REPO_ROOT"
current_phase="package"
enter_phase package
npm ci
package_name="$(npm pack --silent --pack-destination "$package_dir" | tail -n 1)"

cd "$host_parent"
current_phase="generate"
enter_phase generate
npx "@react-native-community/cli@$RN_CLI_VERSION" init "$APP_NAME" \
--version "$RN_VERSION" \
--template "@react-native-community/template@$RN_TEMPLATE_VERSION" \
Expand All @@ -257,8 +269,7 @@ npm pkg set \
"devDependencies.@react-native/metro-config=$RN_VERSION" \
"devDependencies.@react-native/typescript-config=$RN_VERSION" \
"devDependencies.react-test-renderer=$REACT_VERSION"
current_phase="install"
npm install
enter_phase install
npm install "$package_dir/$package_name"

cp "$FIXTURE_DIR/App.tsx" App.tsx
Expand All @@ -279,31 +290,67 @@ plist="ios/$APP_NAME/Info.plist"
/usr/libexec/PlistBuddy -c 'Add :CFBundleURLTypes:0:CFBundleURLSchemes array' "$plist"
/usr/libexec/PlistBuddy -c 'Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string cio-rn-scene-e2e' "$plist"

current_phase="pods"
enter_phase pods
bundle install
bundle exec ruby "$FIXTURE_DIR/configure_podfile.rb" ios/Podfile
bundle exec ruby "$FIXTURE_DIR/configure.rb" "ios/$APP_NAME.xcodeproj" "$APP_NAME"
bundle exec pod install --project-directory=ios

current_phase="compile"
enter_phase compile
# Release builds every simulator architecture by default; the test only runs the destination's.
xcodebuild -quiet \
-workspace "ios/$APP_NAME.xcworkspace" \
-scheme "$APP_NAME" \
-configuration Release \
-destination "platform=iOS Simulator,id=$device_id" \
-derivedDataPath "$derived_data" \
ONLY_ACTIVE_ARCH=YES \
CODE_SIGNING_ALLOWED=NO \
build

app_path="$derived_data/Build/Products/Release-iphonesimulator/$APP_NAME.app"
test -d "$app_path"
enter_phase boot
if [[ -n "$boot_pid" ]]; then
if wait "$boot_pid"; then
:
else
status=$?
echo "error: simctl boot failed (status $status)" >&2
exit "$status"
fi
boot_pid=""
fi
xcrun simctl bootstatus "$device_id" -b
enter_phase app-install
xcrun simctl uninstall "$device_id" "$APP_ID" >/dev/null 2>&1 || true
xcrun simctl install "$device_id" "$app_path"
installed_app=true

# Persistent notification banners, so a slow tap still finds the banner; why and how in set_persistent_banners.py.
enter_phase notification-settings
section_store="$(xcrun simctl list devices -j | jq -r --arg id "$device_id" \
'[.devices[][] | select(.udid == $id)][0].dataPath')/Library/BulletinBoard/VersionedSectionInfo.plist"
notification_settings_log="${RUNNER_TEMP:-${TMPDIR:-/tmp}}/react-native-scene-maestro-notification-settings.log"
for service in com.apple.SpringBoard com.apple.usernotificationsd; do
xcrun simctl spawn "$device_id" launchctl stop "$service"
done
python3 "$REPO_ROOT/.maestro/set_persistent_banners.py" "$section_store" "$APP_ID" "$APP_NAME"
for service in com.apple.SpringBoard com.apple.usernotificationsd; do
xcrun simctl spawn "$device_id" launchctl start "$service"
done
# Right after the write this reads back our own write, so it is a log baseline, not proof
# SpringBoard kept the record. The check after each prepare flow is the gate.
python3 "$REPO_ROOT/.maestro/set_persistent_banners.py" --check "$section_store" "$APP_ID" \
| sed 's/^/after write: /' | tee "$notification_settings_log"
# Pre-approve the URL scheme so simctl openurl never shows SpringBoard's "Open in" prompt,
# like preApproveDeepLinkPromptAsync in Expo's apps/bare-expo/scripts/start-ios-e2e-test.ts.
xcrun simctl spawn "$device_id" defaults write com.apple.launchservices.schemeapproval \
'com.apple.CoreSimulator.CoreSimulatorBridge-->cio-rn-scene-e2e' -string "$APP_ID"

cd "$REPO_ROOT"
for routing_mode in acknowledged linking; do
current_phase="prepare-$routing_mode"
enter_phase "prepare-$routing_mode"
prepare_args=(--device "$device_id" test -e "ROUTING_MODE=$routing_mode" .maestro/scene_push_prepare.yaml)
if [[ -n "${RUNNER_TEMP:-}" ]]; then
prepare_args=(
Expand All @@ -316,18 +363,21 @@ for routing_mode in acknowledged linking; do
)
fi
maestro "${prepare_args[@]}"
enter_phase "notification-settings-$routing_mode"
python3 .maestro/set_persistent_banners.py --check "$section_store" "$APP_ID" \
| sed "s/^/after prepare-$routing_mode: /" | tee -a "$notification_settings_log"

if [[ "$routing_mode" == acknowledged ]]; then
current_phase="ordinary-link-warm-$routing_mode"
enter_phase "ordinary-link-warm-$routing_mode"
run_ordinary_url_flow 'cio-rn-scene-e2e://ordinary-warm' warm
xcrun simctl terminate "$device_id" "$APP_ID"

current_phase="ordinary-link-cold-$routing_mode"
enter_phase "ordinary-link-cold-$routing_mode"
run_ordinary_url_flow 'cio-rn-scene-e2e://ordinary-cold' cold
fi
xcrun simctl terminate "$device_id" "$APP_ID"

current_phase="routing-$routing_mode"
enter_phase "routing-$routing_mode"
run_notification_flow .maestro/scene_push_open.yaml .maestro/fixtures/customerio_scene_cold.apns
run_notification_flow .maestro/scene_push_warm.yaml .maestro/fixtures/customerio_scene_warm.apns
if [[ "$routing_mode" == acknowledged ]]; then
Expand Down
2 changes: 1 addition & 1 deletion .maestro/scene_push_declined.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ name: React Native UIScene declined app-owned URL
retryTapIfNoChange: false
- extendedWaitUntil:
visible: 'Declined count: 1'
timeout: 15000
timeout: 60000
- assertVisible: 'Received: cio-rn-scene-e2e://declined'
- assertNotVisible: 'Declined count: 2'
2 changes: 1 addition & 1 deletion .maestro/scene_push_open.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ name: React Native UIScene cold push routing, open
retryTapIfNoChange: false
- extendedWaitUntil:
visible: "Received: https://customer.io/react-native-scene-e2e/cold"
timeout: 15000
timeout: 60000
2 changes: 1 addition & 1 deletion .maestro/scene_push_prepare.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ name: React Native UIScene push routing, prepare
notifications: allow
- extendedWaitUntil:
visible: 'Customer.io React Native scene E2E ready'
timeout: 15000
timeout: 60000
- assertVisible: 'Routing: ${ROUTING_MODE}'
2 changes: 1 addition & 1 deletion .maestro/scene_push_warm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ name: React Native UIScene warm push routing
retryTapIfNoChange: false
- extendedWaitUntil:
visible: "Received: https://customer.io/react-native-scene-e2e/warm"
timeout: 15000
timeout: 60000
5 changes: 1 addition & 4 deletions .maestro/scene_url_open.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
appId: org.reactjs.native.example.CioRnSceneHost
name: React Native UIScene ordinary URL
---
- tapOn:
text: Open
optional: true
- extendedWaitUntil:
visible: 'Customer.io React Native scene E2E ready'
timeout: 15000
timeout: 60000
- assertVisible: 'Routing: acknowledged'
- assertVisible: 'Received: ${EXPECTED_URL}'
182 changes: 182 additions & 0 deletions .maestro/set_persistent_banners.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
#!/usr/bin/env python3
# The BBSectionInfo record below is adapted from set_notification_permission.py in
# https://github.com/imranbarbhuiya/ios-sim-notification-permission
# under its MIT License:
#
# Copyright (c) 2026 imranbarbhuiya
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Writes a simulator notification record that makes an app's banners persistent.

set_persistent_banners.py <VersionedSectionInfo.plist> <bundle-id> <display-name>
set_persistent_banners.py --check <VersionedSectionInfo.plist> <bundle-id>

iOS removes a temporary banner about six seconds after it appears, so a test tap that
lands later finds the Home screen instead. A persistent banner stays until it is tapped.
iOS keeps the setting in data/Library/BulletinBoard/VersionedSectionInfo.plist as one
NSKeyedArchiver-encoded BBSectionInfo per bundle id. This writes the record iOS 27.2
saves after a user allows notifications, with alertType 2 (Alert, which Settings shows
as the Persistent banner style) instead of 1 (Banner, the Temporary style).

SpringBoard rewrites the file from memory as it stops, so run_scene_push.sh stops it and
usernotificationsd before the write and starts them after. --check decodes the saved
record and fails unless it is still authorized with the persistent style, so a run shows
whether SpringBoard kept it. --check reads the file on disk, not SpringBoard's memory: an
iOS release that ignores alertType would still pass it and bring the late-tap failure
back. The live signal is `alertStyle: Alert` for the app in the simulator's device log.
"""

import os
import plistlib
import sys
import time
from plistlib import UID

AUTHORIZED = 2
PERSISTENT_ALERT_TYPE = 2
# Seconds between the Cocoa reference date (2001-01-01) and the Unix epoch.
COCOA_EPOCH = 978307200


def section_info(bundle_id: str, name: str) -> bytes:
settings = {
"$class": UID(4),
"authorizationStatus": AUTHORIZED,
"authorizationExpirationDate": UID(0),
"lastUserGrantedAuthorizationDate": UID(0),
"alertType": PERSISTENT_ALERT_TYPE,
"pushSettings": 63,
"showsInNotificationCenter": True,
"showsInLockScreen": True,
"showsOnExternalDevices": True,
"notificationCenterSetting": 2,
"lockScreenSetting": 2,
"remoteNotificationsSetting": 2,
"carPlaySetting": 0,
"criticalAlertSetting": 0,
"timeSensitiveSetting": 0,
"userConfiguredTimeSensitiveSetting": False,
"directMessagesSettingKey": 0,
"userConfiguredDirectMessagesSetting": False,
"announceSetting": 1,
"announcePriority": 0,
"bulletinGroupingSetting": 0,
"contentPreviewSetting": 0,
"prioritizationSetting": 2,
"summarizationSetting": 2,
"scheduledDeliverySetting": 1,
"showsCustomSettingsLink": False,
"muteAssertion": UID(0),
}
info = {
"$class": UID(10),
"sectionID": UID(2),
"sectionInfoSettings": UID(3),
"lastSettingChangeDate": UID(5),
"appName": UID(7),
"displayName": UID(8),
"version": UID(9),
"lastSettingSource": 2,
"sectionType": 0,
"sectionCategory": 0,
"subsectionPriority": 0,
"suppressFromSettings": False,
"suppressedSettings": 0,
"isRestricted": False,
"isModificationAllowed": False,
"hasEverBeenUserChanged": False,
"isAppClip": False,
"isLocked": False,
"hideWeeApp": False,
"customSettingsBundle": UID(0),
"customSettingsDetailControllerClass": UID(0),
"icon": UID(0),
"subsections": UID(0),
"subsectionID": UID(0),
"managedSectionInfoSettings": UID(0),
"factorySectionID": UID(0),
"dataProviderIDs": UID(0),
"pathToWeeAppPluginBundle": UID(0),
}
objects = [
"$null",
info,
bundle_id,
settings,
{"$classname": "BBSectionInfoSettings", "$classes": ["BBSectionInfoSettings", "NSObject"]},
{"NS.time": time.time() - COCOA_EPOCH, "$class": UID(6)},
{"$classname": "NSDate", "$classes": ["NSDate", "NSObject"]},
name,
name,
0,
{"$classname": "BBSectionInfo", "$classes": ["BBSectionInfo", "NSObject"]},
]
archive = {
"$version": 100000,
"$archiver": "NSKeyedArchiver",
"$top": {"root": UID(1)},
"$objects": objects,
}
return plistlib.dumps(archive, fmt=plistlib.FMT_BINARY)


def check(sections: dict, bundle_id: str) -> int:
record = sections.get(bundle_id)
if not isinstance(record, bytes):
print(f"error: no notification record for {bundle_id}", file=sys.stderr)
return 1
archive = plistlib.loads(record)
objects = archive["$objects"]
info = objects[archive["$top"]["root"]]
settings = objects[info["sectionInfoSettings"]]
alert_type = settings.get("alertType")
status = settings.get("authorizationStatus")
print(f"{bundle_id} notification record: alertType={alert_type} authorizationStatus={status}")
if alert_type != PERSISTENT_ALERT_TYPE or status != AUTHORIZED:
print("error: notification banners are not persistent; a late banner tap would miss", file=sys.stderr)
return 1
return 0


def main() -> int:
args = sys.argv[1:]
checking = args[:1] == ["--check"]
if len(args) != 3:
print(__doc__.strip(), file=sys.stderr)
return 2
if checking:
args = args[1:]
path, bundle_id = args[0], args[1]
with open(path, "rb") as handle:
store = plistlib.load(handle)
sections = store.get("sectionInfo")
if not isinstance(sections, dict):
print(f"error: {path} has no sectionInfo dictionary", file=sys.stderr)
return 1
if checking:
return check(sections, bundle_id)
sections[bundle_id] = section_info(bundle_id, args[2])
with open(path + ".tmp", "wb") as handle:
plistlib.dump(store, handle, fmt=plistlib.FMT_BINARY)
os.replace(path + ".tmp", path)
return 0


if __name__ == "__main__":
sys.exit(main())
Loading