agentic-mobile-kit 0.7.10 → 0.7.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentic-mobile-kit",
3
- "version": "0.7.10",
3
+ "version": "0.7.11",
4
4
  "description": "One setup for AI-assisted development of React Native apps, bare or Expo: shared rules and workflows for Claude Code, Codex and Antigravity, git hooks, device checks with screenshots, and release tooling for the App Store and Google Play.",
5
5
  "license": "MIT",
6
6
  "author": "prakashpro1",
@@ -20,7 +20,7 @@ This project may also use other AI workflow frameworks (for example Superpowers,
20
20
  | Add a library (ask first) | `npx expo install <package>`: the version that matches the SDK |
21
21
  | Lint, typecheck, test (each skips what the app doesn't have yet) | `sh scripts/amk/pm-run.sh lint`, `sh scripts/amk/pm-run.sh typecheck`, `sh scripts/amk/pm-run.sh test` |
22
22
  | Check dependency versions and the app config | `npx expo install --check`, `npx expo-doctor` |
23
- | Check on devices (release builds, Maestro flows, screenshots) | `sh scripts/amk/verify.sh all --spec <id>`; another iOS scheme: `--scheme <name>`; only some screens: `--screens phone` (or `tablet`, `landscape`, …) |
23
+ | Check on devices (release builds, Maestro flows, screenshots) | `sh scripts/amk/verify.sh all --spec <id>`; another iOS scheme: `--scheme <name>`; only some screens: `--screens phone` (or `tablet`, `landscape`, …); on a real iPhone or iPad the user names: `AMK_IOS_DEVICE=<its UDID>` (the flows clear the app's data on it) |
24
24
  | Check every device at the same time, on a machine with room for it | `sh scripts/amk/verify.sh plan --spec <id>` says whether, and prints the commands: one per device, each for an `m-device-checker` subagent |
25
25
  | Specs: progress, format check, fold a finished feature into the living spec | `node scripts/amk/specs.js status`, `node scripts/amk/specs.js check`, `node scripts/amk/specs.js merge <id>` |
26
26
  | Check a release before tagging it (versions, permission texts, debug leftovers) | `node scripts/amk/release-check.js` |
@@ -20,7 +20,7 @@ This project may also use other AI workflow frameworks (for example Superpowers,
20
20
  | iOS pods (after native dependency changes) | `sh scripts/amk/pod-install.sh` |
21
21
  | iOS build (simulator, no signing) | `sh scripts/amk/ios-build.sh` |
22
22
  | Android build | `cd android && ./gradlew assembleDebug` |
23
- | Check on devices (release builds, Maestro flows, screenshots) | `sh scripts/amk/verify.sh all --spec <id>`; with product flavors it checks the first unless `--flavor <name>`; another iOS scheme: `--scheme <name>`; only some screens: `--screens phone` (or `tablet`, `landscape`, …) |
23
+ | Check on devices (release builds, Maestro flows, screenshots) | `sh scripts/amk/verify.sh all --spec <id>`; with product flavors it checks the first unless `--flavor <name>`; another iOS scheme: `--scheme <name>`; only some screens: `--screens phone` (or `tablet`, `landscape`, …); on a real iPhone or iPad the user names: `AMK_IOS_DEVICE=<its UDID>` (the flows clear the app's data on it) |
24
24
  | Check every device at the same time, on a machine with room for it | `sh scripts/amk/verify.sh plan --spec <id>` says whether, and prints the commands: one per device, each for an `m-device-checker` subagent |
25
25
  | Specs: progress, format check, fold a finished feature into the living spec | `node scripts/amk/specs.js status`, `node scripts/amk/specs.js check`, `node scripts/amk/specs.js merge <id>` |
26
26
  | Check a release before tagging it (versions, permission texts, debug leftovers) | `node scripts/amk/release-check.js` |
@@ -4,6 +4,9 @@
4
4
  # archives with: apps with one per environment (for example "Release Staging") get theirs.
5
5
  # AMK_IOS_SCHEME picks the scheme (default: the one named like the workspace).
6
6
  # Output goes to ios/DerivedData: ios/build holds React Native codegen files from pod install.
7
+ # `ios-build.sh device <UDID>` builds for that iPhone or iPad instead, signed by Xcode's automatic signing for the team
8
+ # in AMK_IOS_TEAM, with the Apple account in Xcode: the first time, Xcode registers the device with the team and makes a
9
+ # development profile for it. The project's own signing settings stay as they are.
7
10
  set -eu
8
11
  config=${CONFIGURATION:-Debug}
9
12
  workspace=$(ls -d ios/*.xcworkspace 2>/dev/null | head -n 1)
@@ -15,6 +18,17 @@ if [ "$config" = Release ]; then
15
18
  [ -n "$config" ] || config=Release
16
19
  fi
17
20
 
21
+ if [ "${1:-}" = device ]; then
22
+ [ -n "${AMK_IOS_TEAM:-}" ] || { echo "Set AMK_IOS_TEAM to the Apple team to sign with (Xcode > Settings > Accounts lists them)."; exit 1; }
23
+ # signed for development whatever the project signs its releases with (a distribution profile doesn't install)
24
+ xcodebuild -workspace "$workspace" -scheme "$scheme" -configuration "$config" -destination "id=$2" \
25
+ -derivedDataPath ios/DerivedData -allowProvisioningUpdates -allowProvisioningDeviceRegistration \
26
+ DEVELOPMENT_TEAM="$AMK_IOS_TEAM" CODE_SIGN_STYLE=Automatic CODE_SIGN_IDENTITY="Apple Development" \
27
+ PROVISIONING_PROFILE_SPECIFIER= -quiet build
28
+ echo "iOS device build OK ($scheme, $config, team $AMK_IOS_TEAM)"
29
+ exit 0
30
+ fi
31
+
18
32
  # only this Mac's simulator architecture: a Release build would otherwise compile Intel and Apple silicon both,
19
33
  # and fail to link libraries that ship without an Intel simulator slice. Not when the project or a pod excludes it
20
34
  # for the simulator (Google's ML Kit pods exclude arm64): then Xcode builds what the project allows.
@@ -20,13 +20,17 @@
20
20
  # (no flows found: a smoke check that launches the app and takes a screenshot)
21
21
  # Evidence per screen: ios/ and android/ (phone, portrait), then -landscape/, -tablet/ and -tablet-landscape/
22
22
  # Env: AMK_ANDROID_FLAVOR, AMK_IOS_SCHEME, AMK_SCREENS (defaults for the options), AMK_IOS_DEVICE (simulator name
23
- # or UDID), AMK_ANDROID_DEVICE (adb serial: the only way to check on a phone, whose app data the flows clear),
23
+ # or UDID, or a connected iPhone's or iPad's: the only way to check on one, whose app data the flows clear),
24
+ # AMK_ANDROID_DEVICE (adb serial: the only way to check on a phone, whose app data the flows clear),
24
25
  # AMK_ANDROID_AVD (the emulator to use, started if it isn't running; other devices are left alone),
25
- # AMK_IOS_TABLET (iPad simulator name or UDID), AMK_ANDROID_TABLET_AVD (tablet emulator), AMK_ANDROID_TABLET (serial),
26
- # AMK_PARALLEL (1 or 0: overrides plan's choice), AMK_DEVICE_WAIT (minutes to wait for a device in use, 30),
27
- # AMK_LOCK_DIR (where runs on this machine claim devices; /tmp/agentic-mobile-kit-<user id>)
26
+ # AMK_IOS_TABLET (iPad simulator, or a connected iPad: name or UDID), AMK_ANDROID_TABLET_AVD (tablet emulator),
27
+ # AMK_ANDROID_TABLET (serial), AMK_IOS_TEAM (the Apple team ID that signs builds for real iPhones and iPads;
28
+ # default: the project's), AMK_PARALLEL (1 or 0: overrides plan's choice), AMK_DEVICE_WAIT (minutes to wait for a
29
+ # device in use, 30), AMK_LOCK_DIR (where runs on this machine claim devices; /tmp/agentic-mobile-kit-<user id>)
28
30
  # A device in use by another run (any project on this machine) is skipped for a free one of the same kind, or waited
29
31
  # for when it was named or none is free.
32
+ # Real iPhones and iPads (iOS 17 or later): Maestro doesn't run on them, so their flows run through maestro-runner, with
33
+ # WebDriverAgent signed by the same team. The app is opened once first, and crash reports it leaves join the evidence.
30
34
  # Flows that log in read ${MAESTRO_EMAIL} and the like from a local, gitignored .maestro/.env.local (never committed).
31
35
  set -eu
32
36
 
@@ -133,18 +137,48 @@ run_flow() { # screen device app_id file name orientation
133
137
  debug="$evidence/maestro-logs/$1-$5"
134
138
  mkdir -p "$debug" "$out/screenshots"
135
139
  rm -f "$debug/maestro.log"
136
- find "$debug" -path '*/takeScreenshot/*.png' -exec rm -f {} + # an earlier run's, which aren't this run's evidence
140
+ # an earlier run's screenshots, which aren't this run's evidence
141
+ find "$debug" \( -path '*/takeScreenshot/*.png' -o -path '*/assets/*.png' \) -exec rm -f {} +
137
142
  target=$4
138
- if [ "$6" != PORTRAIT ]; then
139
- # a turned screen: the flow runs inside one that turns the device first and back to portrait after. Maestro
140
- # reads the path in it itself, so it's a native path (a Windows path in Git Bash)
141
- native=$(cd "$(dirname "$4")" && { pwd -W 2> /dev/null || pwd; })/$(basename "$4")
143
+ # Maestro reads the path in the flows below itself, so it's a native path (a Windows path in Git Bash)
144
+ native=$(cd "$(dirname "$4")" && { pwd -W 2> /dev/null || pwd; })/$(basename "$4")
145
+ if is_real "$2"; then
146
+ # on a real device every flow runs inside one, first: the first launchApp maestro-runner finds in a flow decides
147
+ # whether it answers alerts itself, and for most it does (for permission prompts, which it can't allow ahead),
148
+ # pressing the last button of the app's own alerts too, such as a Delete. Maestro never answers an app's alerts.
149
+ # So one that says to leave permissions alone comes first, where it never runs (on Android only)
150
+ on_complete="" turn=""
151
+ if [ "$6" != PORTRAIT ]; then
152
+ # WebDriverAgent turns the device, then fails the step unless the app in front turned too: here the home
153
+ # screen, which most iPhones never turn. Whether the app turned shows in its screenshots. It knows
154
+ # LANDSCAPE_LEFT only as "landscape"
155
+ on_complete='onFlowComplete:\n - setOrientation:\n orientation: PORTRAIT\n optional: true\n'
156
+ turn='- setOrientation:\n orientation: landscape\n optional: true\n'
157
+ fi
158
+ printf "appId: %s\n${on_complete}---\n- runFlow:\n when:\n platform: Android\n commands:\n - launchApp:\n permissions:\n all: unset\n${turn}- runFlow: '%s'\n" "$3" "$native" > "$debug/screen.yaml"
159
+ target=$debug/screen.yaml
160
+ elif [ "$6" != PORTRAIT ]; then
161
+ # a turned screen: the flow runs inside one that turns the device first and back to portrait after
142
162
  printf "appId: %s\nonFlowComplete:\n - setOrientation: PORTRAIT\n---\n- setOrientation: %s\n- runFlow: '%s'\n" "$3" "$6" "$native" > "$debug/screen.yaml"
143
163
  target=$debug/screen.yaml
144
164
  fi
165
+ rc=0
166
+ if is_real "$2"; then
167
+ # it also saves each named screenshot next to its flow file: the ones it makes there move to its log folder, so
168
+ # the project stays as it was (they're in its report too)
169
+ pngs() { find "$(dirname "$4")" \( -path "$root/.amk" -o -name node_modules \) -prune -o -name '*.png' -print | sort; }
170
+ pngs "$@" > "$debug/.pngs"
171
+ # with the app's build: on a real device, clearState installs the app again
172
+ MAESTRO_RUNNER_NO_TELEMETRY=1 DO_NOT_TRACK=1 npx -y "$runner" --platform ios --driver wda --device "$2" \
173
+ --team-id "$team" --wda-bundle-id "$3.wda" --app-file "$device_app" test -e APP_ID="$3" --output "$debug" \
174
+ --flatten "$target" > "$out/$5.log" 2>&1 || rc=$?
175
+ pngs "$@" | comm -13 "$debug/.pngs" - | while IFS= read -r f; do mv "$f" "$debug/"; done
176
+ # its takeScreenshot files, not the ones of a step that failed (<step>-after.png)
177
+ find "$debug" -path '*/assets/*.png' ! -name '*-[0-9][0-9][0-9]-after.png' -exec cp {} "$out/screenshots/" \;
178
+ return $rc
179
+ fi
145
180
  # screenshots use relative names: older Maestro saves them in the current folder, then in --test-output-dir, and
146
181
  # from 2.7 in the debug output under <flow>/takeScreenshot/, from where they join the screen's evidence
147
- rc=0
148
182
  (cd "$out" && maestro --device "$2" test --test-output-dir "$out" --debug-output "$debug" --flatten-debug-output \
149
183
  -e APP_ID="$3" "$target" > "$out/$5.log" 2>&1) || rc=$?
150
184
  find "$debug" -path '*/takeScreenshot/*.png' -exec cp {} "$out/screenshots/" \;
@@ -183,9 +217,18 @@ run_flows() { # screen device app_id orientation (PORTRAIT, or LANDSCAPE_LEFT to
183
217
  android_ready "$2" || true
184
218
  ok=0
185
219
  run_flow "$1" "$2" "$3" "$f" "$name" "$4" || ok=$?
220
+ elif [ "$ok" != 0 ] && is_real "$2" && grep -qs 'explicitly trusted' "$out/$name.log"; then
221
+ # as launch_check found it does: here after clearState installed the app again, which it opened a moment later
222
+ echo " $1: the device didn't open the app it had just installed again; running flow $name once more"
223
+ sleep 15
224
+ ok=0
225
+ run_flow "$1" "$2" "$3" "$f" "$name" "$4" || ok=$?
186
226
  fi
187
227
  if [ "$ok" = 0 ]; then
188
228
  passed=$((passed + 1))
229
+ elif is_real "$2"; then
230
+ echo " $1: flow $name failed, see ${out#"$root"/}/$name.log and maestro-runner's own log ${debug#"$root"/}/maestro-runner.log"
231
+ status=1
189
232
  else
190
233
  echo " $1: flow $name failed, see ${out#"$root"/}/$name.log and Maestro's own log ${debug#"$root"/}/maestro.log"
191
234
  status=1
@@ -225,6 +268,14 @@ run_flows() { # screen device app_id orientation (PORTRAIT, or LANDSCAPE_LEFT to
225
268
  elif [ "$wrong" != 0 ]; then
226
269
  echo " $1: $wrong screenshots show the screen $was: the device or the app didn't turn, so this screen isn't checked; treating this as a failure"
227
270
  status=1
271
+ # an app that sets its orientation in code (an orientation library, or native code) can keep it although its native
272
+ # settings allow turning: where it does, so the team can say which is right
273
+ set_in=$(git grep -l -E 'lockTo(Portrait|Landscape)|OrientationLock\.|lockPlatformAsync|setRequestedOrientation|supportedInterfaceOrientationsFor' \
274
+ -- ':!scripts/amk' ':!*.md' 2> /dev/null | head -n 3 | tr '\n' ' ')
275
+ if [ -n "$set_in" ]; then
276
+ case $was in upright) other=landscape ;; *) other=portrait ;; esac
277
+ echo " $1: the app sets its orientation in its code (${set_in% }), which can keep it $was. If it's meant to stay $was, take $other out of its native settings (UISupportedInterfaceOrientations in Info.plist, screenOrientation in AndroidManifest.xml) and this screen isn't checked any more; otherwise change that code"
278
+ fi
228
279
  fi
229
280
  }
230
281
 
@@ -249,10 +300,10 @@ check_screens() { # platform phone tablet app_id screens…
249
300
  upright=LANDSCAPE_LEFT turned=PORTRAIT
250
301
  fi
251
302
  case $screen in *-landscape) turn=$turned where=$where-landscape ;; *) turn=$upright ;; esac
252
- # Maestro turns devices from 2.0 on, and taps the right place on a turned iPad from 2.3
303
+ # Maestro turns devices from 2.0 on, and taps the right place on a turned iPad from 2.3 (real ones: maestro-runner)
253
304
  need=2.0.0
254
305
  case $where in ios-tablet*) need=2.3.0 ;; esac
255
- if [ "$turn" != PORTRAIT ] && ! maestro_at_least $need; then
306
+ if [ "$turn" != PORTRAIT ] && ! is_real "$on" && ! maestro_at_least $need; then
256
307
  echo "$where: not checked: turning the device needs Maestro ${need%.0} or later (this is $(maestro_version))"
257
308
  continue
258
309
  fi
@@ -295,7 +346,8 @@ ios() {
295
346
  sh scripts/amk/pod-install.sh > "$evidence/pod-install.log" 2>&1
296
347
  fi
297
348
  fi
298
- # the simulators first, so they boot while Xcode builds
349
+ # the simulators first, so they boot while Xcode builds. A real iPhone or iPad only when named, as the flows clear
350
+ # the app's data on it
299
351
  device="" tablet=""
300
352
  if [ "$build_only" = 0 ]; then
301
353
  screens=$(screens_for ios)
@@ -304,36 +356,67 @@ ios() {
304
356
  take_simulator iPhone "${AMK_IOS_DEVICE:-}" || { status=1; return; }
305
357
  device=$taken
306
358
  if [ -z "$device" ]; then
307
- if [ -n "${AMK_IOS_DEVICE:-}" ]; then echo "ios: no simulator has the name or UDID \"$AMK_IOS_DEVICE\""; else echo "ios: no iPhone simulator found (set AMK_IOS_DEVICE)"; fi
359
+ if [ -n "${AMK_IOS_DEVICE:-}" ]; then echo "ios: no simulator or connected iPhone or iPad has the name or UDID \"$AMK_IOS_DEVICE\""; else echo "ios: no iPhone simulator found (set AMK_IOS_DEVICE)"; fi
308
360
  status=1; return
309
361
  fi
310
362
  fi
311
363
  if echo "$screens" | grep -q '^tablet-'; then
312
364
  take_simulator iPad "${AMK_IOS_TABLET:-}" || { status=1; return; }
313
365
  tablet=$taken
314
- if [ -z "$tablet" ] && [ -n "${AMK_IOS_TABLET:-}" ]; then echo "ios: no simulator has the name or UDID \"$AMK_IOS_TABLET\""; status=1; return; fi
366
+ if [ -z "$tablet" ] && [ -n "${AMK_IOS_TABLET:-}" ]; then echo "ios: no simulator or connected iPad has the name or UDID \"$AMK_IOS_TABLET\""; status=1; return; fi
315
367
  [ -n "$tablet" ] || echo "ios: the app runs on iPad, but there's no iPad simulator, so iPads aren't checked (add one in Xcode, or set AMK_IOS_TABLET)"
316
368
  fi
317
- for d in $device $tablet; do xcrun simctl boot "$d" 2> /dev/null || true; done
369
+ [ -n "$device$tablet" ] || return
370
+ for d in $device $tablet; do
371
+ if is_real "$d"; then echo "ios: checking on $d, a real device; the flows clear the app's data on it"
372
+ else xcrun simctl boot "$d" 2> /dev/null || true; fi
373
+ done
374
+ else
375
+ # the plan's build step: a build for each real device named too
376
+ for n in "${AMK_IOS_DEVICE:-}" "${AMK_IOS_TABLET:-}"; do
377
+ [ -z "$n" ] || [ -n "$(simulators iPhone "$n")" ] || { r=$(real_ios "$n"); [ -z "$r" ] || reals="$reals $r"; }
378
+ done
379
+ fi
380
+ team=$(ios_team)
381
+ if [ -n "$reals" ] && [ -z "$team" ]; then
382
+ echo "ios: a real device runs only apps signed by an Apple team: set AMK_IOS_TEAM to your team ID (Xcode > Settings > Accounts lists them)"
383
+ status=1; return
318
384
  fi
385
+ sims=$build_only # whether to build for simulators: the plan's build step always does
386
+ for d in $device $tablet; do is_real "$d" || sims=1; done
319
387
  # one build of this project at a time; a check without its own build waits for one that's under way
320
388
  claim_wait "build-ios-$project" "" "the iOS build of this project" || { status=1; return; }
321
389
  if [ "$no_build" = 0 ]; then
322
- if ! CONFIGURATION=Release sh scripts/amk/ios-build.sh > "$evidence/ios-build.log" 2>&1; then
390
+ if [ "$sims" = 1 ] && ! CONFIGURATION=Release sh scripts/amk/ios-build.sh > "$evidence/ios-build.log" 2>&1; then
323
391
  echo "ios: release build FAILED, see ${evidence#"$root"/}/ios-build.log"; status=1; return
324
392
  fi
393
+ for d in $reals; do
394
+ if ! CONFIGURATION=Release AMK_IOS_TEAM=$team sh scripts/amk/ios-build.sh device "$d" > "$evidence/ios-device-build.log" 2>&1; then
395
+ echo "ios: release build for $d FAILED, see ${evidence#"$root"/}/ios-device-build.log"; status=1; return
396
+ fi
397
+ done
325
398
  fi
326
399
  unclaim "build-ios-$project"
327
400
  [ "$build_only" = 0 ] || { echo "ios: release build done"; return; }
328
401
  # the newest app: the scheme just built (another scheme's app may still be there from an earlier build)
329
402
  app=$(ls -dt ios/DerivedData/Build/Products/*-iphonesimulator/*.app 2> /dev/null | head -n 1)
330
- [ -n "$app" ] || { echo "ios: there's no build to check yet: run sh scripts/amk/verify.sh build first"; status=1; return; }
331
- app_id=$(/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' "$app/Info.plist")
403
+ device_app=$(ls -dt "$root"/ios/DerivedData/Build/Products/*-iphoneos/*.app 2> /dev/null | head -n 1)
404
+ a=$app
405
+ [ "$sims" = 1 ] || a=$device_app
406
+ if [ -z "$a" ] || { [ -n "$reals" ] && [ -z "$device_app" ]; }; then
407
+ echo "ios: there's no build to check yet: run sh scripts/amk/verify.sh build first"; status=1; return
408
+ fi
409
+ app_id=$(/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' "$a/Info.plist")
332
410
  for d in $device $tablet; do
333
- xcrun simctl bootstatus "$d" -b > /dev/null
334
- xcrun simctl install "$d" "$app"
411
+ if is_real "$d"; then
412
+ launch_check "$d" || { status=1; return; }
413
+ else
414
+ xcrun simctl bootstatus "$d" -b > /dev/null
415
+ xcrun simctl install "$d" "$app"
416
+ fi
335
417
  done
336
418
  check_screens ios "$device" "$tablet" "$app_id" $screens
419
+ for d in $reals; do crash_reports "$d"; done
337
420
  }
338
421
 
339
422
  # the simulators for $1 (iPhone or iPad), best first: the one named in $2 (name or UDID); else the booted ones,
@@ -351,17 +434,87 @@ simulators() {
351
434
  console.log(list.map(d => d.udid).join("\n"));'
352
435
  }
353
436
  # a simulator for $1 (iPhone or iPad) that this run holds, in $taken: the one named in $2, once it's free; else the
354
- # first free one; else the best one, once it's free. Empty when there's none
437
+ # first free one; else the best one, once it's free. Empty when there's none. A name no simulator has can be a real
438
+ # device's
355
439
  take_simulator() {
356
440
  taken=""
357
441
  candidates=$(simulators "$1" "$2")
442
+ if [ -z "$candidates" ] && [ -n "$2" ]; then
443
+ candidates=$(real_ios "$2")
444
+ [ -z "$candidates" ] || reals="$reals $candidates"
445
+ fi
358
446
  [ -n "$candidates" ] || return 0
359
447
  first=$(echo "$candidates" | head -n 1)
360
448
  if [ -z "$2" ]; then
361
449
  for u in $candidates; do claim "ios-$u" "$u" && { taken=$u; break; }; done
362
450
  [ -z "$taken" ] || [ "$taken" = "$first" ] || echo "ios: $first is in use by $(holder "ios-$first"), so checking on $taken"
363
451
  fi
364
- [ -n "$taken" ] || { claim_wait "ios-$first" "$first" "the $1 simulator $first" || return 1; taken=$first; }
452
+ [ -n "$taken" ] || { claim_wait "ios-$first" "$first" "the $1 $first" || return 1; taken=$first; }
453
+ }
454
+
455
+ # Real iPhones and iPads, through Xcode's devicectl (iOS 17 or later). Maestro doesn't run on them, so their flows run
456
+ # through maestro-runner: pinned, as a newer one may behave differently, and without its usage data
457
+ runner=maestro-runner@1.1.29
458
+ reals="" # the real devices this run checks on
459
+ is_real() { case " $reals " in *" $1 "*) ;; *) return 1 ;; esac; }
460
+ # the UDID of the connected iPhone or iPad with the name or UDID $1
461
+ real_ios() {
462
+ xcrun devicectl list devices --json-output "$evidence/.devices.json" > /dev/null 2>&1 || return 0
463
+ WANT=$1 node -e 'const want = process.env.WANT;
464
+ const d = JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).result.devices.find(d => d.hardwareProperties?.reality === "physical" &&
465
+ [d.identifier, d.deviceProperties?.name, d.hardwareProperties.udid].includes(want));
466
+ if (d) console.log(d.hardwareProperties.udid);' "$evidence/.devices.json"
467
+ }
468
+ # the Apple team that signs the app and WebDriverAgent for real devices: AMK_IOS_TEAM, else the project's
469
+ ios_team() { echo "${AMK_IOS_TEAM:-$(sed -n 's/.*DEVELOPMENT_TEAM = "\{0,1\}\([A-Z0-9]\{10\}\)"\{0,1\};.*/\1/p' ios/*.xcodeproj/project.pbxproj 2> /dev/null | head -n 1)}"; }
470
+ # installs the app on the real device $1 and opens it, so what the device needs (trusting the team, unlocking) shows
471
+ # before the flows, and an app that closes at once is caught with its crash report. Notes the crash reports already there
472
+ launch_check() {
473
+ exe=$(/usr/libexec/PlistBuddy -c 'Print CFBundleExecutable' "$device_app/Info.plist")
474
+ crashes "$1" > "$evidence/.crashes-$1"
475
+ log=$evidence/launch-$1.log
476
+ if ! xcrun devicectl device install app --device "$1" "$device_app" > "$log" 2>&1; then
477
+ echo "ios: the app didn't install on $1 (is it unlocked, with Developer Mode on?), see ${log#"$root"/}"
478
+ return 1
479
+ fi
480
+ # a device now and then refuses an app it has just installed for a moment, as if it didn't trust the team
481
+ tries=0
482
+ until said=$(xcrun devicectl device process launch --device "$1" --terminate-existing "$app_id" 2>&1); do
483
+ echo "$said" >> "$log"
484
+ tries=$((tries + 1))
485
+ case $said in
486
+ *'explicitly trusted'*) [ "$tries" -lt 3 ] || {
487
+ echo "ios: $1 doesn't open apps from this team yet: on it, Settings > General > VPN & Device Management > Developer App > Trust, then run this again"
488
+ return 1; } ;;
489
+ *) echo "ios: the app didn't open on $1 (is it unlocked?), see ${log#"$root"/}"; return 1 ;;
490
+ esac
491
+ sleep 10
492
+ done
493
+ echo "$said" >> "$log"
494
+ sleep 10
495
+ xcrun devicectl device info processes --device "$1" --json-output "$evidence/.processes.json" > /dev/null 2>&1 || true
496
+ if ! grep -qs "/$(basename "$device_app")/" "$evidence/.processes.json"; then
497
+ echo "ios: the app closed within 10 seconds of opening on $1"
498
+ crash_reports "$1"
499
+ return 1
500
+ fi
501
+ }
502
+ # the app's crash reports on the real device $1
503
+ crashes() {
504
+ xcrun devicectl device info files --device "$1" --domain-type systemCrashLogs --json-output "$evidence/.files.json" > /dev/null 2>&1 || return 0
505
+ EXE=$exe node -e 'for (const f of JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).result.files || [])
506
+ if (f.relativePath.startsWith(process.env.EXE + "-") && f.relativePath.endsWith(".ips")) console.log(f.relativePath)' "$evidence/.files.json"
507
+ }
508
+ # the ones that weren't there before launch_check join the evidence: the app crashed during the checks
509
+ crash_reports() {
510
+ new=$(crashes "$1" | grep -v -x -F -f "$evidence/.crashes-$1" || true)
511
+ [ -n "$new" ] || return 0
512
+ mkdir -p "$evidence/crashes"
513
+ for c in $new; do
514
+ xcrun devicectl device copy from --device "$1" --domain-type systemCrashLogs --source "$c" --destination "$evidence/crashes/$c" > /dev/null 2>&1 || true
515
+ done
516
+ echo "ios: the app crashed on $1 during the checks: $(echo "$new" | wc -l | tr -d ' ') crash reports in ${evidence#"$root"/}/crashes"
517
+ status=1
365
518
  }
366
519
 
367
520
  # a running emulator's adb serial: of the AVD named in $1 if one is, else of the kind in $2 (phone or tablet) if given