noracu 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,20 +35,20 @@ const stateName = (n) => STATE_NAMES[n] ?? "unknown";
35
35
  // What the two reads of an app's text fields say about text that was typed. `before` is null when the fields could
36
36
  // not be read before the text went in. A field "of mine" is one like the tapped field when one was tapped (same
37
37
  // type, identifier and label), any field otherwise. A field "gained" the text when its new value is its old value
38
- // with the text put in at one place ("hell" turning into "hello" is one letter arriving, not "hello": pre-review
39
- // P3) and neither value came back cut.
38
+ // with the text put in at one place ("hell" turning into "hello" is one letter arriving, not "hello")
39
+ // and neither value came back cut.
40
40
  // "shown" one field was singled out and gained the text: the tapped one, when it is the only one of its
41
41
  // kind in both reads and its value changed; otherwise, when both reads list the same fields, the
42
42
  // only field of mine whose value changed. What other fields did does not matter then.
43
43
  // "cut" that one field did not gain the text as far as its value was read, but the value came back
44
- // cut and was not cut before: the text could not be looked for in all of it (pre-review P15).
44
+ // cut and was not cut before: the text could not be looked for in all of it.
45
45
  // A field whose value reads the same but came back cut, when it was not before, has changed
46
- // too: what was added is past where the read stops (pre-review P16). The other way round — cut
47
- // before, whole now, the same value — is no change: nothing was added (pre-review P17-Grok-1).
46
+ // too: what was added is past where the read stops. The other way round — cut
47
+ // before, whole now, the same value — is no change: nothing was added.
48
48
  // "placeholder" no field at all changed — or the fields were not read before, and none of mine holds the text —
49
49
  // and a field of mine reads empty with the text as its own placeholder: such a field reads the
50
50
  // same whether or not it took the text. Only a field that did not change can be that field: one
51
- // that had a value and reads empty now did not gain the text (pre-review P13).
51
+ // that had a value and reads empty now did not gain the text.
52
52
  // "unread" not read before, and a field of mine has the text in its value or came back cut (any field, when
53
53
  // none of mine is listed): there is nothing to compare it with.
54
54
  // "moved" the two reads do not list the same fields (one appeared, went away, or changed its label), and
@@ -57,9 +57,9 @@ const stateName = (n) => STATE_NAMES[n] ?? "unknown";
57
57
  // before.
58
58
  // "several" the same fields, more than one of mine changed, and one of those gained the text, or came back
59
59
  // cut and was not cut before: it arrived, or may have, and was not tied to one field. A field
60
- // that is cut in both reads says nothing new (pre-review P14).
60
+ // that is cut in both reads says nothing new.
61
61
  // "mismatch" everything else: the reads were compared and do not show the text arriving.
62
- // The text in a field that did not change proves nothing, wherever it is (pre-reviews P12, P13), and neither does
62
+ // The text in a field that did not change proves nothing, wherever it is, and neither does
63
63
  // a field that is not mine.
64
64
  export function fieldShows(before, after, text, key) {
65
65
  const mine = (f) => !key || f.key === key;
@@ -103,6 +103,9 @@ export function fieldShows(before, after, text, key) {
103
103
  export function createIosSession({
104
104
  env = process.env, api = iosApi, approve = () => null, springboardDenied = () => false, spawnImpl, onChild = () => {},
105
105
  now = Date.now, sleep = (ms) => new Promise((r) => setTimeout(r, ms)), runnerDir,
106
+ // the person's brake (NORACU_STOP_FILE): its refusal line, or null — looked at again where a read before an input
107
+ // can take seconds after the queue's own check
108
+ stopCheck = () => null,
106
109
  } = {}) {
107
110
  const dir = runnerDir || env.NORACU_IOS_RUNNER_DIR || join(homedir(), ".noracu", "ios-runner");
108
111
  const readOnly = env.NORACU_READ_ONLY === "1";
@@ -113,6 +116,10 @@ export function createIosSession({
113
116
  let starting = null; // the start in flight, shared by calls that arrive meanwhile
114
117
  let suspect = false; // the last call got no answer: ask for a sign of life before the next one
115
118
  let current = null; // the app the last call named
119
+ // the app (not the Home Screen) this session last launched, acted on or read in front: a later call that names
120
+ // com.apple.springboard — a snapshot of the Home Screen, text typed there — does not change it, so the look before
121
+ // an input named for the Home Screen still asks whether that app is in front
122
+ let brought = null;
116
123
  let epoch = 0; // goes up when a call changes what is in front; indexes of an older epoch are dead
117
124
  let nextIndex = 1, snapSeq = 0;
118
125
  const items = new Map(); // element_index → { snapshot_id, bundle, type, label, id, frame, ts, epoch }
@@ -121,7 +128,8 @@ export function createIosSession({
121
128
  async function resolveDevice() {
122
129
  const want = String(env.NORACU_IOS_UDID || "").trim();
123
130
  if (want && !api.validUdid(want)) return { ok: false, error: "ios_config", message: "NORACU_IOS_UDID is not a device identifier" };
124
- const list = await api.listDevices();
131
+ // a simulator named in NORACU_IOS_UDID is looked up with simctl alone; devicectl answers for iPhones
132
+ const list = await (want && api.isSimulatorUdid(want) ? api.listSimulators() : api.listDevices());
125
133
  if (!list.ok) return list;
126
134
  let d;
127
135
  if (want) {
@@ -146,8 +154,8 @@ export function createIosSession({
146
154
  trackExit(r.exited);
147
155
  }
148
156
  // A runner that was stopped (or a start that failed) is remembered until its xcodebuild has really exited, not
149
- // for a fixed time: each start waits up to STOP_WAIT_MS for it and is refused while it is still there. (Pre-review
150
- // P3: the first refusal used to forget it, so the start after that ran a second test session on the device; and
157
+ // for a fixed time: each start waits up to STOP_WAIT_MS for it and is refused while it is still there. (The
158
+ // first refusal used to forget it, so the start after that ran a second test session on the device; and
151
159
  // an exit that came late was still held against a start made minutes afterwards.)
152
160
  function trackExit(exited) {
153
161
  if (!exited) return;
@@ -155,13 +163,13 @@ export function createIosSession({
155
163
  stopping = p;
156
164
  }
157
165
 
158
- // The lock (pre-review P1). gate() reads it before every input, as before. On top of that no runner op that
166
+ // The lock. gate() reads it before every input, as before. On top of that no runner op that
159
167
  // touches or shows the screen goes out on an "unlocked" answer older than a second: typing after the tap that
160
168
  // focuses the field reads it again, and so does a snapshot or screenshot on its own — a locked phone's screen
161
169
  // shows its notifications, so it is not read either. A tap right after its gate costs no second read.
162
170
  const LOCK_FRESH_MS = 1000;
163
171
  const STOP_WAIT_MS = 4000;
164
- // app_state too: a locked phone's answer to "is it in front" is not read as one (review S4A-s6-grok-2)
172
+ // app_state too: a locked phone's answer to "is it in front" is not read as one
165
173
  const NEEDS_UNLOCKED = new Set(["snapshot", "screenshot", "app_state", "tap", "press", "drag", "type", "keys", "home"]);
166
174
  const INPUT_OPS = new Set(["tap", "press", "drag", "type", "keys", "home"]);
167
175
  let lockOkAt = -Infinity;
@@ -229,37 +237,139 @@ export function createIosSession({
229
237
  }
230
238
 
231
239
  // the runner that is up, asked for a sign of life when in doubt — never a new one
232
- async function liveRunner() {
240
+ async function liveRunner(why = "the runner stopped before the input went out (input never starts one)") {
233
241
  if (runner && suspect) {
234
242
  const p = await runner.client.call("ping", {}, { timeoutMs: 5000 });
235
243
  if (p.ok) suspect = false; else stopRunner();
236
244
  }
237
- return runner ? { ok: true } : { ok: false, error: "runner_unreachable", message: "the runner stopped before the input went out (input never starts one)" };
245
+ return runner ? { ok: true } : { ok: false, error: "runner_unreachable", message: why };
238
246
  }
247
+ // A read a tool makes inside its own call — the element read again before the input, the text fields around the
248
+ // typed text, the state of the app it launched or left — does not start a runner either: a runner that starts puts
249
+ // its own app in front of the screen the call is about. The read answers that the runner stopped; the next call
250
+ // that asks for the iPhone starts it.
251
+ const IN_CALL = "the runner stopped during this call, and a read inside the call does not start it again (a starting runner puts its own app in front of what the iPhone shows)";
239
252
 
240
253
  // an xctest_issue that an internal read met and the tool has not reported yet
241
254
  const takeHeld = () => { const h = heldIssue; heldIssue = null; return h; };
242
255
 
243
- async function rcall(op, args, timeoutMs) {
256
+ async function rcall(op, args, timeoutMs, { inCall = false } = {}) {
244
257
  // Safety net: a failure XCTest recorded that an internal read was answered with, and that the tool which made
245
258
  // the read did not report itself, is not lost — the next input is not sent, and reports it. No runner is
246
259
  // started for that.
247
260
  if (heldIssue && INPUT_OPS.has(op)) { const h = takeHeld(); return { ok: false, error: "xctest_issue", message: h.message, delivery: "not_delivered" }; }
248
261
  // input never starts a runner: a runner that starts puts its own app in front, under the points and the focus the
249
- // input was made for — only the gate (before anything is read for the call) may start one (review S4A-s6-gemini-1)
250
- const up = INPUT_OPS.has(op) ? await liveRunner() : await ensureRunner();
262
+ // input was made for — only the gate (before anything is read for the call) may start one; a read inside a call
263
+ // (inCall) does not start one either
264
+ const up = INPUT_OPS.has(op) ? await liveRunner() : inCall ? await liveRunner(IN_CALL) : await ensureRunner();
251
265
  const cur = runner;
252
266
  if (!up.ok || !cur) return { ok: false, error: up.ok ? "runner_unreachable" : (up.error || "runner_unreachable"), message: up.ok ? "the runner stopped" : (up.message || "the runner stopped"), delivery: "not_delivered" };
253
267
  if (NEEDS_UNLOCKED.has(op)) {
254
268
  const l = await lockRefusal(false);
255
269
  if (l) return { ok: false, error: l.error, message: l.message, delivery: "not_delivered" };
256
270
  }
257
- const r = await cur.client.call(op, args, { timeoutMs });
271
+ // An app that reports itself in front can be covered by something of SpringBoard's own that is not an alert:
272
+ // Control Center pulled down over it. The app's state stays "running in the foreground" and it is read as
273
+ // usual, but a tap goes to Control Center (seen on a device: the tap closed it; on a control it would have
274
+ // switched it). With an app in front SpringBoard shows no icons; with Control Center over it (or with the
275
+ // Home Screen) it does, and the runner's `front` says so. Then nothing is sent — nor when SpringBoard cannot
276
+ // be read. An app that is not in front is left to the runner's own refusal.
277
+ // An input named for the Home Screen. com.apple.springboard always reads "running in the foreground", also
278
+ // while an app — or Spotlight, a process of its own — is what the iPhone shows: after ios_home another app can
279
+ // come forward (a call, the person opening one), the runner does not look for that under this name, and the
280
+ // tap would land in that app. So SpringBoard is looked at first: the Home Screen's pages, Today View and the
281
+ // App Library show icons (on a device: 5 to 40 of them), an app or Spotlight in front shows none. With no icon
282
+ // showing, the input goes to the runner as `springboard_only`: one tap on a button of a system alert is sent,
283
+ // anything else is refused there. Icons can still be on their way in right after ios_home, so with neither an
284
+ // icon nor an alert showing SpringBoard is looked at again, up to four times over 1.6 s.
285
+ let homeCovered = false;
286
+ if (INPUT_OPS.has(op) && op !== "home" && args && args.bundle_id === SPRINGBOARD && args.springboard_only !== true) {
287
+ const bare = (x) => x.ok && x.result?.home !== true && !(x.result?.icons > 0);
288
+ const alerted = (x) => x.ok && x.result?.alerts?.length > 0;
289
+ // The app this session last launched, acted on or read in front still reads as in front: then the Home Screen
290
+ // is not what the iPhone shows, whatever SpringBoard still draws — an icon can stay for a moment after an app
291
+ // came forward (seen on a device right after ios_launch), and Control Center over the app shows icons as well.
292
+ // The input is held to the same rule without looking for icons. A call that named the Home Screen in between
293
+ // (a snapshot of it, this very input) does not change which app that is. A state that cannot be read is a
294
+ // failed look, as the look at SpringBoard below: a failure XCTest recorded ends the session, no answer or a
295
+ // broken one makes the next call ask for a sign of life first, and the input is not sent.
296
+ const failedLook = (x, what) => {
297
+ if (x.error === "xctest_issue") { if (runner === cur) stopRunner(); }
298
+ else if (["ios_timeout", "runner_unreachable", "runner_protocol"].includes(x.error)) suspect = true;
299
+ return { ok: false, error: x.error || "app_not_foreground", message: `${x.message || "the runner did not answer"} (while looking, before the input, at ${what} — the input was not sent)`, delivery: "not_delivered" };
300
+ };
301
+ let appFront = false;
302
+ if (brought) {
303
+ const st = await cur.client.call("app_state", { bundle_id: brought }, { timeoutMs: 10000 });
304
+ if (runner !== cur) return { ok: false, error: "runner_unreachable", message: "the runner stopped", delivery: "not_delivered" };
305
+ if (!st.ok) return failedLook(st, `whether ${brought}, the app this session brought forward, is still in front`);
306
+ appFront = st.result?.state === FOREGROUND;
307
+ }
308
+ if (appFront) { args = { ...args, springboard_only: true }; homeCovered = true; }
309
+ else {
310
+ let f = await cur.client.call("front", {}, { timeoutMs: 10000 });
311
+ if (runner !== cur) return { ok: false, error: "runner_unreachable", message: "the runner stopped", delivery: "not_delivered" };
312
+ for (let i = 0; i < 4 && bare(f) && !alerted(f); i++) {
313
+ await sleep(400);
314
+ f = await cur.client.call("front", {}, { timeoutMs: 10000 });
315
+ if (runner !== cur) return { ok: false, error: "runner_unreachable", message: "the runner stopped", delivery: "not_delivered" };
316
+ }
317
+ if (!f.ok) return failedLook(f, "whether the Home Screen is what the iPhone is showing");
318
+ if (bare(f)) { args = { ...args, springboard_only: true }; homeCovered = true; }
319
+ }
320
+ }
321
+ if (INPUT_OPS.has(op) && op !== "home" && args && args.bundle_id && args.bundle_id !== SPRINGBOARD) {
322
+ const showsIcons = (x) => x.ok && (x.result?.home === true || x.result?.icons > 0);
323
+ let f = await cur.client.call("front", {}, { timeoutMs: 10000 });
324
+ if (runner !== cur) return { ok: false, error: "runner_unreachable", message: "the runner stopped", delivery: "not_delivered" };
325
+ // an app that has just come to the front: the Home Screen's icons can still be on their way out (seen on a
326
+ // device right after ios_launch: one icon was still there at once, none 1.5 s later) — looked at again, up to
327
+ // four times over 1.6 s, before anything is refused
328
+ for (let i = 0; i < 4 && showsIcons(f); i++) {
329
+ await sleep(400);
330
+ f = await cur.client.call("front", {}, { timeoutMs: 10000 });
331
+ if (runner !== cur) return { ok: false, error: "runner_unreachable", message: "the runner stopped", delivery: "not_delivered" };
332
+ }
333
+ // A read made for this check that fails is a failed call like any other (see below): a failure XCTest recorded
334
+ // ends the session, no answer or a broken one makes the next call ask for a sign of life first. The input is
335
+ // not sent, and the answer carries the failure's own name — no overlay was seen.
336
+ const unread = (x) => {
337
+ if (x.error === "xctest_issue") { if (runner === cur) stopRunner(); }
338
+ else if (["ios_timeout", "runner_unreachable", "runner_protocol"].includes(x.error)) suspect = true;
339
+ return { ok: false, error: x.error || "system_overlay", message: `${x.message || "the runner did not answer"} (while looking, before the input, at what the iPhone itself is showing over the app — the input was not sent)`, delivery: "not_delivered" };
340
+ };
341
+ if (!f.ok) return unread(f);
342
+ if (showsIcons(f)) {
343
+ const st = await cur.client.call("app_state", { bundle_id: args.bundle_id }, { timeoutMs: 10000 });
344
+ if (runner !== cur) return { ok: false, error: "runner_unreachable", message: "the runner stopped", delivery: "not_delivered" };
345
+ if (!st.ok) return unread(st);
346
+ if (st.result?.state === 4) return { ok: false, error: "system_overlay", message: "the iPhone is showing something of its own over the app (Control Center pulled down, or the Home Screen while an app is still coming forward) — nothing was sent; look again with ios_snapshot in a moment, and if it is still there, ios_home closes it but leaves the app for the Home Screen (ios_launch brings the app back)", delivery: "not_delivered" };
347
+ }
348
+ }
349
+ // The reads above can take seconds after the queue looked at the stop file and the gate at the lock (SpringBoard
350
+ // looked at up to four times over 1.6 s, each read with its own 10 s limit): right before an input goes out,
351
+ // the lock is read again when its last "unlocked" answer is older than a second, and the stop file is looked at
352
+ // again last — by the client, right before it writes the command, after the connection it may first have to
353
+ // open (up to 5 s; a runner just started has none). Nothing is waited for between that look and the write.
354
+ // ios_type's text after its tap is refused the same way; ios_type then says the field was tapped.
355
+ if (INPUT_OPS.has(op)) {
356
+ const l = await lockRefusal(false);
357
+ if (runner !== cur) return { ok: false, error: "runner_unreachable", message: "the runner stopped", delivery: "not_delivered" };
358
+ if (l) return { ok: false, error: l.error, message: l.message, delivery: "not_delivered" };
359
+ }
360
+ const beforeSend = INPUT_OPS.has(op) ? () => {
361
+ const stop = stopCheck();
362
+ if (!stop) return null;
363
+ const m = /^(\w+): ([\s\S]*)$/.exec(stop) || [null, "user_stopped", stop];
364
+ return { ok: false, error: m[1], message: m[2].replace(/\s*[—;,]?\s*nothing was sent \((?:fail closed; )?delivery=not_delivered, retry=safe\)/, ""), delivery: "not_delivered" };
365
+ } : undefined;
366
+ let r = await cur.client.call(op, args, { timeoutMs, beforeSend });
367
+ if (homeCovered && !r.ok && r.error === "app_not_foreground") r = { ...r, message: "the Home Screen is not what the iPhone is showing: an app or Spotlight is in front, and under com.apple.springboard only one tap on a button of a system alert is sent there — name the app that is in front (ios_snapshot with its bundle_id), or go to the Home Screen with ios_home", plain: true };
258
368
  // An input that got no answer may still be waiting inside the test session: the session ends now, so the
259
- // gesture cannot go out later (pre-review P1; the protocol always said so). Any failure XCTest recorded ends it
369
+ // gesture cannot go out later (the protocol always said so). Any failure XCTest recorded ends it
260
370
  // as well, whichever command was answered with it — an input, a read, or the next command after a late one:
261
- // what state the test session is in is then not known, and a ping answers from the socket alone (pre-review
262
- // P3 and P4). A read that got no answer only makes the next call ask for a sign of life first.
371
+ // what state the test session is in is then not known, and a ping answers from the socket alone.
372
+ // A read that got no answer only makes the next call ask for a sign of life first.
263
373
  const ends = !r.ok && (r.error === "xctest_issue" || (r.error === "ios_timeout" && INPUT_OPS.has(op)));
264
374
  if (ends) { if (runner === cur) stopRunner(); }
265
375
  else if (!r.ok && ["ios_timeout", "runner_unreachable", "runner_protocol"].includes(r.error)) suspect = true;
@@ -275,29 +385,30 @@ export function createIosSession({
275
385
  if (!up.ok || !runner) return { error: `${up.ok ? "runner_unreachable" : up.error}: ${up.ok ? "the runner stopped" : up.message} ${NOT_SENT}` };
276
386
  const l = await lockRefusal(true);
277
387
  if (l) return { error: `${l.error}: ${l.message} ${NOT_SENT}` };
278
- // the runner can exit while the lock is read (review S4A-s6-gemini-1)
388
+ // the runner can exit while the lock is read
279
389
  if (!runner) return { error: `runner_unreachable: the runner stopped ${NOT_SENT}` };
280
390
  return null;
281
391
  }
282
392
  // a runner started during this call: it put its own app in front, so the points and the focus the call was made for
283
- // are gone (review S4A-s6-grok-3). Input given as points or as the focus (no element_index) is refused whenever the
393
+ // are gone. Input given as points or as the focus (no element_index) is refused whenever the
284
394
  // gate or a read started a runner during the call, whatever app it names — the runner's own "not in front" check
285
395
  // depends on how fast the app comes back, so it is not relied on. An element_index of an older epoch is stale.
286
396
  const restarted = () => ({ error: `runner_restarted: the runner started during this call, which puts its own app in front — the screen the points or the focus were meant for is gone; look again (ios_snapshot) ${NOT_SENT}` });
287
397
  const HINTS = {
288
398
  app_not_foreground: " — the app is not in front; call ios_launch first",
289
399
  app_not_running: " — the app is not running; call ios_launch first",
290
- system_alert: " — a system prompt is up on the iPhone; the person answers it there (noracu does not send input while one is up)",
400
+ // device run 2026-11-15: the refusal did not say which prompt was up, so the agent could not tell the person what to answer
401
+ system_alert: " — a system prompt is up on the iPhone; the person answers it there (noracu does not send input while one is up); look at it with ios_screenshot to tell them what it asks",
291
402
  no_keyboard: " — no keyboard is up; tap a text field first (ios_type with element_index does that)",
292
403
  ios_timeout: " — look before acting again (ios_snapshot)",
293
404
  xctest_issue: " — XCTest reported a failure while the command ran; look before acting again (ios_snapshot)",
294
405
  };
295
406
  // While app rules are in force, no input that names com.apple.springboard is sent — not even one tap on a
296
- // button of a system prompt (next-steps R4, 2026-11-12). SpringBoard reads "in front" under every app, so a
407
+ // button of a system prompt (2026-11-12). SpringBoard reads "in front" under every app, so a
297
408
  // point named for it lands on whatever app is in front (one the rules may not allow), a tap on a Home Screen
298
409
  // icon opens an app no rule was asked about (ios_launch is the way that asks), and text goes wherever the
299
410
  // keyboard focus is. ios_home is not input named for SpringBoard and still goes out.
300
- // The refusal comes before the gate (pre-review P5): the gate can start a runner, and a starting runner puts
411
+ // The refusal comes before the gate: the gate can start a runner, and a starting runner puts
301
412
  // its own app in front of what the iPhone was showing — a refusal that says nothing was sent must change
302
413
  // nothing either. The app rule is asked first and answers in its own words.
303
414
  const sbNever = (bundle) => {
@@ -306,8 +417,8 @@ export function createIosSession({
306
417
  return { error: denied || `input_denied: input that names com.apple.springboard (the Home Screen) is not sent while app rules are in force (NORACU_APPROVAL_FILE or NORACU_DENY_APPS) — not even one tap on a system prompt's button; open apps with ios_launch, go home with ios_home ${NOT_SENT}` };
307
418
  };
308
419
  // system_alert comes with two messages: an alert is up, or SpringBoard could not be read so one could not be ruled
309
- // out — only the first is told "a system prompt is up" (review S4B-s8-new-1, S4D)
310
- const hint = (r) => (r.error === "system_alert" && /could not be (read|ruled out)/.test(r.message || "")
420
+ // out — only the first is told "a system prompt is up"
421
+ const hint = (r) => (r.plain ? "" : r.error === "system_alert" && /could not be (read|ruled out)/.test(r.message || "")
311
422
  ? " — noracu could not tell whether a system prompt is up on the iPhone; look at it (ios_screenshot) before acting again"
312
423
  : HINTS[r.error] || "");
313
424
  const inputError = (r) => ({ error: `${r.error}: ${r.message || "the runner refused"}${hint(r)} ${r.delivery === "not_delivered" ? NOT_SENT : UNKNOWN}` });
@@ -328,7 +439,7 @@ export function createIosSession({
328
439
  ({ error: `element_no_longer_valid: element_index ${idx} — ${why}; take a new ios_snapshot ${NOT_SENT}` });
329
440
  // Read the app again and find the very element: same type, label, identifier and frame (2 pt), app in front.
330
441
  async function recheck(idx, it) {
331
- const r = await rcall("snapshot", { bundle_id: it.bundle, max_nodes: 1000 }, 30000);
442
+ const r = await rcall("snapshot", { bundle_id: it.bundle, max_nodes: 1000 }, 30000, { inCall: true });
332
443
  if (!r.ok) return { error: inputError({ ...r, delivery: "not_delivered" }).error };
333
444
  const res = r.result;
334
445
  if (it.bundle !== SPRINGBOARD && res.state !== FOREGROUND) return stale(idx, `${it.bundle} is no longer in front`);
@@ -343,7 +454,7 @@ export function createIosSession({
343
454
  }
344
455
  // the app's text inputs, for the read-back after typing: [{ key, value, cut }]; null when the app cannot be read
345
456
  async function textFields(bundle) {
346
- const r = await rcall("snapshot", { bundle_id: bundle, max_nodes: 1000 }, 30000);
457
+ const r = await rcall("snapshot", { bundle_id: bundle, max_nodes: 1000 }, 30000, { inCall: true });
347
458
  if (!r.ok) { if (r.error === "xctest_issue") heldIssue = r; return null; }
348
459
  if (r.result.truncated === true) return null; // fields past the limit were not read: nothing can be paired
349
460
  return (r.result.nodes || []).filter((n) => TEXTY.has(n.type) && typeof n.value === "string")
@@ -354,11 +465,11 @@ export function createIosSession({
354
465
  const end = now() + ms;
355
466
  let st = null;
356
467
  for (;;) {
357
- const r = await rcall("app_state", { bundle_id: bundle }, 10000);
468
+ const r = await rcall("app_state", { bundle_id: bundle }, 10000, { inCall: true });
358
469
  if (!r.ok) { if (r.error === "xctest_issue") heldIssue = r; return { ok: false, st, failed: true }; }
359
470
  st = r.result.state;
360
471
  // "left the front" is a state seen as not running, suspended or in the background — never unknown (0) or no
361
- // state at all (review S4A-s6-grok-1)
472
+ // state at all
362
473
  if (want ? st === FOREGROUND : [1, 2, 3].includes(st)) return { ok: true, st };
363
474
  if (now() >= end) return { ok: false, st };
364
475
  await sleep(300);
@@ -393,21 +504,30 @@ export function createIosSession({
393
504
  // the runner first: starting it puts its own app in front, which would cover an app launched before it
394
505
  const g = await gate(bundle, "launch");
395
506
  if (g) return g;
396
- const d = runner.device, opts = { terminateExisting: a.terminate_existing === true };
507
+ // the gate can take seconds after the queue looked at the stop file (starting the runner, reading the lock): the
508
+ // stop file is looked at again last, right before devicectl / simctl starts (after devicectl's temporary
509
+ // folder is made) — the launch, which with terminate_existing also stops the running app
510
+ const beforeRun = () => { const stop = stopCheck(); return stop ? { ok: false, error: "user_stopped", stopped: stop } : null; };
511
+ const d = runner.device, opts = { terminateExisting: a.terminate_existing === true, beforeRun };
397
512
  const r = d.simulated ? await api.simLaunch(d.udid, bundle, opts) : await api.launchApp(d.udid, bundle, opts);
513
+ if (r.stopped) return { error: r.stopped };
398
514
  if (!r.ok) {
399
515
  const late = /timeout/.test(r.error);
516
+ // a launch that timed out may still have gone through, and one with terminate_existing may have stopped the
517
+ // running app: either changes what is in front, so the indexes read before it are dead, as after a launch that worked
518
+ if (late || opts.terminateExisting) epoch++;
400
519
  // with terminate_existing the running app may already have been stopped when the launch failed
401
520
  return { error: `${late ? r.error : "launch_failed"}: ${r.message} ${opts.terminateExisting ? "— the running app may already have been stopped (delivery=unknown, retry=unsafe)" : late ? "(delivery=unknown, retry=safe)" : NOT_SENT}` };
402
521
  }
403
522
  epoch++; current = bundle;
523
+ if (bundle !== SPRINGBOARD) brought = bundle;
404
524
  // the launch went out: asking again with terminate_existing would stop the app that was just started
405
525
  const again = opts.terminateExisting ? "unsafe" : "safe";
406
526
  const w = await waitState(bundle, true, 10000);
407
527
  if (heldIssue) { const h = takeHeld(); return { error: `xctest_issue: ${h.message || "XCTest recorded a failure"}${HINTS.xctest_issue} — ${bundle} was started; whether it is in front was not read (delivery=delivered_unverified, retry=${again})` }; }
408
528
  if (w.ok) return { text: `launched ${bundle} — it is in front (delivery=delivered_verified, retry=${again})` };
409
529
  // a read of the app's state failed (with no failure of XCTest's behind it), so the 10 s were not waited
410
- // out: the result says what was read, not "not in front after 10 s" (pre-review P8)
530
+ // out: the result says what was read, not "not in front after 10 s"
411
531
  if (w.failed) return { error: `launch_not_confirmed: ${bundle} was started; ${w.st === null ? "whether it is in front could not be read" : `it was not in front when its state was last read (state ${stateName(w.st)}), and the read after that failed`} — look with ios_screenshot (delivery=delivered_unverified, retry=${again})` };
412
532
  return { error: `launch_not_confirmed: ${bundle} was started but is not in front after 10 s (state ${stateName(w.st)}) — a system prompt may be covering it; look with ios_screenshot (delivery=delivered_unverified, retry=${again})` };
413
533
  },
@@ -437,6 +557,7 @@ export function createIosSession({
437
557
  });
438
558
  while (items.size > ITEMS_KEPT) items.delete(items.keys().next().value);
439
559
  current = p.bundle;
560
+ if (p.bundle !== SPRINGBOARD && res.state === FOREGROUND) brought = p.bundle;
440
561
  const out = { bundle_id: p.bundle, snapshot_id, state: stateName(res.state), screen: res.screen, count: elements.length, truncated: Boolean(res.truncated) || cut, elements };
441
562
  if (p.bundle !== SPRINGBOARD && res.state !== FOREGROUND) out.note = "this app is not in front: its elements cannot be acted on until ios_launch brings it forward";
442
563
  return { text: JSON.stringify(out) };
@@ -476,6 +597,7 @@ export function createIosSession({
476
597
  : await rcall("tap", { bundle_id: bundle, x, y, ...(a.count > 1 ? { count: a.count } : {}) }, 20000);
477
598
  if (!r.ok) return inputError(r);
478
599
  current = bundle;
600
+ if (bundle !== SPRINGBOARD) brought = bundle;
479
601
  return { text: `${press ? `pressed ${a.duration_ms} ms on` : a.count > 1 ? `tapped ×${a.count}` : "tapped"} ${what} at (${x}, ${y}) in ${bundle} — sent; the screen is not checked ${UNVERIFIED}` };
480
602
  },
481
603
 
@@ -486,6 +608,10 @@ export function createIosSession({
486
608
  if (!it) return stale(a.element_index);
487
609
  const n = sbNever(it.bundle); // before the gate, and before the tap that would focus: nothing is sent, no runner is started
488
610
  if (n) return n;
611
+ // only a text input is tapped to take the text: the index of a button or a row would be tapped as what
612
+ // it is — a real press on it — and the text would then go to whatever holds the keyboard. Before the
613
+ // gate: nothing is asked for an input that is not going to be sent.
614
+ if (!TEXTY.has(it.type) && it.type !== "secureTextField") return { error: `not_a_text_field: element_index ${a.element_index} is a ${it.type}${it.label ? ` (${JSON.stringify(String(it.label).slice(0, 40))})` : ""}, not a text field — nothing was tapped or typed; tap what brings the keyboard up with ios_tap, then call ios_type without element_index (delivery=not_delivered, retry=safe)` };
489
615
  const g = await gate(it.bundle);
490
616
  if (g) return g;
491
617
  if (it.epoch !== epoch) return stale(a.element_index); // the gate started a runner: what was read is gone
@@ -528,6 +654,7 @@ export function createIosSession({
528
654
  }
529
655
  const n = [...a.text].length;
530
656
  if (!r.ok) return tapped && r.delivery === "not_delivered" ? { error: `${r.error}: ${r.message || "the runner refused"}${hint(r)} — the field was tapped, no text was typed (delivery=delivered_unverified, retry=unsafe)` } : inputError(r);
657
+ if (bundle !== SPRINGBOARD) brought = bundle;
531
658
  if (secure) return { text: `typed ${n} characters into a secure field in ${bundle} — it never shows its value, so nothing was read back ${UNVERIFIED}` };
532
659
  if (a.text.includes("\n")) return { text: `typed ${n} characters in ${bundle} — the text contains a return, which can submit or clear the field, so nothing was read back ${UNVERIFIED}` };
533
660
  if (n < 4) return { text: `typed ${n} character${n === 1 ? "" : "s"} in ${bundle} — too short to tell from what was already there, so nothing was read back ${UNVERIFIED}` };
@@ -537,7 +664,7 @@ export function createIosSession({
537
664
  const notConfirmed = { error: `type_not_confirmed: ${n} characters were typed in ${bundle} but ${key ? "the field that was tapped was not" : "no text field was"} seen to gain exactly that text (autocorrection or a field that hides its value can cause this) — read the field (ios_snapshot) before typing again ${UNKNOWN}` };
538
665
  // The fields could not be read afterwards (the read failed, or the app has more elements than are read): the
539
666
  // text was not seen to be missing, which type_not_confirmed would say — unverified, and the result names the
540
- // side that could not be read (reviews P5, P6)
667
+ // side that could not be read
541
668
  if (after === null) return { text: `typed ${n} characters in ${bundle} — the text fields ${before !== null ? "could not be read afterwards" : "could not be read before the text went in or afterwards"}, so nothing was read back ${UNVERIFIED}` };
542
669
  // What the two reads say is decided in one place (fieldShows); each of its answers has one sentence here
543
670
  const shown = fieldShows(before, after, a.text, key);
@@ -565,6 +692,7 @@ export function createIosSession({
565
692
  const r = await rcall("keys", { bundle_id: p.bundle, key: a.key, count: n }, 20000 + 100 * n);
566
693
  if (!r.ok) return inputError(r);
567
694
  current = p.bundle;
695
+ if (p.bundle !== SPRINGBOARD) brought = p.bundle;
568
696
  return { text: `pressed ${a.key}${n > 1 ? ` ×${n}` : ""} in ${p.bundle} — sent; the screen is not checked ${UNVERIFIED}` };
569
697
  },
570
698
 
@@ -582,6 +710,7 @@ export function createIosSession({
582
710
  const r = await rcall("drag", args, 25000 + (a.hold_ms ?? 0) + (a.end_hold_ms ?? 0));
583
711
  if (!r.ok) return inputError(r);
584
712
  current = p.bundle;
713
+ if (p.bundle !== SPRINGBOARD) brought = p.bundle;
585
714
  return { text: `swiped (${a.from[0]}, ${a.from[1]}) → (${a.to[0]}, ${a.to[1]}) in ${p.bundle} — sent; the screen is not checked ${UNVERIFIED}` };
586
715
  },
587
716
 
@@ -589,15 +718,18 @@ export function createIosSession({
589
718
  const g = await gate(SPRINGBOARD, "home");
590
719
  if (g) return g;
591
720
  const prev = current;
592
- // whether prev was in front before the press: only then can "left the front" be seen (review S4A-s6-D-1)
721
+ // whether prev was in front before the press: only then can "left the front" be seen
593
722
  let wasFront = null;
594
723
  if (prev && prev !== SPRINGBOARD) {
595
- const pre = await rcall("app_state", { bundle_id: prev }, 10000);
724
+ const pre = await rcall("app_state", { bundle_id: prev }, 10000, { inCall: true });
596
725
  if (!pre.ok && pre.error === "xctest_issue") return inputError({ ...pre, delivery: "not_delivered" });
597
- // tri-state (review S4B-s6-1): in front, seen elsewhere (1/2/3), or not known (0, no state, a failed read)
726
+ // tri-state: in front, seen elsewhere (1/2/3), or not known (0, no state, a failed read)
598
727
  const st = pre.ok ? pre.result?.state : undefined;
599
728
  wasFront = st === FOREGROUND ? true : [1, 2, 3].includes(st) ? false : null;
600
729
  }
730
+ // the read above can take up to 10 s after the queue looked at the stop file: look again before the press
731
+ const stop = stopCheck();
732
+ if (stop) return { error: stop };
601
733
  const r = await rcall("home", {}, 15000);
602
734
  if (!r.ok) return inputError(r);
603
735
  epoch++;
@@ -614,7 +746,7 @@ export function createIosSession({
614
746
  if (heldIssue) { const h = takeHeld(); return { error: `xctest_issue: ${h.message || "XCTest recorded a failure"}${HINTS.xctest_issue} — home was pressed; whether ${prev} left the front was not read (delivery=delivered_unverified, retry=safe)` }; }
615
747
  if (w.ok) { current = SPRINGBOARD; return { text: `home pressed — ${prev} left the front (delivery=delivered_verified, retry=safe)` }; }
616
748
  // seen to stay in front: say so, and keep it as the app later calls default to
617
- // … or it was in front each time it was read and a later read failed, which ended the wait early (pre-review P8)
749
+ // … or it was in front each time it was read and a later read failed, which ended the wait early
618
750
  if (w.st === FOREGROUND) return { error: w.failed
619
751
  ? `home_not_confirmed: home was pressed and ${prev} was still in front when its state was last read; the read after that failed — look with ios_screenshot (delivery=delivered_unverified, retry=safe)`
620
752
  : `home_not_confirmed: home was pressed but ${prev} is still in front after 3 s — look with ios_screenshot (delivery=delivered_unverified, retry=safe)` };
package/src/ios-setup.js CHANGED
@@ -1,7 +1,8 @@
1
1
  // ios-setup — `noracu ios-setup`: build the on-device runner for one iPhone or simulator (0.3.0, EXPERIMENTAL).
2
2
  //
3
3
  // An explicit command; nothing runs on install. It uses Apple's own tools on this Mac:
4
- // xcrun devicectl list devices which device
4
+ // xcrun devicectl list devices which iPhone
5
+ // xcrun simctl list --json which simulator (a simulator's udid is looked up here, not with devicectl)
5
6
  // xcodebuild build-for-testing the runner in ios-runner/, into ~/.noracu/ios-runner/<udid>
6
7
  // For an iPhone the build is signed for the developer team given with --team, and Xcode may create or
7
8
  // update a development provisioning profile in that team (-allowProvisioningUpdates talks to Apple's
@@ -26,7 +27,7 @@ Builds noracu's on-device runner (a UI-test bundle, source in ios-runner/) for o
26
27
  --bundle-prefix <p> bundle identifier prefix for the runner (default: dev.noracu.<teamid>)
27
28
  --register-device let Xcode register this iPhone in the team if it is not registered yet`;
28
29
 
29
- const TEAM_RE = /^[A-Z0-9]{10}$/, PREFIX_RE = /^[A-Za-z0-9][A-Za-z0-9.-]{2,100}$/;
30
+ const TEAM_RE = /^[A-Z0-9]{10}$/, PREFIX_RE = /^(?=.{3,101}$)[A-Za-z0-9][A-Za-z0-9-]*(?:\.[A-Za-z0-9-]+)*$/; // parts between single dots: none empty
30
31
 
31
32
  export function parseArgs(argv) {
32
33
  const o = { team: null, udid: null, prefix: null, register: false, help: false };
@@ -42,7 +43,7 @@ export function parseArgs(argv) {
42
43
  }
43
44
  if (o.team !== null && !TEAM_RE.test(o.team)) return { error: "--team must be a 10-character team identifier (letters and digits, as shown in your Apple developer account)" };
44
45
  if (o.udid !== null && !iosApi.validUdid(o.udid)) return { error: "--udid is not a device identifier" };
45
- if (o.prefix !== null && !PREFIX_RE.test(o.prefix)) return { error: "--bundle-prefix must look like a bundle identifier prefix (letters, digits, dots, hyphens)" };
46
+ if (o.prefix !== null && !PREFIX_RE.test(o.prefix)) return { error: "--bundle-prefix must look like a bundle identifier prefix: letters, digits and hyphens in parts separated by single dots (com.example.me)" };
46
47
  return o;
47
48
  }
48
49
 
@@ -62,6 +63,7 @@ export function explain(output, team = "your team") {
62
63
  if (/isn.t registered|is not registered|doesn.t include the currently selected device|Device .{0,80}isn.t included/i.test(t)) return `this iPhone is not registered in ${team}: run again with --register-device (it adds the device to the team), or register it at developer.apple.com.`;
63
64
  if (/No Account for Team|No profiles for|requires a development team|no signing certificate|Signing for .{0,80}requires/i.test(t)) return `Xcode has no account or certificate for ${team}: open Xcode › Settings › Accounts, sign in, then run this again.`;
64
65
  if (/Developer Mode/i.test(t)) return "turn on Developer Mode on the iPhone (Settings › Privacy & Security › Developer Mode), then run this again.";
66
+ if (/keychain[^\n]{0,120}\b(?:is )?locked|errSecInteractionNotAllowed|User interaction is not allowed/i.test(t)) return "this Mac's keychain is locked, so the signing key cannot be used (usual over ssh): unlock it at the Mac's own screen, or with `security unlock-keychain`, then run this again.";
65
67
  if (/device is locked|unlock the device|is locked/i.test(t)) return "unlock the iPhone and run this again.";
66
68
  return null;
67
69
  }
@@ -73,14 +75,18 @@ export const BUILD_TIMEOUT_MS = 15 * 60 * 1000;
73
75
  // killGraceMs more). Ctrl-C on this command ends the group too.
74
76
  function run(file, argv, spawnImpl, timeoutMs, killGraceMs = 3000, exit = (code) => process.exit(code)) {
75
77
  return new Promise((resolve) => {
76
- let out = "", child, settled = false, timer = null, sigTimer = null, timedOut = false, signalled = false;
78
+ let out = "", child, settled = false, timer = null, sigTimer = null, timedOut = false, signalled = false, sigCode = 130;
77
79
  const signal = (sig) => { try { process.kill(-child.pid, sig); } catch { try { child.kill(sig); } catch { /* already gone */ } } };
78
80
  // Ctrl-C: the group is told to end and this command exits with 130 once xcodebuild is gone, a second later at the latest
79
- const interrupted = () => { if (settled) return; exit(130); done({ code: null, out, signalled: true }); };
80
- const onSignal = () => { if (signalled) return; signalled = true; signal("SIGTERM"); sigTimer = setTimeout(() => { signal("SIGKILL"); interrupted(); }, 1000); sigTimer.unref?.(); };
81
+ // done() first: the handlers and timers are off before exit is called, whatever exit does
82
+ const interrupted = () => { if (settled) return; done({ code: null, out, signalled: true, exitCode: sigCode }); exit(sigCode); };
83
+ // The handler stays until the build is gone (done() takes it off): with one that is gone after the first
84
+ // signal, a second Ctrl-C would be this process's default end — the SIGKILL below would never be sent, and a
85
+ // build that does not end on SIGTERM would go on. 130 for Ctrl-C, 143 for SIGTERM.
86
+ const onSignal = (sig) => { if (signalled) return; signalled = true; clearTimeout(timer); sigCode = sig === "SIGTERM" ? 143 : 130; signal("SIGTERM"); sigTimer = setTimeout(() => { signal("SIGKILL"); interrupted(); }, 1000); sigTimer.unref?.(); };
81
87
  const done = (v) => { if (settled) return; settled = true; clearTimeout(timer); clearTimeout(sigTimer); process.removeListener("SIGINT", onSignal); process.removeListener("SIGTERM", onSignal); resolve(v); };
82
88
  try { child = spawnImpl(file, argv, { stdio: ["ignore", "pipe", "pipe"], detached: true }); } catch (e) { return done({ code: null, out: String(e && e.message) }); }
83
- process.once("SIGINT", onSignal); process.once("SIGTERM", onSignal);
89
+ process.on("SIGINT", onSignal); process.on("SIGTERM", onSignal);
84
90
  timer = setTimeout(() => {
85
91
  timedOut = true;
86
92
  signal("SIGTERM");
@@ -89,7 +95,8 @@ function run(file, argv, spawnImpl, timeoutMs, killGraceMs = 3000, exit = (code)
89
95
  const add = (d) => { out = (out + String(d)).slice(-200000); };
90
96
  child.stdout?.on("data", add); child.stderr?.on("data", add);
91
97
  child.on("error", (e) => done({ code: null, out: String(e && e.message) }));
92
- child.on("close", (code) => (signalled ? interrupted() : done(timedOut ? { code: null, out, timedOut: true } : { code, out })));
98
+ // code null with a signal name: something outside this command ended xcodebuild (not the time limit, not Ctrl-C here)
99
+ child.on("close", (code, sig) => (signalled ? interrupted() : done(timedOut ? { code: null, out, timedOut: true } : { code, out, ...(code === null && sig ? { killedBy: String(sig) } : {}) })));
93
100
  });
94
101
  }
95
102
 
@@ -98,12 +105,14 @@ export async function main(argv, { log = (s) => process.stdout.write(s + "\n"),
98
105
  const o = parseArgs(argv);
99
106
  if (o.error) { log(`noracu ios-setup: ${o.error}\n\n${USAGE}`); return 2; }
100
107
  if (o.help) { log(USAGE); return 0; }
101
- const list = await api.listDevices();
102
- if (!list.ok) { log(`noracu ios-setup: could not list devices (${list.message}) — is Xcode installed?`); return 1; }
108
+ // a simulator's udid is looked up with simctl alone, an iPhone's with devicectl (src/ios-xcuitest.js, listSimulators)
109
+ const sim = o.udid !== null && api.isSimulatorUdid(o.udid);
110
+ const list = await (sim ? api.listSimulators() : api.listDevices());
111
+ if (!list.ok) { log(`noracu ios-setup: could not list ${sim ? "simulators" : "devices"} (${list.message}) — is Xcode installed?`); return 1; }
103
112
  let device;
104
113
  if (o.udid) {
105
114
  device = list.devices.find((d) => d.udid.toLowerCase() === o.udid.toLowerCase());
106
- if (!device) { log("noracu ios-setup: this Mac does not list the device named with --udid"); return 1; }
115
+ if (!device) { log(`noracu ios-setup: this Mac does not list the ${sim ? "simulator" : "device"} named with --udid${sim ? " (xcrun simctl list devices shows the simulators it has)" : ""}`); return 1; }
107
116
  } else {
108
117
  const phones = list.devices.filter((d) => !d.simulated && d.paired && d.tunnel);
109
118
  if (phones.length !== 1) { log(`noracu ios-setup: ${phones.length ? "several iPhones are connected" : "no connected iPhone found"} — name the device with --udid${phones.length ? ": " + phones.map((d) => `${d.udid} (${d.name})`).join(", ") : ""}`); return 1; }
@@ -113,7 +122,13 @@ export async function main(argv, { log = (s) => process.stdout.write(s + "\n"),
113
122
  const prefix = o.prefix || (o.team ? `dev.noracu.${o.team.toLowerCase()}` : null);
114
123
  // the same place the server looks in (NORACU_IOS_RUNNER_DIR, default ~/.noracu/ios-runner)
115
124
  const root = join(home, ".noracu"), base = env.NORACU_IOS_RUNNER_DIR || join(root, "ios-runner"), out = join(base, device.udid);
116
- for (const d of env.NORACU_IOS_RUNNER_DIR ? [base, out] : [root, base, out]) { mkdirSync(d, { recursive: true, mode: 0o700 }); try { chmodSync(d, 0o700); } catch { /* not ours to change */ } }
125
+ // a folder the person named (NORACU_IOS_RUNNER_DIR) that is already there keeps its mode; what noracu makes is 0700
126
+ const theirs = env.NORACU_IOS_RUNNER_DIR && existsSync(base);
127
+ for (const d of env.NORACU_IOS_RUNNER_DIR ? [base, out] : [root, base, out]) {
128
+ mkdirSync(d, { recursive: true, mode: 0o700 });
129
+ if (theirs && d === base) continue;
130
+ try { chmodSync(d, 0o700); } catch { /* not ours to change */ }
131
+ }
117
132
  // A build for another bundle prefix in the same folder leaves products the next build can keep: the runner it names
118
133
  // then still carries the old bundle id, and the server starts an old runner (device run 2026-11-13). When the prefix
119
134
  // changes — or a folder from before this check holds a build of unknown prefix — the earlier build is removed first.
@@ -127,14 +142,16 @@ export async function main(argv, { log = (s) => process.stdout.write(s + "\n"),
127
142
  }
128
143
  log(`Building the runner for ${device.name || device.udid}${device.simulated ? " (simulator)" : ` (team ${o.team}, bundle prefix ${prefix})`} — this takes a minute or two…`);
129
144
  const r = await run(api.XCODEBUILD, buildArgv({ udid: device.udid, simulated: device.simulated, out, team: o.team, prefix, register: o.register }), spawnImpl, buildTimeoutMs, killGraceMs, exit);
130
- if (r.signalled) return 130; // Ctrl-C: not a failed build
145
+ if (r.signalled) return r.exitCode || 130; // Ctrl-C or SIGTERM: not a failed build
131
146
  if (r.timedOut) {
132
147
  log(`noracu ios-setup: the build did not finish in ${Math.round(buildTimeoutMs / 60000)} min and was stopped — a signing or keychain prompt may be waiting on this Mac's screen; answer it and run the command again.\n--- last lines of xcodebuild ---\n${r.out.trim().split("\n").slice(-15).join("\n")}`);
133
148
  return 1;
134
149
  }
135
150
  const xctestrun = r.code === 0 ? await api.findXctestrun(out) : null;
136
151
  if (!xctestrun) {
137
- const why = r.code === null ? `xcodebuild could not be run (${r.out.slice(0, 200)}) — is Xcode installed?` : explain(r.out, o.team ? `team ${o.team}` : "your team");
152
+ const why = r.code === null
153
+ ? (r.killedBy ? `xcodebuild was ended by ${r.killedBy} from outside this command before it finished — run the command again` : `xcodebuild could not be run (${r.out.slice(0, 200)}) — is Xcode installed?`)
154
+ : explain(r.out, o.team ? `team ${o.team}` : "your team");
138
155
  log(`noracu ios-setup: the build failed${why ? `: ${why}` : "."}\n--- last lines of xcodebuild ---\n${r.out.trim().split("\n").slice(-15).join("\n")}`);
139
156
  return 1;
140
157
  }