Skip to content

CI runs: prepare each leased device (language, reduce motion, permissions, keychain reset) #1634

Done
1 of 1 issue completed

Description

@V3RON

Request: #1294

Problem

A CI run that leases many devices has to put each one into a known state before its tests: system language and keyboards, reduced motion, animations off. Nothing in @simlock/e2e does it, so a suite does it from its test code. budgie's suite (fixtures.ts) runs it in the first test on each device: it lists the token's leases to find the one that holds the simulator, calls POST /v1/leases/<id>/exec by hand, reads the event stream itself, and remembers which leases it prepared. A device whose setup fails is not swapped; the test fails.

Other parts of the request have an answer today, which no page names: the e2e runner sets permissions (app.permissions) and resets the keychain between tests (device.clearKeychain()), and a baseline keeps language, locale, reduced motion and permission grants.

Split from #1633 (release every lease of a run), which shipped.

Who it is for

A CI job that runs the e2e runner with @simlock/e2e, leases 5 to 10 simulators or emulators per run on a shared farm, and needs each one in a known state before its tests.

Outcome

  • A suite gives simlockDevices one setup function. It runs once on every device the run leases, after the apps are installed and before any test, and runs simctl or adb commands on that device without knowing a lease id.
  • A device whose setup fails is given back and another is leased, once, as for a failed install.
  • The CI page says which tool sets what: permissions, keychain, language, reduced motion, animations, and when a baseline is the better choice.

How it works for the user

flowchart TD
  A[Runner asks the provider for a device] --> B[Lease granted, apps installed]
  B --> C{setup given?}
  C -->|no| T[Tests run]
  C -->|yes| D[setup runs its commands on the device]
  D -->|ends| T
  D -->|throws| E[Device given back, another one leased, once]
  E --> F[Install and setup again]
  F -->|ends| T
  F -->|throws| X[Run fails: device setup]
  D -->|run aborted| Y[Device given back, run ends]
Loading

Before, in budgie's test code: exec(api, await leaseIdForUdid(api, udid), [...]) from a fixture, with about 100 lines of its own HTTP code.

After:

device: simlockDevices({
  url: process.env.SIMLOCK_URL!,
  token: process.env.SIMLOCK_TOKEN!,
  platform: "ios",
  device: "iPhone 17 Pro",
  setup: async ({ exec }) => {
    await exec(["spawn", "defaults", "write", ".GlobalPreferences", "AppleLanguages", "-array", "en-US"]);
    await exec(["spawn", "defaults", "write", "com.apple.Accessibility", "ReduceMotionEnabled", "-bool", "true"]);
  },
}),

What the run prints, through the runner's log:

simlock: installed com.example.app in 31877 ms
simlock: setup done in 412 ms

and when it fails:

simlock: setup on 6B1E… failed (simctl spawn exited 1: Unexpected argument -bol); leasing another device
simlock: could not set up a device after 2 tries: simctl spawn exited 1: Unexpected argument -bol

Examples

simlockDevices({ …, setup }) at config load:

Input Today After
no setup, or setup: undefined undefined: throws simlockDevices: unknown option "setup"; absent: accepted accepted, nothing runs
setup: async () => {} throws simlockDevices: unknown option "setup" accepted
setup: () => {} (not async) throws simlockDevices: unknown option "setup" accepted
setup: [["spawn", "…"]] throws simlockDevices: unknown option "setup" throws simlockDevices: setup must be a function; got spawn,…
setup: null throws simlockDevices: unknown option "setup" throws simlockDevices: setup must be a function; got null

exec(args) inside setup:

Input After
["spawn", "defaults", "read", "-g"] on iOS runs simctl spawn <this device> defaults read -g
["shell", "getprop"] on Android runs adb -s <this device> shell getprop
["keychain", "booted", "reset"] rejected: simctl keychain failed: PASSTHROUGH_REFUSED
["erase"] rejected: simctl erase failed: PASSTHROUGH_REFUSED
[] rejected: exec needs a command

What could go wrong

  • A setup that fails every time costs two leases and two installs before the run fails. Likely while a team writes its setup; the log names the failed command both times.
  • A setup that hangs outside exec holds the device until the run is aborted. Unlikely; the job's own time limit ends it.
  • A command's error output reaches the CI log (the last line only). A command that prints a secret on failure would show it.

Words used

  • provider: the code the e2e runner asks for one device per test worker. Example: simlockDevices({…}).
  • setup: the function a suite gives the provider, run once per leased device.
  • swap: giving back a device that could not be set up and leasing one other, once.
  • baseline: a device an operator prepared and saved under a name; a lease can start from a copy. Example: checkout.

Non-goals

Completion conditions

  • On a real simulator, a setup that writes a setting through exec has it in place when acquire ends, and reads it back through exec.
  • A setup that throws on the first device makes the run lease one other device and run setup there; a second failure fails the run with the setup's message, and both devices are given back.
  • A run with no setup makes the same calls as before.
  • A setup that is not a function throws at config load, naming the option.
  • The website's CI page documents setup and says how to set permissions, reset the keychain, and when to use a baseline.

Open questions

none

Decisions

No ADR: one package gains one option, and ADR 0077 §3 already says how a package talks to simlock.

Chosen by the maintainer in the session of 2026-11-30: setup lives in @simlock/e2e and the docs, not in the lease request; its shape is a function, not a list of commands.

  • Decided in the session: no keychain call, because device.clearKeychain(), agent-device's settings reset-keychain and simctl keychain reset through exec all do it.
  • Decided in the session: no permission option, because the runner's app.permissions applies them on every fresh launch.
  • Decided in the session: no animations option for Android, because one exec in setup does it.
  • Decided in the session: exec rejects on a non-zero exit code, because a setup command that failed unseen leaves the wrong state behind.
  • Decided in the session: any error from setup swaps the device once, a lost connection included, because a command may have run halfway and a new device is the one known state.
  • Decided in the session: an error names only the tool and its first argument, because later arguments can hold a password.
  • Chosen by the maintainer: an error the farm answered prints only its code, because the farm's text quotes every argument. The text is on the error object.
  • Decided in the session: that text is a field and not the error's cause, because the runner prints an error's causes (X13).
  • Decided in the session: setup runs outside installConcurrency, because that limit is for uploads.
  • Decided in the session: no time limit on setup itself, because each command has the worker's exec.timeoutMs and the run has its abort.

Behaviours

Id Behaviour (invoker, action, what it sees) Seam Cases Task
B1 A config gives setup: it is checked at config load simlockDevices, packages/e2e/src/index.test.ts absent; undefined; async function; plain function; an arrow that returns exec(...) itself type-checks; a list, null and a string are refused with I1's message #1991
B2 The runner acquires a device: setup runs once, after the app and every extra app are installed and before acquire ends, with I1's context, and simlock: setup done in <n> ms is logged; with no setup, nothing is run and nothing is logged createProvider acquire, packages/e2e/src/provider.test.ts iOS; Android; app named and not named; plain function; async function; no setup; the lease is renewed while a long setup runs #1991
B3 setup throws: the device is given back, I1's line is logged, one other device is leased, installed and set up; a second failure fails the acquire with the existing could not set up a device after 2 tries message createProvider acquire, packages/e2e/src/provider.test.ts throws an Error; rejects; throws a string; first fails and second ends; both fail (two releases); install fails first and setup fails second; plain function throws #1991
B4 The run is aborted while setup runs: acquire rejects with the abort's reason without waiting for setup, the device is given back, no other is leased createProvider acquire, packages/e2e/src/provider.test.ts setup never ends; setup rejects because of the abort; an exec in flight is cut; setup is not started when the run aborted during the install #1991
B5 setup calls exec: the command runs on this lease's device, and exec ends with its stdout and stderr createProvider acquire against a local HTTP server that answers the exec route, packages/e2e/src/provider.test.ts iOS sends tool simctl; Android sends adb; stdin sent and left out; stdout and stderr mixed; a message cut across two chunks; a multi-byte character cut across two chunks; comment lines ignored; the request carries the token and this lease's id #1991
B6 exec fails: it rejects with I2's error for the case createProvider acquire against a local HTTP server, packages/e2e/src/provider.test.ts exit 1 with stderr; exit 1 with stdout only; exit 1 with no output; last line over 300 characters; stream error; JSON error before the start; non-JSON answer; stream ends with neither exit nor error; connection refused; a url with a username and password reaches the farm with the bearer token, and with the farm unreachable no error, cause or log line holds either; [] sends no request; the farm's real EXEC_TIMEOUT text (X11) and other-device refusal (X12), each quoting all the arguments: neither the error's message and causes, nor the log lines, nor the final error and its causes hold a later argument, and farmMessage holds the text #1991
B7 On a real simulator a setup writes a setting through exec and reads it back slow lane, e2e/slow-e2e-provider.test.ts write then read com.apple.Accessibility ReduceMotionEnabled is 1 when acquire ends #1991

Stored state

none

Interfaces

Id What Shape and bounds Errors and limits Where Task Used by
I1 setup option and its context setup?: ((device: SetupDevice) => unknown) | undefined; what it returns is awaited and its value ignored. SetupDevice: platform ("ios" or "android"), deviceId (UDID or serial, the lease's), leaseId, app (the target's bundle id or package, string | undefined), signal (the request's), log(line) (the request's), exec (I2). Types SetupDevice, ExecOptions, ExecOutput and the class DeviceCommandError (I2) are exported from the entry file not a function: simlockDevices: setup must be a function; got <value>, the value as the other options print it. Any failure of setup: simlock: setup on <deviceId> failed (<message>); leasing another device. The install's own line keeps its words packages/e2e/src/options.ts, packages/e2e/src/index.ts #1991 #1991
I2 exec of the context exec(args: readonly string[], options?: { stdin?: string }): Promise<{ stdout: string; stderr: string }>. Sends POST <url>/v1/leases/<leaseId>/exec with the token as bearer and body { tool, args, stdin? }, tool being simctl on iOS and adb on Android; stdin is bounded by the route at 8,388,608 characters. The request is aborted by the run's signal <cmd> is the tool and the first argument. Empty args: exec needs a command. Non-zero exit: <cmd> exited <code>: <line>, where line is the last non-blank line of stderr, else of stdout, cut at 300 characters; with neither, <cmd> exited <code>. Stream error or a JSON error answer: <cmd> failed: <code>, the farm's own message kept only in farmMessage. Every rejection of exec is a DeviceCommandError, an Error with the non-enumerable fields exitCode, stdout, stderr, code, farmMessage, each undefined when the case has none. The farm's message is never in message or cause. Another answer: <cmd> failed: the farm answered <status>. Stream ended early or cut: <cmd> failed: the connection closed before the command ended. No connection: <cmd> failed: could not reach the farm, the fetch error as cause. A username and password in url are left out of the url exec requests, so no fetch error can quote them; the token is the only credential sent. No retry. The limit is the worker's exec.timeoutMs (default 10 minutes) and, on a gateway, gateway.execTimeoutMs, both answered as EXEC_TIMEOUT packages/e2e/src/ (a new file beside install.ts) #1991 #1991

Existing code

Commit 096519b.

Searches: rg DeviceSetupFailed packages (6 hits in provider.ts and install.ts, rest tests), rg 'leases/\{id\}/exec' src/http (1 route), rg fetch packages/e2e/src (0), rg 'simlock/e2e|packages/e2e' --glob '!*.md' (the package's manifest, checks, the slow test, the CI page).

Id Code (path:line) Today With this feature Handled by
X1 packages/e2e/src/provider.ts:136 after the install the lease is held and returned setup runs between the install and the hold #1991
X2 packages/e2e/src/provider.ts:141 any error of a lease attempt stops the renewal and releases the lease covers a failed or aborted setup unchanged #1991
X3 packages/e2e/src/provider.ts:161 only DeviceSetupFailed swaps, and the line says install on setup failures are DeviceSetupFailed too; the line names the step that failed #1991
X4 packages/e2e/src/provider.ts:122 the renewal starts before the install a long setup is renewed with no change B2
X5 packages/e2e/src/options.ts:33 (KNOWN) an unknown option throws setup is added #1991
X6 src/http/app-lease-routes.ts:83 exec is authorized by the lease's owner, the token's principal; the id the provider chose is the lease id on a worker and on a gateway (src/gateway/AGENTS.md, "Flow: a lease through a gateway" 6) unchanged; the provider's token made the lease, so it may exec on it #1991
X7 src/http/sse.ts:56 and :64 the stream starts with : open, sends event: and one-line JSON data:, and a comment every 15 s (:7) I2 reads that B5
X8 src/http/app-lease-routes.ts:130, src/http/errors.ts:201 a failure before the command starts is JSON { error: { code, message } } I2 reads that B6
X9 src/drivers/ios/simctl-device.ts:49 fills in the lease's device for spawn and the device-first verbs, refuses another unchanged; setup leaves the device out #1991
X10 packages/e2e/src/config.sample.ts:12 type-checks a config with every option setup is added #1991
X11 src/daemon/dispatcher-exec.ts:251 (the EXEC_TIMEOUT message) the text quotes every argument unchanged; exec prints the code only B6
X12 src/drivers/other-device-refusal.ts:15 the text quotes every argument unchanged; exec prints the code only B6
X13 node_modules/@e2e-dev/core/dist/internal/errors.js:106 at 0.25.0 (messageWithCauses) the runner prints an error's message and up to three causes no farm text in any cause B6

Tasks

Completion conditions: all by #1991; the docs one by its Done when line on ci.mdx.

Open work in the same area:

Written by an agent.

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    feature:spec
    on Nov 17, 2026
  2. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Design posted: every section written from the 2026-11-30 spec session (a setup function in @simlock/e2e plus a CI docs section); Problem rewritten against main, Open questions answered.

    Written by an agent.

  3. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Design settled: nothing left to decide.

    #1634 CI runs: prepare each leased device: #1634
    ADR: none.
    The decisions taken in the session are listed under Decisions.

    Task What it delivers Rows Depends on
    T1 a setup function in @simlock/e2e, run once per leased device, and the CI docs section B1-B7, I1, I2 —

    Check: ready | 0 open findings

    Written by an agent.

  4. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Spec updated: task #1991 added, Tasks section filled.

    Written by an agent.

  5. added
    feature:planned
    and removed
    feature:spec
    on Nov 30, 2026
  6. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Ready to deliver.

    Task What it delivers Depends on
    #1991 a setup function in @simlock/e2e, run once per leased device, and the CI docs section —

    chain 1 of 1 tasks

    Decisions since the design was settled: none.

    Written by an agent.

  7. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: none
    Parked: #1991 — 3 blocking findings open after the last review check (PR #1993, draft); B7 not run on a simulator
    Waiting: none
    Decided: none

    Written by an agent.

  8. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1993 (#1991)
    Parked: none
    Waiting: none
    Decided: #1991 — a password in url could reach the CI log → exec leaves it out of the request (the maintainer's choice)

    Written by an agent.

  9. github-actions commented on Nov 30, 2026

    @github-actions
    Contributor

    Closing: all 1 sub-issues are closed. The PR that closed the last one walks the completion conditions (delivery rule 9); reopen this if one does not hold on main. Flip its ADRs to Accepted if delivery has not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:planned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions