mobile-automator 0.35.2 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobile-automator",
3
- "version": "0.35.2",
3
+ "version": "0.36.0",
4
4
  "description": "Host-agnostic mauto CLI for AI-driven mobile QA automation — analyzes a mobile project and drives devices through mobile-mcp.",
5
5
  "homepage": "https://github.com/sh3lan93/mobile-automator#readme",
6
6
  "repository": {
@@ -34,7 +34,7 @@
34
34
  "test:all": "jest"
35
35
  },
36
36
  "dependencies": {
37
- "@mobilenext/mobile-mcp": "1.0.5",
37
+ "@mobilenext/mobile-mcp": "1.0.13",
38
38
  "@modelcontextprotocol/sdk": "^1.29.0",
39
39
  "ajv": "^8.20.0",
40
40
  "commander": "^12.1.0"
@@ -24,7 +24,7 @@
24
24
  //
25
25
  // For 'verb' entries, `args` documents the mobile-mcp argument keys the bridge
26
26
  // method must pass — deliberately explicit because the keys are inconsistent
27
- // across the engine (launch=packageName, uninstall=bundle_id, install=path).
27
+ // across the engine (launch=packageName, uninstall=packageName, install=path).
28
28
  //
29
29
  // `stepFlags` records a scenario step field that changes how the verb runs:
30
30
  // `{ field, value, flag }` means "when step[field] === value, pass flag". This
@@ -77,7 +77,7 @@ const ACTION_CATALOG = {
77
77
  },
78
78
  uninstall_app: {
79
79
  resolution: 'verb', verb: 'uninstall', bridge: 'uninstallApp',
80
- primitive: 'mobile_uninstall_app', args: ['bundle_id'],
80
+ primitive: 'mobile_uninstall_app', args: ['packageName'],
81
81
  },
82
82
  open_url: {
83
83
  resolution: 'verb', verb: 'open-url', bridge: 'openUrl',
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  const { normalize, parseElements } = require('./element-model');
4
- const { normalizeDevices } = require('./device-model');
5
- const { normalizeCrashes } = require('./crash-model');
4
+ const { deviceRecords, normalizeDevices, isIosSimulator } = require('./device-model');
5
+ const { normalizeCrashes, CrashListUnverifiableError } = require('./crash-model');
6
6
  const { resolveSingleDevice } = require('./device-resolver');
7
7
  const { centredSwipe } = require('./swipe-geometry');
8
8
  const { isAppNotRunning } = require('./app-not-running');
@@ -94,18 +94,28 @@ class DeviceBridge {
94
94
  return this._call('mobile_swipe_on_screen', args);
95
95
  }
96
96
 
97
- // Platform ('android'/'ios') of the connected device. Uses the pinned id when
98
- // one was provided, else the single auto-resolved device.
97
+ // The current device's record (id/name/platform/state/type): the pinned id
98
+ // when one was provided, else the single auto-resolved device. A pinned id
99
+ // that is not listed throws — callers treat that as "could not check".
100
+ async _currentDevice() {
101
+ const records = deviceRecords(await this._call('mobile_list_available_devices', {}));
102
+ const id = this._device || resolveSingleDevice(records); // throws DeviceResolutionError on 0/many
103
+ const match = records.find((d) => d.id === id);
104
+ if (!match) throw this._unknownPlatform(id);
105
+ return match;
106
+ }
107
+
108
+ _unknownPlatform(id) {
109
+ const err = new Error(`Cannot determine the platform of device "${id}".`);
110
+ err.hint = 'Ensure the device is listed by `mauto devices`.';
111
+ return err;
112
+ }
113
+
114
+ // Platform ('android'/'ios') of the current device.
99
115
  async getPlatform() {
100
- const devices = normalizeDevices(await this._call('mobile_list_available_devices', {}));
101
- const id = this._device || resolveSingleDevice(devices); // throws DeviceResolutionError on 0/many
102
- const match = devices.find((d) => d.id === id);
103
- if (!match || !match.platform) {
104
- const err = new Error(`Cannot determine the platform of device "${id}".`);
105
- err.hint = 'Ensure the device is listed by `mauto devices`.';
106
- throw err;
107
- }
108
- return String(match.platform).toLowerCase();
116
+ const device = await this._currentDevice();
117
+ if (!device.platform) throw this._unknownPlatform(device.id);
118
+ return String(device.platform).toLowerCase();
109
119
  }
110
120
 
111
121
  // Physical screen size in pixels, for geometry-based gestures. mobile-mcp
@@ -176,7 +186,7 @@ class DeviceBridge {
176
186
 
177
187
  // Uninstall an app by its bundle/package identifier.
178
188
  async uninstallApp(appId) {
179
- return await this._call('mobile_uninstall_app', { bundle_id: appId });
189
+ return await this._call('mobile_uninstall_app', { packageName: appId });
180
190
  }
181
191
 
182
192
  // Open a URL (deep link or web) on the device.
@@ -201,9 +211,27 @@ class DeviceBridge {
201
211
  // come from the device log and AGE OUT; iOS device/simulator reports are files
202
212
  // that PERSIST and accumulate across runs. Same call, under-inclusive on one
203
213
  // platform and over-inclusive on the other — hence the `since` scoping in
204
- // src/device/failure-probe.js. There is deliberately no platform branch here.
214
+ // src/device/failure-probe.js.
215
+ //
216
+ // ONE platform exception, and only for an EMPTY list: on an iOS simulator the
217
+ // pinned engine (mobilecli 1.0.21, since mobilecli#482) returns `[]` on
218
+ // macOS 27 hosts even right after the app crashed — its filter requires an
219
+ // `is_simulated` key that those simulator reports lack (mobilecli#539). There
220
+ // an empty list is not evidence of "no crash", so we throw the typed
221
+ // CrashListUnverifiableError instead: callers treat it as "could not check"
222
+ // (handleCrashList fails the verb; the failure probe records it at info and
223
+ // leaves `crashes` absent), never as "found none". A
224
+ // non-empty list is real evidence on every platform and is returned as-is,
225
+ // and the device lookup is paid only on an empty list. Remove this guard
226
+ // when the pinned mobilecli fixes #539: re-capture
227
+ // tests/fixtures/device/mobile-mcp-<ver>/ios-sim.crashes.txt with a real
228
+ // crash in it, then drop the guard and its tests.
205
229
  async listCrashes() {
206
- return normalizeCrashes(await this._call('mobile_list_crashes', {}));
230
+ const crashes = normalizeCrashes(await this._call('mobile_list_crashes', {}));
231
+ if (crashes.length === 0 && isIosSimulator(await this._currentDevice())) {
232
+ throw new CrashListUnverifiableError();
233
+ }
234
+ return crashes;
207
235
  }
208
236
 
209
237
  // The full text of one crash report. The engine returns a bare string (its
@@ -107,4 +107,26 @@ function crashTimestampMs(crash) {
107
107
  return parsed > 0 ? parsed : null;
108
108
  }
109
109
 
110
- module.exports = { normalizeCrashes, crashTimestampMs };
110
+ // The engine bug behind the one platform where an empty crash list is not
111
+ // evidence of "no crash": an iOS simulator on a macOS 27 host (mobilecli#539).
112
+ const MOBILECLI_ISSUE_539 = 'https://github.com/mobile-next/mobilecli/issues/539';
113
+
114
+ // Thrown by DeviceBridge#listCrashes when the engine's answer cannot be trusted.
115
+ // Typed (in the shape of device-resolver.js's DeviceResolutionError) so the
116
+ // failure probe can record it as the expected condition it is rather than as a
117
+ // broken engine, and so the `crash` verb maps it onto the `device` envelope.
118
+ class CrashListUnverifiableError extends Error {
119
+ constructor() {
120
+ super(
121
+ 'The device engine cannot confirm the absence of crashes on an iOS simulator: it reports none even after a crash.'
122
+ );
123
+ this.name = 'CrashListUnverifiableError';
124
+ this.kind = 'device';
125
+ this.code = 'crash_list_unverifiable';
126
+ this.hint =
127
+ `On an iOS simulator an empty crash list is not evidence that the app did not crash (upstream bug ${MOBILECLI_ISSUE_539}). ` +
128
+ 'Treat the crash status as unknown, and check that the app is still running by other means (e.g. `mauto elements` or a screenshot).';
129
+ }
130
+ }
131
+
132
+ module.exports = { normalizeCrashes, crashTimestampMs, CrashListUnverifiableError };
@@ -5,12 +5,16 @@
5
5
  // — and drop every other raw mobile-mcp field (no resource-id, no OS-specific
6
6
  // internals). `os` is mapped onto `platform` so the output reads the same way
7
7
  // across the Android/iOS/simulator variants mobile-mcp returns.
8
+ //
9
+ // deviceRecords is the ONE parser of the raw list. Its records also carry
10
+ // `type` (simulator/emulator/real), which DeviceBridge needs internally;
11
+ // normalizeDevices is only the public 4-key view of those records.
8
12
 
9
13
  function nullable(v) {
10
14
  return v === undefined || v === null || v === '' ? null : v;
11
15
  }
12
16
 
13
- function normalizeOne(raw) {
17
+ function recordOf(raw) {
14
18
  if (!raw || typeof raw !== 'object') return null;
15
19
 
16
20
  const id = nullable(
@@ -35,10 +39,12 @@ function normalizeOne(raw) {
35
39
 
36
40
  const state = nullable(raw.state !== undefined ? raw.state : raw.status);
37
41
 
38
- return { id: String(id), name, platform, state };
42
+ const type = nullable(raw.type);
43
+
44
+ return { id: String(id), name, platform, state, type };
39
45
  }
40
46
 
41
- function normalizeDevices(raw) {
47
+ function deviceRecords(raw) {
42
48
  let list;
43
49
  if (Array.isArray(raw)) {
44
50
  list = raw;
@@ -50,10 +56,26 @@ function normalizeDevices(raw) {
50
56
 
51
57
  const out = [];
52
58
  for (const item of list) {
53
- const d = normalizeOne(item);
59
+ const d = recordOf(item);
54
60
  if (d) out.push(d);
55
61
  }
56
62
  return out;
57
63
  }
58
64
 
59
- module.exports = { normalizeDevices };
65
+ function publicView({ id, name, platform, state }) {
66
+ return { id, name, platform, state };
67
+ }
68
+
69
+ function normalizeDevices(raw) {
70
+ return deviceRecords(raw).map(publicView);
71
+ }
72
+
73
+ function isIosSimulator(record) {
74
+ if (!record) return false;
75
+ return (
76
+ String(record.platform || '').toLowerCase() === 'ios' &&
77
+ String(record.type || '').toLowerCase() === 'simulator'
78
+ );
79
+ }
80
+
81
+ module.exports = { deviceRecords, normalizeDevices, isIosSimulator };
@@ -7,14 +7,14 @@ const path = require('path');
7
7
  // tell the user what to do. Pure: message in, hint string (or null) out. It
8
8
  // never throws — a hint classifier that crashes would turn a device failure
9
9
  // into an internal one. Found by the #199 real-device run against mobile-mcp
10
- // 1.0.5 / mobilecli 1.0.13.
10
+ // 1.0.5 / mobilecli 1.0.13; the missing-agent case was re-captured against
11
+ // mobile-mcp 1.0.13 (#248), which installs the agent itself, so that hint now
12
+ // covers only a failed automatic install.
11
13
  //
12
14
  // mauto only TELLS the user which command to run; it never runs mobilecli
13
15
  // itself (the device is driven only through mauto verbs, which wrap
14
16
  // mobile-mcp).
15
17
 
16
- const ISSUE_459 = 'https://github.com/mobile-next/mobile-mcp/issues/459';
17
-
18
18
  // The mobilecli that the pinned mobile-mcp actually spawns — resolved from
19
19
  // mobile-mcp's own directory, since that is the copy whose agent the device
20
20
  // must match. Null when it cannot be resolved; the caller omits `@<version>`.
@@ -35,21 +35,21 @@ function safeVersion(resolver) {
35
35
  }
36
36
  }
37
37
 
38
- // B1 (iOS): mobilecli `agent status` exits 1 when the DeviceKit agent is
39
- // missing and mobile-mcp runs it via execFileSync, so the throw skips its own
40
- // auto-install (upstream mobile-mcp#459). Every verb fails until the agent is
41
- // installed once by hand.
42
- function missingAgentHint(message, resolver) {
38
+ // B1 (iOS): the simulator is missing the DeviceKit agent and the engine's
39
+ // automatic install of it failed (e.g. offline, or `simctl install` failing).
40
+ // The trigger is the shape captured against mobile-mcp 1.0.13 (#248,
41
+ // tests/fixtures/device/mobile-mcp-1.0.13/ios-sim.agent-install-failed.txt):
42
+ // execFileSync's `Command failed: <mobilecli> agent install --device <udid>`.
43
+ // The 1.0.5-era "Agent is not installed on the device" (#199) is unreachable
44
+ // from the pinned engine, which catches `agent status`'s exit itself.
45
+ const FAILED_AGENT_INSTALL = /Command failed:[^\n]*\bagent install --device\s+(\S+)/;
46
+
47
+ function missingAgentHint(udid, resolver) {
43
48
  const version = safeVersion(resolver);
44
49
  const pkg = version ? `mobilecli@${version}` : 'mobilecli';
45
- const cmd = `npx -y ${pkg} agent install --device`;
46
- const m = /--device\s+(\S+)/.exec(message);
47
- const install = m
48
- ? `\`${cmd} ${m[1]}\``
49
- : `\`${cmd}\` followed by the simulator's id from \`mauto devices\``;
50
50
  return (
51
- 'The simulator is missing the device agent the engine needs, and the engine cannot install it ' +
52
- `itself (upstream bug ${ISSUE_459}). Install it once with ${install} ` +
51
+ 'The simulator is missing the device agent the engine needs. The engine normally installs it ' +
52
+ `automatically, but that install failed. Install it once by hand with \`npx -y ${pkg} agent install --device ${udid}\` ` +
53
53
  '(needs network, takes a few seconds), then retry.'
54
54
  );
55
55
  }
@@ -80,9 +80,8 @@ const OUTSIDE_ALLOWED_DIRS_HINT =
80
80
  function engineHint(message, { mobilecliVersion = resolveMobilecliVersion } = {}) {
81
81
  try {
82
82
  if (typeof message !== 'string' || !message) return null;
83
- if (/Agent is not installed on the device/.test(message)) {
84
- return missingAgentHint(message, mobilecliVersion);
85
- }
83
+ const agentInstall = FAILED_AGENT_INSTALL.exec(message);
84
+ if (agentInstall) return missingAgentHint(agentInstall[1], mobilecliVersion);
86
85
  const notFound = /Device "([^"]+)" not found/.exec(message);
87
86
  if (notFound) return deviceNotFoundHint(notFound[1]);
88
87
  if (/not in the list of allowed directories/.test(message)) return OUTSIDE_ALLOWED_DIRS_HINT;
@@ -59,7 +59,7 @@
59
59
  // the genuinely undetermined case (skipped, failed, timed out, unscoped)
60
60
  // leaves the envelope untouched.
61
61
 
62
- const { crashTimestampMs } = require('./crash-model');
62
+ const { crashTimestampMs, CrashListUnverifiableError } = require('./crash-model');
63
63
  const { record } = require('../observe/recorder');
64
64
 
65
65
  // The probe's own budget, deliberately far below the daemon's per-call timeout
@@ -189,6 +189,13 @@ async function probeCrashes({
189
189
  timeoutMs
190
190
  );
191
191
  } catch (err) {
192
+ // An iOS simulator's untrustworthy empty list (mobilecli#539) is an
193
+ // expected engine limitation, not a broken probe: info, not a warn on
194
+ // the user's stderr. Either way `crashes` stays absent ("unknown").
195
+ if (err instanceof CrashListUnverifiableError) {
196
+ record({ level: 'info', src: 'cli', event: 'crash.probe_unverifiable', verb }, recordOpts);
197
+ return;
198
+ }
192
199
  record(
193
200
  {
194
201
  level: 'warn',
@@ -37,6 +37,7 @@ const EVENT_NAMES = Object.freeze([
37
37
  'crash.probe_clear',
38
38
  'crash.probe_unscoped',
39
39
  'crash.probe_failed',
40
+ 'crash.probe_unverifiable',
40
41
  'crash.probe_timeout',
41
42
  'daemon.start',
42
43
  'daemon.stop',