From 4b6f3fc439781cc6ecd326b3b9787459468afb8e Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 14:08:59 +0100 Subject: [PATCH 01/12] test: a socket client presses a button on an iOS simulator (#1659) --- src/drivers/ios/input/device-input.test.ts | 44 ++++++++++++++-------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/drivers/ios/input/device-input.test.ts b/src/drivers/ios/input/device-input.test.ts index 7f0b44cff..106d47170 100644 --- a/src/drivers/ios/input/device-input.test.ts +++ b/src/drivers/ios/input/device-input.test.ts @@ -83,9 +83,36 @@ function decoded(writes: readonly Uint8Array[]): { tag: number; body: unknown }[ } describe("iOS device input", () => { - it("touches, buttons, scrolls, keys and rotations on an iOS simulator reach the HID helper", async () => { + it("a socket client presses a button on an iOS simulator: app_switcher and lock reach the helper, home launches SpringBoard, back is dropped", async () => { const { factory, launcher, processRunner } = setup(); const opening = factory.open(simulator(), new AbortController().signal); + launcher.last.write(envelope(INPUT_TAG.config, { height: 2556, width: 1179 })); + const input = (await opening) as DeviceInput; + + for (const button of ["app_switcher", "lock"] as const) { + input.send({ button, kind: "button" }); + } + expect(decoded(launcher.last.stdinWrites)).toEqual([ + { body: { button: "app_switcher" }, tag: INPUT_TAG.button }, + { body: { button: "lock" }, tag: INPUT_TAG.button }, + ]); + expect(processRunner.calls).toEqual([]); + + input.send({ button: "home", kind: "button" }); + input.send({ button: "back", kind: "button" }); + expect(decoded(launcher.last.stdinWrites)).toHaveLength(2); + expect(processRunner.calls).toEqual([ + { + args: ["simctl", "--set", DEVICE_SET, "launch", "UDID-1", "com.apple.springboard"], + command: "xcrun", + options: { timeoutMs: 10_000 }, + }, + ]); + }); + + it("touches, scrolls, keys and rotations on an iOS simulator reach the HID helper", async () => { + const { factory, launcher } = setup(); + const opening = factory.open(simulator(), new AbortController().signal); expect(launcher.starts).toEqual([ { args: ["UDID-1", "--input"], @@ -109,21 +136,6 @@ describe("iOS device input", () => { ]); const writtenBefore = launcher.last.stdinWrites.length; - input.send({ button: "app_switcher", kind: "button" }); - input.send({ button: "lock", kind: "button" }); - input.send({ button: "back", kind: "button" }); - expect(processRunner.calls).toEqual([]); - expect(launcher.last.stdinWrites).toHaveLength(writtenBefore); - input.send({ button: "home", kind: "button" }); - expect(processRunner.calls).toEqual([ - { - args: ["simctl", "--set", DEVICE_SET, "launch", "UDID-1", "com.apple.springboard"], - command: "xcrun", - options: { timeoutMs: 10_000 }, - }, - ]); - expect(launcher.last.stdinWrites).toHaveLength(writtenBefore); - input.send({ dx: 0, dy: 0.5, kind: "scroll", x: 0.5, y: 0.25 }); input.send({ dx: -0.25, dy: 0, kind: "scroll" }); input.send({ kind: "key", type: "down", usage: 0x04 }); From 111af914d444224e3d683c3b3852acb5ee43907b Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 14:09:21 +0100 Subject: [PATCH 02/12] feat(ios): app switcher and Lock reach the input helper (#1659) --- src/drivers/ios/input/device-input.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/drivers/ios/input/device-input.ts b/src/drivers/ios/input/device-input.ts index 1786d2232..f832f8dbe 100644 --- a/src/drivers/ios/input/device-input.ts +++ b/src/drivers/ios/input/device-input.ts @@ -159,8 +159,10 @@ function within(milliseconds: number, clock: Clock, work: Promise): Promis // why: the helper reads serve-sim's JSON for each tag; JSON leaves out a scroll position the client // sent none of, so the helper scrolls under the centre. -function frameOfMessage(message: Exclude): Uint8Array { +function frameOfMessage(message: InputMessage): Uint8Array { switch (message.kind) { + case "button": + return frameOf(INPUT_TAG.button, { button: message.button }); case "touch": return frameOf(INPUT_TAG.touch, { type: message.type, x: message.x, y: message.y }); case "scroll": @@ -227,7 +229,7 @@ class IosDeviceInput implements DeviceInput { send(message: InputMessage): Promise { if (message.kind === "button") { if (message.button === "home") this.#home(); - return Promise.resolve(); + if (message.button !== "app_switcher" && message.button !== "lock") return Promise.resolve(); } if (message.kind === "key" && !this.#keys) return Promise.resolve(); return this.#child.writeStdin(frameOfMessage(message)).catch((error: unknown) => { @@ -239,8 +241,8 @@ class IosDeviceInput implements DeviceInput { }); } - // why: Xcode 26 and later silently drop the HID home-button press, so Home brings SpringBoard - // forward the way serve-sim does; the app switcher and Lock have no such way and are dropped. + // why: Home keeps one owner, this launch of SpringBoard; the helper presses Home only as part of + // the app switcher (ADR 0085 section 3). #home(): void { const { deviceSet, logger, processRunner } = this.#options; const args = [ From c4a7e17e6bd9e13b75a01686084539f08b573c6d Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 14:09:56 +0100 Subject: [PATCH 03/12] test: a socket client sends a key on an iOS simulator of any runtime (#1659) --- src/drivers/ios/input/device-input.test.ts | 52 +++++++++------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/src/drivers/ios/input/device-input.test.ts b/src/drivers/ios/input/device-input.test.ts index 106d47170..7debe9f80 100644 --- a/src/drivers/ios/input/device-input.test.ts +++ b/src/drivers/ios/input/device-input.test.ts @@ -166,27 +166,33 @@ describe("iOS device input", () => { expect(inXcodeSet.launcher.starts.map((start) => start.env)).toEqual([{ PATH: "/usr/bin" }]); inXcodeSet.launcher.last.write(envelope(INPUT_TAG.config, { height: 2556, width: 1179 })); await xcodeOpen; + }); + it("a socket client sends a key on an iOS simulator of any runtime, and the config never says keyboardUnavailable", async () => { for (const runtimeId of [ + "com.apple.CoreSimulator.SimRuntime.iOS-26-4", "com.apple.CoreSimulator.SimRuntime.iOS-27-0", "com.apple.CoreSimulator.SimRuntime.iOS-28-1", "garbage", ]) { - const other = setup(); - const opened = other.factory.open(simulator(runtimeId), new AbortController().signal); - other.launcher.last.write(envelope(INPUT_TAG.config, { height: 2556, width: 1179 })); - const limited = (await opened) as DeviceInput; - const limitedConfigs: InputScreenConfig[] = []; - limited.onConfig((config) => limitedConfigs.push(config)); - expect(limitedConfigs).toEqual([ - { height: 2556, keyboardUnavailable: true, orientation: "portrait", width: 1179 }, + const { factory, launcher } = setup(); + const opening = factory.open(simulator(runtimeId), new AbortController().signal); + launcher.last.write(envelope(INPUT_TAG.config, { height: 2000, width: 1000 })); + const input = (await opening) as DeviceInput; + const configs: InputScreenConfig[] = []; + input.onConfig((config) => configs.push(config)); + input.send({ kind: "key", type: "down", usage: 0x04 }); + input.send({ kind: "key", type: "up", usage: 0x04 }); + expect(decoded(launcher.last.stdinWrites), runtimeId).toEqual([ + { body: { type: "down", usage: 0x04 }, tag: INPUT_TAG.key }, + { body: { type: "up", usage: 0x04 }, tag: INPUT_TAG.key }, ]); - limited.send({ kind: "key", type: "down", usage: 0x04 }); - limited.send({ kind: "touch", type: "begin", x: 0.5, y: 0.25 }); - limited.send({ kind: "orientation", orientation: "landscape_left" }); - expect(decoded(other.launcher.last.stdinWrites)).toEqual([ - { body: { type: "begin", x: 0.5, y: 0.25 }, tag: INPUT_TAG.touch }, - { body: { orientation: "landscape_left" }, tag: 0x07 }, + + launcher.last.write(envelope(INPUT_TAG.config, { height: 2000, width: 3000 })); + await new Promise((resolve) => setImmediate(resolve)); + expect(configs, runtimeId).toEqual([ + { height: 2000, orientation: "portrait", width: 1000 }, + { height: 2000, orientation: "portrait", width: 3000 }, ]); } }); @@ -245,24 +251,6 @@ describe("iOS device input", () => { { height: 2000, orientation: "portrait", width: 1000 }, ]); expect(logger.warnings).toHaveLength(4); - - const keyless = setup(); - const keylessOpen = keyless.factory.open( - simulator("com.apple.CoreSimulator.SimRuntime.iOS-27-0"), - new AbortController().signal, - ); - keyless.launcher.last.write(envelope(INPUT_TAG.config, { height: 2000, width: 1000 })); - const keylessInput = (await keylessOpen) as DeviceInput; - const keylessConfigs: InputScreenConfig[] = []; - keylessInput.onConfig((config) => keylessConfigs.push(config)); - keyless.launcher.last.write(envelope(INPUT_TAG.config, { height: 2000, width: 3000 })); - await flush(); - expect(keylessConfigs.at(-1)).toEqual({ - height: 2000, - keyboardUnavailable: true, - orientation: "portrait", - width: 3000, - }); }); it("an open rejects when the helper is missing, exits first or reports no size within 10 s, and a helper that exits later fails the input", async () => { From d64125b7964120f2a815350c92033eabd34d9a51 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 14:10:09 +0100 Subject: [PATCH 04/12] feat(ios): keys reach the input helper on every runtime (#1659) --- src/drivers/ios/input/AGENTS.md | 8 +++---- src/drivers/ios/input/device-input.ts | 31 +++------------------------ 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/src/drivers/ios/input/AGENTS.md b/src/drivers/ios/input/AGENTS.md index a7b7eea7a..703ae2ac6 100644 --- a/src/drivers/ios/input/AGENTS.md +++ b/src/drivers/ios/input/AGENTS.md @@ -5,9 +5,9 @@ Flows: [iOS driver](../AGENTS.md), [input](../../../input/AGENTS.md). ## Rules -- The helper's HID client and the runtime rule for keys stay here; core and the input module name neither. -- Home is `xcrun simctl` here and nowhere in the helper (one owner). Xcode 26 and later silently drop the HID home-button press, so Home launches `com.apple.springboard`; a failure is only logged. The app switcher, Lock and Back are dropped. -- Keys are dropped, and the config says `keyboardUnavailable: true`, when the runtime is iOS 27 or later or cannot be read: the iOS 27 guest ignores injected keys. +- The helper's HID client stays here; core and the input module do not name it. +- Home is `xcrun simctl` here and nowhere in the helper (one owner). Home launches `com.apple.springboard`; a failure is only logged. `app_switcher` and `lock` go to the helper (ADR 0085): Lock is one Indigo button press, the app switcher two Home presses 50 ms apart. Back is dropped. +- Keys go to the helper on every runtime, and the config never says `keyboardUnavailable` (ADR 0085). A press the guest ignores is not detected. - The helper follows the driver's device-set rule: `SIMLOCK_IOS_DEVICE_SET` names the owned set under `simlock` and is absent under `default`. The daemon's own value never reaches it. - The open waits for the helper's first size frame (`READY_DEADLINE_MS` in `device-input.ts`), which it writes once its HID client is set up. A missing program, an early exit or no frame rejects the open, and the helper is stopped. - The config is always `portrait`, a rotation included: it is the size of the panel the taps land on. A foldable's helper sends the size again when the panel in use changes (ADR 0075 §4); a size equal to the held one is no change, and a frame that is not a size is warned about and kept out. @@ -17,7 +17,7 @@ Flows: [iOS driver](../AGENTS.md), [input](../../../input/AGENTS.md). ## Known gaps -- **No app switcher or Lock, and no keys on iOS 27 runtimes (#1024).** +- **A CoreSimulator older than 1174.21 was not measured** for the Home and Lock presses (ADR 0085); a worker on one may ignore them silently. - **A screen that does not rotate ignores a rotation, and nothing tells the client** (the iPhone home screen, upside down on a Face ID iPhone). Rotation was checked on Xcode 26.4 (iOS 26.4 runtime) and Xcode 27.0 (iOS 26.4 and 27.0 runtimes) (#1080). - **A one-panel device's input follows its native frame**, so after a rotation taps and picture stay in the same frame; a foldable's follow the upright picture. - **Taps may vanish after a reboot under the lease.** After the health monitor reboots a crashed simulator the helper's HID client is bound to the old boot, until the lease's input reopens. diff --git a/src/drivers/ios/input/device-input.ts b/src/drivers/ios/input/device-input.ts index f832f8dbe..ec3dde0b8 100644 --- a/src/drivers/ios/input/device-input.ts +++ b/src/drivers/ios/input/device-input.ts @@ -17,7 +17,6 @@ import type { Logger, ProcessRunner, } from "../../../ports/index.js"; -import { iosRuntimeVersionFromId } from "../runtime-version.js"; import { stopProgram } from "../screen-capture.js"; export interface IosDeviceInputOptions { @@ -56,14 +55,7 @@ export function createIosDeviceInput(options: IosDeviceInputOptions): DeviceInpu await stopProgram(child, options.clock); throw error; } - return new IosDeviceInput( - options, - device.deviceId, - child, - size, - keysAvailable(device), - sizes, - ); + return new IosDeviceInput(options, device.deviceId, child, size, sizes); }, }; } @@ -77,15 +69,6 @@ function environmentFor(options: IosDeviceInputOptions): NodeJS.ProcessEnv { : { ...environment, SIMLOCK_IOS_DEVICE_SET: options.deviceSet }; } -// why: the iOS 27 guest ignores injected keys (F21), so keys are dropped there; a runtime that cannot -// be read is treated the same, because a key that does nothing is worse than a key refused. -function keysAvailable(device: VirtualDriverDevice | PhysicalDriverDevice): boolean { - const data = device.driverData as { runtimeId?: unknown } | null; - const runtimeId = typeof data?.runtimeId === "string" ? data.runtimeId : ""; - const version = iosRuntimeVersionFromId(runtimeId); - return version !== undefined && version[0] < 27; -} - async function firstSize( child: BytePipeProcess, sizes: AsyncGenerator, @@ -188,7 +171,6 @@ class IosDeviceInput implements DeviceInput { readonly #udid: string; readonly #child: BytePipeProcess; #config: InputScreenConfig; - readonly #keys: boolean; readonly #configListeners = new Set<(config: InputScreenConfig) => void>(); readonly #failedListeners = new Set<(error: Error) => void>(); #closing: Promise | undefined; @@ -198,11 +180,9 @@ class IosDeviceInput implements DeviceInput { udid: string, child: BytePipeProcess, size: InputScreenConfig, - keys: boolean, sizes: AsyncGenerator, ) { - this.#keys = keys; - this.#config = this.#withKeys(size); + this.#config = size; void this.#follow(sizes); void child.exited.then((exit) => { this.#fail(new Error(`The input helper ${describeExit(exit)}`)); @@ -212,16 +192,12 @@ class IosDeviceInput implements DeviceInput { this.#child = child; } - #withKeys(size: InputScreenConfig): InputScreenConfig { - return this.#keys ? size : { ...size, keyboardUnavailable: true }; - } - // why: a foldable's helper sends a size again when the panel in use changes; a size equal to the // one held is no change, and the listeners hear only changes. async #follow(sizes: AsyncGenerator): Promise { for await (const size of sizes) { if (size.width === this.#config.width && size.height === this.#config.height) continue; - this.#config = this.#withKeys(size); + this.#config = size; for (const listener of this.#configListeners) listener(this.#config); } } @@ -231,7 +207,6 @@ class IosDeviceInput implements DeviceInput { if (message.button === "home") this.#home(); if (message.button !== "app_switcher" && message.button !== "lock") return Promise.resolve(); } - if (message.kind === "key" && !this.#keys) return Promise.resolve(); return this.#child.writeStdin(frameOfMessage(message)).catch((error: unknown) => { const failure = new Error( `The input helper stopped taking input: ${error instanceof Error ? error.message : String(error)}`, From 7a1f0521b8ebc3046db69e59badbd17c7c23f150 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 14:11:14 +0100 Subject: [PATCH 05/12] test: the helper's press plan for a button name (#1659) --- .../simlock-screen-capture/ButtonPlan.swift | 15 ++++++++++ .../SimlockCaptureTests/ButtonPlanTests.swift | 28 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 vendor/screen-capture/Sources/simlock-screen-capture/ButtonPlan.swift create mode 100644 vendor/screen-capture/Tests/SimlockCaptureTests/ButtonPlanTests.swift diff --git a/vendor/screen-capture/Sources/simlock-screen-capture/ButtonPlan.swift b/vendor/screen-capture/Sources/simlock-screen-capture/ButtonPlan.swift new file mode 100644 index 000000000..854ea4d62 --- /dev/null +++ b/vendor/screen-capture/Sources/simlock-screen-capture/ButtonPlan.swift @@ -0,0 +1,15 @@ +// simlock's own, MIT-licensed (see NOTICE.md): the Indigo presses behind one button name. +import Foundation + +/// One Indigo button message: the event source, the direction (1 down, 2 up) and the wait before the next step. +struct ButtonStep: Equatable { + let source: Int32 + let direction: Int32 + let pauseAfter: TimeInterval +} + +enum ButtonPlan { + static func steps(for name: String) -> [ButtonStep] { + [] + } +} diff --git a/vendor/screen-capture/Tests/SimlockCaptureTests/ButtonPlanTests.swift b/vendor/screen-capture/Tests/SimlockCaptureTests/ButtonPlanTests.swift new file mode 100644 index 000000000..3b188e674 --- /dev/null +++ b/vendor/screen-capture/Tests/SimlockCaptureTests/ButtonPlanTests.swift @@ -0,0 +1,28 @@ +import XCTest + +@testable import simlock_screen_capture + +final class ButtonPlanTests: XCTestCase { + func testAButtonNameBecomesTheIndigoPressesTheHelperSends() { + let lock = [ + ButtonStep(source: 1, direction: 1, pauseAfter: 0), + ButtonStep(source: 1, direction: 2, pauseAfter: 0), + ] + let switcher = [ + ButtonStep(source: 0, direction: 1, pauseAfter: 0), + ButtonStep(source: 0, direction: 2, pauseAfter: 0.05), + ButtonStep(source: 0, direction: 1, pauseAfter: 0), + ButtonStep(source: 0, direction: 2, pauseAfter: 0), + ] + let cases: [(String, [ButtonStep])] = [ + ("lock", lock), + ("app_switcher", switcher), + ("back", []), + ("siri", []), + ("", []), + ] + for (name, steps) in cases { + XCTAssertEqual(ButtonPlan.steps(for: name), steps, "'\(name)'") + } + } +} From 144c636c0e5a7332460d1d24735b800b4d89f8ec Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 14:11:42 +0100 Subject: [PATCH 06/12] feat(ios): the helper presses Lock and the app switcher (#1659) --- vendor/screen-capture/NOTICE.md | 53 ++++++++++--------- vendor/screen-capture/Package.swift | 2 +- .../simlock-screen-capture/ButtonPlan.swift | 25 ++++++++- .../simlock-screen-capture/HIDInjector.swift | 11 +++- .../simlock-screen-capture/InputMode.swift | 9 +++- 5 files changed, 70 insertions(+), 30 deletions(-) diff --git a/vendor/screen-capture/NOTICE.md b/vendor/screen-capture/NOTICE.md index c047a40b7..dddc3b387 100644 --- a/vendor/screen-capture/NOTICE.md +++ b/vendor/screen-capture/NOTICE.md @@ -45,28 +45,29 @@ otherwise all ours). Upstream keeps the same files in two targets, `Sources/SimNative/` and `Sources/SimNativeSupport/`, and their paths are given per row. -| File | Upstream path | Origin | -| ----------------------------------------------------------------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `simlock-screen-capture/SimFrameworks.swift` | `Sources/SimNative/` | theirs, unchanged | -| `simlock-screen-capture/FramebufferSurfaceSelector.swift` | `Sources/SimNativeSupport/` | theirs, unchanged | -| `simlock-screen-capture/DeviceDisplaySizes.swift` | `Sources/SimNativeSupport/` | theirs, unchanged | -| `simlock-screen-capture/FrameCapture.swift` | `Sources/SimNative/` | theirs, **one patch** (deviation 1) | -| `simlock-screen-capture/HIDInjector.swift` | `Sources/SimNative/` | theirs, **modified by us** — Apache-2.0, `MODIFIED FILE` header; the Duo, Device Hub, pose, Home, app switcher and Lock paths are deleted, and the touch target is `PanelTouch.map` (deviation 3) | -| `SimlockCapture/H264Encoder.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | -| `SimlockCapture/VideoEncoder.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | -| `SimlockCapture/PixelBufferUtils.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | -| `SimlockCapture/Xcode.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | -| `simlock-screen-capture/InputMode.swift` | — | ours, entirely: the `--input` mode that drives `HIDInjector` from stdin | -| `SimlockCapture/Lifecycle.swift`, `SimlockCapture/Options.swift` | — | ours, entirely: the option parser, the envelope, the lifecycle, the scaler, the encode loop | -| `simlock-screen-capture/main.swift`, `simlock-screen-capture/SimulatorSource.swift` | — | ours, entirely: the simulator program and its framebuffer as a `ScreenSource` | -| `simlock-screen-capture/Panels.swift` | — | ours, entirely: which panel of a foldable simulator to stream, the follower of SpringBoard's panel moves, the watchdog for its `log` children, and the upright turn of the inner panel (ADR 0075) | -| `simlock-screen-capture/PanelTouch.swift` | — | ours, entirely: where a tap on the upright picture lands on a panel's digitizer, the inner Duo panel's turned (ADR 0075 §4) | -| `Tests/SimlockCaptureTests/*` | — | ours, entirely: the Swift tests (`swift test --package-path vendor/screen-capture`) | -| `simlock-device-capture/*` (five files) | — | ours, entirely: the iPhone program — the version gate, the CoreDevice source, the RTP receiver, the decoder — rewritten from this repo's own PoC (ADR 0031) | -| `SimlockMediaBridge/*` | — | ours, entirely: the negotiator bridge; it carries the `idevice` HEVC feature string below | -| `Stubs/*` (three interfaces) | — | ours, entirely: hand-written declarations for the parts of CoreDevice we call | -| `scripts/unframe.mjs` | — | ours, entirely: a hand-run diagnostic | -| `Package.swift` | — | ours, entirely | +| File | Upstream path | Origin | +| ----------------------------------------------------------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `simlock-screen-capture/SimFrameworks.swift` | `Sources/SimNative/` | theirs, unchanged | +| `simlock-screen-capture/FramebufferSurfaceSelector.swift` | `Sources/SimNativeSupport/` | theirs, unchanged | +| `simlock-screen-capture/DeviceDisplaySizes.swift` | `Sources/SimNativeSupport/` | theirs, unchanged | +| `simlock-screen-capture/FrameCapture.swift` | `Sources/SimNative/` | theirs, **one patch** (deviation 1) | +| `simlock-screen-capture/HIDInjector.swift` | `Sources/SimNative/` | theirs, **modified by us** — Apache-2.0, `MODIFIED FILE` header; the Duo, Device Hub, pose and Home paths and the upstream button names are deleted, `sendButtonPlan` is added, and the touch target is `PanelTouch.map` (deviation 3) | +| `SimlockCapture/H264Encoder.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | +| `SimlockCapture/VideoEncoder.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | +| `SimlockCapture/PixelBufferUtils.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | +| `SimlockCapture/Xcode.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | +| `simlock-screen-capture/ButtonPlan.swift` | — | ours, entirely: the Indigo presses behind `lock` and `app_switcher` (ADR 0085) | +| `simlock-screen-capture/InputMode.swift` | — | ours, entirely: the `--input` mode that drives `HIDInjector` from stdin | +| `SimlockCapture/Lifecycle.swift`, `SimlockCapture/Options.swift` | — | ours, entirely: the option parser, the envelope, the lifecycle, the scaler, the encode loop | +| `simlock-screen-capture/main.swift`, `simlock-screen-capture/SimulatorSource.swift` | — | ours, entirely: the simulator program and its framebuffer as a `ScreenSource` | +| `simlock-screen-capture/Panels.swift` | — | ours, entirely: which panel of a foldable simulator to stream, the follower of SpringBoard's panel moves, the watchdog for its `log` children, and the upright turn of the inner panel (ADR 0075) | +| `simlock-screen-capture/PanelTouch.swift` | — | ours, entirely: where a tap on the upright picture lands on a panel's digitizer, the inner Duo panel's turned (ADR 0075 §4) | +| `Tests/SimlockCaptureTests/*` | — | ours, entirely: the Swift tests (`swift test --package-path vendor/screen-capture`) | +| `simlock-device-capture/*` (five files) | — | ours, entirely: the iPhone program — the version gate, the CoreDevice source, the RTP receiver, the decoder — rewritten from this repo's own PoC (ADR 0031) | +| `SimlockMediaBridge/*` | — | ours, entirely: the negotiator bridge; it carries the `idevice` HEVC feature string below | +| `Stubs/*` (three interfaces) | — | ours, entirely: hand-written declarations for the parts of CoreDevice we call | +| `scripts/unframe.mjs` | — | ours, entirely: a hand-run diagnostic | +| `Package.swift` | — | ours, entirely | To diff any of the nine serve-sim files, use the command at the end with the upstream path from its row and the file's path under `Sources/`. @@ -137,11 +138,13 @@ tool it runs, and `sim-module.swift` was never taken. **3. `HIDInjector.swift` is serve-sim's file without the paths simlock does not use or does elsewhere.** The Duo hinge and cover paths (`DuoHIDBridge`), the Device Hub keyboard bridge (`DeviceHubKeyboardBridge`), the fold pose (`DevicePose`) and the -`home`, `app_switcher` and `lock` buttons are deleted. Home is the daemon's +`home`, `app_switcher` and `lock` buttons are deleted, and `sendButtonPlan` is added. Home is the daemon's `xcrun simctl --set launch com.apple.springboard` (`src/drivers/ios/input/`), the way upstream does it on Xcode 26 and later ("Xcode 26+ silently drops the Indigo -HID home-button press"), so it has one owner; the app switcher and Lock are Indigo -button presses and are out of scope (#1024). `sendOrientation`'s error for a missing +HID home-button press"), so it has one owner. The app switcher and Lock are Indigo +button presses and come back through `sendButtonPlan`, which sends the steps +`ButtonPlan.swift` (ours) names: Lock is one press, the app switcher two Home presses +50 ms apart (ADR 0085); on the CoreSimulator measured Xcode does not drop them. `sendOrientation`'s error for a missing `PurpleWorkspacePort` no longer says Simulator.app must be running: a simulator with no Simulator.app rotates (#1080). Touch, scroll, key and the rest are upstream's. The file's own `MODIFIED FILE` header is the authoritative wording. diff --git a/vendor/screen-capture/Package.swift b/vendor/screen-capture/Package.swift index 01087b92b..ad90db053 100644 --- a/vendor/screen-capture/Package.swift +++ b/vendor/screen-capture/Package.swift @@ -21,7 +21,7 @@ // other tool it runs. // // Its input mode (`simlock-screen-capture --input`) also carries serve-sim's `HIDInjector.swift`, -// without the Duo, Device Hub, pose, Home, app switcher and Lock paths (NOTICE.md, deviations 3 and 4). +// without the Duo, Device Hub, pose and Home paths; its app switcher and Lock are `ButtonPlan`'s (NOTICE.md, deviations 3 and 4). // // The encoders are serve-sim's files rewritten here: `H264Encoder.swift`, `VideoEncoder.swift`, // `PixelBufferUtils.swift` and `Xcode.swift` now use public VideoToolbox, CoreVideo, CoreMedia and diff --git a/vendor/screen-capture/Sources/simlock-screen-capture/ButtonPlan.swift b/vendor/screen-capture/Sources/simlock-screen-capture/ButtonPlan.swift index 854ea4d62..3462ed55d 100644 --- a/vendor/screen-capture/Sources/simlock-screen-capture/ButtonPlan.swift +++ b/vendor/screen-capture/Sources/simlock-screen-capture/ButtonPlan.swift @@ -9,7 +9,30 @@ struct ButtonStep: Equatable { } enum ButtonPlan { + private static let sourceHome: Int32 = 0 + private static let sourceLock: Int32 = 1 + private static let down: Int32 = 1 + private static let up: Int32 = 2 + + /// The presses for a button name; a name with no plan (Back, Siri, an empty one) gets none, so + /// the helper never sends Home on its own (ADR 0085 section 3). static func steps(for name: String) -> [ButtonStep] { - [] + switch name { + case "lock": + return [ + ButtonStep(source: sourceLock, direction: down, pauseAfter: 0), + ButtonStep(source: sourceLock, direction: up, pauseAfter: 0), + ] + case "app_switcher": + // why: two Home presses 50 ms apart opened the switcher on every runtime measured (ADR 0085). + return [ + ButtonStep(source: sourceHome, direction: down, pauseAfter: 0), + ButtonStep(source: sourceHome, direction: up, pauseAfter: 0.05), + ButtonStep(source: sourceHome, direction: down, pauseAfter: 0), + ButtonStep(source: sourceHome, direction: up, pauseAfter: 0), + ] + default: + return [] + } } } diff --git a/vendor/screen-capture/Sources/simlock-screen-capture/HIDInjector.swift b/vendor/screen-capture/Sources/simlock-screen-capture/HIDInjector.swift index 7024d75da..03f4b692d 100644 --- a/vendor/screen-capture/Sources/simlock-screen-capture/HIDInjector.swift +++ b/vendor/screen-capture/Sources/simlock-screen-capture/HIDInjector.swift @@ -2,7 +2,8 @@ // see NOTICE.md and LICENSES/ in this package) and it is NOT verbatim upstream. simlock's changes // drop what simlock does not use or does elsewhere: the Duo hinge and cover paths, the Device Hub // keyboard bridge, the fold pose, and the Home, app switcher and Lock buttons (Home is the daemon's -// `simctl launch` of SpringBoard, so it has one owner), and the orientation error no longer says +// `simctl launch` of SpringBoard, so it has one owner; the app switcher and Lock are back as +// `sendButtonPlan`, which sends the presses `ButtonPlan` names, ADR 0085), and the orientation error no longer says // Simulator.app must be running, which it need not be; upstream's touch target is replaced by // `PanelTouch.map` and `touchPanel` (ours, ADR 0075 §4); everything else here is upstream's. // `NOTICE.md` prints the one command that diffs this file against pristine upstream at the commit @@ -439,6 +440,14 @@ actor HIDInjector { } } + /// Sends the Indigo presses `ButtonPlan` names for a button, waiting between steps as it says. + func sendButtonPlan(_ steps: [ButtonStep]) async { + for step in steps { + sendHIDButton(eventSource: step.source, direction: step.direction) + if step.pauseAfter > 0 { try? await Task.sleep(for: .seconds(step.pauseAfter)) } + } + } + func sendButton(button: String) async { hidLog("[hid] Sending button: \(button)") diff --git a/vendor/screen-capture/Sources/simlock-screen-capture/InputMode.swift b/vendor/screen-capture/Sources/simlock-screen-capture/InputMode.swift index d124fa343..f02f09ec9 100644 --- a/vendor/screen-capture/Sources/simlock-screen-capture/InputMode.swift +++ b/vendor/screen-capture/Sources/simlock-screen-capture/InputMode.swift @@ -6,6 +6,7 @@ // byte, and serve-sim's JSON for that tag: // // 0x03 touch {"type":"begin"|"move"|"end","x":0..1,"y":0..1} +// 0x04 button {"button":"app_switcher"|"lock"} (any other name sends nothing) // 0x06 key {"type":"down"|"up","usage":} // 0x07 orientation {"orientation":"portrait"|"portrait_upside_down"|"landscape_left"|"landscape_right"} // 0x0b scroll {"dx":-1..1,"dy":-1..1,"x"?:0..1,"y"?:0..1} (fractions of the screen) @@ -13,12 +14,13 @@ // stdout carries an envelope, tag 0x82, `{"width":,"height":}`, once the HID client exists. On // a foldable it follows the panel in use (ADR 0075): taps go to that panel's digitizer, and each move // of the picture to the other panel sends a new 0x82 with that panel's upright size. -// End of stdin ends the program, as it ends a capture. Home is not here: the daemon relaunches -// SpringBoard with `simctl`, which is what serve-sim does on Xcode 26 and later. +// End of stdin ends the program, as it ends a capture. Home alone is not here: the daemon relaunches +// SpringBoard with `simctl` (one owner); the helper presses Home only as part of the app switcher. import Foundation import SimlockCapture private let tagTouch: UInt8 = 0x03 +private let tagButton: UInt8 = 0x04 private let tagKey: UInt8 = 0x06 private let tagScroll: UInt8 = 0x0b private let tagOrientation: UInt8 = 0x07 @@ -94,6 +96,9 @@ func runInput(udid: String) async -> Never { guard let type = fields["type"] as? String, let x = fields["x"] as? Double, let y = fields["y"] as? Double else { continue } await injector.sendTouch(type: type, x: x, y: y, screenWidth: size.width, screenHeight: size.height) + case tagButton: + guard let name = fields["button"] as? String else { continue } + await injector.sendButtonPlan(ButtonPlan.steps(for: name)) case tagKey: guard let type = fields["type"] as? String, let usage = fields["usage"] as? Int, usage >= 0 else { continue } await injector.sendKey(type: type, usage: UInt32(usage)) From 28d58bc6d8ae859c73fb44bb9ee0f9e6b3139c97 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 14:12:53 +0100 Subject: [PATCH 07/12] test(e2e): the input socket types, opens the app switcher and locks on an iOS 27 simulator (#1659) --- ...r-watches-and-drives-its-devices-screen.md | 2 +- docs/internal/adr/README.md | 2 +- docs/internal/agent-rules/toolchain.md | 1 + e2e/slow-ios-input.test.ts | 206 ++++++++++++++++++ .../using-devices/watching-the-screen.mdx | 4 +- 5 files changed, 211 insertions(+), 4 deletions(-) create mode 100644 e2e/slow-ios-input.test.ts diff --git a/docs/internal/adr/0049-a-lease-holder-watches-and-drives-its-devices-screen.md b/docs/internal/adr/0049-a-lease-holder-watches-and-drives-its-devices-screen.md index 648bb8f72..2dc176a7b 100644 --- a/docs/internal/adr/0049-a-lease-holder-watches-and-drives-its-devices-screen.md +++ b/docs/internal/adr/0049-a-lease-holder-watches-and-drives-its-devices-screen.md @@ -1,6 +1,6 @@ # 0049. A lease holder watches and drives its device's screen -- **Status:** Accepted; §3's rotation narrowed by [ADR 0052](0052-an-ios-simulator-takes-serve-sims-rotation.md): an iOS simulator takes `0x07` +- **Status:** Accepted; §3's rotation narrowed by [ADR 0052](0052-an-ios-simulator-takes-serve-sims-rotation.md): an iOS simulator takes `0x07`; §4's iOS 27 keys, app switcher and Lock narrowed by [ADR 0085](0085-an-ios-simulator-takes-keys-on-every-runtime-and-the-app-switcher-and-lock.md) - **Date:** 2026-10-26 - **Issue:** [#1013](https://github.com/callstackincubator/simlock/issues/1013) - **Narrows:** [ADR 0045](0045-a-devices-screen-streams-to-operators-not-a-leases.md) diff --git a/docs/internal/adr/README.md b/docs/internal/adr/README.md index 13db9f1d3..17a36e63c 100644 --- a/docs/internal/adr/README.md +++ b/docs/internal/adr/README.md @@ -87,7 +87,7 @@ the status is stale. | [0046](0046-a-standalone-worker-serves-agent-device-by-default-with-a-private-profile.md) | A standalone worker serves agent-device by default and hands local agents a private profile | Accepted — not yet implemented; narrows 0023 §1, §3–4, 0030 §2, 0039 and 0043 §4 | | [0047](0047-device-exec-fills-in-the-leases-device.md) | `device.exec` fills in the lease's device, and refuses another | Accepted — not yet implemented; extends 0005 §19a; narrows 0003 §11 for one MCP tool | | [0048](0048-an-ios-worker-may-keep-its-simulators-in-xcodes-device-set.md) | An iOS worker may keep its simulators in Xcode's device set | Accepted; narrows 0001 §1, §2, §3, §5, §6 and §7 for iOS under `deviceSet: "default"` | -| [0049](0049-a-lease-holder-watches-and-drives-its-devices-screen.md) | A lease holder watches and drives its device's screen | Accepted; §3 narrowed by 0052 | +| [0049](0049-a-lease-holder-watches-and-drives-its-devices-screen.md) | A lease holder watches and drives its device's screen | Accepted; §3 narrowed by 0052; §4 narrowed by 0085 | | [0050](0050-an-operator-can-forget-a-learned-warm-kind.md) | An operator can forget a learned warm kind | Accepted; how `warm forget` matches a baseline kind narrowed by 0062 | | [0051](0051-configured-warm-targets-come-first-and-learning-can-be-turned-off.md) | Configured warm targets come first, and learning can be turned off | Accepted | | [0052](0052-an-ios-simulator-takes-serve-sims-rotation.md) | An iOS simulator takes serve-sim's rotation | Accepted; narrows 0049 §3 on iOS simulators; §4 narrowed by 0075 | diff --git a/docs/internal/agent-rules/toolchain.md b/docs/internal/agent-rules/toolchain.md index 74cd1418a..5dc208fe9 100644 --- a/docs/internal/agent-rules/toolchain.md +++ b/docs/internal/agent-rules/toolchain.md @@ -211,6 +211,7 @@ The machine can run a line only if: | iOS window | the iOS check; `mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Devices'"` prints a path; `stat -f %Su /dev/console` is not `root` (someone is logged in); `pgrep -x DeviceHub` finds nothing (the test starts DeviceHub itself with `-shutdownStartedDevicesOnQuit NO` and quits it at the end). Run `scripts/slow-e2e.sh e2e/slow-ios-window.test.ts` | | Physical iOS | `uname -s` is `Darwin`; `SIMLOCK_PHYSICAL_IOS` is the UDID of an iPhone on USB (trusted, Developer Mode on, unlocked, Auto-Lock Never); `SIMLOCK_PHYSICAL_IOS_APP` is a `.app` signed for it. `/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" /Library/Developer/PrivateFrameworks/CoreDevice.framework/Resources/Info.plist` prints a version whose major is 642 or later (streaming a phone needs the CoreDevice of Xcode 27 or later; the framework is machine-wide and does not follow `xcode-select`). DeviceHub and Xcode are not running during the lane. The stream cases need the iPhone on iOS 27 or later; an older iPhone runs the refusal case instead. Run `scripts/slow-e2e.sh --physical e2e/slow-ios-physical.test.ts` | | iOS foldable | the iOS check; `xcrun simctl list runtimes` lists iOS 27.1 or later and `xcrun simctl list devicetypes` lists `iPhone Duo`; `SIMLOCK_E2E_AGENT_DEVICE` names agent-device 0.21.35 or later; `command -v ffmpeg` finds it. Run `scripts/slow-e2e.sh e2e/slow-ios-foldable.test.ts` | +| iOS simulator input | the iOS check; `xcrun simctl list runtimes` lists an iOS 27 or later runtime; `uname -m` is `arm64`; `SIMLOCK_E2E_AGENT_DEVICE` names the agent-device the lane pins (agent-device through simlock row). Run `scripts/slow-e2e.sh e2e/slow-ios-input.test.ts` | | agent-device through simlock | `node -v` is 22.12.0 or later (agent-device's own minimum); the iOS check and `uname -m` is `arm64` (the fixture app is arm64 only), or the Android check; `SIMLOCK_E2E_AGENT_DEVICE` (in `.slow-lane.env`) is the absolute path of `bin/agent-device.mjs` in an install of the agent-device version `package.json` pins for `@agent-device/proxy` (`npm install -g agent-device@`, or a checkout at tag `v` built with `pnpm install && pnpm build && pnpm build:android`, the last building the Android snapshot helper); room for two devices: `node -p "os.totalmem() / 2**30"` prints at least 7 for iOS or 12 for Android (simlock's 4 GiB OS reserve plus two of its default 1.5 GiB iOS or 4 GiB Android per-device budgets). Run `scripts/slow-e2e.sh e2e/slow-agent-device.test.ts` or `scripts/slow-e2e.sh e2e/slow-agent-device-gateway.test.ts` | | Physical Android | `command -v adb` finds it; `adb devices -l` lists `$SIMLOCK_PHYSICAL_ANDROID` on a USB transport (a `usb:` field) in state `device`; `SIMLOCK_PHYSICAL_ANDROID_APK` names an APK; `SIMLOCK_PHYSICAL_ANDROID_NETWORK` beside it names an address `adb devices -l` lists in state `device` with no `usb:` field, for the network case. Run `scripts/slow-e2e.sh --physical e2e/slow-android-physical.test.ts` | | agent-device with a physical phone | the agent-device through simlock checks above (the Android or iOS one), and the Physical Android checks with `SIMLOCK_PHYSICAL_ANDROID`, or the Physical iOS checks with `SIMLOCK_PHYSICAL_IOS`; for iOS also `SIMLOCK_E2E_IOS_TEAM_ID` and `SIMLOCK_E2E_IOS_BUNDLE_ID` (in `.slow-lane.env`); set `SIMLOCK_E2E_IOS_PROVISIONING_PROFILE` and `SIMLOCK_E2E_IOS_SIGNING_IDENTITY` only for manual signing, which an Xcode-managed profile fails. Run `scripts/slow-e2e.sh --physical e2e/slow-agent-device-physical.test.ts` | diff --git a/e2e/slow-ios-input.test.ts b/e2e/slow-ios-input.test.ts new file mode 100644 index 000000000..889407ea1 --- /dev/null +++ b/e2e/slow-ios-input.test.ts @@ -0,0 +1,206 @@ +import { execFileSync } from "node:child_process"; +import { mkdtemp } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { afterAll, beforeAll, describe, expect, it } from "vitest"; + +import { + assertPinnedAgentDevice, + cleanupAgents, + FIRST_SNAPSHOT, + freeLoopbackPort, + listLeases, + makeAgent, + newAgentToken, + ok, + openInputSocket, + progress, + waitFor, + waitForAgentDevice, + waitForFree, + withSharedDaemon, + type Agent, + type SharedTestEnv, +} from "./helpers/index.js"; + +const AGENT_DEVICE = process.env.SIMLOCK_E2E_AGENT_DEVICE; +const SETTINGS = "com.apple.Preferences"; +const INPUT_BUTTON = 0x04; +const INPUT_KEY = 0x06; +const INPUT_TOUCH = 0x03; +const INPUT_ADMITTED = 0x83; +const INPUT_CONFIG = 0x82; +// why: USB HID keyboard usages for the letters a, b and c. +const TYPED = [0x04, 0x05, 0x06] as const; + +// why: the file proves an iOS 27 runtime, where ADR 0049 once dropped keys, the app switcher and Lock. +function hasIos27Runtime(): boolean { + if (process.platform !== "darwin" || process.arch !== "arm64") return false; + try { + return /^iOS 2[7-9]|^iOS [3-9]\d/m.test( + execFileSync("xcrun", ["simctl", "list", "runtimes"], { encoding: "utf8" }), + ); + } catch { + return false; + } +} + +interface Box { + readonly x: number; + readonly y: number; + readonly width: number; + readonly height: number; +} + +function* nodesOf(node: unknown): Generator> { + if (typeof node !== "object" || node === null) return; + if (!Array.isArray(node)) yield node as Record; + for (const child of Object.values(node)) yield* nodesOf(child); +} + +function boxOf(node: Record): Box | undefined { + const rect = node["rect"] as Box | undefined; + return rect !== undefined && typeof rect.width === "number" ? rect : undefined; +} + +// why: the search field is the node agent-device names a search field or labels Search; the screen is +// the largest box in the same snapshot, so the tap's fraction is measured against one size. +function searchFieldAndScreen(json: unknown): { field?: Box; screen?: Box } { + const boxed = [...nodesOf(json)].flatMap((node) => { + const box = boxOf(node); + return box === undefined ? [] : [{ box, node }]; + }); + const area = (box: Box) => box.width * box.height; + const screen = boxed.map((entry) => entry.box).sort((left, right) => area(right) - area(left))[0]; + const field = boxed.find(({ node }) => + /search/i.test( + `${String(node["type"])} ${String(node["label"])} ${String(node["identifier"])}`, + ), + )?.box; + return { + ...(field === undefined ? {} : { field }), + ...(screen === undefined ? {} : { screen }), + }; +} + +function isForeground(applicationState: unknown): boolean { + return applicationState === 4 || /foreground/i.test(String(applicationState)); +} + +describe.skipIf(AGENT_DEVICE === undefined || !hasIos27Runtime())( + "iOS simulator input on an iOS 27 runtime", + { tags: ["slow", "ios"] }, + () => { + let env: SharedTestEnv; + + beforeAll(async () => { + const pinned = await assertPinnedAgentDevice("ios"); + env = await withSharedDaemon({ + driver: "real", + configOverrides: { + http: { enabled: true, host: "127.0.0.1", port: await freeLoopbackPort() }, + capabilities: { + "agent-device": { enabled: true, command: pinned }, + input: { enabled: true }, + }, + capacity: { config: { limits: { ios: { maxDevices: 1, maxRunning: 1 } } } }, + }, + }); + const probe = await newAgentToken(env); + await waitForAgentDevice(env, probe.secret); + }, 420_000); + + afterAll(async () => { + await cleanupAgents(); + if (env !== undefined) { + await env.cli(["release", "--all", "--yes"], { timeout: 60_000 }); + await waitForFree(env); + } + await env?.teardown(); + }, 420_000); + + it( + "on a leased iOS 27 simulator, keys sent on the input socket reach Settings' search field, app_switcher takes Settings out of the foreground, and so does lock after Settings is reopened", + { timeout: 900_000 }, + async () => { + const a: Agent = await makeAgent(env, "ios-input"); + ok(await a.run(["open", "--platform", "ios", "--os", ">=27"], { timeout: 330_000 })); + ok(await a.run(["open", SETTINGS])); + const shots = await mkdtemp(join(tmpdir(), "simlock-ios-input-")); + progress(`screenshots of the iOS input test are saved in ${shots}`); + + const snapshot = await a.run(["snapshot", "--json"], FIRST_SNAPSHOT); + ok(snapshot); + const { field, screen } = searchFieldAndScreen(snapshot.json); + expect(field, "Settings' search field in the snapshot").toBeDefined(); + expect(screen, "the screen in the snapshot").toBeDefined(); + const lease = (await listLeases(env))[0]; + const socket = await openInputSocket(env.httpPort, lease?.id ?? "", a.token); + const appState = async () => { + const state = await a.run(["appstate", "--json"]); + ok(state); + const applicationState = (state.data as { applicationState?: unknown } | undefined) + ?.applicationState; + expect(applicationState, "appstate carries applicationState").toBeDefined(); + return applicationState; + }; + const shot = async (name: string) => { + ok(await a.run(["screenshot", join(shots, `${name}.png`)])); + }; + try { + await socket.waitForTag(INPUT_ADMITTED); + const config = (await socket.waitForTag(INPUT_CONFIG)) as Record; + expect(config["keyboardUnavailable"], "no keyboardUnavailable on iOS 27").toBeUndefined(); + + const x = (field!.x + field!.width / 2 - screen!.x) / screen!.width; + const y = (field!.y + field!.height / 2 - screen!.y) / screen!.height; + socket.send(INPUT_TOUCH, { type: "begin", x, y }); + socket.send(INPUT_TOUCH, { type: "end", x, y }); + // why: the first keys on a freshly booted simulator can be lost (ADR 0085 Context), so + // the keys are sent again until they show, up to a bound. + await waitFor( + async () => { + for (const usage of TYPED) { + socket.send(INPUT_KEY, { type: "down", usage }); + socket.send(INPUT_KEY, { type: "up", usage }); + } + const typed = await a.run(["snapshot"]); + return typed.code === 0 && /abc/i.test(typed.stdout); + }, + { interval: 3_000, label: "typed keys in the snapshot", timeout: 60_000 }, + ); + await shot("1-typed"); + expect(isForeground(await appState()), "Settings is in front before the presses").toBe( + true, + ); + + socket.send(INPUT_BUTTON, { button: "app_switcher" }); + await waitFor(async () => !isForeground(await appState()), { + interval: 2_000, + label: "Settings out of the foreground after app_switcher", + timeout: 30_000, + }); + await shot("2-app-switcher"); + + ok(await a.run(["open", SETTINGS])); + await waitFor(async () => isForeground(await appState()), { + interval: 2_000, + label: "Settings reopened", + timeout: 30_000, + }); + socket.send(INPUT_BUTTON, { button: "lock" }); + await waitFor(async () => !isForeground(await appState()), { + interval: 2_000, + label: "Settings out of the foreground after lock", + timeout: 30_000, + }); + await shot("3-lock"); + } finally { + socket.close(); + } + ok(await a.run(["close"])); + await waitForFree(env); + }, + ); + }, +); diff --git a/website/src/content/docs/docs/using-devices/watching-the-screen.mdx b/website/src/content/docs/docs/using-devices/watching-the-screen.mdx index b60a9d37e..954f3ef32 100644 --- a/website/src/content/docs/docs/using-devices/watching-the-screen.mdx +++ b/website/src/content/docs/docs/using-devices/watching-the-screen.mdx @@ -185,8 +185,8 @@ A message is dropped, and the socket stays open, when it isn't valid JSON, has a ### On an iOS simulator - **Taps, swipes and scrolls** work. A scroll is sent as a finger drag. -- **`home`** brings the home screen forward and sends the app to the background. `app_switcher`, `lock` and `back` are dropped. -- **Keys** work on iOS 26 and older. On iOS 27 and newer the simulator ignores injected keys, so they are dropped, and `0x82` carries `"keyboardUnavailable":true`. +- **`home`** brings the home screen forward and sends the app to the background. `app_switcher` opens the app switcher, and `lock` locks the screen or wakes it when it is locked. `back` is dropped, since an iPhone has no Back button. A press the simulator ignores is not detected, and nothing tells the client. +- **Keys** work on every runtime, and `0x82` never says `keyboardUnavailable` for a simulator. - **Orientation (`0x07`)** turns the simulator as if you turned the phone in your hand. A screen that doesn't rotate, such as the iPhone home screen, stays as it is, and nothing tells the client. - `0x82` always says `"orientation":"portrait"`, even after a rotation, and touch positions stay fractions of the screen in portrait. - **On an iPhone Duo** a tap lands at its fraction of the panel in use, upright, folded or unfolded: the cover when folded, the inner panel when unfolded. A fold while the socket is open sends a new `0x82` with the new panel's size, so a client that reads `0x82` follows it. From a3106a54c923762ae7af41908ff7e4d7b82a9b98 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 14:16:13 +0100 Subject: [PATCH 08/12] docs: NOTICE row and input manual say what the helper keeps (#1659) --- src/drivers/ios/input/AGENTS.md | 2 +- vendor/screen-capture/NOTICE.md | 46 ++++++++++++++++----------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/drivers/ios/input/AGENTS.md b/src/drivers/ios/input/AGENTS.md index 703ae2ac6..2d08c6e2e 100644 --- a/src/drivers/ios/input/AGENTS.md +++ b/src/drivers/ios/input/AGENTS.md @@ -1,6 +1,6 @@ # iOS device input -Does: taps, scrolls, Home, keys and rotations on an iOS simulator, through `simlock-screen-capture --input`; a physical iPhone answers unavailable. +Does: taps, scrolls, Home, the app switcher, Lock, keys and rotations on an iOS simulator, through `simlock-screen-capture --input`; a physical iPhone answers unavailable. Flows: [iOS driver](../AGENTS.md), [input](../../../input/AGENTS.md). ## Rules diff --git a/vendor/screen-capture/NOTICE.md b/vendor/screen-capture/NOTICE.md index dddc3b387..d4f9b8d25 100644 --- a/vendor/screen-capture/NOTICE.md +++ b/vendor/screen-capture/NOTICE.md @@ -45,29 +45,29 @@ otherwise all ours). Upstream keeps the same files in two targets, `Sources/SimNative/` and `Sources/SimNativeSupport/`, and their paths are given per row. -| File | Upstream path | Origin | -| ----------------------------------------------------------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `simlock-screen-capture/SimFrameworks.swift` | `Sources/SimNative/` | theirs, unchanged | -| `simlock-screen-capture/FramebufferSurfaceSelector.swift` | `Sources/SimNativeSupport/` | theirs, unchanged | -| `simlock-screen-capture/DeviceDisplaySizes.swift` | `Sources/SimNativeSupport/` | theirs, unchanged | -| `simlock-screen-capture/FrameCapture.swift` | `Sources/SimNative/` | theirs, **one patch** (deviation 1) | -| `simlock-screen-capture/HIDInjector.swift` | `Sources/SimNative/` | theirs, **modified by us** — Apache-2.0, `MODIFIED FILE` header; the Duo, Device Hub, pose and Home paths and the upstream button names are deleted, `sendButtonPlan` is added, and the touch target is `PanelTouch.map` (deviation 3) | -| `SimlockCapture/H264Encoder.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | -| `SimlockCapture/VideoEncoder.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | -| `SimlockCapture/PixelBufferUtils.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | -| `SimlockCapture/Xcode.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | -| `simlock-screen-capture/ButtonPlan.swift` | — | ours, entirely: the Indigo presses behind `lock` and `app_switcher` (ADR 0085) | -| `simlock-screen-capture/InputMode.swift` | — | ours, entirely: the `--input` mode that drives `HIDInjector` from stdin | -| `SimlockCapture/Lifecycle.swift`, `SimlockCapture/Options.swift` | — | ours, entirely: the option parser, the envelope, the lifecycle, the scaler, the encode loop | -| `simlock-screen-capture/main.swift`, `simlock-screen-capture/SimulatorSource.swift` | — | ours, entirely: the simulator program and its framebuffer as a `ScreenSource` | -| `simlock-screen-capture/Panels.swift` | — | ours, entirely: which panel of a foldable simulator to stream, the follower of SpringBoard's panel moves, the watchdog for its `log` children, and the upright turn of the inner panel (ADR 0075) | -| `simlock-screen-capture/PanelTouch.swift` | — | ours, entirely: where a tap on the upright picture lands on a panel's digitizer, the inner Duo panel's turned (ADR 0075 §4) | -| `Tests/SimlockCaptureTests/*` | — | ours, entirely: the Swift tests (`swift test --package-path vendor/screen-capture`) | -| `simlock-device-capture/*` (five files) | — | ours, entirely: the iPhone program — the version gate, the CoreDevice source, the RTP receiver, the decoder — rewritten from this repo's own PoC (ADR 0031) | -| `SimlockMediaBridge/*` | — | ours, entirely: the negotiator bridge; it carries the `idevice` HEVC feature string below | -| `Stubs/*` (three interfaces) | — | ours, entirely: hand-written declarations for the parts of CoreDevice we call | -| `scripts/unframe.mjs` | — | ours, entirely: a hand-run diagnostic | -| `Package.swift` | — | ours, entirely | +| File | Upstream path | Origin | +| ----------------------------------------------------------------------------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `simlock-screen-capture/SimFrameworks.swift` | `Sources/SimNative/` | theirs, unchanged | +| `simlock-screen-capture/FramebufferSurfaceSelector.swift` | `Sources/SimNativeSupport/` | theirs, unchanged | +| `simlock-screen-capture/DeviceDisplaySizes.swift` | `Sources/SimNativeSupport/` | theirs, unchanged | +| `simlock-screen-capture/FrameCapture.swift` | `Sources/SimNative/` | theirs, **one patch** (deviation 1) | +| `simlock-screen-capture/HIDInjector.swift` | `Sources/SimNative/` | theirs, **modified by us** — Apache-2.0, `MODIFIED FILE` header; the Duo, Device Hub, pose, Home, app switcher and Lock paths are deleted, `sendButtonPlan` is added, and the touch target is `PanelTouch.map` (deviation 3) | +| `SimlockCapture/H264Encoder.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | +| `SimlockCapture/VideoEncoder.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | +| `SimlockCapture/PixelBufferUtils.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | +| `SimlockCapture/Xcode.swift` | `Sources/SimNative/` | theirs, **rewritten by us** — a modified file, Apache-2.0, `MODIFIED FILE` header | +| `simlock-screen-capture/ButtonPlan.swift` | — | ours, entirely: the Indigo presses behind `lock` and `app_switcher` (ADR 0085) | +| `simlock-screen-capture/InputMode.swift` | — | ours, entirely: the `--input` mode that drives `HIDInjector` from stdin | +| `SimlockCapture/Lifecycle.swift`, `SimlockCapture/Options.swift` | — | ours, entirely: the option parser, the envelope, the lifecycle, the scaler, the encode loop | +| `simlock-screen-capture/main.swift`, `simlock-screen-capture/SimulatorSource.swift` | — | ours, entirely: the simulator program and its framebuffer as a `ScreenSource` | +| `simlock-screen-capture/Panels.swift` | — | ours, entirely: which panel of a foldable simulator to stream, the follower of SpringBoard's panel moves, the watchdog for its `log` children, and the upright turn of the inner panel (ADR 0075) | +| `simlock-screen-capture/PanelTouch.swift` | — | ours, entirely: where a tap on the upright picture lands on a panel's digitizer, the inner Duo panel's turned (ADR 0075 §4) | +| `Tests/SimlockCaptureTests/*` | — | ours, entirely: the Swift tests (`swift test --package-path vendor/screen-capture`) | +| `simlock-device-capture/*` (five files) | — | ours, entirely: the iPhone program — the version gate, the CoreDevice source, the RTP receiver, the decoder — rewritten from this repo's own PoC (ADR 0031) | +| `SimlockMediaBridge/*` | — | ours, entirely: the negotiator bridge; it carries the `idevice` HEVC feature string below | +| `Stubs/*` (three interfaces) | — | ours, entirely: hand-written declarations for the parts of CoreDevice we call | +| `scripts/unframe.mjs` | — | ours, entirely: a hand-run diagnostic | +| `Package.swift` | — | ours, entirely | To diff any of the nine serve-sim files, use the command at the end with the upstream path from its row and the file's path under `Sources/`. From dc4aa85bf29f0fb63f2612f0aac57014a423c50c Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 14:24:41 +0100 Subject: [PATCH 09/12] fix(ios): the helper logs a button it has no plan for; manual stops restating ButtonPlan (#1659) --- src/drivers/ios/input/AGENTS.md | 4 ++-- .../Sources/simlock-screen-capture/InputMode.swift | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/drivers/ios/input/AGENTS.md b/src/drivers/ios/input/AGENTS.md index 2d08c6e2e..028adce7c 100644 --- a/src/drivers/ios/input/AGENTS.md +++ b/src/drivers/ios/input/AGENTS.md @@ -6,8 +6,8 @@ Flows: [iOS driver](../AGENTS.md), [input](../../../input/AGENTS.md). ## Rules - The helper's HID client stays here; core and the input module do not name it. -- Home is `xcrun simctl` here and nowhere in the helper (one owner). Home launches `com.apple.springboard`; a failure is only logged. `app_switcher` and `lock` go to the helper (ADR 0085): Lock is one Indigo button press, the app switcher two Home presses 50 ms apart. Back is dropped. -- Keys go to the helper on every runtime, and the config never says `keyboardUnavailable` (ADR 0085). A press the guest ignores is not detected. +- Home is `xcrun simctl` here and nowhere in the helper (one owner). Home launches `com.apple.springboard`; a failure is only logged. `app_switcher` and `lock` go to the helper (ADR 0085). Back is dropped. +- Keys go to the helper on every runtime, and the config never says `keyboardUnavailable`. A press the guest ignores is not detected. - The helper follows the driver's device-set rule: `SIMLOCK_IOS_DEVICE_SET` names the owned set under `simlock` and is absent under `default`. The daemon's own value never reaches it. - The open waits for the helper's first size frame (`READY_DEADLINE_MS` in `device-input.ts`), which it writes once its HID client is set up. A missing program, an early exit or no frame rejects the open, and the helper is stopped. - The config is always `portrait`, a rotation included: it is the size of the panel the taps land on. A foldable's helper sends the size again when the panel in use changes (ADR 0075 §4); a size equal to the held one is no change, and a frame that is not a size is warned about and kept out. diff --git a/vendor/screen-capture/Sources/simlock-screen-capture/InputMode.swift b/vendor/screen-capture/Sources/simlock-screen-capture/InputMode.swift index f02f09ec9..c4d5ddfde 100644 --- a/vendor/screen-capture/Sources/simlock-screen-capture/InputMode.swift +++ b/vendor/screen-capture/Sources/simlock-screen-capture/InputMode.swift @@ -98,7 +98,9 @@ func runInput(udid: String) async -> Never { await injector.sendTouch(type: type, x: x, y: y, screenWidth: size.width, screenHeight: size.height) case tagButton: guard let name = fields["button"] as? String else { continue } - await injector.sendButtonPlan(ButtonPlan.steps(for: name)) + let steps = ButtonPlan.steps(for: name) + if steps.isEmpty { log("button \(name) not sent") } + await injector.sendButtonPlan(steps) case tagKey: guard let type = fields["type"] as? String, let usage = fields["usage"] as? Int, usage >= 0 else { continue } await injector.sendKey(type: type, usage: UInt32(usage)) From e723fa34d2e3a0fcf3aada7d720d8a209fd6f7af Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 15:47:28 +0100 Subject: [PATCH 10/12] test(e2e): the iOS input test names its agent-device session, taps the SearchField and reads the presses off the simulator's screen (#1659) --- e2e/helpers/agent-device.ts | 2 + e2e/slow-ios-input.test.ts | 103 ++++++++++++++++++++++-------------- 2 files changed, 64 insertions(+), 41 deletions(-) diff --git a/e2e/helpers/agent-device.ts b/e2e/helpers/agent-device.ts index 0c7948355..5e995518e 100644 --- a/e2e/helpers/agent-device.ts +++ b/e2e/helpers/agent-device.ts @@ -145,6 +145,8 @@ export async function makeAgent( AGENT_DEVICE_STATE_DIR: home, AGENT_DEVICE_DAEMON_AUTH_TOKEN: token.secret, AGENT_DEVICE_NO_UPDATE_NOTIFIER: "1", + // why: the pinned agent-device refuses a leased remote connection without a named session (REMOTE_SESSION_REQUIRED). + AGENT_DEVICE_SESSION: name, ...(options.direct ? { AGENT_DEVICE_DAEMON_BASE_URL: proxyUrl(env) } : {}), }; const background = new Set(); diff --git a/e2e/slow-ios-input.test.ts b/e2e/slow-ios-input.test.ts index 889407ea1..422b7c650 100644 --- a/e2e/slow-ios-input.test.ts +++ b/e2e/slow-ios-input.test.ts @@ -1,7 +1,8 @@ import { execFileSync } from "node:child_process"; -import { mkdtemp } from "node:fs/promises"; +import { mkdtemp, readFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; +import { PNG } from "pngjs"; import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { @@ -63,8 +64,9 @@ function boxOf(node: Record): Box | undefined { return rect !== undefined && typeof rect.width === "number" ? rect : undefined; } -// why: the search field is the node agent-device names a search field or labels Search; the screen is -// the largest box in the same snapshot, so the tap's fraction is measured against one size. +// why: the search field is the node agent-device types a SearchField (Settings' list also holds buttons +// labelled Search, and a cell named "Optimising Search and Siri"); the screen is the largest box in the +// same snapshot, so the tap's fraction is measured against one size. function searchFieldAndScreen(json: unknown): { field?: Box; screen?: Box } { const boxed = [...nodesOf(json)].flatMap((node) => { const box = boxOf(node); @@ -72,26 +74,36 @@ function searchFieldAndScreen(json: unknown): { field?: Box; screen?: Box } { }); const area = (box: Box) => box.width * box.height; const screen = boxed.map((entry) => entry.box).sort((left, right) => area(right) - area(left))[0]; - const field = boxed.find(({ node }) => - /search/i.test( - `${String(node["type"])} ${String(node["label"])} ${String(node["identifier"])}`, - ), - )?.box; + const field = boxed.find(({ node }) => node["type"] === "SearchField")?.box; return { ...(field === undefined ? {} : { field }), ...(screen === undefined ? {} : { screen }), }; } -function isForeground(applicationState: unknown): boolean { - return applicationState === 4 || /foreground/i.test(String(applicationState)); +// why: the share of pixels that moved between two screenshots of one simulator; the app switcher and +// Lock repaint most of a screen, so a press counts when more than CHANGED of it moved. +const CHANGED = 0.3; +function changedFraction(before: PNG, after: PNG): number { + if (before.width !== after.width || before.height !== after.height) return 1; + let moved = 0; + for (let i = 0; i < before.data.length; i += 4) { + const delta = + Math.abs(before.data[i]! - after.data[i]!) + + Math.abs(before.data[i + 1]! - after.data[i + 1]!) + + Math.abs(before.data[i + 2]! - after.data[i + 2]!); + if (delta > 48) moved++; + } + return moved / (before.data.length / 4); } +const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); describe.skipIf(AGENT_DEVICE === undefined || !hasIos27Runtime())( "iOS simulator input on an iOS 27 runtime", { tags: ["slow", "ios"] }, () => { let env: SharedTestEnv; + let leased = false; beforeAll(async () => { const pinned = await assertPinnedAgentDevice("ios"); @@ -114,7 +126,8 @@ describe.skipIf(AGENT_DEVICE === undefined || !hasIos27Runtime())( await cleanupAgents(); if (env !== undefined) { await env.cli(["release", "--all", "--yes"], { timeout: 60_000 }); - await waitForFree(env); + // why: a pool that never leased has no device to wait for; waitForFree expects the replacement a release makes. + if (leased) await waitForFree(env); } await env?.teardown(); }, 420_000); @@ -125,6 +138,7 @@ describe.skipIf(AGENT_DEVICE === undefined || !hasIos27Runtime())( async () => { const a: Agent = await makeAgent(env, "ios-input"); ok(await a.run(["open", "--platform", "ios", "--os", ">=27"], { timeout: 330_000 })); + leased = true; ok(await a.run(["open", SETTINGS])); const shots = await mkdtemp(join(tmpdir(), "simlock-ios-input-")); progress(`screenshots of the iOS input test are saved in ${shots}`); @@ -136,16 +150,33 @@ describe.skipIf(AGENT_DEVICE === undefined || !hasIos27Runtime())( expect(screen, "the screen in the snapshot").toBeDefined(); const lease = (await listLeases(env))[0]; const socket = await openInputSocket(env.httpPort, lease?.id ?? "", a.token); - const appState = async () => { - const state = await a.run(["appstate", "--json"]); - ok(state); - const applicationState = (state.data as { applicationState?: unknown } | undefined) - ?.applicationState; - expect(applicationState, "appstate carries applicationState").toBeDefined(); - return applicationState; + const appState = (await a.run(["appstate", "--json"])).data as + | { device_udid?: string; ios_simulator_device_set?: string } + | undefined; + expect(appState?.device_udid, "appstate names the simulator").toBeDefined(); + const frame = async (name: string): Promise => { + const file = join(shots, `${name}.png`); + execFileSync("xcrun", [ + "simctl", + "--set", + appState!.ios_simulator_device_set!, + "io", + appState!.device_udid!, + "screenshot", + file, + ]); + return PNG.sync.read(await readFile(file)); }; - const shot = async (name: string) => { - ok(await a.run(["screenshot", join(shots, `${name}.png`)])); + const waitForScreenChange = async (before: PNG, name: string): Promise => { + let latest = before; + await waitFor( + async () => { + latest = await frame(name); + return changedFraction(before, latest) > CHANGED; + }, + { interval: 2_000, label: `the screen changed for ${name}`, timeout: 30_000 }, + ); + return latest; }; try { await socket.waitForTag(INPUT_ADMITTED); @@ -169,32 +200,22 @@ describe.skipIf(AGENT_DEVICE === undefined || !hasIos27Runtime())( }, { interval: 3_000, label: "typed keys in the snapshot", timeout: 60_000 }, ); - await shot("1-typed"); - expect(isForeground(await appState()), "Settings is in front before the presses").toBe( - true, - ); + const frameA = await frame("1-typed"); + // why: agent-device's appstate keeps answering runningForeground behind the app switcher and + // its screenshot hangs there, so the presses are read off the simulator's own screen. socket.send(INPUT_BUTTON, { button: "app_switcher" }); - await waitFor(async () => !isForeground(await appState()), { - interval: 2_000, - label: "Settings out of the foreground after app_switcher", - timeout: 30_000, - }); - await shot("2-app-switcher"); + const switcher = await waitForScreenChange(frameA, "2-app-switcher"); ok(await a.run(["open", SETTINGS])); - await waitFor(async () => isForeground(await appState()), { - interval: 2_000, - label: "Settings reopened", - timeout: 30_000, - }); + await sleep(3_000); + const reopened = await frame("2b-reopened"); + expect( + changedFraction(switcher, reopened), + "Settings is back after the switcher", + ).toBeGreaterThan(CHANGED); socket.send(INPUT_BUTTON, { button: "lock" }); - await waitFor(async () => !isForeground(await appState()), { - interval: 2_000, - label: "Settings out of the foreground after lock", - timeout: 30_000, - }); - await shot("3-lock"); + await waitForScreenChange(reopened, "3-lock"); } finally { socket.close(); } From 077c5bb77b6f501d916a39c2712cd9835500c4f7 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 16:12:25 +0100 Subject: [PATCH 11/12] test(e2e): the iOS input test no longer waits for a warm replacement the pool never makes (#1659) No warm pool is configured, so a released simulator is destroyed and waitForFree timed out on 'devices none'. The test waits for no lease and no request instead. --- e2e/slow-ios-input.test.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/e2e/slow-ios-input.test.ts b/e2e/slow-ios-input.test.ts index 422b7c650..2ecb5efc5 100644 --- a/e2e/slow-ios-input.test.ts +++ b/e2e/slow-ios-input.test.ts @@ -11,6 +11,7 @@ import { FIRST_SNAPSHOT, freeLoopbackPort, listLeases, + listRequests, makeAgent, newAgentToken, ok, @@ -18,7 +19,6 @@ import { progress, waitFor, waitForAgentDevice, - waitForFree, withSharedDaemon, type Agent, type SharedTestEnv, @@ -103,7 +103,6 @@ describe.skipIf(AGENT_DEVICE === undefined || !hasIos27Runtime())( { tags: ["slow", "ios"] }, () => { let env: SharedTestEnv; - let leased = false; beforeAll(async () => { const pinned = await assertPinnedAgentDevice("ios"); @@ -126,8 +125,12 @@ describe.skipIf(AGENT_DEVICE === undefined || !hasIos27Runtime())( await cleanupAgents(); if (env !== undefined) { await env.cli(["release", "--all", "--yes"], { timeout: 60_000 }); - // why: a pool that never leased has no device to wait for; waitForFree expects the replacement a release makes. - if (leased) await waitForFree(env); + // why: no warm pool is configured here, so a released simulator is destroyed and no replacement turns ready; waitForFree would wait for one; only the lease and the request have to be gone before the daemon stops. + await waitFor( + async () => + (await listLeases(env)).length === 0 && (await listRequests(env)).length === 0, + { interval: 1_000, label: "no lease and no request after the release", timeout: 120_000 }, + ); } await env?.teardown(); }, 420_000); @@ -138,7 +141,6 @@ describe.skipIf(AGENT_DEVICE === undefined || !hasIos27Runtime())( async () => { const a: Agent = await makeAgent(env, "ios-input"); ok(await a.run(["open", "--platform", "ios", "--os", ">=27"], { timeout: 330_000 })); - leased = true; ok(await a.run(["open", SETTINGS])); const shots = await mkdtemp(join(tmpdir(), "simlock-ios-input-")); progress(`screenshots of the iOS input test are saved in ${shots}`); @@ -220,7 +222,6 @@ describe.skipIf(AGENT_DEVICE === undefined || !hasIos27Runtime())( socket.close(); } ok(await a.run(["close"])); - await waitForFree(env); }, ); }, From 1ba49f7978f7bdbcda7b31914df562f5058eebef Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 16:21:30 +0100 Subject: [PATCH 12/12] docs(adr): 0085 to Accepted (#1659) --- ...takes-keys-on-every-runtime-and-the-app-switcher-and-lock.md | 2 +- docs/internal/adr/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/internal/adr/0085-an-ios-simulator-takes-keys-on-every-runtime-and-the-app-switcher-and-lock.md b/docs/internal/adr/0085-an-ios-simulator-takes-keys-on-every-runtime-and-the-app-switcher-and-lock.md index 67893192a..a7638f6c5 100644 --- a/docs/internal/adr/0085-an-ios-simulator-takes-keys-on-every-runtime-and-the-app-switcher-and-lock.md +++ b/docs/internal/adr/0085-an-ios-simulator-takes-keys-on-every-runtime-and-the-app-switcher-and-lock.md @@ -1,6 +1,6 @@ # 0085. An iOS simulator takes keys on every runtime, and the app switcher and Lock -- **Status:** Accepted — not yet implemented +- **Status:** Accepted - **Date:** 2026-11-17 - **Issue:** [#1024](https://github.com/callstackincubator/simlock/issues/1024) - **Narrows:** [ADR 0049](0049-a-lease-holder-watches-and-drives-its-devices-screen.md) diff --git a/docs/internal/adr/README.md b/docs/internal/adr/README.md index 17a36e63c..a0820ea5b 100644 --- a/docs/internal/adr/README.md +++ b/docs/internal/adr/README.md @@ -117,4 +117,4 @@ the status is stale. | [0080](0080-an-android-worker-may-enrol-phones-reached-over-the-network.md) | An Android worker may enrol phones reached over the network | Accepted; narrows 0022 §6 and §7, and 0073 §2 and §5 | | [0083](0083-a-worker-may-turn-single-slim-services-on-or-off-beside-its-categories.md) | A worker may turn single slim services on or off beside its categories | Accepted; narrows 0060 §1, §2 and 0066 §2 | | [0084](0084-a-worker-may-serve-a-platforms-enrolled-phones-only.md) | A worker may serve a platform's enrolled phones only | Accepted; narrows 0022 and 0009 §4 | -| [0085](0085-an-ios-simulator-takes-keys-on-every-runtime-and-the-app-switcher-and-lock.md) | An iOS simulator takes keys on every runtime, and the app switcher and Lock | Accepted — not yet implemented; narrows 0049 §4 | +| [0085](0085-an-ios-simulator-takes-keys-on-every-runtime-and-the-app-switcher-and-lock.md) | An iOS simulator takes keys on every runtime, and the app switcher and Lock | Accepted; narrows 0049 §4 |