From 79c8e2fe49a1a2aef4ed8e8ccdbda9eb5d330464 Mon Sep 17 00:00:00 2001 From: Alan Vardy Date: Fri, 13 Nov 2026 07:22:08 -0700 Subject: [PATCH 1/9] chore: start alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in --- DELETEME | 1 + 1 file changed, 1 insertion(+) create mode 100644 DELETEME diff --git a/DELETEME b/DELETEME new file mode 100644 index 00000000..cbfd70f0 --- /dev/null +++ b/DELETEME @@ -0,0 +1 @@ +DELETEME (alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in) — placeholder; git rm before merging From 6c26232cc4a6ed9f668b58699a476fcd74630291 Mon Sep 17 00:00:00 2001 From: Alan Vardy Date: Fri, 13 Nov 2026 07:30:28 -0700 Subject: [PATCH 2/9] chore: add plan and task artifacts; drop DELETEME marker --- .../medium.md | 81 +++ .../plan.md | 555 ++++++++++++++++++ DELETEME | 1 - 3 files changed, 636 insertions(+), 1 deletion(-) create mode 100644 .pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/medium.md create mode 100644 .pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/plan.md delete mode 100644 DELETEME diff --git a/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/medium.md b/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/medium.md new file mode 100644 index 00000000..4846f8ee --- /dev/null +++ b/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/medium.md @@ -0,0 +1,81 @@ +# Task + +Change `scripts/run-devices.sh` so the **regular iPhone and iPad legs run in the +simulator** instead of on physical hardware, while the **physical iPhone Duo** +and the **macOS leg stay exactly as they are**. + +Concretely: + +1. **Split the iOS discovery filter.** Today one inline-Python filter over + `xcrun devicectl list devices -j` selects every physical `platform == iOS`, + `deviceType in (iPhone, iPad)` entry, and one build/install/launch loop runs + per entry — which sweeps in the physical `iPhone Duo` + (`scripts/fixtures/devicectl-devices.json`: `Fixture iPhone Duo | iOS iPhone + physical`). Split it so: + * physical **Duo** keeps the existing `devicectl` build / `install` / + `launch` path (targeting `Debug-iphoneos/SingleThread.app`); + * regular physical iPhone/iPad entries are dropped from the device loop. +2. **Add a simulator leg** for a regular iPhone and a regular iPad: + * Defaults `iPhone 17` and `iPad (A16)`, overridable via `SIM_IPHONE=` / + `SIM_IPAD=`, resolved to UDIDs with the **same precedence as + `scripts/test.sh:28-72`** (this worktree's `.simulator_id` → shared + default, pinned by UDID; never a bare ambiguous `name=`). + * Recipe to copy: `simctl boot` → `bootstatus -b` → build with + `-destination` = the sim → `simctl install` → `simctl launch`, against the + **sim** product path `Debug-iphonesimulator/SingleThread.app` (distinct + from the `Debug-iphoneos/` path the Duo uses). + * Respect the per-worktree simulator lock / window conventions (see the + `simulator` skill) — do not boot a shared device another lane holds. +3. **Escape hatch:** add `IOS_TARGET=sim|device` (default `sim`) so the old + all-physical behavior is one env var away. Document it in the header block. +4. **Two decisions the plan must resolve with the human** (the ticket flags + both as "decision needed"): + * Watch leg — leave on physical watches (ticket's assumption) or move to + paired watch sims. + * Duo identity — name match on `iPhone Duo` (fails open if renamed) vs a + hardcoded `DUO_DEVICE_ID=` env override. +5. **Summary output** must report both legs honestly (Duo launched, sims + launched, macOS status) instead of collapsing them into one line. +6. **Update `scripts/test-run-devices.sh` (223 lines):** the + `"every paired physical iPhone installs (Duo included)"` flow assertion + becomes Duo-only (1/1); the discovery-filter fixtures need a sim-vs-device + split; flow tests need a **stubbed `simctl`**; cover both happy and sad + paths (sim boot failure, missing sim product, Duo unreachable). + +Why: each current run costs N device builds and needs unlocked, on-network +hardware for the phone/iPad legs — that friction is what this removes. Sims give +the same "app is running where I can poke at it" feedback without the hardware +dance. No new unit-test target is required — `scripts/test-run-devices.sh` is +the coverage. Out of scope: the watch leg (unless decided above), the macOS leg, +and CI. + +## Why MEDIUM + +M1 holds: approach known — 2 flagged decisions only, no new technology (`simctl` +is already used), and a working recipe exists to copy +(`scripts/appstore-screenshots.sh:548-551`) alongside a UDID-resolution pattern +(`scripts/test.sh:28-72`). M2 holds: no schema/migration, no new subsystem or +integration, no API/UI surface, no new test target; the two open items are +scoped choices resolvable at the plan gate. M3 holds: **MULTI_MODULE** (spans +`scripts/run-devices.sh`, `scripts/test-run-devices.sh`, and the devicectl +fixture) and **BROAD_TEST_SURFACE** (the flow-test harness must gain a stubbed +`simctl` plus sim-vs-device fixtures and sad-path cases). This is known-approach +work at a broad size — one plan step, then the standard implement → review tail. + +## Key files + +* `scripts/run-devices.sh` (468 lines) — the target; iOS discovery filter, + device build/install/launch loop, leg counters, and Phase 3 summary, plus the + `RUN_WATCH` / `RUN_MAC` env-var pattern to mirror for `IOS_TARGET`. +* `scripts/test-run-devices.sh` (223 lines) — the coverage; `extract_filter()`, + `run_flow()` harness, the 3/3-launched assertion to retarget, and the fixture + assertions. +* `scripts/fixtures/devicectl-devices.json` — device inventory fixture; contains + the physical `Fixture iPhone Duo` and the sim entries that drive the + sim-vs-device split. +* `scripts/appstore-screenshots.sh:548-551` — the working `simctl` boot/install/ + launch recipe to copy. +* `scripts/test.sh:28-72` — `.simulator_id` / shared-default UDID resolution and + the multi-runtime ambiguity guard to replicate, not reinvent. +* `Makefile` / `scripts/test.sh` — check whether a new `IOS_TARGET`/fixture seam + needs wiring into the test gate. diff --git a/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/plan.md b/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/plan.md new file mode 100644 index 00000000..38745c18 --- /dev/null +++ b/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/plan.md @@ -0,0 +1,555 @@ +# Implementation Plan + +## Overview + +Change `scripts/run-devices.sh` so the regular iPhone/iPad legs and the Apple +Watch leg run in **simulators** by default, while the physical **iPhone Duo** +and the **macOS** leg stay on hardware. Add `IOS_TARGET=sim|device` (default +`sim`) so the old all-physical iOS sweep is one env var away, report every leg +honestly in the summary, and rewrite `scripts/test-run-devices.sh` to cover the +new behaviour offline (stubbed `simctl`, sim-vs-device fixtures, happy + sad +paths). + +**Decisions locked at the plan gate:** + +1. **`IOS_TARGET` scope (Q1 = A).** The Duo always deploys physically in both + modes. `IOS_TARGET` selects only how the *regular* iPhone/iPad legs run: + `sim` (default) → simulators; `device` → the old all-physical filter. +2. **Watch leg (Q2 = B).** The watch moves to **paired watch simulators**; the + physical `devicectl` watch discovery/install/launch path is removed. (The + watch app installs and launches on an unpaired watch sim — see + `scripts/appstore-screenshots.sh:29-31` — so no `simctl pair` step is + needed.) There is no `WATCH_TARGET` escape hatch: the ticket only asks for + `IOS_TARGET`, so `IOS_TARGET=device` restores the old physical iPhone/iPad + sweep but the watch stays on sims. +3. **Duo identity (Q3 = A, hybrid).** `DUO_DEVICE_ID=` wins when set; + otherwise a case-insensitive substring match on the device name + (`iPhone Duo`). This avoids the silent-drop failure mode of a name-only + match. + +**Out of scope (unchanged):** the macOS leg, CI, and the watch +auto-registration/4016 messaging (deleted with the physical watch path). + +## Verified ground truth (checked this session) + +- `scripts/run-devices.sh:41-56` declares the env vars and product paths to + mirror. `RUN_WATCH`/`RUN_MAC` (lines 42-43 in the file as read) are the + pattern for `IOS_TARGET`. +- Product paths: `$DERIVED_DATA/Build/Products/${CONFIGURATION}-iphoneos/SingleThread.app` + (Duo), `${CONFIGURATION}-watchos/SingleThreadWatch.app` (old physical watch), + `$CONFIGURATION/SingleThread.app` (macOS). The sim paths are + `Debug-iphonesimulator/SingleThread.app` and + `Debug-watchsimulator/SingleThreadWatch.app` + (`scripts/appstore-screenshots.sh:176,179`). +- The iOS discovery filter is the **first** `<<'PY'` heredoc + (`scripts/run-devices.sh:~88-133`); the watch filter is the second. The + deciding predicates are `platform == "iOS"`, `deviceType in ("iPhone","iPad")`, + `reality == "physical"`. +- Simulator UDID resolution to copy: `resolve_sim_udid()` at + `scripts/test.sh:27-36` (anchored `index(s, n " (") == 1`), worktree + precedence at `scripts/test.sh:53-75`. +- simctl boot/install/launch recipe to copy: + `scripts/appstore-screenshots.sh:696-700` (iOS) and `:834-837` (watch), + launch at `:623-625` / `:816-818`. +- `scripts/test-run-devices.sh` has `extract_filter()` (`:51-58`), a PATH-stub + harness `run_flow()` (`:129-147`), stubs for `xcodebuild`/`xcrun`/`open` + (`:117-127`), and product dirs `Debug-watchos`/`Debug-iphoneos`/`Debug` + (`:118-120`). **No `simctl` stub exists.** +- Fixture (`scripts/fixtures/devicectl-devices.json`) physical iOS entries: + `Fixture iPhone` (devMode enabled), `Fixture iPad DevMode Off`, + `Fixture iPhone Duo` (devMode disabled); simulated: `Fixture iPhone Sim`. +- No simulator lock file exists in this repo (only the `.simulator_id` + convention); `scripts/run-devices.sh` is not in the `Makefile` and is invoked + via the fish alias `r` (`~/.dev/dotfiles/fish/functions/r.fish`). + +--- + +## Phase 1: Walking skeleton — sim iPhone leg end-to-end + +Thinnest path that makes the new default real: `IOS_TARGET` exists, discovery +splits to Duo-only, and one regular iPhone boots in the simulator, gets the app +built/installed/launched, and is reported separately from the Duo. + +### Changes + +#### 1. Env vars + header — `scripts/run-devices.sh` + +**File**: `scripts/run-devices.sh` +**Action**: modify + +Add after `RUN_MAC` (around line 46): + +```bash +IOS_TARGET="${IOS_TARGET:-sim}" +SIM_IPHONE="${SIM_IPHONE:-}" # explicit UDID or device name; empty = worktree sim, else iPhone 17 +SIM_IPAD="${SIM_IPAD:-}" # explicit UDID or device name; empty = iPad (A16) +SIM_WATCH="${SIM_WATCH:-}" # explicit UDID or device name; empty = Apple Watch Series 11 (46mm) +DUO_DEVICE_ID="${DUO_DEVICE_ID:-}" +``` + +Add the default simulator names and the sim product paths alongside the +`APP_PATH` block: + +```bash +DEFAULT_IPHONE_SIM="iPhone 17" +DEFAULT_IPAD_SIM="iPad (A16)" +DEFAULT_WATCH_SIM="Apple Watch Series 11 (46mm)" +SIM_APP_PATH="$DERIVED_DATA/Build/Products/${CONFIGURATION}-iphonesimulator/SingleThread.app" +``` + +Update the header docstring (lines 4-40) to state: the regular iPhone/iPad legs +run in simulators by default; the iPhone Duo and macOS stay physical; the watch +runs in a simulator (Phase 3); and document the new overrides +(`IOS_TARGET=sim|device` default `sim`, `SIM_IPHONE=`, `SIM_IPAD=`, +`SIM_WATCH=`, `DUO_DEVICE_ID=`). Describe `IOS_TARGET=device` as "the old +all-physical iPhone/iPad sweep (the Duo is always deployed physically)". + +#### 2. UDID resolution helpers — `scripts/run-devices.sh` + +**File**: `scripts/run-devices.sh` +**Action**: modify + +Add after `cd "$(dirname "$0")/.."` (line 58). Copy `resolve_sim_udid` verbatim +from `scripts/test.sh:27-36` and add a worktree-preferring resolver: + +```bash +# Pin a name-only simulator to a concrete UDID. An anchored name match stops +# `iPhone 17` selecting the leftover "Gate iPhone 17" sim (scripts/test.sh:27-36). +resolve_sim_udid() { + local name="$1" + xcrun simctl list devices available \ + | awk -v n="$name" '{ s = $0; sub(/^[ \t]+/, "", s); if (index(s, n " (") == 1) print }' \ + | head -1 \ + | sed -E 's/.*\(([A-F0-9-]+)\).*/\1/' +} + +# Precedence: an explicit UDID passes through; else this worktree's dedicated +# simulator (.simulator_id, written by the worktree_sim fish function); else the +# named default. Always yields a concrete UDID — never a bare `name=`. +resolve_ios_udid() { # $1 = value (UDID or name), $2 = default name, $3 = 1 to prefer .simulator_id + local value="$1" default="$2" prefer_worktree="$3" udid="" + if [[ -n "$value" ]]; then + if [[ "$value" =~ ^[A-Fa-f0-9-]{36}$ ]]; then printf '%s\n' "$value"; return 0; fi + resolve_sim_udid "$value"; return 0 + fi + if [[ "$prefer_worktree" -eq 1 && -f .simulator_id ]]; then + udid="$(tr -d '[:space:]' < .simulator_id)" + if [[ -n "$udid" ]] && xcrun simctl list devices 2>/dev/null | grep -qF "($udid)"; then + printf '%s\n' "$udid"; return 0 + fi + fi + resolve_sim_udid "$default" +} +``` + +`SIM_IPHONE`/`SIM_IPAD`/`SIM_WATCH` are empty by default; the resolver's `$2` +is the named fallback, so no name is baked into the env vars. Keep +`.simulator_id` preference for the iPhone only (`$3=1`); the iPad and watch use +`$3=0`. + +Resolve the targets up front (just before the sim leg), then iterate the +resolved list — the iPad is added to this same array in Phase 2: + +```bash +sim_targets=() +if [[ "$IOS_TARGET" == "sim" ]]; then + sim_targets+=("iPhone|$(resolve_ios_udid "$SIM_IPHONE" "$DEFAULT_IPHONE_SIM" 1)") +fi +``` + +In device mode `sim_targets` stays empty and no simulator is touched. + +#### 3. Split the iOS discovery filter — `scripts/run-devices.sh` + +**File**: `scripts/run-devices.sh` +**Action**: modify + +Change the filter invocation to pass a mode and the Duo override, and branch the +predicate on `sys.argv[3]`: + +```bash +done < <(python3 - "$DEVICES_JSON" "$UNREACHABLE_LOG" "$IOS_TARGET" "$DUO_DEVICE_ID" <<'PY' +import json +import sys + +mode = sys.argv[3] if len(sys.argv) > 3 else "device" +duo_id = sys.argv[4] if len(sys.argv) > 4 else "" +# ... open payload/unreachable_log as today ... +``` + +Replace the device-selection predicate (the `platform`/`deviceType`/`reality` +block) with: + +```python + if hardware.get("platform") != "iOS": + continue + if hardware.get("deviceType") not in ("iPhone", "iPad"): + continue + if hardware.get("reality") != "physical": + continue + if mode != "device": + # Default sim mode: only the physical iPhone Duo is a devicectl + # target. DUO_DEVICE_ID wins when set; otherwise a name match. + if duo_id: + if device.get("identifier") != duo_id: + continue + elif "iphone duo" not in name.lower(): + continue +``` + +Update the surrounding comments to explain the split. Keep the unreachable +detection and Developer-Mode note unchanged. Change the discovery banner to +branch on mode: `==> Discovering the paired iPhone Duo…` in sim mode, the +existing all-physical banner in device mode. + +Also update the comment block above the loop (the "Building against each +device's own destination" note) to say it applies to the Duo / device mode. + +#### 4. iPhone simulator leg — `scripts/run-devices.sh` + +**File**: `scripts/run-devices.sh` +**Action**: modify + +Add `SIM_TOTAL`/`SIM_LAUNCHED` counters next to `IOS_LAUNCHED`. Insert a new +block **before** the device (Duo) loop, guarded by `[[ "$IOS_TARGET" == "sim" ]]`: + +```bash +# ── iPhone/iPad simulator leg ───────────────────────────────────────────────── +SIM_TOTAL=0 +SIM_LAUNCHED=0 +if [[ "$IOS_TARGET" == "sim" ]]; then + for spec in "${sim_targets[@]}"; do + sim_label="${spec%%|*}"; udid="${spec#*|}" + SIM_TOTAL=$((SIM_TOTAL + 1)) + if [[ -z "$udid" ]]; then + echo "❌ No available simulator for $sim_label — set SIM_IPHONE=/SIM_IPAD= to pin one." >&2 + failures=$((failures + 1)); continue + fi + echo "" + echo "==> Booting $sim_label simulator ($udid)…" + if ! xcrun simctl bootstatus "$udid" -b; then + echo "❌ Simulator $sim_label ($udid) failed to boot." >&2 + failures=$((failures + 1)); continue + fi + echo "==> Building $SCHEME ($CONFIGURATION) for the $sim_label simulator…" + if ! xcodebuild -scheme "$SCHEME" -destination "id=$udid" \ + -configuration "$CONFIGURATION" -derivedDataPath "$DERIVED_DATA" build; then + echo "❌ Build failed for the $sim_label simulator." >&2 + failures=$((failures + 1)); continue + fi + if [[ ! -d "$SIM_APP_PATH" ]]; then + echo "❌ Built app not found at $SIM_APP_PATH" >&2 + failures=$((failures + 1)); continue + fi + echo "==> Installing on the $sim_label simulator…" + if ! xcrun simctl install "$udid" "$SIM_APP_PATH"; then + echo "❌ Install failed on the $sim_label simulator." >&2 + failures=$((failures + 1)); continue + fi + echo "==> Launching on the $sim_label simulator…" + if xcrun simctl launch "$udid" "$BUNDLE_ID"; then + SIM_LAUNCHED=$((SIM_LAUNCHED + 1)) + else + echo "❌ Launch failed on the $sim_label simulator." >&2 + failures=$((failures + 1)) + fi + done +fi +``` + +(`bootstatus -b` boots a shutdown device and blocks until booted; the +codebase treats a non-zero bootstatus as a boot failure — keep `simctl boot … +|| true` optional/unnecessary here so the sad path is testable.) + +Update the zero-device gate (`if [[ ${#DEVICES[@]} -eq 0 ]]`) so sim mode does +not fail-fast when no Duo is found but `IOS_TARGET=sim` is set — sims always +provide an iOS target. Simplest: change the gate condition to +`if [[ ${#DEVICES[@]} -eq 0 && "$IOS_TARGET" != "sim" ]]`. + +#### 5. Summary split — `scripts/run-devices.sh` + +**File**: `scripts/run-devices.sh` +**Action**: modify + +Replace the first summary line with mode-aware lines: + +```bash +if [[ "$IOS_TARGET" == "sim" ]]; then + echo " iPhone/iPad (sim): $SIM_LAUNCHED/$SIM_TOTAL launched" + echo " iPhone Duo (device): $IOS_LAUNCHED/${#DEVICES[@]} launched, $UNREACHABLE_COUNT unreachable" +else + echo " iPhone/iPad (device): $IOS_LAUNCHED/${#DEVICES[@]} launched, $UNREACHABLE_COUNT unreachable" +fi +``` + +Update the final success sentence to count sims honestly, e.g. +`summary="Installed and launched on ${#DEVICES[@]} device(s) and $SIM_LAUNCHED simulator(s)"`. + +#### 6. Offline coverage — `scripts/test-run-devices.sh` + +**File**: `scripts/test-run-devices.sh` +**Action**: modify + +- **Filter invocation/args**: both `python3 "$work/ios.py"` calls (fixture + assertions `:66-95` and the wrong-shape block `:98-113`) must now pass mode + + Duo id, e.g.: + `python3 "$work/ios.py" "$FIXTURE" "$work/ios-unreachable.log" sim` for the + Duo assertions and `... device` for the legacy all-physical assertions. +- **New filter assertions** (sim mode): emits `|Fixture iPhone Duo` =1; + excludes `|Fixture iPhone` =0, `|Fixture iPad DevMode Off` =0, + `|Fixture iPhone Sim` =0; "Developer Mode off" count =1; unreachable =0. +- **`DUO_DEVICE_ID` assertion**: run the filter in sim mode with the Duo's + identifier (`CCCCCCCC-…0009`, exact value from the fixture) and assert it is + the only emission; with a bogus id assert 0 emissions. +- **Stubs**: extend the `xcrun` stub (`:124`) to answer simulator listings — + `simctl list devices [available]` prints deterministic lines including + `iPhone 17 (11111111-1111-1111-1111-111111111111) (Shutdown)` and + `iPad (A16) (22222222-…) (Shutdown)`; a `STUB_SIM_BOOT_FAIL=1` env makes + `simctl bootstatus` exit 1. Create + `"$work/derived/Build/Products/Debug-iphonesimulator/SingleThread.app"` next + to the existing product dirs (`:118-120`). +- **Flow assertions**: + - Retarget `"every paired physical iPhone installs (Duo included)"` → assert + the Duo-only discovery + sim line, e.g. want text + `iPhone Duo (device): 1/1 launched` and absent `No reachable iPhone/iPad found.` + (`DEVICES_JSON_IN="$FIXTURE" RUN_WATCH=0 RUN_MAC=0`). + - Add `"default sim mode launches the iPhone simulator"`: want + `iPhone/iPad (sim): 1/1 launched` and `==> Launching on the iPhone simulator`. + - Add `"IOS_TARGET=device restores the all-physical sweep"`: env + `IOS_TARGET=device`, want `iPhone/iPad (device): 3/3 launched`, absent + `iPhone/iPad (sim)`. + +### Verification +#### Automated +- [ ] `bash -n scripts/run-devices.sh` passes +- [ ] `shellcheck -S warning --exclude=SC1111 scripts/run-devices.sh` passes +- [ ] `bash scripts/test-run-devices.sh` passes (all filter + flow checks) +- [ ] `make lint` passes (no source changes, sanity only) + +#### Manual +- [ ] `IOS_TARGET=device DEVICES_JSON_IN=scripts/fixtures/devicectl-devices.json RUN_WATCH=0 RUN_MAC=0 ./scripts/run-devices.sh` emits the old all-physical discovery/filter messages and the `(device)` summary line (stub or real hardware not required for the discovery lines; use the test harness log). +- [ ] After the sim leg runs for real, `xcrun simctl list devices | grep 11111111` is irrelevant — instead confirm the booted worktree sim shows the app launched. + +--- + +## Phase 2: iPad simulator leg + sim sad paths + +Add the iPad to the sim target list, make the loop drive both, and cover the +simulator failure modes. + +### Changes + +#### 1. iPad target — `scripts/run-devices.sh` + +**File**: `scripts/run-devices.sh` +**Action**: modify + +Extend the loop's target list to two entries (the loop already handles a list): + +```bash + sim_targets+=("iPad|$(resolve_ios_udid "$SIM_IPAD" "$DEFAULT_IPAD_SIM" 0)") +``` + +The iPad is resolved with `$3=0` so it never inherits `.simulator_id`. +(`SIM_TOTAL` becomes 2 automatically.) + +No lock machinery is added: this repo has no lock file. Respect the +`.simulator_id` convention (iPhone only) and never call +`simctl shutdown all`/`booted` — boot exactly the resolved UDIDs and leave them +running, since the point of the script is a live app to poke at. + +#### 2. Sad-path coverage — `scripts/test-run-devices.sh` + +**File**: `scripts/test-run-devices.sh` +**Action**: modify + +- Update the phase-1 sim flow expectation to `iPhone/iPad (sim): 2/2 launched`. +- Add `"simulator boot failure is a failed step"`: env `STUB_SIM_BOOT_FAIL=1`, + expect exit 1 and `failed to boot`; assert the Duo/macOS legs still ran. +- Add `"missing sim product is a failed step"`: pass + `DERIVED_DATA="$work/derived-nosim"` (a tree with `Debug`/`Debug-iphoneos`/ + `Debug-watchos` but no `Debug-iphonesimulator`) in the `run_flow` env args + (later `env` assignments win), expect exit 1 and `Built app not found at`. +- Add `"unresolvable iPad sim is a failed step"`: `SIM_IPAD=No Such Device`, + expect exit 1 and `No available simulator for iPad`. + +### Verification +#### Automated +- [ ] `bash -n scripts/run-devices.sh` and `shellcheck -S warning --exclude=SC1111 scripts/run-devices.sh` pass +- [ ] `bash scripts/test-run-devices.sh` passes, including the three new sad-path flows + +#### Manual +- [ ] `./scripts/run-devices.sh` (or `r`) boots the worktree iPhone sim **and** + the iPad sim, installs/launches `SingleThread` on both, and the summary prints + `iPhone/iPad (sim): 2/2 launched`. +- [ ] With `SIM_IPAD=No Such Device ./scripts/run-devices.sh`, the run reports + the iPad as a failed step but still launches the Duo (if present) and macOS. + +--- + +## Phase 3: Watch leg on paired watch simulators + +Replace the physical watch discovery + devicectl loop with a watch-sim +boot/build/install/launch leg; delete the now-dead watch filter and its +messaging. + +### Changes + +#### 1. Remove the physical watch path — `scripts/run-devices.sh` + +**File**: `scripts/run-devices.sh` +**Action**: modify + +Delete: +- the second `<<'PY'` discovery heredoc and the whole `WATCH_DEVICES` / + `WATCH_UNREACHABLE_COUNT` discovery block (the block guarded by `RUN_WATCH`), +- `WATCH_UNREACHABLE_LOG` from the env block and the `trap`, and + `WATCH_UNREACHABLE_COUNT` from the `failures` tally, +- `WATCH_BUILD_NEEDED` and every reference to it (zero-device gate, banner + wording), +- the per-watch loop and the generic unreachable-watch fallback build, +- `WATCH_LAUNCHED`/`WATCH_FAILED`'s physical semantics and + `record_watch_launch_form` / `WATCH_LAUNCH_FORM` / `WATCH_LAUNCH_FORM_MIXED` + (simctl launch has no flag variance). + +Keep `RUN_WATCH` (and its `=0` skip semantics) and `WATCH_BUNDLE_ID`. + +Add a `WATCH_SIM_APP_PATH`: +`$DERIVED_DATA/Build/Products/${CONFIGURATION}-watchsimulator/SingleThreadWatch.app`. + +#### 2. Watch simulator leg — `scripts/run-devices.sh` + +**File**: `scripts/run-devices.sh` +**Action**: modify + +```bash +# ── Apple Watch simulator leg ───────────────────────────────────────────────── +WATCH_TOTAL=0 +WATCH_LAUNCHED=0 +WATCH_FAILED=0 +if [[ "$RUN_WATCH" -eq 1 ]]; then + watch_udid="$(resolve_sim_udid "$SIM_WATCH")" + if [[ -z "$watch_udid" ]]; then + echo " (no '$SIM_WATCH' simulator available — skipping the Apple Watch leg; set SIM_WATCH= to pin one)" + else + WATCH_TOTAL=1 + echo "" + echo "==> Booting Apple Watch simulator ($SIM_WATCH, $watch_udid)…" + if ! xcrun simctl bootstatus "$watch_udid" -b; then + echo "❌ Apple Watch simulator failed to boot." >&2 + failures=$((failures + 1)); WATCH_FAILED=1 + else + echo "==> Building SingleThreadWatch ($CONFIGURATION) for the simulator…" + if ! xcodebuild -scheme SingleThreadWatch -destination "id=$watch_udid" \ + -configuration "$CONFIGURATION" -derivedDataPath "$DERIVED_DATA" build; then + echo "❌ Watch build failed." >&2 + failures=$((failures + 1)); WATCH_FAILED=1 + elif [[ ! -d "$WATCH_SIM_APP_PATH" ]]; then + echo "❌ Built watch app not found at $WATCH_SIM_APP_PATH" >&2 + failures=$((failures + 1)); WATCH_FAILED=1 + else + echo "==> Installing on the Apple Watch simulator…" + if ! xcrun simctl install "$watch_udid" "$WATCH_SIM_APP_PATH"; then + echo "❌ Watch install failed." >&2 + failures=$((failures + 1)); WATCH_FAILED=1 + else + echo "==> Launching $WATCH_BUNDLE_ID on the Apple Watch simulator…" + if xcrun simctl launch "$watch_udid" "$WATCH_BUNDLE_ID"; then + WATCH_LAUNCHED=1 + else + echo "❌ Watch launch failed." >&2 + failures=$((failures + 1)); WATCH_FAILED=1 + fi + fi + fi + fi + fi +fi +``` + +#### 3. Watch summary line — `scripts/run-devices.sh` + +**File**: `scripts/run-devices.sh` +**Action**: modify + +```bash +if [[ "$RUN_WATCH" -eq 0 ]]; then + echo " Apple Watch (sim): skipped (RUN_WATCH=0)" +elif [[ "$WATCH_TOTAL" -eq 0 ]]; then + echo " Apple Watch (sim): no simulator available (not a failure)" +else + echo " Apple Watch (sim): $WATCH_LAUNCHED launched, $WATCH_FAILED failed" +fi +``` + +Drop the launch-flag lines. Update the final success sentence's watch phrase to +the same `and $WATCH_LAUNCHED Apple Watch(es)` wording if any watch launched. + +#### 4. Update the header — `scripts/run-devices.sh` + +**File**: `scripts/run-devices.sh` +**Action**: modify + +Add `SIM_WATCH=` to the overrides list. Replace the "Apple Watch prerequisite" +paragraph (wrist / paired-iPhone / tunnel) with the simulator requirement: the +named watch simulator must exist; `simctl` installs and launches the watch app +on an unpaired watch sim (`scripts/appstore-screenshots.sh:29-31`). + +#### 5. Rewrite watch coverage — `scripts/test-run-devices.sh` + +**File**: `scripts/test-run-devices.sh` +**Action**: modify + +- Delete `extract_filter 2`, `"$work/watch.py"`, and every watch-filter fixture + assertion (`:88-95`); the "did a heredoc move" guard reduces to the single iOS + filter (`extract_filter 1`). +- Delete the `watch()` fixture helper, `flow-unreachable-watch.json`, + `flow-reachable-watch.json`, and the watch flows + `"unreachable-watch-only still builds"` / `"reachable-watch-only succeeds"`. +- Extend the `xcrun` stub to resolve the watch name + (`Apple Watch Series 11 (46mm) (33333333-…) (Shutdown)`) and stub + `simctl install`/`launch`; create + `"$work/derived/Build/Products/Debug-watchsimulator/SingleThreadWatch.app"` + and drop the now-unused `Debug-watchos` dir if nothing reads it. +- Keep/extend `"no iOS and no watch keeps the iOS fail-fast"` and + `"RUN_WATCH=0 emits no watch output"` against `flow-no-devices.json` with + `IOS_TARGET=device` so the old fail-fast semantics stay asserted. +- Add `"watch simulator leg launches"`: default env, want + `Apple Watch (sim): 1 launched, 0 failed` and + `==> Launching app.alanvardy.SingleThread.watchkitapp on the Apple Watch simulator`. +- Add `"no watch simulator available is not a failure"`: + `SIM_WATCH=No Such Watch`, expect a `no ... simulator available` notice, the + watch leg skipped without a failure, and exit 0 when macOS/watch are the only + legs (mirrors the old "no installable watch found (not a failure)" behavior). +- Add `"watch simulator boot failure is a failed step"`: + `STUB_SIM_BOOT_FAIL=1` plus `IOS_TARGET=device`/no iOS devices, expect exit 1 + and `Apple Watch simulator failed to boot`. + +### Verification +#### Automated +- [ ] `bash -n scripts/run-devices.sh` and + `shellcheck -S warning --exclude=SC1111 scripts/run-devices.sh` pass +- [ ] `bash scripts/test-run-devices.sh` passes with the rewritten watch flows +- [ ] No `devicectl` watch references remain: + `rg -n 'WATCH_DEVICES|WATCH_UNREACHABLE|watchkitapp.*devicectl|4016' scripts/run-devices.sh` returns nothing + +#### Manual +- [ ] `./scripts/run-devices.sh` (or `r`) boots an Apple Watch simulator, + installs and launches `SingleThreadWatch`, and prints + `Apple Watch (sim): 1 launched, 0 failed`. +- [ ] `RUN_WATCH=0 ./scripts/run-devices.sh` prints `Apple Watch (sim): skipped (RUN_WATCH=0)` and does no watch build. +- [ ] With `IOS_TARGET=device` and a Duo + watches present, only the Duo is + touched on hardware and the watch still runs on the simulator. + +--- + +## Post-plan gate (parent, after all phases commit) + +- [ ] `./scripts/test.sh` via the `run-gate` skill (build + lint + Periphery + + unit + UI) — the full CI-identical gate runs **once** after the phases commit. +- [ ] `make format` + `make lint` before the final commit. +- [ ] Confirm no `IOS_TARGET`/fixture seam needs wiring into `scripts/test.sh` or + the `Makefile`: `scripts/test-run-devices.sh` is currently standalone and not + referenced by the gate, so no wiring is expected — verify with + `rg -n 'test-run-devices' Makefile scripts/test.sh` and add a gate step only + if the repo convention requires it. diff --git a/DELETEME b/DELETEME deleted file mode 100644 index cbfd70f0..00000000 --- a/DELETEME +++ /dev/null @@ -1 +0,0 @@ -DELETEME (alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in) — placeholder; git rm before merging From c153389a58e54e847d62ac1125c991ee05227447 Mon Sep 17 00:00:00 2001 From: Alan Vardy Date: Fri, 13 Nov 2026 07:32:55 -0700 Subject: [PATCH 3/9] =?UTF-8?q?Phase=201:=20walking=20skeleton=20=E2=80=94?= =?UTF-8?q?=20sim=20iPhone=20leg=20end-to-end?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/run-devices.sh | 166 +++++++++++++++++++++++++++++++----- scripts/test-run-devices.sh | 83 +++++++++++++++--- 2 files changed, 215 insertions(+), 34 deletions(-) diff --git a/scripts/run-devices.sh b/scripts/run-devices.sh index 119f3ac6..6e202323 100755 --- a/scripts/run-devices.sh +++ b/scripts/run-devices.sh @@ -1,15 +1,24 @@ #!/usr/bin/env bash set -euo pipefail -# scripts/run-devices.sh — build SingleThread for iOS, install + launch it on -# every paired iPhone/iPad that has Developer Mode enabled (via devicectl), -# install + launch the watch app on every paired Apple Watch that is reachable, -# and (by default) also build + launch it on the host Mac. +# scripts/run-devices.sh — build SingleThread for iOS, install + launch it in a +# simulator (the regular iPhone; the iPad follows), deploy it physically to the +# iPhone Duo (via devicectl), install + launch the watch app on every paired +# Apple Watch that is reachable, and (by default) also build + launch it on the +# host Mac. Set IOS_TARGET=device to build + launch on every paired physical +# iPhone/iPad instead (the Duo is always deployed physically). # # ./scripts/run-devices.sh # # Overrides (same env-override pattern as scripts/test.sh): # SCHEME=… BUNDLE_ID=… CONFIGURATION=… DERIVED_DATA=… +# IOS_TARGET=sim # sim (default) → the regular iPhone/iPad legs run on +# # simulators; device → the old all-physical sweep +# SIM_IPHONE=… # UDID or device name for the iPhone sim; empty → this +# # worktree's .simulator_id, else the iPhone 17 default +# SIM_IPAD=… # UDID or device name for the iPad sim; empty → iPad (A16) +# SIM_WATCH=… # UDID or device name for the watch sim; empty → Apple Watch Series 11 (46mm) +# DUO_DEVICE_ID=… # UDID of the physical iPhone Duo; empty → name match on "iPhone Duo" # RUN_WATCH=0 # skip the watchOS build + install + launch step (default RUN_WATCH=1) # RUN_MAC=0 # skip the macOS build + launch step (default RUN_MAC=1) # WATCH_BUNDLE_ID=… # defaults to ${BUNDLE_ID}.watchkitapp @@ -40,6 +49,11 @@ CONFIGURATION="${CONFIGURATION:-Debug}" DERIVED_DATA="${DERIVED_DATA:-DerivedData}" RUN_WATCH="${RUN_WATCH:-1}" RUN_MAC="${RUN_MAC:-1}" +IOS_TARGET="${IOS_TARGET:-sim}" +SIM_IPHONE="${SIM_IPHONE:-}" # explicit UDID or device name; empty = worktree sim, else iPhone 17 +SIM_IPAD="${SIM_IPAD:-}" # explicit UDID or device name; empty = iPad (A16) +SIM_WATCH="${SIM_WATCH:-}" # explicit UDID or device name; empty = Apple Watch Series 11 (46mm) +DUO_DEVICE_ID="${DUO_DEVICE_ID:-}" WATCH_BUNDLE_ID="${WATCH_BUNDLE_ID:-${BUNDLE_ID}.watchkitapp}" DEVICES_JSON_IN="${DEVICES_JSON_IN:-}" DEVICES_JSON="${TMPDIR:-/tmp}/run-devices-$$.json" @@ -50,11 +64,46 @@ trap 'rm -f "$DEVICES_JSON" "$UNREACHABLE_LOG" "$WATCH_UNREACHABLE_LOG"' EXIT APP_PATH="$DERIVED_DATA/Build/Products/${CONFIGURATION}-iphoneos/SingleThread.app" WATCH_APP_PATH="$DERIVED_DATA/Build/Products/${CONFIGURATION}-watchos/SingleThreadWatch.app" MAC_APP_PATH="$DERIVED_DATA/Build/Products/$CONFIGURATION/SingleThread.app" +SIM_APP_PATH="$DERIVED_DATA/Build/Products/${CONFIGURATION}-iphonesimulator/SingleThread.app" + +DEFAULT_IPHONE_SIM="iPhone 17" cd "$(dirname "$0")/.." +# Pin a name-only simulator to a concrete UDID. An anchored name match stops +# `iPhone 17` selecting the leftover "Gate iPhone 17" sim (scripts/test.sh:27-36). +resolve_sim_udid() { + local name="$1" + xcrun simctl list devices available \ + | awk -v n="$name" '{ s = $0; sub(/^[ \t]+/, "", s); if (index(s, n " (") == 1) print }' \ + | head -1 \ + | sed -E 's/.*\(([A-F0-9-]+)\).*/\1/' +} + +# Precedence: an explicit UDID passes through; else this worktree's dedicated +# simulator (.simulator_id, written by the worktree_sim fish function); else the +# named default. Always yields a concrete UDID — never a bare `name=`. +resolve_ios_udid() { # $1 = value (UDID or name), $2 = default name, $3 = 1 to prefer .simulator_id + local value="$1" default="$2" prefer_worktree="$3" udid="" + if [[ -n "$value" ]]; then + if [[ "$value" =~ ^[A-Fa-f0-9-]{36}$ ]]; then printf '%s\n' "$value"; return 0; fi + resolve_sim_udid "$value"; return 0 + fi + if [[ "$prefer_worktree" -eq 1 && -f .simulator_id ]]; then + udid="$(tr -d '[:space:]' < .simulator_id)" + if [[ -n "$udid" ]] && xcrun simctl list devices 2>/dev/null | grep -qF "($udid)"; then + printf '%s\n' "$udid"; return 0 + fi + fi + resolve_sim_udid "$default" +} + # ── Discover devices ───────────────────────────────────────────────────────── -echo "==> Discovering paired iPhone/iPad devices…" +if [[ "$IOS_TARGET" == "sim" ]]; then + echo "==> Discovering the paired iPhone Duo…" +else + echo "==> Discovering paired iPhone/iPad devices…" +fi if [[ -n "$DEVICES_JSON_IN" ]]; then # Offline seam: a saved inventory is replayed so the discovery filters can be # checked without hardware. The temp copy keeps the EXIT trap's cleanup valid. @@ -73,21 +122,28 @@ elif ! xcrun devicectl list devices -j "$DEVICES_JSON" >/dev/null 2>&1; then exit 1 fi -# Emits "identifier|name" per qualifying device (platform iOS, iPhone or iPad, -# physical). Simulated devices are excluded — they are not devicectl install -# targets; a paired physical phone whose Developer Mode is off still qualifies -# and is named on stderr, so a newly paired device (e.g. a second iPhone) is -# never silently omitted. Unreachable qualifying devices are logged to -# "$UNREACHABLE_LOG" for the failure -# tally, so a phone that is locked / off-network / has Remote Device Services down -# is reported with the real reason instead of a raw devicectl 4016 install error. +# Emits "identifier|name" per qualifying devicectl target (platform iOS, iPhone +# or iPad, physical). Simulated devices are excluded — they are not devicectl +# install targets. In sim mode (the default) only the physical iPhone Duo is a +# devicectl target: DUO_DEVICE_ID wins when set, otherwise the name is matched +# case-insensitively on "iPhone Duo"; the regular iPhone/iPad legs run on +# simulators instead. In device mode every paired physical iPhone/iPad qualifies +# (the old all-physical sweep). A paired physical phone whose Developer Mode is +# off still qualifies and is named on stderr, so a newly paired device (e.g. a +# second iPhone) is never silently omitted. Unreachable qualifying devices are +# logged to "$UNREACHABLE_LOG" for the failure tally, so a phone that is locked / +# off-network / has Remote Device Services down is reported with the real reason +# instead of a raw devicectl 4016 install error. DEVICES=() while IFS= read -r entry; do DEVICES+=("$entry") -done < <(python3 - "$DEVICES_JSON" "$UNREACHABLE_LOG" <<'PY' +done < <(python3 - "$DEVICES_JSON" "$UNREACHABLE_LOG" "$IOS_TARGET" "$DUO_DEVICE_ID" <<'PY' import json import sys +mode = sys.argv[3] if len(sys.argv) > 3 else "device" +duo_id = sys.argv[4] if len(sys.argv) > 4 else "" + with open(sys.argv[1], encoding="utf-8") as fh: payload = json.load(fh) @@ -107,6 +163,14 @@ with open(sys.argv[2], "a", encoding="utf-8") as unreachable_log: if hardware.get("reality") != "physical": continue name = props.get("name", "unknown device") + if mode != "device": + # Default sim mode: only the physical iPhone Duo is a devicectl + # target. DUO_DEVICE_ID wins when set; otherwise a name match. + if duo_id: + if device.get("identifier") != duo_id: + continue + elif "iphone duo" not in name.lower(): + continue # Physical devices install over a connection (localNetwork, wired, or # sameMachine for local simulators). When CoreDevice cannot reach the # device — locked, asleep, on another network, or Remote Device @@ -208,7 +272,7 @@ if [[ "$RUN_WATCH" -eq 1 ]] && [[ ${#WATCH_DEVICES[@]} -gt 0 || "$WATCH_UNREACHA WATCH_BUILD_NEEDED=1 fi -if [[ ${#DEVICES[@]} -eq 0 ]]; then +if [[ ${#DEVICES[@]} -eq 0 && "$IOS_TARGET" != "sim" ]]; then if [[ "$UNREACHABLE_COUNT" -gt 0 && "$WATCH_BUILD_NEEDED" -eq 0 ]]; then echo "❌ $UNREACHABLE_COUNT device(s) found but unreachable — see messages above (unlock the device and connect it to this Mac's Wi-Fi, then retry)." >&2 exit 1 @@ -234,11 +298,16 @@ failures=0 failures=$((failures + UNREACHABLE_COUNT)) failures=$((failures + WATCH_UNREACHABLE_COUNT)) -# iOS leg counters (reported by the Phase 3 summary). A device is counted as -# launched only once devicectl launch exits 0, so a failed install is not -# reported as "launched". +# iOS leg counters (reported by the summary). A device is counted as launched +# only once devicectl launch exits 0, so a failed install is not reported as +# "launched". IOS_LAUNCHED=0 +# Simulator leg counters: in sim mode the regular iPhone/iPad legs report +# separately from the physical Duo (see the summary). +SIM_TOTAL=0 +SIM_LAUNCHED=0 + # Watch leg counters (reported by the Phase 3 summary). WATCH_LAUNCHED=0 WATCH_FAILED=0 @@ -259,7 +328,57 @@ record_watch_launch_form() { fi } -# ── Build + install + launch per iOS device ─────────────────────────────────── +# ── iPhone/iPad simulator leg ───────────────────────────────── +# In sim mode the regular iPhone/iPad legs run on simulators; the iPhone Duo is +# still deployed physically by the device loop below. Targets are resolved to a +# concrete UDID up front so a bare `name=` destination never reaches xcodebuild. +if [[ "$IOS_TARGET" == "sim" ]]; then + sim_targets=("iPhone|$(resolve_ios_udid "$SIM_IPHONE" "$DEFAULT_IPHONE_SIM" 1)") + for spec in "${sim_targets[@]}"; do + sim_label="${spec%%|*}" + sim_udid="${spec#*|}" + SIM_TOTAL=$((SIM_TOTAL + 1)) + if [[ -z "$sim_udid" ]]; then + echo "❌ No available simulator for $sim_label — set SIM_IPHONE=/SIM_IPAD= to pin one." >&2 + failures=$((failures + 1)) + continue + fi + echo "" + echo "==> Booting the $sim_label simulator ($sim_udid)…" + if ! xcrun simctl bootstatus "$sim_udid" -b; then + echo "❌ Simulator $sim_label ($sim_udid) failed to boot." >&2 + failures=$((failures + 1)) + continue + fi + echo "==> Building $SCHEME ($CONFIGURATION) for the $sim_label simulator…" + if ! xcodebuild -scheme "$SCHEME" -destination "id=$sim_udid" \ + -configuration "$CONFIGURATION" -derivedDataPath "$DERIVED_DATA" build; then + echo "❌ Build failed for the $sim_label simulator." >&2 + failures=$((failures + 1)) + continue + fi + if [[ ! -d "$SIM_APP_PATH" ]]; then + echo "❌ Built app not found at $SIM_APP_PATH" >&2 + failures=$((failures + 1)) + continue + fi + echo "==> Installing on the $sim_label simulator…" + if ! xcrun simctl install "$sim_udid" "$SIM_APP_PATH"; then + echo "❌ Install failed on the $sim_label simulator." >&2 + failures=$((failures + 1)) + continue + fi + echo "==> Launching on the $sim_label simulator…" + if xcrun simctl launch "$sim_udid" "$BUNDLE_ID"; then + SIM_LAUNCHED=$((SIM_LAUNCHED + 1)) + else + echo "❌ Launch failed on the $sim_label simulator." >&2 + failures=$((failures + 1)) + fi + done +fi + +# ── Build + install + launch per iOS device (Duo / device mode) ────────────── # Building against each device's own destination — rather than one # generic/platform=iOS build — is what auto-registers a newly paired phone: # -allowProvisioningDeviceRegistration only registers the *destination* device, @@ -432,7 +551,12 @@ fi # ── Summary ──────────────────────────────────────────────────────────────────── echo "" echo "==> Summary" -echo " iPhone/iPad: $IOS_LAUNCHED/${#DEVICES[@]} launched, $UNREACHABLE_COUNT unreachable" +if [[ "$IOS_TARGET" == "sim" ]]; then + echo " iPhone/iPad (sim): $SIM_LAUNCHED/$SIM_TOTAL launched" + echo " iPhone Duo (device): $IOS_LAUNCHED/${#DEVICES[@]} launched, $UNREACHABLE_COUNT unreachable" +else + echo " iPhone/iPad (device): $IOS_LAUNCHED/${#DEVICES[@]} launched, $UNREACHABLE_COUNT unreachable" +fi if [[ "$RUN_WATCH" -eq 0 ]]; then echo " Apple Watch: skipped (RUN_WATCH=0)" elif [[ ${#WATCH_DEVICES[@]} -eq 0 && "$WATCH_UNREACHABLE_COUNT" -eq 0 ]]; then @@ -459,7 +583,7 @@ fi echo "" if [[ "$failures" -eq 0 ]]; then - summary="Installed and launched on ${#DEVICES[@]} device(s)" + summary="Installed and launched on ${#DEVICES[@]} device(s) and $SIM_LAUNCHED simulator(s)" [[ "$RUN_MAC" -eq 1 ]] && summary="$summary and macOS" [[ "$WATCH_LAUNCHED" -gt 0 ]] && summary="$summary and $WATCH_LAUNCHED Apple Watch(es)" echo "✅ $summary." diff --git a/scripts/test-run-devices.sh b/scripts/test-run-devices.sh index 8de0ceb3..2dcc17a7 100755 --- a/scripts/test-run-devices.sh +++ b/scripts/test-run-devices.sh @@ -64,28 +64,59 @@ if [[ ! -s "$work/ios.py" || ! -s "$work/watch.py" ]]; then exit 1 fi -python3 "$work/ios.py" "$FIXTURE" "$work/ios-unreachable.log" > "$work/ios-out" 2> "$work/ios-stderr" +python3 "$work/ios.py" "$FIXTURE" "$work/ios-unreachable.log" device \ + > "$work/ios-out" 2> "$work/ios-stderr" +python3 "$work/ios.py" "$FIXTURE" "$work/ios-sim-unreachable.log" sim \ + > "$work/ios-sim-out" 2> "$work/ios-sim-stderr" python3 "$work/watch.py" "$FIXTURE" "$work/watch-unreachable.log" > "$work/watch-out" 2> "$work/watch-stderr" -for produced in ios-out ios-stderr watch-out watch-stderr; do +for produced in ios-out ios-stderr ios-sim-out ios-sim-stderr watch-out watch-stderr; do if [[ ! -e "$work/$produced" ]]; then echo "❌ a discovery filter did not produce $work/$produced" >&2 exit 1 fi done -check "iOS filter emits the reachable physical iPhone" \ +# IOS_TARGET=device (the legacy all-physical sweep): every paired physical +# iPhone/iPad qualifies. +check "device mode emits the reachable physical iPhone" \ "1" "$(grep -c '|Fixture iPhone$' "$work/ios-out" || true)" -check "iOS filter emits the paired iPhone Duo even with Developer Mode off" \ +check "device mode emits the paired iPhone Duo even with Developer Mode off" \ "1" "$(grep -c '|Fixture iPhone Duo$' "$work/ios-out" || true)" -check "iOS filter emits the physical iPad with Developer Mode off" \ +check "device mode emits the physical iPad with Developer Mode off" \ "1" "$(grep -c '|Fixture iPad DevMode Off$' "$work/ios-out" || true)" -check "iOS filter excludes a simulated iOS device" \ +check "device mode excludes a simulated iOS device" \ "0" "$(grep -c '|Fixture iPhone Sim$' "$work/ios-out" || true)" -check "iOS filter warns about Developer Mode off" \ +check "device mode warns about Developer Mode off" \ "2" "$(grep -c 'Developer Mode off' "$work/ios-stderr" || true)" -check "iOS filter logs no unreachable devices" \ +check "device mode logs no unreachable devices" \ "0" "$(wc -l < "$work/ios-unreachable.log" | tr -d ' ')" +# IOS_TARGET=sim (the default): only the physical iPhone Duo is a devicectl +# target; the regular iPhone/iPad run on simulators. +check "sim mode emits the paired iPhone Duo" \ + "1" "$(grep -c '|Fixture iPhone Duo$' "$work/ios-sim-out" || true)" +check "sim mode excludes the regular physical iPhone" \ + "0" "$(grep -c '|Fixture iPhone$' "$work/ios-sim-out" || true)" +check "sim mode excludes the physical iPad" \ + "0" "$(grep -c '|Fixture iPad DevMode Off$' "$work/ios-sim-out" || true)" +check "sim mode excludes a simulated iOS device" \ + "0" "$(grep -c '|Fixture iPhone Sim$' "$work/ios-sim-out" || true)" +check "sim mode warns about the Duo's Developer Mode off" \ + "1" "$(grep -c 'Developer Mode off' "$work/ios-sim-stderr" || true)" +check "sim mode logs no unreachable devices" \ + "0" "$(wc -l < "$work/ios-sim-unreachable.log" | tr -d ' ')" + +# DUO_DEVICE_ID wins over the name match: an explicit identifier selects exactly +# the Duo, and a non-matching identifier selects nothing. +python3 "$work/ios.py" "$FIXTURE" "$work/ios-duo-unreachable.log" sim \ + "CCCCCCCC-0000-0000-0000-000000000009" > "$work/ios-duo-out" 2>/dev/null +check "sim mode selects only the DUO_DEVICE_ID device" \ + "CCCCCCCC-0000-0000-0000-000000000009|Fixture iPhone Duo" "$(cat "$work/ios-duo-out")" +python3 "$work/ios.py" "$FIXTURE" "$work/ios-bogus-unreachable.log" sim \ + "BBBBBBBB-0000-0000-0000-000000000000" > "$work/ios-bogus-out" 2>/dev/null +check "sim mode ignores a non-matching DUO_DEVICE_ID" \ + "0" "$(wc -c < "$work/ios-bogus-out" | tr -d ' ')" + check "watch filter emits only the reachable physical watch" \ "AAAAAAAA-0000-0000-0000-000000000002|Fixture Watch Reachable" "$(cat "$work/watch-out")" check "watch filter logs the tunnel-down watch as unreachable" \ @@ -99,7 +130,7 @@ check "watch filter reports the developer-mode-disabled watch" \ # filters emit nothing without a traceback (run-devices.sh rejects invalid JSON # up front; this covers the valid-JSON/wrong-shape case). echo '{}' > "$work/empty-inventory.json" -python3 "$work/ios.py" "$work/empty-inventory.json" "$work/ios-empty-unreachable.log" \ +python3 "$work/ios.py" "$work/empty-inventory.json" "$work/ios-empty-unreachable.log" sim \ > "$work/ios-empty-out" 2> "$work/ios-empty-stderr" python3 "$work/watch.py" "$work/empty-inventory.json" "$work/watch-empty-unreachable.log" \ > "$work/watch-empty-out" 2> "$work/watch-empty-stderr" @@ -120,6 +151,7 @@ stub_dir="$work/stubs" mkdir -p "$stub_dir" \ "$work/derived/Build/Products/Debug-watchos/SingleThreadWatch.app" \ "$work/derived/Build/Products/Debug-iphoneos/SingleThread.app" \ + "$work/derived/Build/Products/Debug-iphonesimulator/SingleThread.app" \ "$work/derived/Build/Products/Debug/SingleThread.app" cat > "$stub_dir/xcodebuild" <<'STUB' #!/usr/bin/env bash @@ -133,7 +165,26 @@ if [[ "${STUB_MAC_BUILD_FAIL:-0}" == "1" ]]; then fi exit 0 STUB -printf '#!/usr/bin/env bash\nexit 0\n' > "$stub_dir/xcrun" +# simctl listings are answered from a fixed inventory so the sim legs resolve a +# concrete UDID; every devicectl/other call is a no-op success. +cat > "$stub_dir/xcrun" <<'STUB' +#!/usr/bin/env bash +if [[ "$1" == "simctl" ]]; then + case "$2" in + list) + printf ' iPhone 17 (11111111-1111-1111-1111-111111111111) (Shutdown)\n' + printf ' iPad (A16) (22222222-2222-2222-2222-222222222222) (Shutdown)\n' + printf ' Apple Watch Series 11 (46mm) (33333333-3333-3333-3333-333333333333) (Shutdown)\n' + exit 0 + ;; + bootstatus) + [[ "${STUB_SIM_BOOT_FAIL:-0}" == "1" ]] && exit 1 + exit 0 + ;; + esac +fi +exit 0 +STUB printf '#!/usr/bin/env bash\nexit 0\n' > "$stub_dir/open" chmod +x "$stub_dir/xcodebuild" "$stub_dir/xcrun" "$stub_dir/open" @@ -200,13 +251,19 @@ run_flow "reachable-watch-only succeeds" 0 \ DEVICES_JSON_IN="$work/flow-reachable-watch.json" RUN_WATCH=1 RUN_MAC=0 run_flow "no iOS and no watch keeps the iOS fail-fast" 1 \ "No reachable iPhone/iPad found." "==> Building SingleThreadWatch" \ - DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=1 RUN_MAC=0 + DEVICES_JSON_IN="$work/flow-no-devices.json" IOS_TARGET=device RUN_WATCH=1 RUN_MAC=0 run_flow "RUN_WATCH=0 emits no watch output" 1 \ "No reachable iPhone/iPad found." "Apple Watch" \ + DEVICES_JSON_IN="$work/flow-no-devices.json" IOS_TARGET=device RUN_WATCH=0 RUN_MAC=0 +run_flow "default sim mode launches the iPhone simulator" 0 \ + "iPhone/iPad (sim): 1/1 launched" "No reachable iPhone/iPad found." \ DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=0 -run_flow "every paired physical iPhone installs (Duo included)" 0 \ - "3/3 launched" "No reachable iPhone/iPad found." \ +run_flow "sim mode deploys only the iPhone Duo physically" 0 \ + "iPhone Duo (device): 1/1 launched" "No reachable iPhone/iPad found." \ DEVICES_JSON_IN="$FIXTURE" RUN_WATCH=0 RUN_MAC=0 +run_flow "IOS_TARGET=device restores the all-physical sweep" 0 \ + "iPhone/iPad (device): 3/3 launched" "iPhone/iPad (sim)" \ + DEVICES_JSON_IN="$FIXTURE" IOS_TARGET=device RUN_WATCH=0 RUN_MAC=0 run_flow "macOS success is reported in the summary" 0 \ "macOS: built and launched" "macOS: build failed" \ DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=1 From 4b476798e3899c2cee7651e9419badc3267cb6f2 Mon Sep 17 00:00:00 2001 From: Alan Vardy Date: Fri, 13 Nov 2026 07:34:57 -0700 Subject: [PATCH 4/9] Phase 2: iPad simulator leg and sim sad paths --- scripts/run-devices.sh | 6 +++++- scripts/test-run-devices.sh | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/scripts/run-devices.sh b/scripts/run-devices.sh index 6e202323..6d7a1e9b 100755 --- a/scripts/run-devices.sh +++ b/scripts/run-devices.sh @@ -67,6 +67,7 @@ MAC_APP_PATH="$DERIVED_DATA/Build/Products/$CONFIGURATION/SingleThread.app" SIM_APP_PATH="$DERIVED_DATA/Build/Products/${CONFIGURATION}-iphonesimulator/SingleThread.app" DEFAULT_IPHONE_SIM="iPhone 17" +DEFAULT_IPAD_SIM="iPad (A16)" cd "$(dirname "$0")/.." @@ -333,7 +334,10 @@ record_watch_launch_form() { # still deployed physically by the device loop below. Targets are resolved to a # concrete UDID up front so a bare `name=` destination never reaches xcodebuild. if [[ "$IOS_TARGET" == "sim" ]]; then - sim_targets=("iPhone|$(resolve_ios_udid "$SIM_IPHONE" "$DEFAULT_IPHONE_SIM" 1)") + sim_targets=( + "iPhone|$(resolve_ios_udid "$SIM_IPHONE" "$DEFAULT_IPHONE_SIM" 1)" + "iPad|$(resolve_ios_udid "$SIM_IPAD" "$DEFAULT_IPAD_SIM" 0)" + ) for spec in "${sim_targets[@]}"; do sim_label="${spec%%|*}" sim_udid="${spec#*|}" diff --git a/scripts/test-run-devices.sh b/scripts/test-run-devices.sh index 2dcc17a7..ae1e6451 100755 --- a/scripts/test-run-devices.sh +++ b/scripts/test-run-devices.sh @@ -152,7 +152,10 @@ mkdir -p "$stub_dir" \ "$work/derived/Build/Products/Debug-watchos/SingleThreadWatch.app" \ "$work/derived/Build/Products/Debug-iphoneos/SingleThread.app" \ "$work/derived/Build/Products/Debug-iphonesimulator/SingleThread.app" \ - "$work/derived/Build/Products/Debug/SingleThread.app" + "$work/derived/Build/Products/Debug/SingleThread.app" \ + "$work/derived-nosim/Build/Products/Debug-watchos/SingleThreadWatch.app" \ + "$work/derived-nosim/Build/Products/Debug-iphoneos/SingleThread.app" \ + "$work/derived-nosim/Build/Products/Debug/SingleThread.app" cat > "$stub_dir/xcodebuild" <<'STUB' #!/usr/bin/env bash if [[ "${STUB_MAC_BUILD_FAIL:-0}" == "1" ]]; then @@ -256,8 +259,21 @@ run_flow "RUN_WATCH=0 emits no watch output" 1 \ "No reachable iPhone/iPad found." "Apple Watch" \ DEVICES_JSON_IN="$work/flow-no-devices.json" IOS_TARGET=device RUN_WATCH=0 RUN_MAC=0 run_flow "default sim mode launches the iPhone simulator" 0 \ - "iPhone/iPad (sim): 1/1 launched" "No reachable iPhone/iPad found." \ + "iPhone/iPad (sim): 2/2 launched" "No reachable iPhone/iPad found." \ DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=0 +run_flow "simulator boot failure is a failed step" 1 \ + "failed to boot" "" \ + DEVICES_JSON_IN="$FIXTURE" RUN_WATCH=0 RUN_MAC=1 STUB_SIM_BOOT_FAIL=1 +check "boot failure still runs the Duo leg" "1" \ + "$(grep -c 'iPhone Duo (device): 1/1 launched' "$work/flow-simulator boot failure is a failed step.log" || true)" +check "boot failure still runs the macOS leg" "1" \ + "$(grep -c 'macOS: built and launched' "$work/flow-simulator boot failure is a failed step.log" || true)" +run_flow "missing sim product is a failed step" 1 \ + "Built app not found at" "" \ + DEVICES_JSON_IN="$FIXTURE" RUN_WATCH=0 RUN_MAC=0 DERIVED_DATA="$work/derived-nosim" +run_flow "unresolvable iPad sim is a failed step" 1 \ + "No available simulator for iPad" "" \ + DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=0 SIM_IPAD="No Such Device" run_flow "sim mode deploys only the iPhone Duo physically" 0 \ "iPhone Duo (device): 1/1 launched" "No reachable iPhone/iPad found." \ DEVICES_JSON_IN="$FIXTURE" RUN_WATCH=0 RUN_MAC=0 From 40fc0191d7144c6bdadb29cf1e3055995bfe0d0a Mon Sep 17 00:00:00 2001 From: Alan Vardy Date: Fri, 13 Nov 2026 07:38:43 -0700 Subject: [PATCH 5/9] Phase 3: watch leg on watch simulators --- scripts/run-devices.sh | 267 +++++++++--------------------------- scripts/test-run-devices.sh | 98 ++++--------- 2 files changed, 89 insertions(+), 276 deletions(-) diff --git a/scripts/run-devices.sh b/scripts/run-devices.sh index 6d7a1e9b..d3c19f77 100755 --- a/scripts/run-devices.sh +++ b/scripts/run-devices.sh @@ -3,10 +3,10 @@ set -euo pipefail # scripts/run-devices.sh — build SingleThread for iOS, install + launch it in a # simulator (the regular iPhone; the iPad follows), deploy it physically to the -# iPhone Duo (via devicectl), install + launch the watch app on every paired -# Apple Watch that is reachable, and (by default) also build + launch it on the -# host Mac. Set IOS_TARGET=device to build + launch on every paired physical -# iPhone/iPad instead (the Duo is always deployed physically). +# iPhone Duo (via devicectl), install + launch the watch app on an Apple Watch +# simulator, and (by default) also build + launch it on the host Mac. Set +# IOS_TARGET=device to build + launch on every paired physical iPhone/iPad +# instead (the Duo is always deployed physically). # # ./scripts/run-devices.sh # @@ -25,8 +25,8 @@ set -euo pipefail # DEVICES_JSON_IN=… # dev seam: read a saved `xcrun devicectl list devices -j` # # inventory instead of querying CoreDevice (offline filter checks) # -# Devices are discovered dynamically each run, so a new iPhone/iPad/Apple Watch -# is picked up without editing this script. A newly paired device is registered +# Devices are discovered dynamically each run, so a new iPhone/iPad is picked +# up without editing this script. A newly paired device is registered # in the developer account during its own build (-allowProvisioningDeviceRegistration), # so no manual Xcode step is needed before it can install. A device that is unreachable (locked, asleep, # off this Wi-Fi, unplugged mid-run) is detected during discovery and reported @@ -38,10 +38,12 @@ set -euo pipefail # to carry the In-App Purchase entitlement — see make mac-run / the TestFlight # runbook for the signed flow. # -# Apple Watch prerequisite: the watch must be on your wrist with its paired -# iPhone nearby and unlocked, so CoreDevice's network tunnel to the watch is up. -# A paired watch with the tunnel down is reported as unreachable with that hint -# rather than surfacing a raw devicectl 4016 assertion later. +# Apple Watch prerequisite: the watch runs on a simulator, not on hardware, so +# no wrist / paired-iPhone / CoreDevice tunnel is involved. The named watch +# simulator must exist (xcrun simctl list devices); the app installs and launches +# on an unpaired watch sim (see scripts/appstore-screenshots.sh:29-31), so no +# simctl pair step is needed. An unavailable watch sim is a notice, not a +# failure; set SIM_WATCH= to pin one. SCHEME="${SCHEME:-SingleThread}" BUNDLE_ID="${BUNDLE_ID:-app.alanvardy.SingleThread}" @@ -58,16 +60,16 @@ WATCH_BUNDLE_ID="${WATCH_BUNDLE_ID:-${BUNDLE_ID}.watchkitapp}" DEVICES_JSON_IN="${DEVICES_JSON_IN:-}" DEVICES_JSON="${TMPDIR:-/tmp}/run-devices-$$.json" UNREACHABLE_LOG="${TMPDIR:-/tmp}/run-devices-unreachable-$$.log" -WATCH_UNREACHABLE_LOG="${TMPDIR:-/tmp}/run-devices-watch-unreachable-$$.log" -trap 'rm -f "$DEVICES_JSON" "$UNREACHABLE_LOG" "$WATCH_UNREACHABLE_LOG"' EXIT +trap 'rm -f "$DEVICES_JSON" "$UNREACHABLE_LOG"' EXIT APP_PATH="$DERIVED_DATA/Build/Products/${CONFIGURATION}-iphoneos/SingleThread.app" -WATCH_APP_PATH="$DERIVED_DATA/Build/Products/${CONFIGURATION}-watchos/SingleThreadWatch.app" MAC_APP_PATH="$DERIVED_DATA/Build/Products/$CONFIGURATION/SingleThread.app" SIM_APP_PATH="$DERIVED_DATA/Build/Products/${CONFIGURATION}-iphonesimulator/SingleThread.app" +WATCH_SIM_APP_PATH="$DERIVED_DATA/Build/Products/${CONFIGURATION}-watchsimulator/SingleThreadWatch.app" DEFAULT_IPHONE_SIM="iPhone 17" DEFAULT_IPAD_SIM="iPad (A16)" +DEFAULT_WATCH_SIM="Apple Watch Series 11 (46mm)" cd "$(dirname "$0")/.." @@ -159,8 +161,7 @@ with open(sys.argv[2], "a", encoding="utf-8") as unreachable_log: if hardware.get("deviceType") not in ("iPhone", "iPad"): continue # A paired iOS simulator shares platform/deviceType with a physical - # device but is not a devicectl install target, so exclude it here the - # same way the watch filter does. + # device but is not a devicectl install target, so exclude it here. if hardware.get("reality") != "physical": continue name = props.get("name", "unknown device") @@ -199,93 +200,13 @@ if [[ -s "$UNREACHABLE_LOG" ]]; then UNREACHABLE_COUNT=$(wc -l < "$UNREACHABLE_LOG" | tr -d ' ') fi -# Emits "identifier|name" per *reachable* physical Apple Watch. The four paired -# watch simulators appear in the same inventory, so `reality == "physical"` is -# part of the filter; watch sims are excluded silently. A watch that is paired -# but has its CoreDevice tunnel down cannot be installed to, and devicectl would -# fail every later call with a raw 4016 — it goes to "$WATCH_UNREACHABLE_LOG" -# and is named here with the wrist/paired-iPhone cause instead. A watch that is -# not paired with this Mac is skipped quietly: there is nothing to install to -# and it is not a failure (zero watches found is a notice, not an error). -# -# RUN_WATCH=0 skips all of this — no watch output, no watch failures — so the -# run is byte-for-byte the pre-watch-script behavior. -WATCH_DEVICES=() -WATCH_UNREACHABLE_COUNT=0 -if [[ "$RUN_WATCH" -eq 1 ]]; then - echo "==> Discovering paired Apple Watches…" - while IFS= read -r entry; do - WATCH_DEVICES+=("$entry") - done < <(python3 - "$DEVICES_JSON" "$WATCH_UNREACHABLE_LOG" <<'PY' -import json -import sys - -with open(sys.argv[1], encoding="utf-8") as fh: - payload = json.load(fh) - -with open(sys.argv[2], "a", encoding="utf-8") as unreachable_log: - result = payload.get("result") if isinstance(payload, dict) else None - devices = result.get("devices", []) if isinstance(result, dict) else [] - for device in devices: - hardware = device.get("hardwareProperties", {}) - props = device.get("deviceProperties", {}) - if hardware.get("platform") != "watchOS": - continue - if hardware.get("deviceType") != "appleWatch": - continue - # reality is "physical" for a wrist-worn watch and "simulated" for the - # paired watch simulators listed alongside it in the same inventory. - if hardware.get("reality") != "physical": - continue - name = props.get("name", "unknown watch") - if props.get("developerModeStatus") != "enabled": - print(f" (skipping {name} — Developer Mode disabled)", file=sys.stderr) - continue - conn = device.get("connectionProperties", {}) or {} - conn_props = (device.get("properties") or {}).get("connection") or {} - if conn.get("pairingState") != "paired": - print(f" (skipping {name} — not paired with this Mac; pair it in Xcode → Window → Devices and Simulators)", file=sys.stderr) - continue - # Only "connected" means CoreDevice has a live tunnel to the watch - # (the state a real watch reports when it is off the wrist / its paired - # iPhone is asleep is "disconnected", which the iOS predicate above does - # not treat as unreachable — the watch needs its own check). - if conn_props.get("state") != "connected": - print(f" (skipping {name} — unreachable (watch off the wrist, or its paired iPhone is asleep / on another network?)\n put the watch on your wrist, unlock its paired iPhone, keep it near this Mac, then retry)", file=sys.stderr) - print(name, file=unreachable_log) - continue - print(f"{device['identifier']}|{name}") -PY - ) - - if [[ -s "$WATCH_UNREACHABLE_LOG" ]]; then - WATCH_UNREACHABLE_COUNT=$(wc -l < "$WATCH_UNREACHABLE_LOG" | tr -d ' ') - fi -fi - -# A discovered physical watch is a reason to continue even with no reachable -# iOS device: the watch app is built below, and an unreachable watch is reported -# as a failed step instead of being masked by an iOS-only early exit. With -# RUN_WATCH=0 both watch arrays stay empty, so this is false and the run keeps -# the pre-watch iOS-only behavior. -WATCH_BUILD_NEEDED=0 -if [[ "$RUN_WATCH" -eq 1 ]] && [[ ${#WATCH_DEVICES[@]} -gt 0 || "$WATCH_UNREACHABLE_COUNT" -gt 0 ]]; then - WATCH_BUILD_NEEDED=1 -fi - if [[ ${#DEVICES[@]} -eq 0 && "$IOS_TARGET" != "sim" ]]; then - if [[ "$UNREACHABLE_COUNT" -gt 0 && "$WATCH_BUILD_NEEDED" -eq 0 ]]; then + if [[ "$UNREACHABLE_COUNT" -gt 0 ]]; then echo "❌ $UNREACHABLE_COUNT device(s) found but unreachable — see messages above (unlock the device and connect it to this Mac's Wi-Fi, then retry)." >&2 exit 1 fi if [[ "$RUN_MAC" -eq 1 ]]; then - if [[ "$WATCH_BUILD_NEEDED" -eq 1 ]]; then - echo " (no reachable iPhone/iPad found — macOS + Apple Watch run only)" - else - echo " (no reachable iPhone/iPad found — macOS run only)" - fi - elif [[ "$WATCH_BUILD_NEEDED" -eq 1 ]]; then - echo " (no reachable iPhone/iPad found — Apple Watch run only)" + echo " (no reachable iPhone/iPad found — macOS run only)" else echo "❌ No reachable iPhone/iPad found." >&2 echo " Pair an iPhone/iPad, unlock it, and connect it to this Mac's Wi-Fi, then retry." >&2 @@ -297,7 +218,6 @@ failures=0 # Devices that are paired but unreachable count as failed steps, matching the # old behavior where the guaranteed-failing install attempt was tried and failed. failures=$((failures + UNREACHABLE_COUNT)) -failures=$((failures + WATCH_UNREACHABLE_COUNT)) # iOS leg counters (reported by the summary). A device is counted as launched # only once devicectl launch exits 0, so a failed install is not reported as @@ -309,26 +229,15 @@ IOS_LAUNCHED=0 SIM_TOTAL=0 SIM_LAUNCHED=0 -# Watch leg counters (reported by the Phase 3 summary). +# Watch simulator leg counters (reported by the summary). +WATCH_TOTAL=0 WATCH_LAUNCHED=0 WATCH_FAILED=0 -WATCH_LAUNCH_FORM="none" -WATCH_LAUNCH_FORM_MIXED=0 # macOS leg status (reported by the summary). Set to the outcome inside the # macOS block below so a failed build is not reported as "built and launched". MAC_STATUS="not run" -# The first successful watch launch records the flag form that worked; if a -# later watch needs the other form, say so instead of silently overwriting it. -record_watch_launch_form() { - if [[ "$WATCH_LAUNCH_FORM" == "none" ]]; then - WATCH_LAUNCH_FORM="$1" - elif [[ "$WATCH_LAUNCH_FORM" != "$1" ]]; then - WATCH_LAUNCH_FORM_MIXED=1 - fi -} - # ── iPhone/iPad simulator leg ───────────────────────────────── # In sim mode the regular iPhone/iPad legs run on simulators; the iPhone Duo is # still deployed physically by the device loop below. Targets are resolved to a @@ -433,93 +342,52 @@ if [[ ${#DEVICES[@]} -gt 0 ]]; then done fi -# ── Apple Watch step ───────────────────────────────────────────────────────── -# As with iOS, each reachable watch is built against its own destination so a -# newly paired watch is auto-registered (see the iOS note above). When only an -# unreachable watch was found there is no install target, so fall back to one -# generic build that still surfaces a build/signing failure. -if [[ "$WATCH_BUILD_NEEDED" -eq 1 ]]; then - if [[ ${#WATCH_DEVICES[@]} -eq 0 ]]; then +# ── Apple Watch simulator leg ──────────────────────────────────────────────── +# The watch runs on a simulator, not on hardware. The watch app installs and +# launches on an unpaired watch sim (scripts/appstore-screenshots.sh:29-31), so +# no simctl pair step is needed. An unavailable watch simulator is a notice, not +# a failure; RUN_WATCH=0 skips the leg entirely. +if [[ "$RUN_WATCH" -eq 1 ]]; then + watch_udid="$(resolve_ios_udid "$SIM_WATCH" "$DEFAULT_WATCH_SIM" 0)" + if [[ -z "$watch_udid" ]]; then + echo " (no '$SIM_WATCH' simulator available — skipping the Apple Watch leg; set SIM_WATCH= to pin one)" + else + WATCH_TOTAL=1 echo "" - echo "==> Building SingleThreadWatch ($CONFIGURATION)…" - if ! xcodebuild -scheme SingleThreadWatch \ - -destination 'generic/platform=watchOS' \ - -configuration "$CONFIGURATION" \ - -derivedDataPath "$DERIVED_DATA" \ - -allowProvisioningUpdates \ - build; then - echo "❌ Watch build failed." >&2 - echo " If this is a signing error (No profiles for '$WATCH_BUNDLE_ID'), open Xcode →" >&2 - echo " Settings → Accounts, sign in with team 6NWX2DHB9Q, then retry." >&2 - failures=$((failures + 1)) - WATCH_FAILED=$((WATCH_FAILED + 1)) - elif [[ ! -d "$WATCH_APP_PATH" ]]; then - echo "❌ Built watch app not found at $WATCH_APP_PATH" >&2 - echo " The watch product path may have changed — check the SingleThreadWatch" >&2 - echo " scheme's destination and the Products dir." >&2 + echo "==> Booting Apple Watch simulator ($SIM_WATCH, $watch_udid)…" + if ! xcrun simctl bootstatus "$watch_udid" -b; then + echo "❌ Apple Watch simulator failed to boot." >&2 failures=$((failures + 1)) - WATCH_FAILED=$((WATCH_FAILED + 1)) - fi - else - for entry in "${WATCH_DEVICES[@]}"; do - watch_id="${entry%%|*}" - watch_name="${entry#*|}" - - echo "" - echo "==> Building SingleThreadWatch ($CONFIGURATION) for ${watch_name}…" - if ! xcodebuild -scheme SingleThreadWatch \ - -destination "id=$watch_id" \ - -configuration "$CONFIGURATION" \ - -derivedDataPath "$DERIVED_DATA" \ - -allowProvisioningUpdates \ - -allowProvisioningDeviceRegistration \ - build; then - echo "❌ Watch build failed on $watch_name." >&2 - echo " If this is a signing error (No profiles for '$WATCH_BUNDLE_ID'), open Xcode →" >&2 - echo " Settings → Accounts, sign in with team 6NWX2DHB9Q, then retry." >&2 - failures=$((failures + 1)) - WATCH_FAILED=$((WATCH_FAILED + 1)) - continue - fi - - if [[ ! -d "$WATCH_APP_PATH" ]]; then - echo "❌ Built watch app not found at $WATCH_APP_PATH" >&2 - echo " The watch product path may have changed — check the SingleThreadWatch" >&2 - echo " scheme's destination and the Products dir." >&2 + WATCH_FAILED=1 + else + echo "==> Building SingleThreadWatch ($CONFIGURATION) for the simulator…" + if ! xcodebuild -scheme SingleThreadWatch -destination "id=$watch_udid" \ + -configuration "$CONFIGURATION" -derivedDataPath "$DERIVED_DATA" build; then + echo "❌ Watch build failed." >&2 failures=$((failures + 1)) - WATCH_FAILED=$((WATCH_FAILED + 1)) - continue - fi - - echo "==> Installing on ${watch_name}…" - if ! watch_install_output=$(xcrun devicectl device install app --device "$watch_id" "$WATCH_APP_PATH" 2>&1); then - echo "$watch_install_output" >&2 - echo "❌ Watch install failed on $watch_name." >&2 - if [[ "$watch_install_output" == *4016* ]]; then - echo " devicectl lost the connection to the watch mid-run (error 4016) — put it on" >&2 - echo " your wrist, unlock its paired iPhone, keep it near this Mac, then retry." >&2 - fi + WATCH_FAILED=1 + elif [[ ! -d "$WATCH_SIM_APP_PATH" ]]; then + echo "❌ Built watch app not found at $WATCH_SIM_APP_PATH" >&2 failures=$((failures + 1)) - WATCH_FAILED=$((WATCH_FAILED + 1)) - continue - fi - - echo "==> Launching $WATCH_BUNDLE_ID on ${watch_name}…" - if xcrun devicectl device process launch --terminate-existing --activate --device "$watch_id" "$WATCH_BUNDLE_ID"; then - WATCH_LAUNCHED=$((WATCH_LAUNCHED + 1)) - record_watch_launch_form "--terminate-existing --activate" + WATCH_FAILED=1 else - echo "⚠️ --activate was rejected (it is not supported on every watchOS version) — retrying without it…" >&2 - if xcrun devicectl device process launch --terminate-existing --device "$watch_id" "$WATCH_BUNDLE_ID"; then - WATCH_LAUNCHED=$((WATCH_LAUNCHED + 1)) - record_watch_launch_form "--terminate-existing" - else - echo "❌ Watch launch failed on $watch_name (both the --activate and the minimal form failed)." >&2 + echo "==> Installing on the Apple Watch simulator…" + if ! xcrun simctl install "$watch_udid" "$WATCH_SIM_APP_PATH"; then + echo "❌ Watch install failed." >&2 failures=$((failures + 1)) - WATCH_FAILED=$((WATCH_FAILED + 1)) + WATCH_FAILED=1 + else + echo "==> Launching $WATCH_BUNDLE_ID on the Apple Watch simulator…" + if xcrun simctl launch "$watch_udid" "$WATCH_BUNDLE_ID"; then + WATCH_LAUNCHED=1 + else + echo "❌ Watch launch failed." >&2 + failures=$((failures + 1)) + WATCH_FAILED=1 + fi fi fi - done + fi fi fi @@ -562,22 +430,11 @@ else echo " iPhone/iPad (device): $IOS_LAUNCHED/${#DEVICES[@]} launched, $UNREACHABLE_COUNT unreachable" fi if [[ "$RUN_WATCH" -eq 0 ]]; then - echo " Apple Watch: skipped (RUN_WATCH=0)" -elif [[ ${#WATCH_DEVICES[@]} -eq 0 && "$WATCH_UNREACHABLE_COUNT" -eq 0 ]]; then - echo " Apple Watch: no installable watch found (not a failure)" + echo " Apple Watch (sim): skipped (RUN_WATCH=0)" +elif [[ "$WATCH_TOTAL" -eq 0 ]]; then + echo " Apple Watch (sim): no simulator available (not a failure)" else - watch_line=" Apple Watch: $WATCH_LAUNCHED launched, $WATCH_FAILED failed, $WATCH_UNREACHABLE_COUNT unreachable" - if [[ "$WATCH_UNREACHABLE_COUNT" -gt 0 ]]; then - watch_line="$watch_line (tunnel down — is the watch on your wrist?)" - fi - echo "$watch_line" - if [[ "$WATCH_LAUNCHED" -gt 0 ]]; then - if [[ "$WATCH_LAUNCH_FORM_MIXED" -eq 1 ]]; then - echo " Watch launch flags: $WATCH_LAUNCH_FORM (a later watch needed the other form)" - else - echo " Watch launch flags: $WATCH_LAUNCH_FORM" - fi - fi + echo " Apple Watch (sim): $WATCH_LAUNCHED launched, $WATCH_FAILED failed" fi if [[ "$RUN_MAC" -eq 1 ]]; then echo " macOS: $MAC_STATUS" diff --git a/scripts/test-run-devices.sh b/scripts/test-run-devices.sh index ae1e6451..34133032 100755 --- a/scripts/test-run-devices.sh +++ b/scripts/test-run-devices.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # Offline checks for scripts/run-devices.sh discovery + summary behaviour. # -# Covers what a hardware-free run can: script syntax, shellcheck, the two inline -# python discovery filters replayed against a saved `xcrun devicectl list +# Covers what a hardware-free run can: script syntax, shellcheck, the inline +# python discovery filter replayed against a saved `xcrun devicectl list # devices -j` inventory (scripts/fixtures/devicectl-devices.json), and the bash # control flow (zero-device gate, failure tally, build gate, summary, exit # codes) replayed with stubbed xcrun/xcodebuild. The install/launch legs against -# a real watch are verified by a hardware run of ./scripts/run-devices.sh. +# real hardware or simulators are verified by a manual run of ./scripts/run-devices.sh. set -euo pipefail cd "$(dirname "$0")/.." @@ -47,9 +47,9 @@ fi work="$(mktemp -d)" trap 'rm -rf "$work"' EXIT -# The two discovery filters are inline python heredocs. Extract them in file -# order (1 = iOS, 2 = watch) so the fixture assertions below exercise the exact -# code the script runs — no copy that can drift. +# The discovery filter is an inline python heredoc. Extract it in file order +# (there is now a single filter) so the fixture assertions below exercise the +# exact code the script runs — no copy that can drift. extract_filter() { awk -v want="$1" -v open="<<'PY'" ' index($0, open) { n++; inblock = 1; next } @@ -58,9 +58,8 @@ extract_filter() { ' "$SCRIPT" } extract_filter 1 > "$work/ios.py" -extract_filter 2 > "$work/watch.py" -if [[ ! -s "$work/ios.py" || ! -s "$work/watch.py" ]]; then - echo "❌ could not extract both discovery filters from $SCRIPT (did a heredoc move?)" >&2 +if [[ ! -s "$work/ios.py" ]]; then + echo "❌ could not extract the discovery filter from $SCRIPT (did a heredoc move?)" >&2 exit 1 fi @@ -68,10 +67,9 @@ python3 "$work/ios.py" "$FIXTURE" "$work/ios-unreachable.log" device \ > "$work/ios-out" 2> "$work/ios-stderr" python3 "$work/ios.py" "$FIXTURE" "$work/ios-sim-unreachable.log" sim \ > "$work/ios-sim-out" 2> "$work/ios-sim-stderr" -python3 "$work/watch.py" "$FIXTURE" "$work/watch-unreachable.log" > "$work/watch-out" 2> "$work/watch-stderr" -for produced in ios-out ios-stderr ios-sim-out ios-sim-stderr watch-out watch-stderr; do +for produced in ios-out ios-stderr ios-sim-out ios-sim-stderr; do if [[ ! -e "$work/$produced" ]]; then - echo "❌ a discovery filter did not produce $work/$produced" >&2 + echo "❌ the discovery filter did not produce $work/$produced" >&2 exit 1 fi done @@ -117,31 +115,16 @@ python3 "$work/ios.py" "$FIXTURE" "$work/ios-bogus-unreachable.log" sim \ check "sim mode ignores a non-matching DUO_DEVICE_ID" \ "0" "$(wc -c < "$work/ios-bogus-out" | tr -d ' ')" -check "watch filter emits only the reachable physical watch" \ - "AAAAAAAA-0000-0000-0000-000000000002|Fixture Watch Reachable" "$(cat "$work/watch-out")" -check "watch filter logs the tunnel-down watch as unreachable" \ - "Fixture Watch Ultra" "$(cat "$work/watch-unreachable.log")" -check "watch filter reports the unpaired watch" \ - "1" "$(grep -c 'not paired with this Mac' "$work/watch-stderr" || true)" -check "watch filter reports the developer-mode-disabled watch" \ - "1" "$(grep -c 'Developer Mode disabled' "$work/watch-stderr" || true)" - # A saved inventory that is valid JSON but not a devicectl payload must make the -# filters emit nothing without a traceback (run-devices.sh rejects invalid JSON +# filter emit nothing without a traceback (run-devices.sh rejects invalid JSON # up front; this covers the valid-JSON/wrong-shape case). echo '{}' > "$work/empty-inventory.json" python3 "$work/ios.py" "$work/empty-inventory.json" "$work/ios-empty-unreachable.log" sim \ > "$work/ios-empty-out" 2> "$work/ios-empty-stderr" -python3 "$work/watch.py" "$work/empty-inventory.json" "$work/watch-empty-unreachable.log" \ - > "$work/watch-empty-out" 2> "$work/watch-empty-stderr" check "iOS filter tolerates an inventory missing result.devices" \ "0" "$(wc -c < "$work/ios-empty-out" | tr -d ' ')" check "iOS filter emits no traceback on a missing-shape inventory" \ "0" "$(grep -c 'Traceback' "$work/ios-empty-stderr" || true)" -check "watch filter tolerates an inventory missing result.devices" \ - "0" "$(wc -c < "$work/watch-empty-out" | tr -d ' ')" -check "watch filter emits no traceback on a missing-shape inventory" \ - "0" "$(grep -c 'Traceback' "$work/watch-empty-stderr" || true)" # ── Control flow — stubbed tooling, no hardware ───────────────────────────── # Replays the script end-to-end so the zero-device gate, failure tally, build @@ -149,11 +132,10 @@ check "watch filter emits no traceback on a missing-shape inventory" \ # devicectl call at exit 0. stub_dir="$work/stubs" mkdir -p "$stub_dir" \ - "$work/derived/Build/Products/Debug-watchos/SingleThreadWatch.app" \ "$work/derived/Build/Products/Debug-iphoneos/SingleThread.app" \ "$work/derived/Build/Products/Debug-iphonesimulator/SingleThread.app" \ + "$work/derived/Build/Products/Debug-watchsimulator/SingleThreadWatch.app" \ "$work/derived/Build/Products/Debug/SingleThread.app" \ - "$work/derived-nosim/Build/Products/Debug-watchos/SingleThreadWatch.app" \ "$work/derived-nosim/Build/Products/Debug-iphoneos/SingleThread.app" \ "$work/derived-nosim/Build/Products/Debug/SingleThread.app" cat > "$stub_dir/xcodebuild" <<'STUB' @@ -169,7 +151,8 @@ fi exit 0 STUB # simctl listings are answered from a fixed inventory so the sim legs resolve a -# concrete UDID; every devicectl/other call is a no-op success. +# concrete UDID; bootstatus honours STUB_SIM_BOOT_FAIL; every devicectl/other +# call (including simctl install/launch) is a no-op success. cat > "$stub_dir/xcrun" <<'STUB' #!/usr/bin/env bash if [[ "$1" == "simctl" ]]; then @@ -191,40 +174,7 @@ STUB printf '#!/usr/bin/env bash\nexit 0\n' > "$stub_dir/open" chmod +x "$stub_dir/xcodebuild" "$stub_dir/xcrun" "$stub_dir/open" -python3 - "$work" <<'PY' -import json -import pathlib -import sys - -work = pathlib.Path(sys.argv[1]) - - -def watch(state, tunnel): - return { - "identifier": "AAAAAAAA-0000-0000-0000-000000000001", - "hardwareProperties": { - "platform": "watchOS", - "deviceType": "appleWatch", - "reality": "physical", - }, - "deviceProperties": {"name": "Stub Watch", "developerModeStatus": "enabled"}, - "connectionProperties": { - "pairingState": "paired", - "transportType": "localNetwork", - "tunnelState": tunnel, - }, - "properties": {"connection": {"pairingState": "paired", "state": state}}, - } - - -(work / "flow-unreachable-watch.json").write_text( - json.dumps({"result": {"devices": [watch("disconnected", "disconnected")]}}) -) -(work / "flow-reachable-watch.json").write_text( - json.dumps({"result": {"devices": [watch("connected", "connected")]}}) -) -(work / "flow-no-devices.json").write_text(json.dumps({"result": {"devices": []}})) -PY +echo '{"result": {"devices": []}}' > "$work/flow-no-devices.json" run_flow() { local label="$1" want_exit="$2" want_text="$3" want_absent="$4" @@ -246,12 +196,6 @@ run_flow() { fi } -run_flow "unreachable-watch-only still builds" 1 \ - "==> Building SingleThreadWatch" "No reachable iPhone/iPad found." \ - DEVICES_JSON_IN="$work/flow-unreachable-watch.json" RUN_WATCH=1 RUN_MAC=0 -run_flow "reachable-watch-only succeeds" 0 \ - "and 1 Apple Watch(es)" "No reachable iPhone/iPad found." \ - DEVICES_JSON_IN="$work/flow-reachable-watch.json" RUN_WATCH=1 RUN_MAC=0 run_flow "no iOS and no watch keeps the iOS fail-fast" 1 \ "No reachable iPhone/iPad found." "==> Building SingleThreadWatch" \ DEVICES_JSON_IN="$work/flow-no-devices.json" IOS_TARGET=device RUN_WATCH=1 RUN_MAC=0 @@ -286,6 +230,18 @@ run_flow "macOS success is reported in the summary" 0 \ run_flow "macOS build failure is reported in the summary" 1 \ "macOS: build failed" "macOS: built and launched" \ DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=1 STUB_MAC_BUILD_FAIL=1 +run_flow "watch simulator leg launches" 0 \ + "Apple Watch (sim): 1 launched, 0 failed" "" \ + DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=1 RUN_MAC=0 +check "watch simulator leg launches the watch bundle" "1" \ + "$(grep -c '==> Launching app.alanvardy.SingleThread.watchkitapp on the Apple Watch simulator' \ + "$work/flow-watch simulator leg launches.log" || true)" +run_flow "no watch simulator available is not a failure" 0 \ + "no 'No Such Watch' simulator available" "" \ + DEVICES_JSON_IN="$work/flow-no-devices.json" IOS_TARGET=device SIM_WATCH="No Such Watch" RUN_MAC=1 +run_flow "watch simulator boot failure is a failed step" 1 \ + "Apple Watch simulator failed to boot" "" \ + DEVICES_JSON_IN="$work/flow-no-devices.json" IOS_TARGET=device RUN_MAC=1 STUB_SIM_BOOT_FAIL=1 echo "" if [[ "$fail" -eq 0 ]]; then From 1185c97011720306d3029debdacd67f34bf5b35b Mon Sep 17 00:00:00 2001 From: Alan Vardy Date: Fri, 13 Nov 2026 07:39:20 -0700 Subject: [PATCH 6/9] chore: record implement artifacts for VAR-1175 --- .../implement.md | 98 +++++++++++++++++++ .../plan.md | 25 +++-- 2 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 .pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/implement.md diff --git a/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/implement.md b/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/implement.md new file mode 100644 index 00000000..5b72976c --- /dev/null +++ b/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/implement.md @@ -0,0 +1,98 @@ +# Implementation Summary + +Ticket: VAR-1175 — run the regular iPhone and iPad legs in simulators. +Branch: `alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in` + +## Commits + +| Phase | Commit | Description | +|-------|------------|----------------------------------------------------| +| 1 | `40425634` | Walking skeleton — sim iPhone leg end-to-end | +| 2 | `de664f63` | iPad simulator leg and sim sad paths | +| 3 | `f46205ca` | Watch leg on watch simulators | + +Bootstrap commit (parent): `b0b7b4f9` — plan/task artifacts added, `DELETEME` +marker removed (`git rm DELETEME`) as required before merge. + +## What shipped + +`scripts/run-devices.sh` now: + +- Runs the **regular iPhone and iPad legs in simulators** by default + (`IOS_TARGET=sim`), booting via `simctl bootstatus -b`, building with + `-destination id=`, then `simctl install` / `simctl launch`. +- Keeps the **physical iPhone Duo** on devicectl in both modes. + `DUO_DEVICE_ID=` wins when set, otherwise a case-insensitive + substring match on the device name (`iPhone Duo`). +- Runs the **Apple Watch leg on a watch simulator** + (`Apple Watch Series 11 (46mm)` by default); the physical watch discovery / + devicectl install / launch path, `WATCH_UNREACHABLE*`, + `WATCH_BUILD_NEEDED`, the launch-form bookkeeping and the 4016 messaging are + gone. An unavailable watch sim is a notice, not a failure. +- Offers `IOS_TARGET=device` to restore the old all-physical iPhone/iPad sweep + (the Duo is still deployed physically, and the watch still runs on a sim — + there is deliberately no `WATCH_TARGET`). +- Resolves simulator names to concrete UDIDs (`resolve_sim_udid` copied from + `scripts/test.sh`, anchored `index(s, n " (") == 1` match) so `iPhone 17` + never picks up the leftover `Gate iPhone 17` sim; the iPhone prefers this + worktree's `.simulator_id`, the iPad and watch never inherit it. +- Reports every leg honestly in the summary: + `iPhone/iPad (sim): N/M launched` + `iPhone Duo (device): …` in sim mode, + `iPhone/iPad (device): …` in device mode, `Apple Watch (sim): …` or + `skipped (RUN_WATCH=0)`. + +`scripts/test-run-devices.sh` was rewritten for the new behaviour and stays +offline-only (stubbed `xcrun`/`xcodebuild`/`open`, sim-vs-device fixtures). + +## Automated Checks + +- [x] `bash -n scripts/run-devices.sh` passes (all phases) +- [x] `bash -n scripts/test-run-devices.sh` passes +- [x] `shellcheck -S warning --exclude=SC1111 scripts/run-devices.sh` passes +- [x] `bash scripts/test-run-devices.sh` passes — all filter and flow checks, + including the sim happy path (`2/2 launched`), `IOS_TARGET=device` + oracle, `DUO_DEVICE_ID`, boot failure, missing sim product, unresolvable + iPad sim, watch launch, no-watch-sim notice, and watch boot failure +- [x] `make lint` passes (0 violations, 248 files) +- [x] No watch `devicectl` references remain in `scripts/run-devices.sh` + (`WATCH_DEVICES|WATCH_UNREACHABLE|watchkitapp.*devicectl` → nothing; the + `4016` alternative still matches two pre-existing **iOS-only** comments, + which are in scope for neither this ticket nor Phase 3) +- [x] `test-run-devices.sh` needs no gate wiring: + `rg -n 'test-run-devices' Makefile scripts/test.sh` returns nothing + +## Observations (not changed — out of plan scope) + +- Phase 3 used `resolve_ios_udid "$SIM_WATCH" "$DEFAULT_WATCH_SIM" 0` rather + than the plan's literal `resolve_sim_udid "$SIM_WATCH"`, so the documented + "empty → Apple Watch Series 11 (46mm)" default and the + `SIM_WATCH=No Such Watch` sad path both behave as the header and tests say. +- The header still describes devicectl provisioning-device registration for + the Duo (still accurate); the simulator legs don't need it. + +## Manual Verification Items (from the plan) + +- [ ] `IOS_TARGET=device DEVICES_JSON_IN=scripts/fixtures/devicectl-devices.json RUN_WATCH=0 RUN_MAC=0 ./scripts/run-devices.sh` + emits the old all-physical discovery/filter messages and the `(device)` + summary line. +- [ ] After the sim leg runs for real, confirm the booted worktree sim shows the + app launched. +- [ ] `./scripts/run-devices.sh` (or `r`) boots the worktree iPhone sim **and** + the iPad sim, installs/launches `SingleThread` on both, and the summary + prints `iPhone/iPad (sim): 2/2 launched`. +- [ ] With `SIM_IPAD=No Such Device ./scripts/run-devices.sh`, the run reports + the iPad as a failed step but still launches the Duo (if present) and + macOS. +- [ ] `./scripts/run-devices.sh` (or `r`) boots an Apple Watch simulator, + installs and launches `SingleThreadWatch`, and prints + `Apple Watch (sim): 1 launched, 0 failed`. +- [ ] `RUN_WATCH=0 ./scripts/run-devices.sh` prints + `Apple Watch (sim): skipped (RUN_WATCH=0)` and does no watch build. +- [ ] With `IOS_TARGET=device` and a Duo + watches present, only the Duo is + touched on hardware and the watch still runs on the simulator. + +## Post-plan gate (review step) + +- [ ] `./scripts/test.sh` via the `run-gate` skill (build + lint + Periphery + + unit + UI) — runs **once**, after the phases commit. +- [ ] `make format` + `make lint` before the final commit. diff --git a/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/plan.md b/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/plan.md index 38745c18..fc1948e5 100644 --- a/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/plan.md +++ b/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/plan.md @@ -321,10 +321,10 @@ Update the final success sentence to count sims honestly, e.g. ### Verification #### Automated -- [ ] `bash -n scripts/run-devices.sh` passes -- [ ] `shellcheck -S warning --exclude=SC1111 scripts/run-devices.sh` passes -- [ ] `bash scripts/test-run-devices.sh` passes (all filter + flow checks) -- [ ] `make lint` passes (no source changes, sanity only) +- [x] `bash -n scripts/run-devices.sh` passes +- [x] `shellcheck -S warning --exclude=SC1111 scripts/run-devices.sh` passes +- [x] `bash scripts/test-run-devices.sh` passes (all filter + flow checks) +- [x] `make lint` passes (no source changes, sanity only) #### Manual - [ ] `IOS_TARGET=device DEVICES_JSON_IN=scripts/fixtures/devicectl-devices.json RUN_WATCH=0 RUN_MAC=0 ./scripts/run-devices.sh` emits the old all-physical discovery/filter messages and the `(device)` summary line (stub or real hardware not required for the discovery lines; use the test harness log). @@ -375,8 +375,8 @@ running, since the point of the script is a live app to poke at. ### Verification #### Automated -- [ ] `bash -n scripts/run-devices.sh` and `shellcheck -S warning --exclude=SC1111 scripts/run-devices.sh` pass -- [ ] `bash scripts/test-run-devices.sh` passes, including the three new sad-path flows +- [x] `bash -n scripts/run-devices.sh` and `shellcheck -S warning --exclude=SC1111 scripts/run-devices.sh` pass +- [x] `bash scripts/test-run-devices.sh` passes, including the three new sad-path flows #### Manual - [ ] `./scripts/run-devices.sh` (or `r`) boots the worktree iPhone sim **and** @@ -527,11 +527,14 @@ on an unpaired watch sim (`scripts/appstore-screenshots.sh:29-31`). ### Verification #### Automated -- [ ] `bash -n scripts/run-devices.sh` and +- [x] `bash -n scripts/run-devices.sh` and `shellcheck -S warning --exclude=SC1111 scripts/run-devices.sh` pass -- [ ] `bash scripts/test-run-devices.sh` passes with the rewritten watch flows -- [ ] No `devicectl` watch references remain: +- [x] `bash scripts/test-run-devices.sh` passes with the rewritten watch flows +- [x] No `devicectl` watch references remain: `rg -n 'WATCH_DEVICES|WATCH_UNREACHABLE|watchkitapp.*devicectl|4016' scripts/run-devices.sh` returns nothing + (all watch-path references are gone; the `4016` alternative still matches two + pre-existing *iOS*-only comments about the physical-phone unreachable check — + altering those would change iOS behavior and is out of Phase 3 scope) #### Manual - [ ] `./scripts/run-devices.sh` (or `r`) boots an Apple Watch simulator, @@ -548,8 +551,10 @@ on an unpaired watch sim (`scripts/appstore-screenshots.sh:29-31`). - [ ] `./scripts/test.sh` via the `run-gate` skill (build + lint + Periphery + unit + UI) — the full CI-identical gate runs **once** after the phases commit. - [ ] `make format` + `make lint` before the final commit. -- [ ] Confirm no `IOS_TARGET`/fixture seam needs wiring into `scripts/test.sh` or +- [x] Confirm no `IOS_TARGET`/fixture seam needs wiring into `scripts/test.sh` or the `Makefile`: `scripts/test-run-devices.sh` is currently standalone and not referenced by the gate, so no wiring is expected — verify with `rg -n 'test-run-devices' Makefile scripts/test.sh` and add a gate step only if the repo convention requires it. + (verified: `rg -n 'test-run-devices' Makefile scripts/test.sh` returns nothing — + the harness stays standalone, no gate wiring needed) From a2ac73f0bd1c2ed1184032276a23a9aaf00df9ab Mon Sep 17 00:00:00 2001 From: Alan Vardy Date: Fri, 13 Nov 2026 08:20:21 -0700 Subject: [PATCH 7/9] fix: scope ControlPlateModifier to macOS --- .../done.md | 18 +++ SingleThread/ControlPlateModifier.swift | 108 +++++++++--------- 2 files changed, 74 insertions(+), 52 deletions(-) create mode 100644 .pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/done.md diff --git a/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/done.md b/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/done.md new file mode 100644 index 00000000..6eb232b2 --- /dev/null +++ b/.pi/orksorksorks/alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in/done.md @@ -0,0 +1,18 @@ +# Done + +- **Branch / head SHA**: `alanvardy-var-1175-run-the-regular-iphone-and-ipad-legs-in` / `2631b6875afa5afc88c1ce55a42977520cab8a31` (`fix: scope ControlPlateModifier to macOS`) +- **Mechanical checks**: + - `bash -n scripts/run-devices.sh` and `scripts/test-run-devices.sh`: pass. + - `./scripts/test-run-devices.sh`: pass (32 checks). + - `make lint`: pass (0 violations). + - `make format`: pass (no changes after the fix). + - `git diff --check`: pass. + - Shellcheck: pass except pre-existing `SC1111` unicode-quote warning at `scripts/run-devices.sh:124` (identical on `main`). + - Full CI-identical gate on `0d362077`: executable stages **PASS** — iOS UI 6/6, watch UI 1/1, watch unit 81/81, mac unit 862/862; warning-check 20/20; format/lint/build passed. The original gate aborted at Periphery with 2 findings in `ControlPlateModifier.swift`; the test-stage verdict was obtained via the authorized Option B continuation with Periphery skipped. + - **Periphery false positive fixed** in `2631b687`: `SingleThread/ControlPlateModifier.swift` is now compiled only on macOS, where its `.controlPlate()` usages live. `periphery scan --strict -- -destination "platform=iOS Simulator,id=BD205AB3-B188-48F1-B45A-3EE33B972ABB"` now reports **no unused code**. The macOS build also succeeds. The full gate was **not rerun** after this fix; targeted checks cover the changed file. +- **Review outcome**: No blockers. The bounded reviewer found no merge-blocking issue. Two non-blocking P1s remain deferred to the user: (1) `devicectl list` failure still hard-aborts `IOS_TARGET=sim` before the simulator legs run; (2) a set-but-nonmatching `DUO_DEVICE_ID` silently drops the Duo with no notice. Optional P2s noted: validate `IOS_TARGET` (`sim|device`), fix the empty `SIM_WATCH` notice text, adjust summary wording for device/no-Duo cases, mirror `test.sh`'s stale `.simulator_id` warning, wire the new offline harness into CI, and remove the walking-skeleton header wording. No P1/P2 fixes were applied because the review ran without `autofix`; the user's [1]/[2] menu decision remains open. +- **Remaining manual items**: + - Apply the P1s (and optionally P2s) if desired. + - Run the full gate again for the new fix commit if a complete post-fix verdict is required. + - Run `./scripts/run-devices.sh` against real hardware/simulators; the sim/Duo/watch/macOS legs were verified offline via stubs only. + - Complete the manual verification items in `plan.md`/`implement.md`. diff --git a/SingleThread/ControlPlateModifier.swift b/SingleThread/ControlPlateModifier.swift index a437059f..c3bdab9c 100644 --- a/SingleThread/ControlPlateModifier.swift +++ b/SingleThread/ControlPlateModifier.swift @@ -1,56 +1,60 @@ -import SwiftUI - -/// A scheme-adaptive circular plate that ensures controls are legible against -/// any background photo in both light and dark modes. -/// -/// Applies a 56×56 frame, a solid fill circle, and a shadow that lifts the -/// control above the background. -/// -/// Colours adapt to the current colour scheme unless explicitly overridden: -/// - Dark mode: black plate, white glyph -/// - Light mode: off-white plate, dark glyph -struct ControlPlateModifier: ViewModifier { - // MARK: Internal - - /// Overrides the scheme-adaptive plate fill. Defaults to `nil` (auto). - var fill: Color? - /// Overrides the scheme-adaptive glyph colour. Defaults to `nil` (auto). - var glyph: Color? - - func body(content: Content) -> some View { - let resolvedFill = fill ?? (colorScheme == .dark ? .black : Color(white: Self.lightPlateWhite)) - let resolvedGlyph = glyph ?? (colorScheme == .dark ? .white : Color(white: Self.darkGlyphWhite)) - - content - .foregroundStyle(resolvedGlyph) - .frame(width: Self.plateSize, height: Self.plateSize) - .background(resolvedFill, in: Circle()) - .shadow(radius: Self.shadowRadius) - } - - // MARK: Private +#if os(macOS) - private static let plateSize: CGFloat = 56 - private static let lightPlateWhite: Double = 0.92 - private static let darkGlyphWhite: Double = 0.15 - private static let shadowRadius: CGFloat = 4 + import SwiftUI - @Environment(\.colorScheme) - private var colorScheme -} - -extension View { - /// Wraps the view in a scheme-adaptive circular plate with a contrasting - /// stroke outline so the control remains visible against any background. + /// A scheme-adaptive circular plate that ensures controls are legible against + /// any background photo in both light and dark modes. + /// + /// Applies a 56×56 frame, a solid fill circle, and a shadow that lifts the + /// control above the background. /// - /// - Parameters: - /// - fill: Plate fill colour override. `nil` picks dark‑mode black - /// / light‑mode off‑white. - /// - glyph: Glyph colour override. `nil` picks dark‑mode white - /// / light‑mode near‑black. - func controlPlate( - fill: Color? = nil, - glyph: Color? = nil) -> some View { - modifier(ControlPlateModifier(fill: fill, glyph: glyph)) + /// Colours adapt to the current colour scheme unless explicitly overridden: + /// - Dark mode: black plate, white glyph + /// - Light mode: off-white plate, dark glyph + struct ControlPlateModifier: ViewModifier { + // MARK: Internal + + /// Overrides the scheme-adaptive plate fill. Defaults to `nil` (auto). + var fill: Color? + /// Overrides the scheme-adaptive glyph colour. Defaults to `nil` (auto). + var glyph: Color? + + func body(content: Content) -> some View { + let resolvedFill = fill ?? (colorScheme == .dark ? .black : Color(white: Self.lightPlateWhite)) + let resolvedGlyph = glyph ?? (colorScheme == .dark ? .white : Color(white: Self.darkGlyphWhite)) + + content + .foregroundStyle(resolvedGlyph) + .frame(width: Self.plateSize, height: Self.plateSize) + .background(resolvedFill, in: Circle()) + .shadow(radius: Self.shadowRadius) + } + + // MARK: Private + + private static let plateSize: CGFloat = 56 + private static let lightPlateWhite: Double = 0.92 + private static let darkGlyphWhite: Double = 0.15 + private static let shadowRadius: CGFloat = 4 + + @Environment(\.colorScheme) + private var colorScheme } -} + + extension View { + /// Wraps the view in a scheme-adaptive circular plate with a contrasting + /// stroke outline so the control remains visible against any background. + /// + /// - Parameters: + /// - fill: Plate fill colour override. `nil` picks dark‑mode black + /// / light‑mode off‑white. + /// - glyph: Glyph colour override. `nil` picks dark‑mode white + /// / light‑mode near‑black. + func controlPlate( + fill: Color? = nil, + glyph: Color? = nil) -> some View { + modifier(ControlPlateModifier(fill: fill, glyph: glyph)) + } + } + +#endif From 717a74971b64e0589341379e38b2b9f398b9b20d Mon Sep 17 00:00:00 2001 From: Alan Vardy Date: Fri, 13 Nov 2026 08:51:44 -0700 Subject: [PATCH 8/9] fix(run-devices): match renamed iPhone Duo by model; add SEED_FILE - Match the physical iPhone Duo by hardware productType (iPhone19,4) as well as name, so a renamed device (e.g. "Alan's Duo") is no longer silently dropped in IOS_TARGET=sim. - Warn when sim mode finds no physical Duo at all. - Add SEED_FILE= to pass a --seed to the iPhone/iPad simulator launches for seeded manual testing. - Rename the fixture Duo; offline checks cover both behaviours. --- scripts/fixtures/devicectl-devices.json | 4 +-- scripts/run-devices.sh | 41 ++++++++++++++++++++++--- scripts/test-run-devices.sh | 40 +++++++++++++++++++++--- 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/scripts/fixtures/devicectl-devices.json b/scripts/fixtures/devicectl-devices.json index 5894b468..4c357d11 100644 --- a/scripts/fixtures/devicectl-devices.json +++ b/scripts/fixtures/devicectl-devices.json @@ -258,12 +258,12 @@ "deviceProperties": { "bootState": "booted", "developerModeStatus": "disabled", - "name": "Fixture iPhone Duo" + "name": "Fixture Duo Renamed" }, "hardwareProperties": { "deviceType": "iPhone", "ecid": 1, - "marketingName": "Fixture iPhone Duo", + "marketingName": "iPhone", "platform": "iOS", "productType": "iPhone19,4", "reality": "physical", diff --git a/scripts/run-devices.sh b/scripts/run-devices.sh index d3c19f77..330ea76f 100755 --- a/scripts/run-devices.sh +++ b/scripts/run-devices.sh @@ -24,6 +24,10 @@ set -euo pipefail # WATCH_BUNDLE_ID=… # defaults to ${BUNDLE_ID}.watchkitapp # DEVICES_JSON_IN=… # dev seam: read a saved `xcrun devicectl list devices -j` # # inventory instead of querying CoreDevice (offline filter checks) +# SEED_FILE=… # path to a `--seed` JSON; when set, the iPhone/iPad +# # simulator launches pass it so the app boots with +# # deterministic reminders for manual testing. Empty = +# # a plain launch (production behaviour). # # Devices are discovered dynamically each run, so a new iPhone/iPad is picked # up without editing this script. A newly paired device is registered @@ -58,6 +62,7 @@ SIM_WATCH="${SIM_WATCH:-}" # explicit UDID or device name; empty = Apple Wat DUO_DEVICE_ID="${DUO_DEVICE_ID:-}" WATCH_BUNDLE_ID="${WATCH_BUNDLE_ID:-${BUNDLE_ID}.watchkitapp}" DEVICES_JSON_IN="${DEVICES_JSON_IN:-}" +SEED_FILE="${SEED_FILE:-}" DEVICES_JSON="${TMPDIR:-/tmp}/run-devices-$$.json" UNREACHABLE_LOG="${TMPDIR:-/tmp}/run-devices-unreachable-$$.log" trap 'rm -f "$DEVICES_JSON" "$UNREACHABLE_LOG"' EXIT @@ -73,6 +78,17 @@ DEFAULT_WATCH_SIM="Apple Watch Series 11 (46mm)" cd "$(dirname "$0")/.." +# Read the optional seed once, up front, so a bad path fails before any build +# work. Empty SEED_ARGS keeps the production launch (no `--seed`). +SEED_ARGS=() +if [[ -n "$SEED_FILE" ]]; then + if [[ ! -f "$SEED_FILE" ]]; then + echo "❌ SEED_FILE=$SEED_FILE could not be read." >&2 + exit 1 + fi + SEED_ARGS=(--seed "$(cat "$SEED_FILE")") +fi + # Pin a name-only simulator to a concrete UDID. An anchored name match stops # `iPhone 17` selecting the leftover "Gate iPhone 17" sim (scripts/test.sh:27-36). resolve_sim_udid() { @@ -128,9 +144,12 @@ fi # Emits "identifier|name" per qualifying devicectl target (platform iOS, iPhone # or iPad, physical). Simulated devices are excluded — they are not devicectl # install targets. In sim mode (the default) only the physical iPhone Duo is a -# devicectl target: DUO_DEVICE_ID wins when set, otherwise the name is matched -# case-insensitively on "iPhone Duo"; the regular iPhone/iPad legs run on -# simulators instead. In device mode every paired physical iPhone/iPad qualifies +# devicectl target: DUO_DEVICE_ID wins when set; otherwise the device is matched +# by its name (case-insensitive "iPhone Duo") OR its hardware model, productType +# "iPhone19,4" — a device can be renamed in the field (e.g. "Alan's Duo") while +# its model stays the Duo, so name alone would silently drop it. The regular +# iPhone/iPad legs run on simulators instead. In device mode every paired +# physical iPhone/iPad qualifies # (the old all-physical sweep). A paired physical phone whose Developer Mode is # off still qualifies and is named on stderr, so a newly paired device (e.g. a # second iPhone) is never silently omitted. Unreachable qualifying devices are @@ -171,7 +190,7 @@ with open(sys.argv[2], "a", encoding="utf-8") as unreachable_log: if duo_id: if device.get("identifier") != duo_id: continue - elif "iphone duo" not in name.lower(): + elif "iphone duo" not in name.lower() and hardware.get("productType") != "iPhone19,4": continue # Physical devices install over a connection (localNetwork, wired, or # sameMachine for local simulators). When CoreDevice cannot reach the @@ -214,6 +233,12 @@ if [[ ${#DEVICES[@]} -eq 0 && "$IOS_TARGET" != "sim" ]]; then fi fi +# A renamed Duo that still fails the model match is worth naming loudly: the +# simulator legs run either way, but the physical leg is silently absent. +if [[ "$IOS_TARGET" == "sim" && ${#DEVICES[@]} -eq 0 && "$UNREACHABLE_COUNT" -eq 0 ]]; then + echo " (no physical iPhone Duo found — the simulator legs still run; set DUO_DEVICE_ID= to pin one)" +fi + failures=0 # Devices that are paired but unreachable count as failed steps, matching the # old behavior where the guaranteed-failing install attempt was tried and failed. @@ -282,7 +307,13 @@ if [[ "$IOS_TARGET" == "sim" ]]; then continue fi echo "==> Launching on the $sim_label simulator…" - if xcrun simctl launch "$sim_udid" "$BUNDLE_ID"; then + # SEED_FILE (if any) rides along as `--seed ` so a manual run can + # boot against deterministic reminders instead of an empty EventKit store. + sim_launch=("$BUNDLE_ID") + if [[ ${#SEED_ARGS[@]} -gt 0 ]]; then + sim_launch+=("${SEED_ARGS[@]}") + fi + if xcrun simctl launch "$sim_udid" "${sim_launch[@]}"; then SIM_LAUNCHED=$((SIM_LAUNCHED + 1)) else echo "❌ Launch failed on the $sim_label simulator." >&2 diff --git a/scripts/test-run-devices.sh b/scripts/test-run-devices.sh index 34133032..c48fc0ac 100755 --- a/scripts/test-run-devices.sh +++ b/scripts/test-run-devices.sh @@ -78,8 +78,8 @@ done # iPhone/iPad qualifies. check "device mode emits the reachable physical iPhone" \ "1" "$(grep -c '|Fixture iPhone$' "$work/ios-out" || true)" -check "device mode emits the paired iPhone Duo even with Developer Mode off" \ - "1" "$(grep -c '|Fixture iPhone Duo$' "$work/ios-out" || true)" +check "device mode emits a renamed iPhone Duo (hardware model match) with Developer Mode off" \ + "1" "$(grep -c '|Fixture Duo Renamed$' "$work/ios-out" || true)" check "device mode emits the physical iPad with Developer Mode off" \ "1" "$(grep -c '|Fixture iPad DevMode Off$' "$work/ios-out" || true)" check "device mode excludes a simulated iOS device" \ @@ -91,8 +91,8 @@ check "device mode logs no unreachable devices" \ # IOS_TARGET=sim (the default): only the physical iPhone Duo is a devicectl # target; the regular iPhone/iPad run on simulators. -check "sim mode emits the paired iPhone Duo" \ - "1" "$(grep -c '|Fixture iPhone Duo$' "$work/ios-sim-out" || true)" +check "sim mode emits a renamed iPhone Duo by hardware model" \ + "1" "$(grep -c '|Fixture Duo Renamed$' "$work/ios-sim-out" || true)" check "sim mode excludes the regular physical iPhone" \ "0" "$(grep -c '|Fixture iPhone$' "$work/ios-sim-out" || true)" check "sim mode excludes the physical iPad" \ @@ -109,7 +109,7 @@ check "sim mode logs no unreachable devices" \ python3 "$work/ios.py" "$FIXTURE" "$work/ios-duo-unreachable.log" sim \ "CCCCCCCC-0000-0000-0000-000000000009" > "$work/ios-duo-out" 2>/dev/null check "sim mode selects only the DUO_DEVICE_ID device" \ - "CCCCCCCC-0000-0000-0000-000000000009|Fixture iPhone Duo" "$(cat "$work/ios-duo-out")" + "CCCCCCCC-0000-0000-0000-000000000009|Fixture Duo Renamed" "$(cat "$work/ios-duo-out")" python3 "$work/ios.py" "$FIXTURE" "$work/ios-bogus-unreachable.log" sim \ "BBBBBBBB-0000-0000-0000-000000000000" > "$work/ios-bogus-out" 2>/dev/null check "sim mode ignores a non-matching DUO_DEVICE_ID" \ @@ -167,6 +167,12 @@ if [[ "$1" == "simctl" ]]; then [[ "${STUB_SIM_BOOT_FAIL:-0}" == "1" ]] && exit 1 exit 0 ;; + launch) + if [[ -n "${STUB_LAUNCH_LOG:-}" ]]; then + printf '%s\n' "$@" >> "$STUB_LAUNCH_LOG" + fi + exit 0 + ;; esac fi exit 0 @@ -243,6 +249,30 @@ run_flow "watch simulator boot failure is a failed step" 1 \ "Apple Watch simulator failed to boot" "" \ DEVICES_JSON_IN="$work/flow-no-devices.json" IOS_TARGET=device RUN_MAC=1 STUB_SIM_BOOT_FAIL=1 +# ── Seeding ───────────────────────────────────────────────────────────── +# SEED_FILE feeds `--seed ` to each simulator launch so a manual run boots +# with deterministic reminders; a bad path fails before any build work, and an +# unset SEED_FILE leaves the launch plain. +echo '{"reminders":[{"title":"Seeded one"}]}' > "$work/seed.json" +run_flow "SEED_FILE seeds the simulator launches" 0 \ + "iPhone/iPad (sim): 2/2 launched" "" \ + DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=0 \ + SEED_FILE="$work/seed.json" STUB_LAUNCH_LOG="$work/seed-launch.log" +check "seed rides along on both simulator launches via --seed" "2" \ + "$(grep -c -- '--seed' "$work/seed-launch.log" || true)" +check "the seed payload itself reaches simctl" "2" \ + "$(grep -c 'Seeded one' "$work/seed-launch.log" || true)" +run_flow "a no-SEED_FILE launch passes no --seed" 0 \ + "iPhone/iPad (sim): 2/2 launched" "" \ + DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=0 \ + STUB_LAUNCH_LOG="$work/plain-launch.log" +check "no --seed when SEED_FILE is unset" "0" \ + "$(grep -c -- '--seed' "$work/plain-launch.log" || true)" +run_flow "a missing SEED_FILE is a hard error" 1 \ + "SEED_FILE=" "" \ + DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=0 \ + SEED_FILE="$work/does-not-exist.json" + echo "" if [[ "$fail" -eq 0 ]]; then echo "✅ run-devices.sh offline checks passed." From 3a1c201e70ef88235fdc7862dba32f5daec9d142 Mon Sep 17 00:00:00 2001 From: Alan Vardy Date: Fri, 13 Nov 2026 10:02:21 -0700 Subject: [PATCH 9/9] fixes --- scripts/fixtures/run-devices-seed.json | 10 ++++ scripts/run-devices.sh | 69 +++++++++++++++++++++++--- scripts/test-run-devices.sh | 55 +++++++++++++++++--- 3 files changed, 118 insertions(+), 16 deletions(-) create mode 100644 scripts/fixtures/run-devices-seed.json diff --git a/scripts/fixtures/run-devices-seed.json b/scripts/fixtures/run-devices-seed.json new file mode 100644 index 00000000..d97364f3 --- /dev/null +++ b/scripts/fixtures/run-devices-seed.json @@ -0,0 +1,10 @@ +{ + "reminders": [ + {"title": "Buy groceries", "notes": "milk, eggs, bread", "priority": 5}, + {"title": "Call mom", "priority": 1}, + {"title": "Water the plants"}, + {"title": "Book dentist appointment", "notes": "before the end of the month"}, + {"title": "Reply to Alex"} + ], + "calendars": ["Errands"] +} diff --git a/scripts/run-devices.sh b/scripts/run-devices.sh index 330ea76f..540efaca 100755 --- a/scripts/run-devices.sh +++ b/scripts/run-devices.sh @@ -24,10 +24,13 @@ set -euo pipefail # WATCH_BUNDLE_ID=… # defaults to ${BUNDLE_ID}.watchkitapp # DEVICES_JSON_IN=… # dev seam: read a saved `xcrun devicectl list devices -j` # # inventory instead of querying CoreDevice (offline filter checks) -# SEED_FILE=… # path to a `--seed` JSON; when set, the iPhone/iPad -# # simulator launches pass it so the app boots with -# # deterministic reminders for manual testing. Empty = -# # a plain launch (production behaviour). +# SEED_FILE=… # path to a `--seed` JSON passed to the iPhone/iPad +# # simulator launches so the app boots with +# # deterministic reminders for manual testing. Defaults +# # to scripts/fixtures/run-devices-seed.json (no EventKit +# # permission prompt on the sims). Set SEED_FILE= (empty) +# # for a plain launch (production behaviour, needs +# # Reminders access). # # Devices are discovered dynamically each run, so a new iPhone/iPad is picked # up without editing this script. A newly paired device is registered @@ -42,6 +45,17 @@ set -euo pipefail # to carry the In-App Purchase entitlement — see make mac-run / the TestFlight # runbook for the signed flow. # +# Seeding: the phone's JSON `--seed` seeds the iPhone/iPad legs; the watch app +# is a separate process and takes its own `--ui-testing` seam (a demo card with +# full Reminders access), so it shows a reminder instead of the access prompt. +# +# Simulator windows: simctl alone boots headlessly, so each simulator leg opens +# the device GUI on the booted UDID — Xcode 27's Device Hub via the +# `devices://device/open?id=` deep link (`open -b com.apple.dt.Devices`), +# falling back to Simulator.app's `open -a Simulator --args -CurrentDeviceUDID +# ` on older Xcode. The first call cold-launches the GUI; while it runs, +# later booted devices get their own windows. +# # Apple Watch prerequisite: the watch runs on a simulator, not on hardware, so # no wrist / paired-iPhone / CoreDevice tunnel is involved. The named watch # simulator must exist (xcrun simctl list devices); the app installs and launches @@ -62,7 +76,11 @@ SIM_WATCH="${SIM_WATCH:-}" # explicit UDID or device name; empty = Apple Wat DUO_DEVICE_ID="${DUO_DEVICE_ID:-}" WATCH_BUNDLE_ID="${WATCH_BUNDLE_ID:-${BUNDLE_ID}.watchkitapp}" DEVICES_JSON_IN="${DEVICES_JSON_IN:-}" -SEED_FILE="${SEED_FILE:-}" +# Default the sim launches to a checked-in seed so `run-devices` boots with +# reminders and without the EventKit permission gate. `${SEED_FILE-…}` (not +# `:-`) keeps an explicitly empty SEED_FILE= as the plain production launch. +DEFAULT_SEED_FILE="scripts/fixtures/run-devices-seed.json" +SEED_FILE="${SEED_FILE-$DEFAULT_SEED_FILE}" DEVICES_JSON="${TMPDIR:-/tmp}/run-devices-$$.json" UNREACHABLE_LOG="${TMPDIR:-/tmp}/run-devices-unreachable-$$.log" trap 'rm -f "$DEVICES_JSON" "$UNREACHABLE_LOG"' EXIT @@ -78,8 +96,8 @@ DEFAULT_WATCH_SIM="Apple Watch Series 11 (46mm)" cd "$(dirname "$0")/.." -# Read the optional seed once, up front, so a bad path fails before any build -# work. Empty SEED_ARGS keeps the production launch (no `--seed`). +# Read the seed once, up front, so a bad path fails before any build work. +# Empty SEED_ARGS keeps the production launch (no `--seed`). SEED_ARGS=() if [[ -n "$SEED_FILE" ]]; then if [[ ! -f "$SEED_FILE" ]]; then @@ -89,6 +107,16 @@ if [[ -n "$SEED_FILE" ]]; then SEED_ARGS=(--seed "$(cat "$SEED_FILE")") fi +# The watch app is a separate process and does not receive the phone's JSON +# `--seed`; its own `--ui-testing` seam seeds a demo card and reports full +# Reminders access, so the watch sim shows a reminder instead of the EventKit +# access prompt. Tie it to the same seed switch so an empty SEED_FILE= also +# leaves the watch in production mode. +WATCH_LAUNCH_ARGS=() +if [[ ${#SEED_ARGS[@]} -gt 0 ]]; then + WATCH_LAUNCH_ARGS=(--ui-testing) +fi + # Pin a name-only simulator to a concrete UDID. An anchored name match stops # `iPhone 17` selecting the leftover "Gate iPhone 17" sim (scripts/test.sh:27-36). resolve_sim_udid() { @@ -117,6 +145,27 @@ resolve_ios_udid() { # $1 = value (UDID or name), $2 = default name, $3 = 1 to p resolve_sim_udid "$default" } +# Bring a booted simulator's window to the front. Simulator.app attaches a +# window to every device booted while it is alive, and on a *fresh* launch +# `--args -CurrentDeviceUDID` pins which device it opens with; when it is +# already running the booted device's window attaches on its own, so `open` +# only brings it forward. A visible window is the point of a manual run, so a +# failure here is reported but not tallied as a failed step. +show_sim_window() { # $1 = UDID + # Xcode 27 removed Simulator.app in favour of Device Hub + # (`com.apple.dt.Devices`), which focuses a booted device via its + # `devices://device/open?id=` deep link. Older Xcode keeps Simulator.app + # and its `-CurrentDeviceUDID` launch arg. Prefer whichever is installed. + if open -b com.apple.dt.Devices 2>/dev/null; then + open "devices://device/open?id=$1" 2>/dev/null || true + return 0 + fi + if open -a Simulator --args -CurrentDeviceUDID "$1" 2>/dev/null; then + return 0 + fi + echo " (note: could not open a device window for $1 — it is booted and installed; open Device Hub or Simulator manually to see it)" >&2 +} + # ── Discover devices ───────────────────────────────────────────────────────── if [[ "$IOS_TARGET" == "sim" ]]; then echo "==> Discovering the paired iPhone Duo…" @@ -288,6 +337,8 @@ if [[ "$IOS_TARGET" == "sim" ]]; then failures=$((failures + 1)) continue fi + echo "==> Showing the $sim_label simulator window…" + show_sim_window "$sim_udid" echo "==> Building $SCHEME ($CONFIGURATION) for the $sim_label simulator…" if ! xcodebuild -scheme "$SCHEME" -destination "id=$sim_udid" \ -configuration "$CONFIGURATION" -derivedDataPath "$DERIVED_DATA" build; then @@ -391,6 +442,8 @@ if [[ "$RUN_WATCH" -eq 1 ]]; then failures=$((failures + 1)) WATCH_FAILED=1 else + echo "==> Showing the Apple Watch simulator window…" + show_sim_window "$watch_udid" echo "==> Building SingleThreadWatch ($CONFIGURATION) for the simulator…" if ! xcodebuild -scheme SingleThreadWatch -destination "id=$watch_udid" \ -configuration "$CONFIGURATION" -derivedDataPath "$DERIVED_DATA" build; then @@ -409,7 +462,7 @@ if [[ "$RUN_WATCH" -eq 1 ]]; then WATCH_FAILED=1 else echo "==> Launching $WATCH_BUNDLE_ID on the Apple Watch simulator…" - if xcrun simctl launch "$watch_udid" "$WATCH_BUNDLE_ID"; then + if xcrun simctl launch "$watch_udid" "$WATCH_BUNDLE_ID" "${WATCH_LAUNCH_ARGS[@]}"; then WATCH_LAUNCHED=1 else echo "❌ Watch launch failed." >&2 diff --git a/scripts/test-run-devices.sh b/scripts/test-run-devices.sh index c48fc0ac..7db92965 100755 --- a/scripts/test-run-devices.sh +++ b/scripts/test-run-devices.sh @@ -177,7 +177,15 @@ if [[ "$1" == "simctl" ]]; then fi exit 0 STUB -printf '#!/usr/bin/env bash\nexit 0\n' > "$stub_dir/open" +# `open` is used both by the macOS leg and the simulator-window step; log its +# args so the window checks can assert the pinned UDID. +cat > "$stub_dir/open" <<'STUB' +#!/usr/bin/env bash +if [[ -n "${STUB_OPEN_LOG:-}" ]]; then + printf '%s\n' "$@" >> "$STUB_OPEN_LOG" +fi +exit 0 +STUB chmod +x "$stub_dir/xcodebuild" "$stub_dir/xcrun" "$stub_dir/open" echo '{"result": {"devices": []}}' > "$work/flow-no-devices.json" @@ -211,6 +219,16 @@ run_flow "RUN_WATCH=0 emits no watch output" 1 \ run_flow "default sim mode launches the iPhone simulator" 0 \ "iPhone/iPad (sim): 2/2 launched" "No reachable iPhone/iPad found." \ DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=0 +run_flow "a successful sim leg opens the simulator window" 0 \ + "iPhone/iPad (sim): 2/2 launched" "" \ + DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=0 \ + STUB_OPEN_LOG="$work/open.log" +check "the iPhone simulator window is pinned by UDID" "1" \ + "$(grep -c '11111111-1111-1111-1111-111111111111' "$work/open.log" || true)" +check "the iPad simulator window is pinned by UDID" "1" \ + "$(grep -c '22222222-2222-2222-2222-222222222222' "$work/open.log" || true)" +check "the simulator window uses the Device Hub deep link" "2" \ + "$(grep -c 'devices://device/open?id=' "$work/open.log" || true)" run_flow "simulator boot failure is a failed step" 1 \ "failed to boot" "" \ DEVICES_JSON_IN="$FIXTURE" RUN_WATCH=0 RUN_MAC=1 STUB_SIM_BOOT_FAIL=1 @@ -238,10 +256,15 @@ run_flow "macOS build failure is reported in the summary" 1 \ DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=1 STUB_MAC_BUILD_FAIL=1 run_flow "watch simulator leg launches" 0 \ "Apple Watch (sim): 1 launched, 0 failed" "" \ - DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=1 RUN_MAC=0 + DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=1 RUN_MAC=0 \ + STUB_OPEN_LOG="$work/watch-open.log" STUB_LAUNCH_LOG="$work/watch-launch.log" check "watch simulator leg launches the watch bundle" "1" \ "$(grep -c '==> Launching app.alanvardy.SingleThread.watchkitapp on the Apple Watch simulator' \ "$work/flow-watch simulator leg launches.log" || true)" +check "the watch simulator window is pinned by UDID" "1" \ + "$(grep -c '33333333-3333-3333-3333-333333333333' "$work/watch-open.log" || true)" +check "the watch app launches with its --ui-testing seam" "1" \ + "$(grep -c -- '--ui-testing' "$work/watch-launch.log" || true)" run_flow "no watch simulator available is not a failure" 0 \ "no 'No Such Watch' simulator available" "" \ DEVICES_JSON_IN="$work/flow-no-devices.json" IOS_TARGET=device SIM_WATCH="No Such Watch" RUN_MAC=1 @@ -250,9 +273,19 @@ run_flow "watch simulator boot failure is a failed step" 1 \ DEVICES_JSON_IN="$work/flow-no-devices.json" IOS_TARGET=device RUN_MAC=1 STUB_SIM_BOOT_FAIL=1 # ── Seeding ───────────────────────────────────────────────────────────── -# SEED_FILE feeds `--seed ` to each simulator launch so a manual run boots -# with deterministic reminders; a bad path fails before any build work, and an -# unset SEED_FILE leaves the launch plain. +# The simulator launches seed by default from scripts/fixtures/run-devices-seed.json +# so a manual run boots with deterministic reminders and no EventKit permission +# gate. SEED_FILE= overrides the fixture; an explicitly empty SEED_FILE= leaves +# the launch plain (production behaviour), and a bad path fails before any build +# work. +run_flow "the default seed fixture seeds the simulator launches" 0 \ + "iPhone/iPad (sim): 2/2 launched" "" \ + DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=0 \ + STUB_LAUNCH_LOG="$work/default-seed-launch.log" +check "the default fixture rides along on both simulator launches via --seed" "2" \ + "$(grep -c -- '--seed' "$work/default-seed-launch.log" || true)" +check "the default fixture payload reaches simctl" "2" \ + "$(grep -c 'Buy groceries' "$work/default-seed-launch.log" || true)" echo '{"reminders":[{"title":"Seeded one"}]}' > "$work/seed.json" run_flow "SEED_FILE seeds the simulator launches" 0 \ "iPhone/iPad (sim): 2/2 launched" "" \ @@ -262,12 +295,18 @@ check "seed rides along on both simulator launches via --seed" "2" \ "$(grep -c -- '--seed' "$work/seed-launch.log" || true)" check "the seed payload itself reaches simctl" "2" \ "$(grep -c 'Seeded one' "$work/seed-launch.log" || true)" -run_flow "a no-SEED_FILE launch passes no --seed" 0 \ +run_flow "an empty SEED_FILE= launch passes no --seed" 0 \ "iPhone/iPad (sim): 2/2 launched" "" \ DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=0 \ - STUB_LAUNCH_LOG="$work/plain-launch.log" -check "no --seed when SEED_FILE is unset" "0" \ + SEED_FILE= STUB_LAUNCH_LOG="$work/plain-launch.log" +check "no --seed when SEED_FILE is empty" "0" \ "$(grep -c -- '--seed' "$work/plain-launch.log" || true)" +run_flow "an empty SEED_FILE= leaves the watch in production mode" 0 \ + "Apple Watch (sim): 1 launched, 0 failed" "" \ + DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=1 RUN_MAC=0 \ + SEED_FILE= STUB_LAUNCH_LOG="$work/watch-plain-launch.log" +check "no --ui-testing when SEED_FILE is empty" "0" \ + "$(grep -c -- '--ui-testing' "$work/watch-plain-launch.log" || true)" run_flow "a missing SEED_FILE is a hard error" 1 \ "SEED_FILE=" "" \ DEVICES_JSON_IN="$work/flow-no-devices.json" RUN_WATCH=0 RUN_MAC=0 \