appstore-precheck 1.18.0 → 1.20.0

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +256 -0
  2. package/README.md +108 -39
  3. package/bin/cli.js +8 -0
  4. package/package.json +2 -2
  5. package/skills/appstore-precheck/SKILL.md +99 -157
  6. package/skills/appstore-precheck/guidelines-baseline.json +285 -36
  7. package/skills/appstore-precheck/guidelines-fingerprints.json +319 -93
  8. package/skills/appstore-precheck/references/finding-commentary.md +93 -0
  9. package/skills/appstore-precheck/references/methodology.md +81 -26
  10. package/skills/appstore-precheck/references/optional-review.md +56 -0
  11. package/skills/appstore-precheck/references/pierre-deep-review.md +323 -44
  12. package/skills/appstore-precheck/references/review-catalog.json +740 -0
  13. package/skills/appstore-precheck/references/screenshot-vision-review.md +8 -8
  14. package/skills/appstore-precheck/references/simulator-dynamic-review.md +398 -54
  15. package/skills/appstore-precheck/references/typesafe-example.json +239 -0
  16. package/skills/appstore-precheck/references/typesafe.md +216 -0
  17. package/skills/appstore-precheck/scripts/app-discover.sh +138 -0
  18. package/skills/appstore-precheck/scripts/artifact-review.sh +10 -0
  19. package/skills/appstore-precheck/scripts/augment-json.py +29 -0
  20. package/skills/appstore-precheck/scripts/build-run.sh +5 -0
  21. package/skills/appstore-precheck/scripts/coverage-sections.sh +6 -0
  22. package/skills/appstore-precheck/scripts/dynamic-run.sh +400 -0
  23. package/skills/appstore-precheck/scripts/dynamic.sh +329 -0
  24. package/skills/appstore-precheck/scripts/evidence.sh +49 -15
  25. package/skills/appstore-precheck/scripts/findings.sh +76 -26
  26. package/skills/appstore-precheck/scripts/framework-detect.sh +101 -0
  27. package/skills/appstore-precheck/scripts/guideline-cite.sh +4 -1
  28. package/skills/appstore-precheck/scripts/lib/artifact-review.py +518 -0
  29. package/skills/appstore-precheck/scripts/lib/asc-client.py +293 -0
  30. package/skills/appstore-precheck/scripts/lib/build-evidence.py +50 -0
  31. package/skills/appstore-precheck/scripts/lib/build-exec.py +50 -0
  32. package/skills/appstore-precheck/scripts/lib/build-plan.py +106 -0
  33. package/skills/appstore-precheck/scripts/lib/build-plan.sh +15 -0
  34. package/skills/appstore-precheck/scripts/lib/build-run.py +177 -0
  35. package/skills/appstore-precheck/scripts/lib/coverage-run.sh +23 -0
  36. package/skills/appstore-precheck/scripts/lib/coverage-sections.py +244 -0
  37. package/skills/appstore-precheck/scripts/lib/dyn-bundle.sh +185 -0
  38. package/skills/appstore-precheck/scripts/lib/dyn-demo-login.py +111 -0
  39. package/skills/appstore-precheck/scripts/lib/dyn-device.sh +123 -0
  40. package/skills/appstore-precheck/scripts/lib/dyn-explore.py +312 -0
  41. package/skills/appstore-precheck/scripts/lib/dyn-geometry.sh +75 -0
  42. package/skills/appstore-precheck/scripts/lib/dyn-guideline-capture.py +301 -0
  43. package/skills/appstore-precheck/scripts/lib/dyn-guidelines.py +112 -0
  44. package/skills/appstore-precheck/scripts/lib/dyn-guidelines.sh +23 -0
  45. package/skills/appstore-precheck/scripts/lib/dyn-hosts.sh +134 -0
  46. package/skills/appstore-precheck/scripts/lib/dyn-process.py +75 -0
  47. package/skills/appstore-precheck/scripts/lib/dyn-quorum.sh +90 -0
  48. package/skills/appstore-precheck/scripts/lib/dyn-scrub.py +79 -0
  49. package/skills/appstore-precheck/scripts/lib/dyn-signals.sh +120 -0
  50. package/skills/appstore-precheck/scripts/lib/guideline-text.sh +23 -5
  51. package/skills/appstore-precheck/scripts/lib/metadata-review.py +369 -0
  52. package/skills/appstore-precheck/scripts/lib/optin-scan.sh +73 -0
  53. package/skills/appstore-precheck/scripts/lib/optional-records.py +60 -0
  54. package/skills/appstore-precheck/scripts/lib/png-uniform.py +115 -0
  55. package/skills/appstore-precheck/scripts/lib/runtime-blocking.py +26 -0
  56. package/skills/appstore-precheck/scripts/lib/safe_write.py +61 -0
  57. package/skills/appstore-precheck/scripts/lib/scan-guidelines.sh +199 -0
  58. package/skills/appstore-precheck/scripts/lib/static-guidelines.py +341 -0
  59. package/skills/appstore-precheck/scripts/lib/static-reader.py +39 -0
  60. package/skills/appstore-precheck/scripts/metadata-review.sh +4 -0
  61. package/skills/appstore-precheck/scripts/opt-in-review.py +160 -0
  62. package/skills/appstore-precheck/scripts/runtime-review.sh +5 -0
  63. package/skills/appstore-precheck/scripts/scan.sh +132 -21
  64. package/skills/appstore-precheck/scripts/semantic/__init__.py +1 -0
  65. package/skills/appstore-precheck/scripts/semantic/client.py +95 -0
  66. package/skills/appstore-precheck/scripts/semantic/collect.py +165 -0
  67. package/skills/appstore-precheck/scripts/semantic/engine.py +320 -0
  68. package/skills/appstore-precheck/scripts/semantic/questions.py +167 -0
  69. package/skills/appstore-precheck/scripts/semantic/review_v4.py +81 -0
  70. package/skills/appstore-precheck/scripts/semantic-review.py +61 -0
@@ -0,0 +1,400 @@
1
+ #!/usr/bin/env bash
2
+ # dynamic-run.sh — the Phase 6 runner: a throwaway simulator, N deterministic launch
3
+ # repeats, the observation-based D-checks, and a transcript dynamic.sh can reconcile.
4
+ # macOS + Xcode only (xcrun). Bash 3.2 compatible. It NEVER builds: the .app must
5
+ # already exist (app-discover.sh finds one; the user confirms it).
6
+ #
7
+ # WHAT IT OBSERVES (each line carries its rule id; see simulator-dynamic-review.md)
8
+ # D0 dyn-install create → boot → status bar → privacy reset → install
9
+ # D1 dyn-launch N repeats, each on an erased device; four signals per repeat
10
+ # (process, screenshot, log stream, accessibility tree);
11
+ # FINDING only when every repeat failed, mixed carries its ratio
12
+ # D2 dyn-first-screen a non-blank first screen (screenshot + process)
13
+ # D7 dyn-dark-mode geometry heuristics under `simctl ui appearance dark`
14
+ # D8 dyn-dynamic-type the same at accessibility-extra-extra-extra-large
15
+ # D9 dyn-ipad-layout (--ipad) the same on an iPad simulator this run creates
16
+ # D10 dyn-shipped-* the INSTALLED bundle: Info.plist keys vs the repo plist,
17
+ # DTXcode (SDK floor), otool -L — nothing executed
18
+ # D11 dyn-hosts-contacted hosts from CFNetwork diagnostics (opt-in --pktap adds DNS)
19
+ # The selector-based checks (D3 paywall, D3b Restore tap, D4 prompts, D5 demo login,
20
+ # D6 screenshot parity) stay with the agent + Maestro MCP; on Flutter / KMP they are
21
+ # SKIPped up front here because those toolkits expose no semantics to Maestro.
22
+ #
23
+ # WHAT IT NEVER DOES: xcodebuild / flutter / gradle; touch a device it did not create
24
+ # (a --udid device is launched on, never erased, reset or deleted); write under the repo.
25
+ #
26
+ # USAGE
27
+ # dynamic-run.sh --app <path.app> [--repo DIR] [--framework rn|flutter|kmp|native]
28
+ # [--repo-plist Info.plist] [--repeats 3] [--window 10]
29
+ # [--device-type ID] [--runtime ID] [--ipad] [--pktap] [--out DIR] [--dry-run]
30
+ # dynamic-run.sh --udid <UDID> --bundle-id <id> [same options]
31
+ # Output: the transcript on stdout (also <out>/transcript.txt) + <out>/run.json.
32
+ # Then: dynamic.sh --transcript <out>/transcript.txt --findings <scan.json> \
33
+ # --target simulator --build-config <from run.json>
34
+ # Exit 0 ran; 3 setup failed (every check SKIP); 64 usage; 66 missing file; 69 no xcrun.
35
+
36
+ set -u
37
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
38
+ # shellcheck source=framework-detect.sh
39
+ . "$HERE/framework-detect.sh"
40
+ # shellcheck source=lib/dyn-quorum.sh
41
+ . "$HERE/lib/dyn-quorum.sh"
42
+ # shellcheck source=lib/dyn-device.sh
43
+ . "$HERE/lib/dyn-device.sh"
44
+ # shellcheck source=lib/dyn-signals.sh
45
+ . "$HERE/lib/dyn-signals.sh"
46
+ # shellcheck source=lib/dyn-geometry.sh
47
+ . "$HERE/lib/dyn-geometry.sh"
48
+ # shellcheck source=lib/dyn-hosts.sh
49
+ . "$HERE/lib/dyn-hosts.sh"
50
+ # shellcheck source=lib/dyn-bundle.sh
51
+ . "$HERE/lib/dyn-bundle.sh"
52
+ # shellcheck source=lib/dyn-guidelines.sh
53
+ . "$HERE/lib/dyn-guidelines.sh"
54
+
55
+ # --- Arguments --------------------------------------------------------------------
56
+ APP="" UDID="" BID="" REPO="" FRAMEWORK="" REPO_PLIST="" REPEATS=3 WINDOW=10
57
+ DEVTYPE="" RUNTIME="" IPAD=0 PKTAP=0 OUT="" DYN_DRY_RUN=0 EXPLORE=0 DEMO=0 AUTH_NAV=""
58
+ usage_err() { echo "dynamic-run.sh: $1" >&2; exit 64; }
59
+ need() { [[ $# -ge 2 ]] || usage_err "$1 needs a value"; }
60
+ while [[ $# -gt 0 ]]; do
61
+ case "$1" in
62
+ --app) need "$@"; APP="$2"; shift 2 ;;
63
+ --udid) need "$@"; UDID="$2"; shift 2 ;;
64
+ --bundle-id) need "$@"; BID="$2"; shift 2 ;;
65
+ --repo) need "$@"; REPO="$2"; shift 2 ;;
66
+ --framework) need "$@"; FRAMEWORK="$2"; shift 2 ;;
67
+ --repo-plist) need "$@"; REPO_PLIST="$2"; shift 2 ;;
68
+ --repeats) need "$@"; REPEATS="$2"; shift 2 ;;
69
+ --window) need "$@"; WINDOW="$2"; shift 2 ;;
70
+ --device-type) need "$@"; DEVTYPE="$2"; shift 2 ;;
71
+ --runtime) need "$@"; RUNTIME="$2"; shift 2 ;;
72
+ --out) need "$@"; OUT="$2"; shift 2 ;;
73
+ --explore) EXPLORE=1; shift ;;
74
+ --demo-login) DEMO=1; shift ;;
75
+ --authorized-navigation) need "$@"; AUTH_NAV="$2"; EXPLORE=1; shift 2 ;;
76
+ --ipad) IPAD=1; shift ;;
77
+ --pktap) PKTAP=1; shift ;;
78
+ --dry-run) DYN_DRY_RUN=1; shift ;;
79
+ *) usage_err "unknown option '$1'" ;;
80
+ esac
81
+ done
82
+ if [[ -n "$AUTH_NAV" ]]; then
83
+ [[ -f "$AUTH_NAV" ]] || usage_err '--authorized-navigation needs a JSON allowlist file'
84
+ fi
85
+ export DYN_DRY_RUN
86
+ if [[ -n "$APP" && -n "$UDID" ]]; then usage_err "give --app OR --udid, not both"; fi
87
+ if [[ -z "$APP" && -z "$UDID" ]]; then usage_err "one of --app <path.app> or --udid <UDID> --bundle-id <id> is required"; fi
88
+ if [[ -n "$UDID" && -z "$BID" ]]; then usage_err "--udid needs --bundle-id"; fi
89
+ [[ "$REPEATS" =~ ^[0-9]+$ ]] && (( REPEATS >= 1 )) || usage_err "--repeats must be a positive integer"
90
+ [[ "$WINDOW" =~ ^[0-9]+$ ]] || usage_err "--window must be an integer number of seconds"
91
+ case "$FRAMEWORK" in ""|rn|flutter|kmp|native) ;; *) usage_err "--framework must be rn|flutter|kmp|native" ;; esac
92
+ if [[ -n "$APP" ]]; then
93
+ [[ -d "$APP" ]] || { echo "dynamic-run.sh: no such .app: $APP" >&2; exit 66; }
94
+ [[ -f "$APP/Info.plist" ]] || { echo "dynamic-run.sh: $APP has no Info.plist (not an installable bundle)" >&2; exit 66; }
95
+ fi
96
+ [[ -n "$REPO" && ! -d "$REPO" ]] && { echo "dynamic-run.sh: --repo is not a directory: $REPO" >&2; exit 66; }
97
+ command -v xcrun >/dev/null 2>&1 || { echo "dynamic-run.sh: xcrun not found — this tier needs macOS with Xcode (it is permanently local-only)" >&2; exit 69; }
98
+ [[ -z "$FRAMEWORK" ]] && { if [[ -n "$REPO" ]]; then FRAMEWORK="$(detect_framework "$REPO")"; else FRAMEWORK=native; fi; }
99
+ [[ -n "$OUT" ]] || OUT="$(mktemp -d "${TMPDIR:-/tmp}/precheck-dynamic.XXXXXX")"
100
+ if [[ -n "$REPO" ]]; then
101
+ python3 - "$OUT" "$REPO" <<'PYCODE' || usage_err '--out must be outside the project'
102
+ from pathlib import Path
103
+ import sys
104
+ out, repo = [Path(x).resolve() for x in sys.argv[1:]]
105
+ raise SystemExit(1 if out == repo or repo in out.parents else 0)
106
+ PYCODE
107
+ fi
108
+ mkdir -p "$OUT" || { echo "dynamic-run.sh: cannot create --out $OUT" >&2; exit 66; }
109
+ OUT="$(cd "$OUT" && pwd -P)"
110
+ for _output in transcript.txt plan.txt run.json owned-simulators.txt deleted-simulators.txt cleanup-failures.txt; do
111
+ [[ ! -L "$OUT/$_output" ]] || usage_err 'output file is a symlink'
112
+ done
113
+ [[ ! -L "$OUT/explore" ]] || usage_err 'exploration output is a symlink'
114
+ rm -f "$OUT/explore/screen-inventory.json"
115
+ DYN_OWNED_LEDGER="$OUT/owned-simulators.txt"; : > "$DYN_OWNED_LEDGER"; export DYN_OWNED_LEDGER
116
+ DYN_EXT_DIR="$(mktemp -d "$OUT/guideline-observations.XXXXXX")" || { echo "dynamic-run.sh: cannot create private observations directory" >&2; exit 66; }
117
+ TRANSCRIPT="$OUT/transcript.txt"; : > "$TRANSCRIPT"
118
+ DYN_PLAN_FILE="$OUT/plan.txt"; : > "$DYN_PLAN_FILE"; export DYN_PLAN_FILE
119
+
120
+ # --- Transcript helpers -------------------------------------------------------------
121
+ emit() { printf '%s\n' "$1" | tee -a "$TRANSCRIPT"; }
122
+ note() { printf '# %s\n' "$1" | tee -a "$TRANSCRIPT"; }
123
+ skip_all() { # skip_all <reason> — every observation this runner owns, as SKIP with one cause.
124
+ local id g
125
+ for id in dyn-launch dyn-first-screen dyn-dark-mode dyn-dynamic-type dyn-ipad-layout \
126
+ dyn-shipped-bundle dyn-shipped-sdk dyn-shipped-links dyn-hosts-contacted \
127
+ dyn-cpu-idle dyn-capture-indicator dyn-musickit-auth dyn-miniapp-index \
128
+ dyn-miniapp-rating-label dyn-location-timing; do
129
+ case "$id" in dyn-launch|dyn-first-screen) g=2.1 ;; dyn-dark-mode|dyn-dynamic-type) g=4.0 ;; dyn-ipad-layout) g=2.4.1 ;;
130
+ dyn-shipped-sdk) g=2.1 ;; dyn-shipped-links) g=2.5.1 ;; dyn-hosts-contacted) g=5.1.2 ;; dyn-cpu-idle) g=2.4.2 ;; dyn-capture-indicator) g=2.5.14 ;;
131
+ dyn-musickit-auth) g=4.5.2 ;; dyn-miniapp-index) g=4.7.4 ;; dyn-miniapp-rating-label) g=4.7.5 ;;
132
+ dyn-location-timing) g=5.1.5 ;; *) g=5.1.1 ;; esac
133
+ emit "$(dyn_line SKIP "$g" "$id" "$1")"
134
+ done
135
+ }
136
+
137
+ if (( DEMO && EXPLORE )) && [[ -z "$AUTH_NAV" ]]; then
138
+ EXPLORE=0
139
+ note 'authenticated exploration disabled: --demo-login requires explicit --authorized-navigation allowlist'
140
+ fi
141
+
142
+ # --- Identity of the app under test ---------------------------------------------------
143
+ BUILD_CONFIG="unknown" EXE="" APP_LABEL=""
144
+ if [[ -n "$APP" ]]; then
145
+ BID="$(dyn_plist_string "$APP/Info.plist" CFBundleIdentifier)"
146
+ EXE="$(dyn_plist_string "$APP/Info.plist" CFBundleExecutable)"
147
+ BUILD_CONFIG="$(dyn_config_from_dir "$APP")"
148
+ APP_LABEL="$(basename "$(dirname "$APP")")/$(basename "$APP")"
149
+ [[ -n "$BID" ]] || { emit "$(dyn_line SKIP setup dyn-install "$APP_LABEL has no CFBundleIdentifier in Info.plist; not installable")"; skip_all "setup failed: no bundle id"; exit 3; }
150
+ fi
151
+ [[ -n "$EXE" ]] || EXE="${BID##*.}"
152
+
153
+ # Metro precondition (React Native): a Debug .app without an embedded main.jsbundle
154
+ # loads its JS from Metro on port 8081. Without Metro EVERY RN app "crashes on launch",
155
+ # which would be a false FINDING, so the launch checks are SKIPped instead.
156
+ METRO_SKIP=0
157
+ if [[ "$FRAMEWORK" == rn && -n "$APP" && ! -f "$APP/main.jsbundle" ]]; then
158
+ if ! (exec 3<>/dev/tcp/127.0.0.1/8081) 2>/dev/null; then METRO_SKIP=1; fi
159
+ fi
160
+
161
+ # --- Teardown, always -------------------------------------------------------------------
162
+ CREATED_UDID="" CREATED_IPAD="" PKTAP_PID=""
163
+ cleanup() {
164
+ dyn_log_stop
165
+ [[ -n "$PKTAP_PID" ]] && { sudo kill "$PKTAP_PID" 2>/dev/null || kill "$PKTAP_PID" 2>/dev/null; PKTAP_PID=""; }
166
+ dyn_device_teardown "$CREATED_UDID"; CREATED_UDID=""
167
+ dyn_device_teardown "$CREATED_IPAD"; CREATED_IPAD=""
168
+ return 0
169
+ }
170
+ trap cleanup EXIT
171
+ trap 'exit 130' INT
172
+ trap 'exit 143' TERM
173
+
174
+ # --- D0: device + install -------------------------------------------------------------------
175
+ [[ -n "$RUNTIME" ]] || RUNTIME="$(dyn_pick_runtime)"
176
+ [[ -n "$DEVTYPE" ]] || DEVTYPE="$(dyn_pick_device_type iphone)"
177
+ DEV_NAME="precheck-$(date +%Y%m%d%H%M%S)-$$"
178
+ if [[ -n "$APP" ]]; then
179
+ [[ -n "$RUNTIME" && -n "$DEVTYPE" ]] || { emit "$(dyn_line SKIP setup dyn-install "no available iOS runtime / iPhone device type to create a simulator from")"; skip_all "setup failed: no runtime"; exit 3; }
180
+ CREATED_UDID="$(dyn_device_create "$DEV_NAME" "$DEVTYPE" "$RUNTIME")"
181
+ [[ -n "$CREATED_UDID" ]] || { emit "$(dyn_line SKIP setup dyn-install "simctl create failed for $DEVTYPE on $RUNTIME")"; skip_all "setup failed: simctl create"; exit 3; }
182
+ UDID="$CREATED_UDID"
183
+ dyn_device_boot "$UDID"
184
+ dyn_device_prepare "$UDID"
185
+ if ! inst_err="$(dyn_device_install "$UDID" "$APP" 2>&1 >/dev/null)"; then
186
+ emit "$(dyn_line SKIP setup dyn-install "simctl install failed for $APP_LABEL: ${inst_err:-non-zero exit} (wrong architecture, a device build, or a corrupt bundle)")"
187
+ skip_all "setup failed: simctl install"; exit 3
188
+ fi
189
+ emit "$(dyn_line PASS setup dyn-install "installed $BID from $APP_LABEL on $DEV_NAME ($UDID, created by this run; erased before each repeat, deleted after; build config $BUILD_CONFIG from the directory name)")"
190
+ else
191
+ emit "$(dyn_line PASS setup dyn-install "using user-supplied device $UDID for $BID (not created by this run: never erased, reset or deleted; repeats relaunch without a fresh erase, so they are less deterministic; build config unknown)")"
192
+ fi
193
+ INSTALLED="$(dyn_device_container "$UDID" "$BID")"
194
+ [[ -n "$INSTALLED" && -d "$INSTALLED" ]] || INSTALLED="$APP"
195
+
196
+ # --- D10: the installed bundle (nothing executed) -----------------------------------------------
197
+ if [[ -n "$INSTALLED" && -f "$INSTALLED/Info.plist" ]]; then
198
+ if [[ -z "$REPO_PLIST" && -n "$REPO" ]]; then
199
+ while IFS= read -r p; do
200
+ [[ "$(dyn_plist_string "$p" CFBundleIdentifier)" == "$BID" ]] && { REPO_PLIST="$p"; break; }
201
+ done < <(find "$REPO" -name Info.plist -not -path '*/build/*' -not -path '*/DerivedData/*' -not -path '*/Pods/*' -not -path '*/node_modules/*' 2>/dev/null)
202
+ fi
203
+ while IFS= read -r l; do emit "$l"; done < <(dyn_bundle_plist_lines "$INSTALLED/Info.plist" "$REPO_PLIST")
204
+ emit "$(dyn_bundle_sdk_line "$INSTALLED/Info.plist")"
205
+ emit "$(dyn_bundle_links_line "$INSTALLED")"
206
+ else
207
+ emit "$(dyn_line SKIP 5.1.1 dyn-shipped-bundle "installed bundle path could not be resolved (simctl get_app_container)")"
208
+ emit "$(dyn_line SKIP 2.1 dyn-shipped-sdk "installed bundle path could not be resolved")"
209
+ emit "$(dyn_line SKIP 2.5.1 dyn-shipped-links "installed bundle path could not be resolved")"
210
+ fi
211
+
212
+ # --- pktap (opt-in, sudo) ---------------------------------------------------------------------------
213
+ if (( PKTAP )) && [[ "$DYN_DRY_RUN" != 1 ]]; then
214
+ sudo -n tcpdump -i pktap,en0 -k P -w "$OUT/capture.pcap" >/dev/null 2>&1 & PKTAP_PID=$!
215
+ sleep 1; kill -0 "$PKTAP_PID" 2>/dev/null || { PKTAP_PID=""; note "pktap capture could not start (sudo -n tcpdump); hosts come from CFNetwork diagnostics only"; }
216
+ elif (( PKTAP )); then
217
+ dyn_plan "sudo tcpdump -i pktap,en0 -k P -w $OUT/capture.pcap &"
218
+ fi
219
+
220
+ # --- D1 / D2: N launch repeats ----------------------------------------------------------------------
221
+ FRESH_ERASES=0 DEMO_PASS=0 DEMO_FIND=0 DEMO_SKIP=0
222
+ L_PASS=0 L_FIND=0 L_SKIP=0 S_PASS=0 S_FIND=0 S_SKIP=0 LAST_DETAIL="" LAST_SIGNALS="" LAUNCH_KIND="SKIP"
223
+ if (( METRO_SKIP )); then
224
+ emit "$(dyn_line SKIP 2.1 dyn-launch "Metro bundler not running on 127.0.0.1:8081 and $APP_LABEL embeds no main.jsbundle; a React Native Debug build cannot load its JavaScript, so a launch would fail for a reason that is not the app's — start Metro or supply a release bundle")"
225
+ emit "$(dyn_line SKIP 2.1 dyn-first-screen "launch skipped (Metro not running)")"
226
+ else
227
+ i=1
228
+ while (( i <= REPEATS )); do
229
+ if [[ -n "$CREATED_UDID" ]]; then
230
+ if ! dyn_device_erase "$UDID" || ! dyn_device_boot "$UDID" || ! dyn_device_install "$UDID" "$APP" >/dev/null 2>&1; then
231
+ L_SKIP=$((L_SKIP+1)); S_SKIP=$((S_SKIP+1)); i=$((i+1)); continue
232
+ fi
233
+ dyn_device_prepare "$UDID"
234
+ [[ "$DYN_DRY_RUN" == 1 ]] || FRESH_ERASES=$((FRESH_ERASES+1))
235
+ fi
236
+ r="$(dyn_repeat "$UDID" "$BID" "$EXE" "$WINDOW" "$OUT" "$i")"
237
+ kind="$(cut -f1 <<<"$r")"; LAST_DETAIL="$(cut -f2 <<<"$r")"; LAST_SIGNALS="$(cut -f3 <<<"$r")"
238
+ case "$kind" in PASS) L_PASS=$((L_PASS+1)) ;; FINDING) L_FIND=$((L_FIND+1)) ;; *) L_SKIP=$((L_SKIP+1)) ;; esac
239
+ # D2 from the same repeat: a varied screenshot with a live process is a real first screen.
240
+ proc="${LAST_SIGNALS%%,*}"; rest="${LAST_SIGNALS#*,}"; shot="${rest%%,*}"
241
+ if [[ "$shot" == varied && "$proc" == alive ]]; then S_PASS=$((S_PASS+1))
242
+ elif [[ "$shot" == uniform || "$proc" == dead ]]; then S_FIND=$((S_FIND+1))
243
+ else S_SKIP=$((S_SKIP+1)); fi
244
+ if [[ -n "$CREATED_UDID" && "$DYN_DRY_RUN" != 1 && "$kind" == PASS ]]; then
245
+ dyn_extended_capture "$i"
246
+ fi
247
+ i=$((i+1))
248
+ done
249
+ q="$(dyn_quorum "$L_PASS" "$L_FIND" "$L_SKIP")"; LAUNCH_KIND="$(cut -f1 <<<"$q")"
250
+ FRESH_NOTE="fresh erase not established"
251
+ (( FRESH_ERASES == REPEATS && REPEATS >= 3 )) && FRESH_NOTE="fresh erase verified"
252
+ emit "$(dyn_line "$LAUNCH_KIND" 2.1 dyn-launch "$(cut -f2 <<<"$q"); last repeat: $LAST_DETAIL; window ${WINDOW}s; screenshots $OUT/launch-*.png; $FRESH_NOTE")"
253
+ q="$(dyn_quorum "$S_PASS" "$S_FIND" "$S_SKIP")"
254
+ emit "$(dyn_line "$(cut -f1 <<<"$q")" 2.1 dyn-first-screen "$(cut -f2 <<<"$q") (a non-blank screenshot with the process alive after ${WINDOW}s; a splash stuck as a flat frame counts as failed)")"
255
+ fi
256
+
257
+ dyn_extended_report
258
+
259
+ # --- D7 / D8: dark mode and Dynamic Type geometry ------------------------------------------------------
260
+ geometry_pass() { # geometry_pass <rule-id> <guideline> <label> <tag>
261
+ local id="$1" g="$2" label="$3" tag="$4" tree png hier
262
+ png="$OUT/$tag.png"; hier="$OUT/$tag.json"
263
+ [[ "$DYN_DRY_RUN" == 1 ]] || sleep 2
264
+ dyn_signal_screenshot "$UDID" "$png" >/dev/null
265
+ tree="$(dyn_signal_tree "$UDID" "$hier")"
266
+ if [[ "$DYN_DRY_RUN" == 1 ]]; then emit "$(dyn_line SKIP "$g" "$id" "dry run: $label not observed")"; return 0; fi
267
+ [[ "$tree" == unread ]] && { emit "$(dyn_line SKIP "$g" "$id" "$label: accessibility tree could not be read (Maestro missing or timed out); screenshot $png for a human eye")"; return 0; }
268
+ emit "$(dyn_geometry_line "$(dyn_geometry_report "$hier" 0 0)" "$g" "$id" "$label" "$png")"
269
+ }
270
+ if (( METRO_SKIP )) || [[ "$LAUNCH_KIND" != PASS && "$L_PASS" -eq 0 ]]; then
271
+ emit "$(dyn_line SKIP 4.0 dyn-dark-mode "app did not stay up on any launch; layout not judged")"
272
+ emit "$(dyn_line SKIP 4.0 dyn-dynamic-type "app did not stay up on any launch; layout not judged")"
273
+ else
274
+ dyn_device_appearance "$UDID" dark
275
+ geometry_pass dyn-dark-mode 4.0 "dark appearance" dark
276
+ dyn_device_appearance "$UDID" light
277
+ dyn_device_content_size "$UDID" accessibility-extra-extra-extra-large
278
+ geometry_pass dyn-dynamic-type 4.0 "Dynamic Type accessibility-extra-extra-extra-large" dynamic-type
279
+ dyn_device_content_size "$UDID" large
280
+ fi
281
+
282
+ # --- D9: iPad (opt-in) --------------------------------------------------------------------------------
283
+ if (( IPAD )); then
284
+ if [[ -n "$INSTALLED" && -f "$INSTALLED/Info.plist" ]] && ! dyn_plist_supports_ipad "$INSTALLED/Info.plist"; then
285
+ emit "$(dyn_line SKIP 2.4.1 dyn-ipad-layout "not applicable: UIDeviceFamily has no iPad entry (an iPhone-only app runs in compatibility mode)")"
286
+ elif (( METRO_SKIP )); then
287
+ emit "$(dyn_line SKIP 2.4.1 dyn-ipad-layout "launch skipped (Metro not running)")"
288
+ else
289
+ IPAD_TYPE="$(dyn_pick_device_type ipad)"
290
+ CREATED_IPAD="$(dyn_device_create "${DEV_NAME}-ipad" "$IPAD_TYPE" "$RUNTIME")"
291
+ if [[ -z "$CREATED_IPAD" ]]; then
292
+ emit "$(dyn_line SKIP 2.4.1 dyn-ipad-layout "simctl create failed for $IPAD_TYPE")"
293
+ else
294
+ dyn_device_boot "$CREATED_IPAD"; dyn_device_prepare "$CREATED_IPAD"
295
+ if dyn_device_install "$CREATED_IPAD" "${APP:-}" >/dev/null 2>&1; then
296
+ saved="$UDID"; UDID="$CREATED_IPAD"
297
+ r="$(dyn_repeat "$UDID" "$BID" "$EXE" "$WINDOW" "$OUT" ipad)"
298
+ if [[ "$DYN_DRY_RUN" == 1 ]]; then emit "$(dyn_line SKIP 2.4.1 dyn-ipad-layout "dry run: iPad layout not observed")"
299
+ elif [[ "$(cut -f1 <<<"$r")" == PASS ]]; then geometry_pass dyn-ipad-layout 2.4.1 "iPad layout ($IPAD_TYPE)" ipad-layout
300
+ else emit "$(dyn_line SKIP 2.4.1 dyn-ipad-layout "app did not stay up on the iPad simulator: $(cut -f2 <<<"$r")")"; fi
301
+ UDID="$saved"
302
+ else
303
+ emit "$(dyn_line SKIP 2.4.1 dyn-ipad-layout "simctl install failed on the iPad simulator")"
304
+ fi
305
+ fi
306
+ fi
307
+ fi
308
+
309
+ # Demo credentials are introduced only after every normal screenshot/geometry pass.
310
+ run_demo_phase() {
311
+ local i=1 r kind demo_result fresh=0 fresh_note='fresh erase not established' q
312
+ (( DEMO )) || return 0
313
+ if [[ -z "$CREATED_UDID" || "$DYN_DRY_RUN" == 1 || "$L_PASS" -eq 0 ]]; then
314
+ DEMO_SKIP="$REPEATS"
315
+ else
316
+ while (( i <= REPEATS )); do
317
+ if ! dyn_device_erase "$UDID" || ! dyn_device_boot "$UDID" || ! dyn_device_install "$UDID" "$APP" >/dev/null 2>&1; then
318
+ DEMO_SKIP=$((DEMO_SKIP+1)); i=$((i+1)); continue
319
+ fi
320
+ dyn_device_prepare "$UDID"
321
+ fresh=$((fresh+1))
322
+ r="$(dyn_repeat "$UDID" "$BID" "$EXE" "$WINDOW" "$OUT" "demo-$i")"
323
+ kind="$(cut -f1 <<<"$r")"
324
+ if [[ "$kind" == PASS ]]; then
325
+ demo_result="$(python3 -B "$HERE/lib/dyn-demo-login.py" "$UDID" "$BID")"
326
+ case "$demo_result" in PASS*) DEMO_PASS=$((DEMO_PASS+1));; FINDING*) DEMO_FIND=$((DEMO_FIND+1));; *) DEMO_SKIP=$((DEMO_SKIP+1));; esac
327
+ else DEMO_SKIP=$((DEMO_SKIP+1)); fi
328
+ i=$((i+1))
329
+ done
330
+ fi
331
+ (( fresh == REPEATS && fresh >= 3 )) && fresh_note='fresh erase verified'
332
+ q="$(dyn_quorum "$DEMO_PASS" "$DEMO_FIND" "$DEMO_SKIP")"
333
+ emit "$(dyn_line "$(cut -f1 <<<"$q")" 2.1 dyn-demo-login "$(cut -f2 <<<"$q"); explicit login rejection count $DEMO_FIND; $fresh_note")"
334
+ }
335
+
336
+ run_exploration() {
337
+ local args=( --udid "$UDID" --bundle-id "$BID" --out "$OUT/explore" )
338
+ (( EXPLORE )) && [[ -n "$CREATED_UDID" && "$DYN_DRY_RUN" != 1 && "$L_PASS" -gt 0 ]] || return 0
339
+ [[ -z "$AUTH_NAV" ]] || args+=( --authorized-navigation "$AUTH_NAV" )
340
+ (( ! DEMO )) || args+=( --authenticated )
341
+ python3 -B "$HERE/lib/dyn-explore.py" "${args[@]}" >/dev/null 2>&1 || note 'screen exploration unavailable; inventory is not complete'
342
+ }
343
+
344
+ run_demo_phase
345
+ run_exploration
346
+
347
+ # --- D11: hosts contacted -----------------------------------------------------------------------------
348
+ HOSTS="$OUT/hosts.txt"; : > "$HOSTS"
349
+ cat "$OUT"/log-*.txt 2>/dev/null > "$OUT/log-all.txt" || : > "$OUT/log-all.txt"
350
+ dyn_hosts_from_log "$OUT/log-all.txt" >> "$HOSTS"
351
+ if [[ -n "$PKTAP_PID" ]]; then
352
+ sudo kill "$PKTAP_PID" 2>/dev/null || kill "$PKTAP_PID" 2>/dev/null; PKTAP_PID=""; sleep 1
353
+ tcpdump -nn -r "$OUT/capture.pcap" 'udp port 53' > "$OUT/dns.txt" 2>/dev/null || true
354
+ dyn_hosts_from_tcpdump_text "$OUT/dns.txt" >> "$HOSTS"
355
+ fi
356
+ sort -u -o "$HOSTS" "$HOSTS"
357
+ HOST_NOTE=""
358
+ if (( METRO_SKIP )); then HOST_NOTE="launch skipped (Metro not running)"
359
+ elif [[ "$DYN_DRY_RUN" == 1 ]]; then HOST_NOTE="dry run"
360
+ elif [[ ! -s "$HOSTS" && "$FRAMEWORK" == flutter ]]; then HOST_NOTE="Flutter's Dart HttpClient bypasses CFNetwork, so the log-based capture cannot see it; re-run with --pktap (sudo tcpdump) to read DNS for every process"
361
+ elif [[ ! -s "$HOSTS" ]]; then HOST_NOTE="CFNetwork diagnostics saw no request in a ${WINDOW}s window across $REPEATS repeat(s); a networking stack that bypasses CFNetwork would also be invisible here (--pktap)"
362
+ elif [[ -n "$PKTAP_PID" || -s "$OUT/dns.txt" ]]; then HOST_NOTE="CFNetwork diagnostics + DNS (pktap)"
363
+ else HOST_NOTE="CFNetwork diagnostics only; a stack that bypasses CFNetwork is invisible here"; fi
364
+ PRIV=""; [[ -n "$INSTALLED" && -f "$INSTALLED/PrivacyInfo.xcprivacy" ]] && PRIV="$INSTALLED/PrivacyInfo.xcprivacy"
365
+ emit "$(dyn_hosts_line "$(dyn_hosts_parity "$HOSTS" "$PRIV")" "$HOST_NOTE")"
366
+
367
+ # --- Selector-based checks: pre-SKIP on toolkits without semantics, else left to the agent ----------------
368
+ case "$FRAMEWORK" in
369
+ flutter|kmp)
370
+ why="not driveable on $FRAMEWORK: the accessibility tree exposes no semantics to Maestro (empty or single-node on a healthy screen), so selector-based steps cannot find controls; judge by screenshot"
371
+ emit "$(dyn_line SKIP 3.1.2 dyn-restore-tap "$why")"
372
+ emit "$(dyn_line SKIP 2.1 dyn-demo-login "$why")"
373
+ emit "$(dyn_line SKIP '5.1.1(ii)' dyn-permission-prompt "$why (trigger half); the OS prompt itself is native and visible in a screenshot")"
374
+ note "agent: D3 paywall, D6 screenshot parity remain observation-based and can still be judged from screenshots" ;;
375
+ *)
376
+ note "agent: selector-based checks left for Maestro MCP — D3 dyn-paywall-visible, D3b dyn-restore-tap, D4 dyn-permission-prompt:<KEY>, D5 dyn-demo-login, D6 dyn-screenshot-parity; one flow per maestro invocation; labels are in accessibilityText" ;;
377
+ esac
378
+
379
+ # --- Run metadata ------------------------------------------------------------------------------------------
380
+ jq -n --arg app "${APP:-}" --arg bid "$BID" --arg cfg "$BUILD_CONFIG" --arg fw "$FRAMEWORK" \
381
+ --arg udid "$UDID" --arg name "$DEV_NAME" --arg type "$DEVTYPE" --arg rt "$RUNTIME" \
382
+ --argjson n "$REPEATS" --argjson w "$WINDOW" --arg out "$OUT" --arg observations "$DYN_EXT_DIR" \
383
+ --argjson created "$([[ -n "$CREATED_UDID" ]] && echo true || echo false)" \
384
+ --argjson metro "$([[ "$METRO_SKIP" == 1 ]] && echo true || echo false)" \
385
+ --argjson dry "$([[ "$DYN_DRY_RUN" == 1 ]] && echo true || echo false)" \
386
+ --argjson fresh "$FRESH_ERASES" --argjson dp "$DEMO_PASS" --argjson df "$DEMO_FIND" --argjson ds "$DEMO_SKIP" \
387
+ --argjson lp "$L_PASS" --argjson lf "$L_FIND" --argjson ls "$L_SKIP" '
388
+ {app:(if $app=="" then null else $app end), bundle_id:$bid, build_config:$cfg, framework:$fw,
389
+ device:{udid:$udid, name:$name, type:$type, runtime:$rt, created_by_this_run:$created},
390
+ guideline_observations:$observations, fresh_erases:$fresh, demo_login:{pass:$dp,finding:$df,skip:$ds}, repeats:$n, window_seconds:$w, launch:{pass:$lp, finding:$lf, skip:$ls}, metro_skipped:$metro,
391
+ dry_run:$dry, out:$out, transcript:($out + "/transcript.txt"),
392
+ next:("dynamic.sh --transcript " + $out + "/transcript.txt --findings <scan.json> --target simulator --build-config " + $cfg)}' > "$OUT/run.json"
393
+ # Teardown now (the EXIT trap becomes a no-op) so the transcript and the plan are complete.
394
+ cleanup
395
+ if [[ "$DYN_DRY_RUN" == 1 ]]; then
396
+ echo "# dry run — the plan (nothing above was executed):"
397
+ cat "$DYN_PLAN_FILE"
398
+ fi
399
+ echo "dynamic-run: transcript $TRANSCRIPT · run.json $OUT/run.json · build config $BUILD_CONFIG (pass it to dynamic.sh --build-config)" >&2
400
+ exit 0