agentlane 0.0.0 → 0.4.0-rc.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.
- package/CHANGELOG.md +118 -0
- package/LICENSE +27 -0
- package/README.md +167 -2
- package/dist/agents/claude-plugin.js +79 -0
- package/dist/agents/cli.js +258 -0
- package/dist/agents/detect.js +88 -0
- package/dist/agents/init.js +251 -0
- package/dist/agents/launcher.js +32 -0
- package/dist/agents/package.js +119 -0
- package/dist/agents/skills.js +59 -0
- package/dist/agents/toml.js +325 -0
- package/dist/agents/wiring-check.js +117 -0
- package/dist/agents/wiring.js +374 -0
- package/dist/bench/host.js +104 -0
- package/dist/bench/live.js +511 -0
- package/dist/bench/mcp-client.js +91 -0
- package/dist/bench/model.js +15 -0
- package/dist/bench/report.js +162 -0
- package/dist/bench/run.js +121 -0
- package/dist/bench/schedule.js +140 -0
- package/dist/bench/stats.js +59 -0
- package/dist/bench-cli.js +167 -0
- package/dist/browser/aria.js +184 -0
- package/dist/browser/control.js +203 -0
- package/dist/browser/env.js +118 -0
- package/dist/browser/evidence.js +44 -0
- package/dist/browser/install.js +361 -0
- package/dist/browser/kinds.js +10 -0
- package/dist/browser/lane-browser.js +224 -0
- package/dist/browser/libraries.js +56 -0
- package/dist/browser/paths.js +29 -0
- package/dist/browser/release.js +121 -0
- package/dist/browser/screen.js +19 -0
- package/dist/browser/signin.js +154 -0
- package/dist/browser/stop.js +163 -0
- package/dist/browser/tools.js +25 -0
- package/dist/cache/build.js +154 -0
- package/dist/cache/config.js +186 -0
- package/dist/cache/index.js +4 -0
- package/dist/cache/key.js +196 -0
- package/dist/cache/store.js +303 -0
- package/dist/cli.js +178 -0
- package/dist/clock.js +4 -0
- package/dist/devices/adb.js +160 -0
- package/dist/devices/android.js +214 -0
- package/dist/devices/backend.js +7 -0
- package/dist/devices/bundler.js +46 -0
- package/dist/devices/common.js +51 -0
- package/dist/devices/controls.js +65 -0
- package/dist/devices/dial.js +56 -0
- package/dist/devices/emulator.js +396 -0
- package/dist/devices/hygiene.js +202 -0
- package/dist/devices/index.js +5 -0
- package/dist/devices/launch.js +76 -0
- package/dist/devices/simctl.js +119 -0
- package/dist/devices/tools.js +1 -0
- package/dist/devices/variant.js +99 -0
- package/dist/devices/xcrun.js +265 -0
- package/dist/driver/absence.js +54 -0
- package/dist/driver/caller.js +51 -0
- package/dist/driver/client.js +312 -0
- package/dist/driver/diff.js +180 -0
- package/dist/driver/elements.js +70 -0
- package/dist/driver/engine-main.js +13 -0
- package/dist/driver/engine.js +499 -0
- package/dist/driver/errors.js +11 -0
- package/dist/driver/exec.js +66 -0
- package/dist/driver/failure.js +156 -0
- package/dist/driver/flow.js +94 -0
- package/dist/driver/idle.js +100 -0
- package/dist/driver/images.js +68 -0
- package/dist/driver/install.js +272 -0
- package/dist/driver/lock.js +101 -0
- package/dist/driver/look.js +223 -0
- package/dist/driver/maestro-child.js +194 -0
- package/dist/driver/maestro-runs.js +46 -0
- package/dist/driver/paths.js +105 -0
- package/dist/driver/pixels.js +144 -0
- package/dist/driver/plan.js +108 -0
- package/dist/driver/release.js +7 -0
- package/dist/driver/runner.js +42 -0
- package/dist/driver/selector.js +91 -0
- package/dist/driver/session.js +474 -0
- package/dist/driver/suggest.js +86 -0
- package/dist/driver/supervisor.js +251 -0
- package/dist/driver/tree.js +426 -0
- package/dist/driver-cli.js +865 -0
- package/dist/evidence/device.js +177 -0
- package/dist/evidence/evidence.js +304 -0
- package/dist/evidence/files.js +92 -0
- package/dist/hooks/env.js +81 -0
- package/dist/hooks/run.js +101 -0
- package/dist/mcp/server.js +69 -0
- package/dist/mcp/tools.js +246 -0
- package/dist/name.js +22 -0
- package/dist/plugin/aims.js +465 -0
- package/dist/plugin/conventions.js +73 -0
- package/dist/plugin/guard.js +163 -0
- package/dist/plugin/hook-cli.js +216 -0
- package/dist/plugin/session-name.js +28 -0
- package/dist/plugin/shell.js +254 -0
- package/dist/processes.js +77 -0
- package/dist/project/config.js +316 -0
- package/dist/project/schema.js +335 -0
- package/dist/project/validate.js +224 -0
- package/dist/registry/config.js +142 -0
- package/dist/registry/format.js +22 -0
- package/dist/registry/owner.js +265 -0
- package/dist/registry/paths.js +50 -0
- package/dist/registry/ports.js +26 -0
- package/dist/registry/prune.js +160 -0
- package/dist/registry/refusal.js +53 -0
- package/dist/registry/registry.js +1027 -0
- package/dist/registry/resources.js +117 -0
- package/dist/registry/rows.js +115 -0
- package/dist/registry/status.js +85 -0
- package/dist/registry/store.js +274 -0
- package/dist/registry/types.js +1 -0
- package/dist/registry-cli.js +544 -0
- package/dist/services/services.js +268 -0
- package/dist/services/system.js +189 -0
- package/dist/up/deps.js +1 -0
- package/dist/up/doctor.js +424 -0
- package/dist/up/exec.js +133 -0
- package/dist/up/lane-files.js +75 -0
- package/dist/up/lane-services.js +38 -0
- package/dist/up/maestro-env.js +172 -0
- package/dist/up/preflight.js +232 -0
- package/dist/up/release.js +148 -0
- package/dist/up/resources.js +178 -0
- package/dist/up/restart.js +87 -0
- package/dist/up/setup.js +28 -0
- package/dist/up/up.js +610 -0
- package/dist/up-cli.js +258 -0
- package/dist/usage.js +16 -0
- package/package.json +58 -3
- package/schema/agentlane.schema.json +675 -0
- package/skills/create-verification-skill/LICENSE +21 -0
- package/skills/create-verification-skill/SKILL.md +88 -0
- package/skills/dev-loop/LICENSE +21 -0
- package/skills/dev-loop/SKILL.md +61 -0
- package/skills/device/SKILL.md +8 -0
- package/skills/drive/SKILL.md +64 -0
- package/skills/maintain-verification-skill/LICENSE +21 -0
- package/skills/maintain-verification-skill/SKILL.md +42 -0
- package/skills/setup/SKILL.md +80 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { isAlive, killGroup } from "./exec.js";
|
|
2
|
+
import { CallTimeout, ChildGone, MaestroChild, textOf } from "./maestro-child.js";
|
|
3
|
+
import { listeningPorts, processRows, runnersOn } from "./runner.js";
|
|
4
|
+
/** A Maestro session that failed again after one restart, or a call that can't safely be retried. */
|
|
5
|
+
export class SessionFailure extends Error {
|
|
6
|
+
name = 'SessionFailure';
|
|
7
|
+
kind;
|
|
8
|
+
attempts;
|
|
9
|
+
constructor(kind, attempts) {
|
|
10
|
+
super(attempts.join('; then '));
|
|
11
|
+
this.kind = kind;
|
|
12
|
+
this.attempts = attempts;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const DEFAULT_TIMEOUTS = { inspect_screen: 60_000, take_screenshot: 60_000, run: 600_000 };
|
|
16
|
+
// Maestro reports a device it lost this way, and a fresh session reaches it again.
|
|
17
|
+
const UNREACHABLE = /Device became unreachable/i;
|
|
18
|
+
// Maestro's MCP server says this when it opens a session for a device adb doesn't list at that moment. An emulator's
|
|
19
|
+
// adb transport drops now and then; the next call rebuilds the session (patch 0002) and reinstalls the driver.
|
|
20
|
+
const NOT_CONNECTED = /Device with id \S+ is not connected/i;
|
|
21
|
+
/**
|
|
22
|
+
* Keeps one warm `maestro mcp` session for one simulator. A session that dies is restarted once and the call retried
|
|
23
|
+
* when that is safe; a second failure surfaces as a SessionFailure. When the XCTest runner dies, the whole Maestro
|
|
24
|
+
* process group goes with it, so its xcodebuild can't relaunch a runner later, and the next call starts fresh.
|
|
25
|
+
*/
|
|
26
|
+
export class Supervisor {
|
|
27
|
+
options;
|
|
28
|
+
starting;
|
|
29
|
+
current;
|
|
30
|
+
runnerPid;
|
|
31
|
+
startedAt;
|
|
32
|
+
watch;
|
|
33
|
+
stopping = false;
|
|
34
|
+
lost;
|
|
35
|
+
starts = 0;
|
|
36
|
+
restarts = [];
|
|
37
|
+
constructor(options) {
|
|
38
|
+
this.options = options;
|
|
39
|
+
this.watch = setInterval(() => {
|
|
40
|
+
this.checkRunner();
|
|
41
|
+
}, options.runnerWatchMs ?? 500);
|
|
42
|
+
this.watch.unref();
|
|
43
|
+
}
|
|
44
|
+
log(line) {
|
|
45
|
+
this.options.log(line);
|
|
46
|
+
}
|
|
47
|
+
cleanUp(why) {
|
|
48
|
+
const cleanup = this.options.cleanup;
|
|
49
|
+
if (!cleanup)
|
|
50
|
+
return;
|
|
51
|
+
cleanup().catch((error) => {
|
|
52
|
+
this.log(`device cleanup after ${why} failed: ${error.message}`);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
checkRunner() {
|
|
56
|
+
const pid = this.runnerPid;
|
|
57
|
+
if (pid === undefined || isAlive(pid))
|
|
58
|
+
return;
|
|
59
|
+
this.drop(`its XCTest runner (pid ${String(pid)}) is gone`);
|
|
60
|
+
}
|
|
61
|
+
drop(reason) {
|
|
62
|
+
const child = this.current;
|
|
63
|
+
this.runnerPid = undefined;
|
|
64
|
+
if (!child)
|
|
65
|
+
return;
|
|
66
|
+
this.log(`dropping maestro ${String(child.pid)}: ${reason}`);
|
|
67
|
+
this.lost = reason;
|
|
68
|
+
this.current = undefined;
|
|
69
|
+
this.starting = undefined;
|
|
70
|
+
void child.kill();
|
|
71
|
+
}
|
|
72
|
+
ensure() {
|
|
73
|
+
if (this.stopping)
|
|
74
|
+
return Promise.reject(new SessionFailure('start-failed', ['the driver is stopping']));
|
|
75
|
+
if (this.current?.alive)
|
|
76
|
+
return Promise.resolve(this.current);
|
|
77
|
+
if (!this.starting) {
|
|
78
|
+
this.starts += 1;
|
|
79
|
+
const began = Date.now();
|
|
80
|
+
this.startedAt = began;
|
|
81
|
+
const starting = MaestroChild.start({
|
|
82
|
+
...this.options,
|
|
83
|
+
log: line => {
|
|
84
|
+
this.log(line);
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
this.starting = starting;
|
|
88
|
+
starting.then(child => {
|
|
89
|
+
if (this.starting !== starting) {
|
|
90
|
+
void child.kill();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.current = child;
|
|
94
|
+
this.log(`maestro ${String(child.pid)} answered initialize in ${String(Date.now() - began)} ms`);
|
|
95
|
+
void child.exited.then(why => {
|
|
96
|
+
if (this.current === child) {
|
|
97
|
+
this.current = undefined;
|
|
98
|
+
this.runnerPid = undefined;
|
|
99
|
+
if (!this.stopping) {
|
|
100
|
+
this.lost ??= `Maestro ${why}`;
|
|
101
|
+
this.cleanUp(`Maestro ${why}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (this.starting === starting)
|
|
105
|
+
this.starting = undefined;
|
|
106
|
+
});
|
|
107
|
+
}, () => {
|
|
108
|
+
if (this.starting === starting)
|
|
109
|
+
this.starting = undefined;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return this.starting;
|
|
113
|
+
}
|
|
114
|
+
async restart(reason) {
|
|
115
|
+
this.log(`restarting maestro: ${reason}`);
|
|
116
|
+
this.restarts.push(reason);
|
|
117
|
+
const old = this.current;
|
|
118
|
+
this.current = undefined;
|
|
119
|
+
this.starting = undefined;
|
|
120
|
+
this.runnerPid = undefined;
|
|
121
|
+
if (old)
|
|
122
|
+
await old.kill();
|
|
123
|
+
}
|
|
124
|
+
async adoptRunner() {
|
|
125
|
+
if (this.options.platform !== 'ios' || this.runnerPid !== undefined)
|
|
126
|
+
return;
|
|
127
|
+
const rows = await (this.options.rows ?? processRows)();
|
|
128
|
+
const runners = runnersOn(rows, this.options.deviceId);
|
|
129
|
+
const newest = runners.reduce((best, row) => (best && best.pid > row.pid ? best : row), undefined);
|
|
130
|
+
if (newest) {
|
|
131
|
+
this.runnerPid = newest.pid;
|
|
132
|
+
this.log(`watching the XCTest runner, pid ${String(newest.pid)}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Calls a Maestro tool on this simulator. Returns `respawned` when the session had to be rebuilt first, so the
|
|
137
|
+
* caller can say so: a rebuilt session lost whatever the old runner held.
|
|
138
|
+
*/
|
|
139
|
+
async call(name, args, options) {
|
|
140
|
+
const attempts = [];
|
|
141
|
+
let respawned = this.lost !== undefined;
|
|
142
|
+
if (this.lost !== undefined)
|
|
143
|
+
attempts.push(this.lost);
|
|
144
|
+
this.lost = undefined;
|
|
145
|
+
const timeoutMs = this.options.timeouts?.[name] ?? DEFAULT_TIMEOUTS[name] ?? 60_000;
|
|
146
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
147
|
+
let child;
|
|
148
|
+
try {
|
|
149
|
+
child = await this.ensure();
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
attempts.push(`Maestro didn't start: ${error.message}`);
|
|
153
|
+
if (attempt === 0 && !this.stopping) {
|
|
154
|
+
respawned = true;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
throw new SessionFailure('start-failed', attempts);
|
|
158
|
+
}
|
|
159
|
+
let result;
|
|
160
|
+
try {
|
|
161
|
+
result = await child.callTool(name, { ...args, device_id: this.options.deviceId }, timeoutMs);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
if (error instanceof CallTimeout) {
|
|
165
|
+
attempts.push(error.message);
|
|
166
|
+
await this.restart(error.message);
|
|
167
|
+
throw new SessionFailure('timeout', attempts);
|
|
168
|
+
}
|
|
169
|
+
if (error instanceof ChildGone) {
|
|
170
|
+
attempts.push(`${error.message} during ${name}`);
|
|
171
|
+
await this.restart(error.message);
|
|
172
|
+
if (options.retry && attempt === 0 && !this.stopping) {
|
|
173
|
+
respawned = true;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
throw new SessionFailure('session-died', attempts);
|
|
177
|
+
}
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
if (result.isError && NOT_CONNECTED.test(textOf(result))) {
|
|
181
|
+
attempts.push(textOf(result));
|
|
182
|
+
this.log(`${name}: ${textOf(result)}`);
|
|
183
|
+
if (options.retry && attempt === 0 && !this.stopping) {
|
|
184
|
+
await new Promise(resolve => setTimeout(resolve, this.options.pauseMs ?? 500));
|
|
185
|
+
respawned = true;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
throw new SessionFailure('unreachable', attempts);
|
|
189
|
+
}
|
|
190
|
+
if (result.isError && UNREACHABLE.test(textOf(result))) {
|
|
191
|
+
attempts.push(textOf(result));
|
|
192
|
+
await this.restart(textOf(result));
|
|
193
|
+
if (options.retry && attempt === 0 && !this.stopping) {
|
|
194
|
+
respawned = true;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
throw new SessionFailure('unreachable', attempts);
|
|
198
|
+
}
|
|
199
|
+
if (this.startedAt !== undefined) {
|
|
200
|
+
this.log(`first ${name} on this Maestro answered ${String(Date.now() - this.startedAt)} ms after it was spawned`);
|
|
201
|
+
this.startedAt = undefined;
|
|
202
|
+
}
|
|
203
|
+
await this.adoptRunner();
|
|
204
|
+
return { result, respawned };
|
|
205
|
+
}
|
|
206
|
+
throw new SessionFailure('session-died', attempts);
|
|
207
|
+
}
|
|
208
|
+
async status() {
|
|
209
|
+
return {
|
|
210
|
+
maestroPid: this.current?.pid,
|
|
211
|
+
runnerPid: this.runnerPid,
|
|
212
|
+
runnerPorts: this.runnerPid === undefined ? [] : await listeningPorts(this.runnerPid),
|
|
213
|
+
starts: this.starts,
|
|
214
|
+
restarts: [...this.restarts],
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Stops Maestro (which stops its runner and xcodebuild, or on Android uninstalls its driver), then kills whatever of
|
|
219
|
+
* that is left. `clean: false` kills Maestro without its own shutdown and leaves the device alone: for a device the
|
|
220
|
+
* lane no longer holds, where that shutdown would uninstall the driver from under its new holder.
|
|
221
|
+
*/
|
|
222
|
+
async stop(options = {}) {
|
|
223
|
+
const clean = options.clean !== false;
|
|
224
|
+
this.stopping = true;
|
|
225
|
+
clearInterval(this.watch);
|
|
226
|
+
const runner = this.runnerPid;
|
|
227
|
+
const pending = this.starting;
|
|
228
|
+
const child = this.current ?? (pending ? await pending.catch(() => undefined) : undefined);
|
|
229
|
+
if (child) {
|
|
230
|
+
const pid = child.pid;
|
|
231
|
+
if (clean)
|
|
232
|
+
await child.stop();
|
|
233
|
+
else
|
|
234
|
+
await child.kill();
|
|
235
|
+
killGroup(pid);
|
|
236
|
+
}
|
|
237
|
+
if (clean && this.options.platform === 'android' && this.options.cleanup) {
|
|
238
|
+
await this.options.cleanup().catch((error) => {
|
|
239
|
+
this.log(`device cleanup after the stop failed: ${error.message}`);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
if (runner !== undefined && isAlive(runner)) {
|
|
243
|
+
this.log(`stopping the XCTest runner, pid ${String(runner)}`);
|
|
244
|
+
killGroup(runner, 'SIGTERM');
|
|
245
|
+
for (let waited = 0; waited < 2000 && isAlive(runner); waited += 100)
|
|
246
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
247
|
+
if (isAlive(runner))
|
|
248
|
+
killGroup(runner);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
// XCUIElement.ElementType raw values, in Apple's declaration order (XCUIElementTypes.h).
|
|
2
|
+
const XCUI_ELEMENT_TYPES = [
|
|
3
|
+
'Any',
|
|
4
|
+
'Other',
|
|
5
|
+
'Application',
|
|
6
|
+
'Group',
|
|
7
|
+
'Window',
|
|
8
|
+
'Sheet',
|
|
9
|
+
'Drawer',
|
|
10
|
+
'Alert',
|
|
11
|
+
'Dialog',
|
|
12
|
+
'Button',
|
|
13
|
+
'RadioButton',
|
|
14
|
+
'RadioGroup',
|
|
15
|
+
'CheckBox',
|
|
16
|
+
'DisclosureTriangle',
|
|
17
|
+
'PopUpButton',
|
|
18
|
+
'ComboBox',
|
|
19
|
+
'MenuButton',
|
|
20
|
+
'ToolbarButton',
|
|
21
|
+
'Popover',
|
|
22
|
+
'Keyboard',
|
|
23
|
+
'Key',
|
|
24
|
+
'NavigationBar',
|
|
25
|
+
'TabBar',
|
|
26
|
+
'TabGroup',
|
|
27
|
+
'Toolbar',
|
|
28
|
+
'StatusBar',
|
|
29
|
+
'Table',
|
|
30
|
+
'TableRow',
|
|
31
|
+
'TableColumn',
|
|
32
|
+
'Outline',
|
|
33
|
+
'OutlineRow',
|
|
34
|
+
'Browser',
|
|
35
|
+
'CollectionView',
|
|
36
|
+
'Slider',
|
|
37
|
+
'PageIndicator',
|
|
38
|
+
'ProgressIndicator',
|
|
39
|
+
'ActivityIndicator',
|
|
40
|
+
'SegmentedControl',
|
|
41
|
+
'Picker',
|
|
42
|
+
'PickerWheel',
|
|
43
|
+
'Switch',
|
|
44
|
+
'Toggle',
|
|
45
|
+
'Link',
|
|
46
|
+
'Image',
|
|
47
|
+
'Icon',
|
|
48
|
+
'SearchField',
|
|
49
|
+
'ScrollView',
|
|
50
|
+
'ScrollBar',
|
|
51
|
+
'StaticText',
|
|
52
|
+
'TextField',
|
|
53
|
+
'SecureTextField',
|
|
54
|
+
'DatePicker',
|
|
55
|
+
'TextView',
|
|
56
|
+
'Menu',
|
|
57
|
+
'MenuItem',
|
|
58
|
+
'MenuBar',
|
|
59
|
+
'MenuBarItem',
|
|
60
|
+
'Map',
|
|
61
|
+
'WebView',
|
|
62
|
+
'IncrementArrow',
|
|
63
|
+
'DecrementArrow',
|
|
64
|
+
'Timeline',
|
|
65
|
+
'RatingIndicator',
|
|
66
|
+
'ValueIndicator',
|
|
67
|
+
'SplitGroup',
|
|
68
|
+
'Splitter',
|
|
69
|
+
'RelevanceIndicator',
|
|
70
|
+
'ColorWell',
|
|
71
|
+
'HelpTag',
|
|
72
|
+
'Matte',
|
|
73
|
+
'DockItem',
|
|
74
|
+
'Ruler',
|
|
75
|
+
'RulerMarker',
|
|
76
|
+
'Grid',
|
|
77
|
+
'LevelIndicator',
|
|
78
|
+
'Cell',
|
|
79
|
+
'LayoutArea',
|
|
80
|
+
'LayoutItem',
|
|
81
|
+
'Handle',
|
|
82
|
+
'Stepper',
|
|
83
|
+
'Tab',
|
|
84
|
+
'TouchBar',
|
|
85
|
+
'StatusItem',
|
|
86
|
+
];
|
|
87
|
+
const ROLE_BY_TYPE = {
|
|
88
|
+
Application: 'app',
|
|
89
|
+
Window: 'window',
|
|
90
|
+
Group: 'group',
|
|
91
|
+
Sheet: 'sheet',
|
|
92
|
+
Drawer: 'sheet',
|
|
93
|
+
Popover: 'sheet',
|
|
94
|
+
Alert: 'alert',
|
|
95
|
+
Dialog: 'alert',
|
|
96
|
+
Button: 'button',
|
|
97
|
+
ToolbarButton: 'button',
|
|
98
|
+
PopUpButton: 'button',
|
|
99
|
+
MenuButton: 'button',
|
|
100
|
+
DisclosureTriangle: 'button',
|
|
101
|
+
IncrementArrow: 'button',
|
|
102
|
+
DecrementArrow: 'button',
|
|
103
|
+
RadioButton: 'checkbox',
|
|
104
|
+
CheckBox: 'checkbox',
|
|
105
|
+
Switch: 'switch',
|
|
106
|
+
Toggle: 'switch',
|
|
107
|
+
Link: 'link',
|
|
108
|
+
Cell: 'cell',
|
|
109
|
+
TableRow: 'cell',
|
|
110
|
+
OutlineRow: 'cell',
|
|
111
|
+
StaticText: 'text',
|
|
112
|
+
TextField: 'field',
|
|
113
|
+
ComboBox: 'field',
|
|
114
|
+
SecureTextField: 'secure-field',
|
|
115
|
+
SearchField: 'search',
|
|
116
|
+
TextView: 'textview',
|
|
117
|
+
Image: 'image',
|
|
118
|
+
Icon: 'icon',
|
|
119
|
+
DockItem: 'icon',
|
|
120
|
+
Keyboard: 'keyboard',
|
|
121
|
+
Key: 'key',
|
|
122
|
+
NavigationBar: 'navbar',
|
|
123
|
+
TabBar: 'tabbar',
|
|
124
|
+
TabGroup: 'tabbar',
|
|
125
|
+
Tab: 'tab',
|
|
126
|
+
Toolbar: 'toolbar',
|
|
127
|
+
StatusBar: 'statusbar',
|
|
128
|
+
Table: 'list',
|
|
129
|
+
Outline: 'list',
|
|
130
|
+
CollectionView: 'list',
|
|
131
|
+
Grid: 'list',
|
|
132
|
+
ScrollView: 'scroll',
|
|
133
|
+
Slider: 'slider',
|
|
134
|
+
Stepper: 'stepper',
|
|
135
|
+
Picker: 'picker',
|
|
136
|
+
PickerWheel: 'picker',
|
|
137
|
+
DatePicker: 'picker',
|
|
138
|
+
SegmentedControl: 'segmented',
|
|
139
|
+
ProgressIndicator: 'progress',
|
|
140
|
+
ActivityIndicator: 'progress',
|
|
141
|
+
PageIndicator: 'progress',
|
|
142
|
+
Menu: 'menu',
|
|
143
|
+
MenuItem: 'menuitem',
|
|
144
|
+
MenuBarItem: 'menuitem',
|
|
145
|
+
Map: 'map',
|
|
146
|
+
WebView: 'web',
|
|
147
|
+
};
|
|
148
|
+
export const INTERACTIVE_ROLES = new Set([
|
|
149
|
+
'button',
|
|
150
|
+
'cell',
|
|
151
|
+
'checkbox',
|
|
152
|
+
'field',
|
|
153
|
+
'icon',
|
|
154
|
+
'link',
|
|
155
|
+
'menuitem',
|
|
156
|
+
'picker',
|
|
157
|
+
'search',
|
|
158
|
+
'secure-field',
|
|
159
|
+
'segmented',
|
|
160
|
+
'slider',
|
|
161
|
+
'stepper',
|
|
162
|
+
'switch',
|
|
163
|
+
'tab',
|
|
164
|
+
'textview',
|
|
165
|
+
]);
|
|
166
|
+
// Android view classes by their simple name, as uiautomator reports them (a view's getAccessibilityClassName). React
|
|
167
|
+
// Native reports a view with an accessibilityRole under the matching widget class, and a Pressable without one as a
|
|
168
|
+
// clickable android.view.ViewGroup.
|
|
169
|
+
const ROLE_BY_ANDROID_CLASS = {
|
|
170
|
+
Button: 'button',
|
|
171
|
+
ImageButton: 'button',
|
|
172
|
+
AppCompatButton: 'button',
|
|
173
|
+
AppCompatImageButton: 'button',
|
|
174
|
+
MaterialButton: 'button',
|
|
175
|
+
FloatingActionButton: 'button',
|
|
176
|
+
ExtendedFloatingActionButton: 'button',
|
|
177
|
+
EditText: 'field',
|
|
178
|
+
AutoCompleteTextView: 'field',
|
|
179
|
+
MultiAutoCompleteTextView: 'field',
|
|
180
|
+
AppCompatEditText: 'field',
|
|
181
|
+
TextInputEditText: 'field',
|
|
182
|
+
Switch: 'switch',
|
|
183
|
+
SwitchCompat: 'switch',
|
|
184
|
+
SwitchMaterial: 'switch',
|
|
185
|
+
MaterialSwitch: 'switch',
|
|
186
|
+
ToggleButton: 'switch',
|
|
187
|
+
CheckBox: 'checkbox',
|
|
188
|
+
AppCompatCheckBox: 'checkbox',
|
|
189
|
+
MaterialCheckBox: 'checkbox',
|
|
190
|
+
RadioButton: 'checkbox',
|
|
191
|
+
AppCompatRadioButton: 'checkbox',
|
|
192
|
+
MaterialRadioButton: 'checkbox',
|
|
193
|
+
CheckedTextView: 'checkbox',
|
|
194
|
+
TextView: 'text',
|
|
195
|
+
AppCompatTextView: 'text',
|
|
196
|
+
MaterialTextView: 'text',
|
|
197
|
+
ImageView: 'image',
|
|
198
|
+
AppCompatImageView: 'image',
|
|
199
|
+
ShapeableImageView: 'image',
|
|
200
|
+
ScrollView: 'scroll',
|
|
201
|
+
HorizontalScrollView: 'scroll',
|
|
202
|
+
NestedScrollView: 'scroll',
|
|
203
|
+
RecyclerView: 'list',
|
|
204
|
+
ListView: 'list',
|
|
205
|
+
GridView: 'list',
|
|
206
|
+
SeekBar: 'slider',
|
|
207
|
+
AppCompatSeekBar: 'slider',
|
|
208
|
+
Slider: 'slider',
|
|
209
|
+
RangeSlider: 'slider',
|
|
210
|
+
RatingBar: 'slider',
|
|
211
|
+
ProgressBar: 'progress',
|
|
212
|
+
LinearProgressIndicator: 'progress',
|
|
213
|
+
CircularProgressIndicator: 'progress',
|
|
214
|
+
WebView: 'web',
|
|
215
|
+
Spinner: 'picker',
|
|
216
|
+
AppCompatSpinner: 'picker',
|
|
217
|
+
NumberPicker: 'picker',
|
|
218
|
+
DatePicker: 'picker',
|
|
219
|
+
TimePicker: 'picker',
|
|
220
|
+
TabWidget: 'tabbar',
|
|
221
|
+
TabLayout: 'tabbar',
|
|
222
|
+
Toolbar: 'toolbar',
|
|
223
|
+
MaterialToolbar: 'toolbar',
|
|
224
|
+
};
|
|
225
|
+
/** The role of an Android view: its class's, or a button for a clickable view whose class names no control. */
|
|
226
|
+
export function roleOfAndroidClass(className, clickable) {
|
|
227
|
+
const simple = className.slice(className.lastIndexOf('.') + 1);
|
|
228
|
+
const role = ROLE_BY_ANDROID_CLASS[simple] ?? 'other';
|
|
229
|
+
return clickable && !INTERACTIVE_ROLES.has(role) ? 'button' : role;
|
|
230
|
+
}
|
|
231
|
+
export function roleOfElementType(elementType) {
|
|
232
|
+
const name = typeof elementType === 'number' || /^\d+$/.test(elementType)
|
|
233
|
+
? XCUI_ELEMENT_TYPES[Number(elementType)]
|
|
234
|
+
: elementType.replace(/^XCUIElementType/, '');
|
|
235
|
+
return (name === undefined ? undefined : ROLE_BY_TYPE[name]) ?? 'other';
|
|
236
|
+
}
|
|
237
|
+
const BOUNDS = /^\[(-?\d+),(-?\d+)\]\[(-?\d+),(-?\d+)\]$/;
|
|
238
|
+
export function parseBounds(text) {
|
|
239
|
+
const match = BOUNDS.exec(text ?? '');
|
|
240
|
+
if (!match)
|
|
241
|
+
return undefined;
|
|
242
|
+
const [x1, y1, x2, y2] = match.slice(1).map(Number);
|
|
243
|
+
return { x1, y1, x2, y2 };
|
|
244
|
+
}
|
|
245
|
+
export function formatBounds(rect) {
|
|
246
|
+
return `[${String(rect.x1)},${String(rect.y1)}][${String(rect.x2)},${String(rect.y2)}]`;
|
|
247
|
+
}
|
|
248
|
+
export function area(rect) {
|
|
249
|
+
return Math.max(0, rect.x2 - rect.x1) * Math.max(0, rect.y2 - rect.y1);
|
|
250
|
+
}
|
|
251
|
+
export function intersects(a, b) {
|
|
252
|
+
return a.x1 < b.x2 && b.x1 < a.x2 && a.y1 < b.y2 && b.y1 < a.y2;
|
|
253
|
+
}
|
|
254
|
+
function str(value) {
|
|
255
|
+
return typeof value === 'string' ? value : '';
|
|
256
|
+
}
|
|
257
|
+
function isRecord(value) {
|
|
258
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
259
|
+
}
|
|
260
|
+
function records(value) {
|
|
261
|
+
return Array.isArray(value) ? value.filter(isRecord) : [];
|
|
262
|
+
}
|
|
263
|
+
function screenOf(root) {
|
|
264
|
+
const queue = [root];
|
|
265
|
+
for (let node = queue.shift(); node; node = queue.shift()) {
|
|
266
|
+
if (node.bounds && area(node.bounds) > 0)
|
|
267
|
+
return node.bounds;
|
|
268
|
+
queue.push(...node.children);
|
|
269
|
+
}
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
// An Android read holds one tree per window, the status and navigation bars' among them, and uiautomator clips every
|
|
273
|
+
// node's bounds to the display, so the largest node is the display.
|
|
274
|
+
function androidScreenOf(root) {
|
|
275
|
+
let best;
|
|
276
|
+
const walk = (node) => {
|
|
277
|
+
if (node.bounds && area(node.bounds) > (best ? area(best) : 0))
|
|
278
|
+
best = node.bounds;
|
|
279
|
+
node.children.forEach(walk);
|
|
280
|
+
};
|
|
281
|
+
walk(root);
|
|
282
|
+
return best;
|
|
283
|
+
}
|
|
284
|
+
const SYSTEM_BAR_SHARE = 0.07;
|
|
285
|
+
const SYSTEM_UI_ID = 'com.android.systemui:id/';
|
|
286
|
+
function systemUiOnly(node) {
|
|
287
|
+
let ids = 0;
|
|
288
|
+
const walk = (n) => {
|
|
289
|
+
if (n.id !== '') {
|
|
290
|
+
if (!n.id.startsWith(SYSTEM_UI_ID))
|
|
291
|
+
return false;
|
|
292
|
+
ids += 1;
|
|
293
|
+
}
|
|
294
|
+
return n.children.every(walk);
|
|
295
|
+
};
|
|
296
|
+
return walk(node) && ids > 0;
|
|
297
|
+
}
|
|
298
|
+
function edgeStrip(bounds, screen) {
|
|
299
|
+
if (!bounds)
|
|
300
|
+
return false;
|
|
301
|
+
const width = screen.x2 - screen.x1;
|
|
302
|
+
const height = screen.y2 - screen.y1;
|
|
303
|
+
const across = bounds.x1 <= screen.x1 && bounds.x2 >= screen.x2;
|
|
304
|
+
const down = bounds.y1 <= screen.y1 && bounds.y2 >= screen.y2;
|
|
305
|
+
const atTopOrBottom = bounds.y1 <= screen.y1 || bounds.y2 >= screen.y2;
|
|
306
|
+
const atLeftOrRight = bounds.x1 <= screen.x1 || bounds.x2 >= screen.x2;
|
|
307
|
+
return ((across && atTopOrBottom && bounds.y2 - bounds.y1 <= height * SYSTEM_BAR_SHARE) ||
|
|
308
|
+
(down && atLeftOrRight && bounds.x2 - bounds.x1 <= width * SYSTEM_BAR_SHARE));
|
|
309
|
+
}
|
|
310
|
+
/** Drops Android's status and navigation bars: System UI windows drawn as a strip along an edge of the display. */
|
|
311
|
+
function withoutSystemBars(node, screen) {
|
|
312
|
+
return {
|
|
313
|
+
...node,
|
|
314
|
+
children: node.children
|
|
315
|
+
.filter(child => !(edgeStrip(child.bounds, screen) && systemUiOnly(child)))
|
|
316
|
+
.map(child => withoutSystemBars(child, screen)),
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
function finish(source, typed, root, android = false) {
|
|
320
|
+
const screen = android ? androidScreenOf(root) : screenOf(root);
|
|
321
|
+
if (!screen)
|
|
322
|
+
return { readable: false, source, reason: 'The screen read has no element with a size.' };
|
|
323
|
+
return { readable: true, source, typed, screen, root: android ? withoutSystemBars(root, screen) : root };
|
|
324
|
+
}
|
|
325
|
+
function fromCompact(element, android) {
|
|
326
|
+
const cls = str(element.cls);
|
|
327
|
+
return {
|
|
328
|
+
role: android ? roleOfAndroidClass(cls, element.clickable === true) : cls ? roleOfElementType(cls) : undefined,
|
|
329
|
+
id: str(element.rid),
|
|
330
|
+
label: str(element.a11y),
|
|
331
|
+
text: str(element.txt),
|
|
332
|
+
value: str(element.val),
|
|
333
|
+
hint: str(element.hint),
|
|
334
|
+
bounds: parseBounds(str(element.b)),
|
|
335
|
+
enabled: element.enabled !== false,
|
|
336
|
+
focused: element.focused === true,
|
|
337
|
+
selected: element.selected === true,
|
|
338
|
+
checked: element.checked === true,
|
|
339
|
+
children: records(element.c).map(child => fromCompact(child, android)),
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
/** Parses Maestro's `inspect_screen` text: compact JSON with `ui_schema` and `elements`, after any prose prefix. */
|
|
343
|
+
export function parseInspectScreen(output) {
|
|
344
|
+
const start = output.indexOf('{');
|
|
345
|
+
if (start < 0)
|
|
346
|
+
return { readable: false, source: 'inspect_screen', reason: unreadableText(output) };
|
|
347
|
+
let data;
|
|
348
|
+
try {
|
|
349
|
+
data = JSON.parse(output.slice(start));
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
return { readable: false, source: 'inspect_screen', reason: unreadableText(output) };
|
|
353
|
+
}
|
|
354
|
+
if (!isRecord(data) || !Array.isArray(data.elements)) {
|
|
355
|
+
return { readable: false, source: 'inspect_screen', reason: 'The screen read has no element list.' };
|
|
356
|
+
}
|
|
357
|
+
const android = isRecord(data.ui_schema) && data.ui_schema.platform === 'android';
|
|
358
|
+
const children = records(data.elements).map(element => fromCompact(element, android));
|
|
359
|
+
const typed = children.length > 0 &&
|
|
360
|
+
children.every(function hasRole(node) {
|
|
361
|
+
return node.role !== undefined && node.children.every(hasRole);
|
|
362
|
+
});
|
|
363
|
+
const root = { ...emptyNode(), children };
|
|
364
|
+
return finish('inspect_screen', typed, root, android);
|
|
365
|
+
}
|
|
366
|
+
function unreadableText(output) {
|
|
367
|
+
const firstLine = output.trim().split('\n')[0] ?? '';
|
|
368
|
+
return firstLine ? `The screen read is not a view tree: ${firstLine.slice(0, 200)}` : 'The screen read is empty.';
|
|
369
|
+
}
|
|
370
|
+
function fromAxElement(element) {
|
|
371
|
+
const frame = isRecord(element.frame) ? element.frame : {};
|
|
372
|
+
const x = Number(frame.X ?? 0);
|
|
373
|
+
const y = Number(frame.Y ?? 0);
|
|
374
|
+
const title = str(element.title);
|
|
375
|
+
const value = str(element.value);
|
|
376
|
+
const role = roleOfElementType(typeof element.elementType === 'number' ? element.elementType : 0);
|
|
377
|
+
return {
|
|
378
|
+
role,
|
|
379
|
+
id: str(element.identifier),
|
|
380
|
+
label: str(element.label),
|
|
381
|
+
text: title || value,
|
|
382
|
+
value,
|
|
383
|
+
hint: str(element.placeholderValue),
|
|
384
|
+
bounds: {
|
|
385
|
+
x1: Math.trunc(x),
|
|
386
|
+
y1: Math.trunc(y),
|
|
387
|
+
x2: Math.trunc(x + Number(frame.Width ?? 0)),
|
|
388
|
+
y2: Math.trunc(y + Number(frame.Height ?? 0)),
|
|
389
|
+
},
|
|
390
|
+
enabled: element.enabled !== false,
|
|
391
|
+
focused: element.hasFocus === true,
|
|
392
|
+
selected: element.selected === true,
|
|
393
|
+
checked: (role === 'switch' || role === 'checkbox') && value === '1',
|
|
394
|
+
children: records(element.children).map(fromAxElement),
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
/** Parses the iOS runner's `/viewHierarchy` response (`{depth, axElement}`), which carries element types. */
|
|
398
|
+
export function parseRunnerHierarchy(output) {
|
|
399
|
+
let data;
|
|
400
|
+
try {
|
|
401
|
+
data = JSON.parse(output);
|
|
402
|
+
}
|
|
403
|
+
catch {
|
|
404
|
+
return { readable: false, source: 'runner', reason: unreadableText(output) };
|
|
405
|
+
}
|
|
406
|
+
if (!isRecord(data) || !isRecord(data.axElement)) {
|
|
407
|
+
return { readable: false, source: 'runner', reason: 'The screen read has no root element.' };
|
|
408
|
+
}
|
|
409
|
+
return finish('runner', true, fromAxElement(data.axElement));
|
|
410
|
+
}
|
|
411
|
+
export function emptyNode() {
|
|
412
|
+
return {
|
|
413
|
+
role: undefined,
|
|
414
|
+
id: '',
|
|
415
|
+
label: '',
|
|
416
|
+
text: '',
|
|
417
|
+
value: '',
|
|
418
|
+
hint: '',
|
|
419
|
+
bounds: undefined,
|
|
420
|
+
enabled: true,
|
|
421
|
+
focused: false,
|
|
422
|
+
selected: false,
|
|
423
|
+
checked: false,
|
|
424
|
+
children: [],
|
|
425
|
+
};
|
|
426
|
+
}
|