agent-device 0.4.2 → 0.5.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/README.md +2 -9
- package/dist/src/797.js +1 -1
- package/dist/src/bin.js +5 -5
- package/dist/src/daemon.js +16 -20
- package/package.json +7 -9
- package/skills/agent-device/SKILL.md +3 -6
- package/skills/agent-device/references/permissions.md +3 -15
- package/skills/agent-device/references/snapshot-refs.md +1 -4
- package/dist/bin/axsnapshot +0 -0
- package/ios-runner/AXSnapshot/Package.swift +0 -18
- package/ios-runner/AXSnapshot/Sources/AXSnapshot/main.swift +0 -444
- package/src/__tests__/cli-close.test.ts +0 -155
- package/src/__tests__/cli-help.test.ts +0 -102
- package/src/bin.ts +0 -3
- package/src/cli.ts +0 -305
- package/src/core/__tests__/capabilities.test.ts +0 -75
- package/src/core/__tests__/dispatch-open.test.ts +0 -25
- package/src/core/__tests__/open-target.test.ts +0 -55
- package/src/core/capabilities.ts +0 -57
- package/src/core/dispatch.ts +0 -382
- package/src/core/open-target.ts +0 -27
- package/src/daemon/__tests__/device-ready.test.ts +0 -52
- package/src/daemon/__tests__/is-predicates.test.ts +0 -68
- package/src/daemon/__tests__/selectors.test.ts +0 -261
- package/src/daemon/__tests__/session-routing.test.ts +0 -108
- package/src/daemon/__tests__/session-selector.test.ts +0 -64
- package/src/daemon/__tests__/session-store.test.ts +0 -142
- package/src/daemon/__tests__/snapshot-processing.test.ts +0 -47
- package/src/daemon/action-utils.ts +0 -29
- package/src/daemon/context.ts +0 -48
- package/src/daemon/device-ready.ts +0 -155
- package/src/daemon/handlers/__tests__/find.test.ts +0 -99
- package/src/daemon/handlers/__tests__/interaction.test.ts +0 -22
- package/src/daemon/handlers/__tests__/replay-heal.test.ts +0 -509
- package/src/daemon/handlers/__tests__/session-reinstall.test.ts +0 -219
- package/src/daemon/handlers/__tests__/session.test.ts +0 -820
- package/src/daemon/handlers/__tests__/snapshot-handler.test.ts +0 -92
- package/src/daemon/handlers/__tests__/snapshot.test.ts +0 -128
- package/src/daemon/handlers/find.ts +0 -324
- package/src/daemon/handlers/interaction.ts +0 -550
- package/src/daemon/handlers/parse-utils.ts +0 -8
- package/src/daemon/handlers/record-trace.ts +0 -154
- package/src/daemon/handlers/session.ts +0 -1137
- package/src/daemon/handlers/snapshot.ts +0 -439
- package/src/daemon/is-predicates.ts +0 -46
- package/src/daemon/selectors.ts +0 -540
- package/src/daemon/session-routing.ts +0 -22
- package/src/daemon/session-selector.ts +0 -39
- package/src/daemon/session-store.ts +0 -296
- package/src/daemon/snapshot-processing.ts +0 -131
- package/src/daemon/types.ts +0 -56
- package/src/daemon-client.ts +0 -272
- package/src/daemon.ts +0 -295
- package/src/platforms/__tests__/boot-diagnostics.test.ts +0 -59
- package/src/platforms/android/__tests__/index.test.ts +0 -274
- package/src/platforms/android/devices.ts +0 -196
- package/src/platforms/android/index.ts +0 -784
- package/src/platforms/android/ui-hierarchy.ts +0 -312
- package/src/platforms/boot-diagnostics.ts +0 -128
- package/src/platforms/ios/__tests__/index.test.ts +0 -312
- package/src/platforms/ios/__tests__/runner-client.test.ts +0 -155
- package/src/platforms/ios/apps.ts +0 -358
- package/src/platforms/ios/ax-snapshot.ts +0 -207
- package/src/platforms/ios/config.ts +0 -28
- package/src/platforms/ios/devicectl.ts +0 -134
- package/src/platforms/ios/devices.ts +0 -100
- package/src/platforms/ios/index.ts +0 -20
- package/src/platforms/ios/runner-client.ts +0 -994
- package/src/platforms/ios/simulator.ts +0 -164
- package/src/utils/__tests__/args.test.ts +0 -239
- package/src/utils/__tests__/daemon-client.test.ts +0 -95
- package/src/utils/__tests__/exec.test.ts +0 -16
- package/src/utils/__tests__/finders.test.ts +0 -34
- package/src/utils/__tests__/keyed-lock.test.ts +0 -55
- package/src/utils/__tests__/process-identity.test.ts +0 -33
- package/src/utils/__tests__/retry.test.ts +0 -44
- package/src/utils/args.ts +0 -239
- package/src/utils/command-schema.ts +0 -622
- package/src/utils/device.ts +0 -84
- package/src/utils/errors.ts +0 -35
- package/src/utils/exec.ts +0 -339
- package/src/utils/finders.ts +0 -101
- package/src/utils/interactive.ts +0 -4
- package/src/utils/interactors.ts +0 -173
- package/src/utils/keyed-lock.ts +0 -14
- package/src/utils/output.ts +0 -204
- package/src/utils/process-identity.ts +0 -100
- package/src/utils/retry.ts +0 -180
- package/src/utils/snapshot.ts +0 -64
- package/src/utils/timeouts.ts +0 -9
- package/src/utils/version.ts +0 -26
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import {
|
|
4
|
-
IOS_SAFARI_BUNDLE_ID,
|
|
5
|
-
isDeepLinkTarget,
|
|
6
|
-
isWebUrl,
|
|
7
|
-
resolveIosDeviceDeepLinkBundleId,
|
|
8
|
-
} from '../open-target.ts';
|
|
9
|
-
|
|
10
|
-
test('isDeepLinkTarget accepts URL-style deep links', () => {
|
|
11
|
-
assert.equal(isDeepLinkTarget('myapp://home'), true);
|
|
12
|
-
assert.equal(isDeepLinkTarget('https://example.com'), true);
|
|
13
|
-
assert.equal(isDeepLinkTarget('tel:123456789'), true);
|
|
14
|
-
assert.equal(isDeepLinkTarget('mailto:test@example.com'), true);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('isDeepLinkTarget rejects app identifiers and malformed URLs', () => {
|
|
18
|
-
assert.equal(isDeepLinkTarget('com.example.app'), false);
|
|
19
|
-
assert.equal(isDeepLinkTarget('settings'), false);
|
|
20
|
-
assert.equal(isDeepLinkTarget('http:/x'), false);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('isWebUrl accepts http and https URLs', () => {
|
|
24
|
-
assert.equal(isWebUrl('https://example.com'), true);
|
|
25
|
-
assert.equal(isWebUrl('http://example.com/path'), true);
|
|
26
|
-
assert.equal(isWebUrl('https://example.com/path?q=1'), true);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('isWebUrl rejects custom schemes and non-URLs', () => {
|
|
30
|
-
assert.equal(isWebUrl('myapp://home'), false);
|
|
31
|
-
assert.equal(isWebUrl('tel:123456789'), false);
|
|
32
|
-
assert.equal(isWebUrl('com.example.app'), false);
|
|
33
|
-
assert.equal(isWebUrl('settings'), false);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('resolveIosDeviceDeepLinkBundleId prefers active app context', () => {
|
|
37
|
-
assert.equal(
|
|
38
|
-
resolveIosDeviceDeepLinkBundleId('com.example.app', 'myapp://home'),
|
|
39
|
-
'com.example.app',
|
|
40
|
-
);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('resolveIosDeviceDeepLinkBundleId falls back to Safari for web URLs', () => {
|
|
44
|
-
assert.equal(
|
|
45
|
-
resolveIosDeviceDeepLinkBundleId(undefined, 'https://example.com/path'),
|
|
46
|
-
IOS_SAFARI_BUNDLE_ID,
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('resolveIosDeviceDeepLinkBundleId returns undefined for custom scheme without app context', () => {
|
|
51
|
-
assert.equal(
|
|
52
|
-
resolveIosDeviceDeepLinkBundleId(undefined, 'myapp://home'),
|
|
53
|
-
undefined,
|
|
54
|
-
);
|
|
55
|
-
});
|
package/src/core/capabilities.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { DeviceInfo } from '../utils/device.ts';
|
|
2
|
-
|
|
3
|
-
type KindMatrix = {
|
|
4
|
-
simulator?: boolean;
|
|
5
|
-
device?: boolean;
|
|
6
|
-
emulator?: boolean;
|
|
7
|
-
unknown?: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
type CommandCapability = {
|
|
11
|
-
ios?: KindMatrix;
|
|
12
|
-
android?: KindMatrix;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const COMMAND_CAPABILITY_MATRIX: Record<string, CommandCapability> = {
|
|
16
|
-
// iOS simulator-only.
|
|
17
|
-
alert: { ios: { simulator: true }, android: {} },
|
|
18
|
-
pinch: { ios: { simulator: true }, android: {} },
|
|
19
|
-
'app-switcher': { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
20
|
-
apps: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
21
|
-
back: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
22
|
-
boot: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
23
|
-
click: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
24
|
-
close: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
25
|
-
fill: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
26
|
-
find: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
27
|
-
focus: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
28
|
-
get: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
29
|
-
is: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
30
|
-
home: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
31
|
-
'long-press': { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
32
|
-
open: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
33
|
-
reinstall: { ios: { simulator: true }, android: { emulator: true, device: true, unknown: true } },
|
|
34
|
-
press: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
35
|
-
record: { ios: { simulator: true }, android: { emulator: true, device: true, unknown: true } },
|
|
36
|
-
screenshot: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
37
|
-
scroll: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
38
|
-
scrollintoview: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
39
|
-
swipe: { ios: { simulator: true }, android: { emulator: true, device: true, unknown: true } },
|
|
40
|
-
settings: { ios: { simulator: true }, android: { emulator: true, device: true, unknown: true } },
|
|
41
|
-
snapshot: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
42
|
-
type: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
43
|
-
wait: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export function isCommandSupportedOnDevice(command: string, device: DeviceInfo): boolean {
|
|
47
|
-
const capability = COMMAND_CAPABILITY_MATRIX[command];
|
|
48
|
-
if (!capability) return true;
|
|
49
|
-
const byPlatform = capability[device.platform];
|
|
50
|
-
if (!byPlatform) return false;
|
|
51
|
-
const kind = (device.kind ?? 'unknown') as keyof KindMatrix;
|
|
52
|
-
return byPlatform[kind] === true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function listCapabilityCommands(): string[] {
|
|
56
|
-
return Object.keys(COMMAND_CAPABILITY_MATRIX).sort();
|
|
57
|
-
}
|
package/src/core/dispatch.ts
DELETED
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'node:fs';
|
|
2
|
-
import pathModule from 'node:path';
|
|
3
|
-
import { AppError } from '../utils/errors.ts';
|
|
4
|
-
import { selectDevice, type DeviceInfo } from '../utils/device.ts';
|
|
5
|
-
import { listAndroidDevices } from '../platforms/android/devices.ts';
|
|
6
|
-
import {
|
|
7
|
-
appSwitcherAndroid,
|
|
8
|
-
backAndroid,
|
|
9
|
-
ensureAdb,
|
|
10
|
-
homeAndroid,
|
|
11
|
-
setAndroidSetting,
|
|
12
|
-
snapshotAndroid,
|
|
13
|
-
} from '../platforms/android/index.ts';
|
|
14
|
-
import { listIosDevices } from '../platforms/ios/devices.ts';
|
|
15
|
-
import { getInteractor, type RunnerContext } from '../utils/interactors.ts';
|
|
16
|
-
import { runIosRunnerCommand } from '../platforms/ios/runner-client.ts';
|
|
17
|
-
import { snapshotAx } from '../platforms/ios/ax-snapshot.ts';
|
|
18
|
-
import { setIosSetting } from '../platforms/ios/index.ts';
|
|
19
|
-
import { isDeepLinkTarget } from './open-target.ts';
|
|
20
|
-
import type { RawSnapshotNode } from '../utils/snapshot.ts';
|
|
21
|
-
import type { CliFlags } from '../utils/command-schema.ts';
|
|
22
|
-
|
|
23
|
-
export type CommandFlags = Omit<CliFlags, 'json' | 'help' | 'version'>;
|
|
24
|
-
|
|
25
|
-
export async function resolveTargetDevice(flags: CommandFlags): Promise<DeviceInfo> {
|
|
26
|
-
const selector = {
|
|
27
|
-
platform: flags.platform,
|
|
28
|
-
deviceName: flags.device,
|
|
29
|
-
udid: flags.udid,
|
|
30
|
-
serial: flags.serial,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
if (selector.platform === 'android') {
|
|
34
|
-
await ensureAdb();
|
|
35
|
-
const devices = await listAndroidDevices();
|
|
36
|
-
return await selectDevice(devices, selector);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (selector.platform === 'ios') {
|
|
40
|
-
const devices = await listIosDevices();
|
|
41
|
-
return await selectDevice(devices, selector);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const devices: DeviceInfo[] = [];
|
|
45
|
-
try {
|
|
46
|
-
devices.push(...(await listAndroidDevices()));
|
|
47
|
-
} catch {
|
|
48
|
-
// ignore
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
devices.push(...(await listIosDevices()));
|
|
52
|
-
} catch {
|
|
53
|
-
// ignore
|
|
54
|
-
}
|
|
55
|
-
return await selectDevice(devices, selector);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async function dispatchCommand(
|
|
59
|
-
device: DeviceInfo,
|
|
60
|
-
command: string,
|
|
61
|
-
positionals: string[],
|
|
62
|
-
outPath?: string,
|
|
63
|
-
context?: {
|
|
64
|
-
appBundleId?: string;
|
|
65
|
-
activity?: string;
|
|
66
|
-
verbose?: boolean;
|
|
67
|
-
logPath?: string;
|
|
68
|
-
traceLogPath?: string;
|
|
69
|
-
snapshotInteractiveOnly?: boolean;
|
|
70
|
-
snapshotCompact?: boolean;
|
|
71
|
-
snapshotDepth?: number;
|
|
72
|
-
snapshotScope?: string;
|
|
73
|
-
snapshotRaw?: boolean;
|
|
74
|
-
snapshotBackend?: 'ax' | 'xctest';
|
|
75
|
-
count?: number;
|
|
76
|
-
intervalMs?: number;
|
|
77
|
-
holdMs?: number;
|
|
78
|
-
jitterPx?: number;
|
|
79
|
-
pauseMs?: number;
|
|
80
|
-
pattern?: 'one-way' | 'ping-pong';
|
|
81
|
-
},
|
|
82
|
-
): Promise<Record<string, unknown> | void> {
|
|
83
|
-
const runnerCtx: RunnerContext = {
|
|
84
|
-
appBundleId: context?.appBundleId,
|
|
85
|
-
verbose: context?.verbose,
|
|
86
|
-
logPath: context?.logPath,
|
|
87
|
-
traceLogPath: context?.traceLogPath,
|
|
88
|
-
};
|
|
89
|
-
const interactor = getInteractor(device, runnerCtx);
|
|
90
|
-
switch (command) {
|
|
91
|
-
case 'open': {
|
|
92
|
-
const app = positionals[0];
|
|
93
|
-
const url = positionals[1];
|
|
94
|
-
if (positionals.length > 2) {
|
|
95
|
-
throw new AppError('INVALID_ARGS', 'open accepts at most two arguments: <app|url> [url]');
|
|
96
|
-
}
|
|
97
|
-
if (!app) {
|
|
98
|
-
await interactor.openDevice();
|
|
99
|
-
return { app: null };
|
|
100
|
-
}
|
|
101
|
-
if (url !== undefined) {
|
|
102
|
-
if (device.platform !== 'ios') {
|
|
103
|
-
throw new AppError('INVALID_ARGS', 'open <app> <url> is supported only on iOS');
|
|
104
|
-
}
|
|
105
|
-
if (isDeepLinkTarget(app)) {
|
|
106
|
-
throw new AppError('INVALID_ARGS', 'open <app> <url> requires an app target as the first argument');
|
|
107
|
-
}
|
|
108
|
-
if (!isDeepLinkTarget(url)) {
|
|
109
|
-
throw new AppError('INVALID_ARGS', 'open <app> <url> requires a valid URL target');
|
|
110
|
-
}
|
|
111
|
-
await interactor.open(app, {
|
|
112
|
-
activity: context?.activity,
|
|
113
|
-
appBundleId: context?.appBundleId,
|
|
114
|
-
url,
|
|
115
|
-
});
|
|
116
|
-
return { app, url };
|
|
117
|
-
}
|
|
118
|
-
await interactor.open(app, { activity: context?.activity, appBundleId: context?.appBundleId });
|
|
119
|
-
return { app };
|
|
120
|
-
}
|
|
121
|
-
case 'close': {
|
|
122
|
-
const app = positionals[0];
|
|
123
|
-
if (!app) {
|
|
124
|
-
return { closed: 'session' };
|
|
125
|
-
}
|
|
126
|
-
await interactor.close(app);
|
|
127
|
-
return { app };
|
|
128
|
-
}
|
|
129
|
-
case 'press': {
|
|
130
|
-
const [x, y] = positionals.map(Number);
|
|
131
|
-
if (Number.isNaN(x) || Number.isNaN(y)) throw new AppError('INVALID_ARGS', 'press requires x y');
|
|
132
|
-
const count = requireIntInRange(context?.count ?? 1, 'count', 1, 200);
|
|
133
|
-
const intervalMs = requireIntInRange(context?.intervalMs ?? 0, 'interval-ms', 0, 10_000);
|
|
134
|
-
const holdMs = requireIntInRange(context?.holdMs ?? 0, 'hold-ms', 0, 10_000);
|
|
135
|
-
const jitterPx = requireIntInRange(context?.jitterPx ?? 0, 'jitter-px', 0, 100);
|
|
136
|
-
|
|
137
|
-
for (let index = 0; index < count; index += 1) {
|
|
138
|
-
const [dx, dy] = computeDeterministicJitter(index, jitterPx);
|
|
139
|
-
const targetX = x + dx;
|
|
140
|
-
const targetY = y + dy;
|
|
141
|
-
if (holdMs > 0) await interactor.longPress(targetX, targetY, holdMs);
|
|
142
|
-
else await interactor.tap(targetX, targetY);
|
|
143
|
-
if (index < count - 1 && intervalMs > 0) await sleep(intervalMs);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return { x, y, count, intervalMs, holdMs, jitterPx };
|
|
147
|
-
}
|
|
148
|
-
case 'swipe': {
|
|
149
|
-
const x1 = Number(positionals[0]);
|
|
150
|
-
const y1 = Number(positionals[1]);
|
|
151
|
-
const x2 = Number(positionals[2]);
|
|
152
|
-
const y2 = Number(positionals[3]);
|
|
153
|
-
if ([x1, y1, x2, y2].some(Number.isNaN)) {
|
|
154
|
-
throw new AppError('INVALID_ARGS', 'swipe requires x1 y1 x2 y2 [durationMs]');
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const requestedDurationMs = positionals[4] ? Number(positionals[4]) : 250;
|
|
158
|
-
const durationMs = requireIntInRange(requestedDurationMs, 'durationMs', 16, 10_000);
|
|
159
|
-
const effectiveDurationMs = device.platform === 'ios' ? 60 : durationMs;
|
|
160
|
-
const count = requireIntInRange(context?.count ?? 1, 'count', 1, 200);
|
|
161
|
-
const pauseMs = requireIntInRange(context?.pauseMs ?? 0, 'pause-ms', 0, 10_000);
|
|
162
|
-
const pattern = context?.pattern ?? 'one-way';
|
|
163
|
-
if (pattern !== 'one-way' && pattern !== 'ping-pong') {
|
|
164
|
-
throw new AppError('INVALID_ARGS', `Invalid pattern: ${pattern}`);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
for (let index = 0; index < count; index += 1) {
|
|
168
|
-
const reverse = pattern === 'ping-pong' && index % 2 === 1;
|
|
169
|
-
if (reverse) await interactor.swipe(x2, y2, x1, y1, effectiveDurationMs);
|
|
170
|
-
else await interactor.swipe(x1, y1, x2, y2, effectiveDurationMs);
|
|
171
|
-
if (index < count - 1 && pauseMs > 0) await sleep(pauseMs);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return {
|
|
175
|
-
x1,
|
|
176
|
-
y1,
|
|
177
|
-
x2,
|
|
178
|
-
y2,
|
|
179
|
-
durationMs,
|
|
180
|
-
effectiveDurationMs,
|
|
181
|
-
timingMode: device.platform === 'ios' ? 'safe-normalized' : 'direct',
|
|
182
|
-
count,
|
|
183
|
-
pauseMs,
|
|
184
|
-
pattern,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
case 'long-press': {
|
|
188
|
-
const x = Number(positionals[0]);
|
|
189
|
-
const y = Number(positionals[1]);
|
|
190
|
-
const durationMs = positionals[2] ? Number(positionals[2]) : undefined;
|
|
191
|
-
if (Number.isNaN(x) || Number.isNaN(y)) {
|
|
192
|
-
throw new AppError('INVALID_ARGS', 'long-press requires x y [durationMs]');
|
|
193
|
-
}
|
|
194
|
-
await interactor.longPress(x, y, durationMs);
|
|
195
|
-
return { x, y, durationMs };
|
|
196
|
-
}
|
|
197
|
-
case 'focus': {
|
|
198
|
-
const [x, y] = positionals.map(Number);
|
|
199
|
-
if (Number.isNaN(x) || Number.isNaN(y)) throw new AppError('INVALID_ARGS', 'focus requires x y');
|
|
200
|
-
await interactor.focus(x, y);
|
|
201
|
-
return { x, y };
|
|
202
|
-
}
|
|
203
|
-
case 'type': {
|
|
204
|
-
const text = positionals.join(' ');
|
|
205
|
-
if (!text) throw new AppError('INVALID_ARGS', 'type requires text');
|
|
206
|
-
await interactor.type(text);
|
|
207
|
-
return { text };
|
|
208
|
-
}
|
|
209
|
-
case 'fill': {
|
|
210
|
-
const x = Number(positionals[0]);
|
|
211
|
-
const y = Number(positionals[1]);
|
|
212
|
-
const text = positionals.slice(2).join(' ');
|
|
213
|
-
if (Number.isNaN(x) || Number.isNaN(y) || !text) {
|
|
214
|
-
throw new AppError('INVALID_ARGS', 'fill requires x y text');
|
|
215
|
-
}
|
|
216
|
-
await interactor.fill(x, y, text);
|
|
217
|
-
return { x, y, text };
|
|
218
|
-
}
|
|
219
|
-
case 'scroll': {
|
|
220
|
-
const direction = positionals[0];
|
|
221
|
-
const amount = positionals[1] ? Number(positionals[1]) : undefined;
|
|
222
|
-
if (!direction) throw new AppError('INVALID_ARGS', 'scroll requires direction');
|
|
223
|
-
await interactor.scroll(direction, amount);
|
|
224
|
-
return { direction, amount };
|
|
225
|
-
}
|
|
226
|
-
case 'scrollintoview': {
|
|
227
|
-
const text = positionals.join(' ').trim();
|
|
228
|
-
if (!text) throw new AppError('INVALID_ARGS', 'scrollintoview requires text');
|
|
229
|
-
const result = await interactor.scrollIntoView(text);
|
|
230
|
-
if (result?.attempts) return { text, attempts: result.attempts };
|
|
231
|
-
return { text };
|
|
232
|
-
}
|
|
233
|
-
case 'pinch': {
|
|
234
|
-
if (device.platform === 'android') {
|
|
235
|
-
throw new AppError(
|
|
236
|
-
'UNSUPPORTED_OPERATION',
|
|
237
|
-
'Android pinch is not supported in current adb backend; requires instrumentation-based backend.',
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
const scale = Number(positionals[0]);
|
|
241
|
-
const x = positionals[1] ? Number(positionals[1]) : undefined;
|
|
242
|
-
const y = positionals[2] ? Number(positionals[2]) : undefined;
|
|
243
|
-
if (Number.isNaN(scale) || scale <= 0) {
|
|
244
|
-
throw new AppError('INVALID_ARGS', 'pinch requires scale > 0');
|
|
245
|
-
}
|
|
246
|
-
await runIosRunnerCommand(
|
|
247
|
-
device,
|
|
248
|
-
{ command: 'pinch', scale, x, y, appBundleId: context?.appBundleId },
|
|
249
|
-
{ verbose: context?.verbose, logPath: context?.logPath, traceLogPath: context?.traceLogPath },
|
|
250
|
-
);
|
|
251
|
-
return { scale, x, y };
|
|
252
|
-
}
|
|
253
|
-
case 'screenshot': {
|
|
254
|
-
const positionalPath = positionals[0];
|
|
255
|
-
const screenshotPath = positionalPath ?? outPath ?? `./screenshot-${Date.now()}.png`;
|
|
256
|
-
await fs.mkdir(pathModule.dirname(screenshotPath), { recursive: true });
|
|
257
|
-
await interactor.screenshot(screenshotPath);
|
|
258
|
-
return { path: screenshotPath };
|
|
259
|
-
}
|
|
260
|
-
case 'back': {
|
|
261
|
-
if (device.platform === 'ios') {
|
|
262
|
-
await runIosRunnerCommand(
|
|
263
|
-
device,
|
|
264
|
-
{ command: 'back', appBundleId: context?.appBundleId },
|
|
265
|
-
{ verbose: context?.verbose, logPath: context?.logPath, traceLogPath: context?.traceLogPath },
|
|
266
|
-
);
|
|
267
|
-
return { action: 'back' };
|
|
268
|
-
}
|
|
269
|
-
await backAndroid(device);
|
|
270
|
-
return { action: 'back' };
|
|
271
|
-
}
|
|
272
|
-
case 'home': {
|
|
273
|
-
if (device.platform === 'ios') {
|
|
274
|
-
await runIosRunnerCommand(
|
|
275
|
-
device,
|
|
276
|
-
{ command: 'home', appBundleId: context?.appBundleId },
|
|
277
|
-
{ verbose: context?.verbose, logPath: context?.logPath, traceLogPath: context?.traceLogPath },
|
|
278
|
-
);
|
|
279
|
-
return { action: 'home' };
|
|
280
|
-
}
|
|
281
|
-
await homeAndroid(device);
|
|
282
|
-
return { action: 'home' };
|
|
283
|
-
}
|
|
284
|
-
case 'app-switcher': {
|
|
285
|
-
if (device.platform === 'ios') {
|
|
286
|
-
await runIosRunnerCommand(
|
|
287
|
-
device,
|
|
288
|
-
{ command: 'appSwitcher', appBundleId: context?.appBundleId },
|
|
289
|
-
{ verbose: context?.verbose, logPath: context?.logPath, traceLogPath: context?.traceLogPath },
|
|
290
|
-
);
|
|
291
|
-
return { action: 'app-switcher' };
|
|
292
|
-
}
|
|
293
|
-
await appSwitcherAndroid(device);
|
|
294
|
-
return { action: 'app-switcher' };
|
|
295
|
-
}
|
|
296
|
-
case 'settings': {
|
|
297
|
-
const [setting, state, appBundleId] = positionals;
|
|
298
|
-
if (device.platform === 'ios') {
|
|
299
|
-
await setIosSetting(device, setting, state, appBundleId ?? context?.appBundleId);
|
|
300
|
-
return { setting, state };
|
|
301
|
-
}
|
|
302
|
-
await setAndroidSetting(device, setting, state);
|
|
303
|
-
return { setting, state };
|
|
304
|
-
}
|
|
305
|
-
case 'snapshot': {
|
|
306
|
-
const backend = context?.snapshotBackend ?? 'xctest';
|
|
307
|
-
if (device.platform === 'ios') {
|
|
308
|
-
// Keep this guard for non-daemon callers that invoke dispatch directly.
|
|
309
|
-
if (backend === 'ax' && device.kind !== 'simulator') {
|
|
310
|
-
throw new AppError(
|
|
311
|
-
'UNSUPPORTED_OPERATION',
|
|
312
|
-
'AX snapshot backend is not supported on iOS physical devices; use --backend xctest',
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
if (backend === 'ax') {
|
|
316
|
-
const ax = await snapshotAx(device, { traceLogPath: context?.traceLogPath });
|
|
317
|
-
return { nodes: ax.nodes ?? [], truncated: false, backend: 'ax' };
|
|
318
|
-
}
|
|
319
|
-
const result = (await runIosRunnerCommand(
|
|
320
|
-
device,
|
|
321
|
-
{
|
|
322
|
-
command: 'snapshot',
|
|
323
|
-
appBundleId: context?.appBundleId,
|
|
324
|
-
interactiveOnly: context?.snapshotInteractiveOnly,
|
|
325
|
-
compact: context?.snapshotCompact,
|
|
326
|
-
depth: context?.snapshotDepth,
|
|
327
|
-
scope: context?.snapshotScope,
|
|
328
|
-
raw: context?.snapshotRaw,
|
|
329
|
-
},
|
|
330
|
-
{ verbose: context?.verbose, logPath: context?.logPath, traceLogPath: context?.traceLogPath },
|
|
331
|
-
)) as { nodes?: RawSnapshotNode[]; truncated?: boolean };
|
|
332
|
-
const nodes = result.nodes ?? [];
|
|
333
|
-
if (nodes.length === 0 && device.kind === 'simulator') {
|
|
334
|
-
throw new AppError(
|
|
335
|
-
'COMMAND_FAILED',
|
|
336
|
-
'XCTest snapshot returned 0 nodes on iOS simulator. You can try --backend ax for diagnostics, but AX snapshots are not recommended.',
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
return { nodes, truncated: result.truncated ?? false, backend: 'xctest' };
|
|
340
|
-
}
|
|
341
|
-
const androidResult = await snapshotAndroid(device, {
|
|
342
|
-
interactiveOnly: context?.snapshotInteractiveOnly,
|
|
343
|
-
compact: context?.snapshotCompact,
|
|
344
|
-
depth: context?.snapshotDepth,
|
|
345
|
-
scope: context?.snapshotScope,
|
|
346
|
-
raw: context?.snapshotRaw,
|
|
347
|
-
});
|
|
348
|
-
return { nodes: androidResult.nodes ?? [], truncated: androidResult.truncated ?? false, backend: 'android' };
|
|
349
|
-
}
|
|
350
|
-
default:
|
|
351
|
-
throw new AppError('INVALID_ARGS', `Unknown command: ${command}`);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
const DETERMINISTIC_JITTER_PATTERN: ReadonlyArray<readonly [number, number]> = [
|
|
356
|
-
[0, 0],
|
|
357
|
-
[1, 0],
|
|
358
|
-
[0, 1],
|
|
359
|
-
[-1, 0],
|
|
360
|
-
[0, -1],
|
|
361
|
-
[1, 1],
|
|
362
|
-
[-1, 1],
|
|
363
|
-
[1, -1],
|
|
364
|
-
[-1, -1],
|
|
365
|
-
];
|
|
366
|
-
|
|
367
|
-
function requireIntInRange(value: number, name: string, min: number, max: number): number {
|
|
368
|
-
if (!Number.isFinite(value) || !Number.isInteger(value) || value < min || value > max) {
|
|
369
|
-
throw new AppError('INVALID_ARGS', `${name} must be an integer between ${min} and ${max}`);
|
|
370
|
-
}
|
|
371
|
-
return value;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
function computeDeterministicJitter(index: number, jitterPx: number): [number, number] {
|
|
375
|
-
if (jitterPx <= 0) return [0, 0];
|
|
376
|
-
const [dx, dy] = DETERMINISTIC_JITTER_PATTERN[index % DETERMINISTIC_JITTER_PATTERN.length];
|
|
377
|
-
return [dx * jitterPx, dy * jitterPx];
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
async function sleep(ms: number): Promise<void> {
|
|
381
|
-
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
382
|
-
}
|
package/src/core/open-target.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export function isDeepLinkTarget(input: string): boolean {
|
|
2
|
-
const value = input.trim();
|
|
3
|
-
if (!value) return false;
|
|
4
|
-
if (/\s/.test(value)) return false;
|
|
5
|
-
const match = /^([A-Za-z][A-Za-z0-9+.-]*):(.+)$/.exec(value);
|
|
6
|
-
if (!match) return false;
|
|
7
|
-
const scheme = match[1]?.toLowerCase();
|
|
8
|
-
const rest = match[2] ?? '';
|
|
9
|
-
if (scheme === 'http' || scheme === 'https' || scheme === 'ws' || scheme === 'wss' || scheme === 'ftp' || scheme === 'ftps') {
|
|
10
|
-
return rest.startsWith('//');
|
|
11
|
-
}
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function isWebUrl(input: string): boolean {
|
|
16
|
-
const scheme = input.trim().split(':')[0]?.toLowerCase();
|
|
17
|
-
return scheme === 'http' || scheme === 'https';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const IOS_SAFARI_BUNDLE_ID = 'com.apple.mobilesafari';
|
|
21
|
-
|
|
22
|
-
export function resolveIosDeviceDeepLinkBundleId(appBundleId: string | undefined, url: string): string | undefined {
|
|
23
|
-
const bundleId = appBundleId?.trim();
|
|
24
|
-
if (bundleId) return bundleId;
|
|
25
|
-
if (isWebUrl(url)) return IOS_SAFARI_BUNDLE_ID;
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { parseIosReadyPayload, resolveIosReadyHint } from '../device-ready.ts';
|
|
4
|
-
|
|
5
|
-
test('parseIosReadyPayload reads tunnelState from direct connectionProperties', () => {
|
|
6
|
-
const parsed = parseIosReadyPayload({
|
|
7
|
-
result: {
|
|
8
|
-
connectionProperties: {
|
|
9
|
-
tunnelState: 'connected',
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
assert.equal(parsed.tunnelState, 'connected');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('parseIosReadyPayload reads tunnelState from nested device connectionProperties', () => {
|
|
17
|
-
const parsed = parseIosReadyPayload({
|
|
18
|
-
result: {
|
|
19
|
-
device: {
|
|
20
|
-
connectionProperties: {
|
|
21
|
-
tunnelState: 'connecting',
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
assert.equal(parsed.tunnelState, 'connecting');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('parseIosReadyPayload returns empty payload for malformed input', () => {
|
|
30
|
-
assert.deepEqual(parseIosReadyPayload(null), {});
|
|
31
|
-
assert.deepEqual(parseIosReadyPayload({}), {});
|
|
32
|
-
assert.deepEqual(
|
|
33
|
-
parseIosReadyPayload({
|
|
34
|
-
result: { connectionProperties: { tunnelState: 123 } },
|
|
35
|
-
}),
|
|
36
|
-
{},
|
|
37
|
-
);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('resolveIosReadyHint maps known connection errors', () => {
|
|
41
|
-
const connecting = resolveIosReadyHint('', 'Device is busy (Connecting to iPhone)');
|
|
42
|
-
assert.match(connecting, /still connecting/i);
|
|
43
|
-
|
|
44
|
-
const coreDeviceTimeout = resolveIosReadyHint('CoreDeviceService timed out', '');
|
|
45
|
-
assert.match(coreDeviceTimeout, /coredevice service/i);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('resolveIosReadyHint falls back to generic guidance', () => {
|
|
49
|
-
const hint = resolveIosReadyHint('unexpected failure', '');
|
|
50
|
-
assert.match(hint, /unlocked/i);
|
|
51
|
-
assert.match(hint, /xcode/i);
|
|
52
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { evaluateIsPredicate, isSupportedPredicate } from '../is-predicates.ts';
|
|
4
|
-
|
|
5
|
-
const baseNode = {
|
|
6
|
-
ref: 'e1',
|
|
7
|
-
index: 0,
|
|
8
|
-
type: 'XCUIElementTypeTextField',
|
|
9
|
-
label: 'Email',
|
|
10
|
-
value: '',
|
|
11
|
-
identifier: 'login_email',
|
|
12
|
-
rect: { x: 0, y: 0, width: 100, height: 40 },
|
|
13
|
-
enabled: true,
|
|
14
|
-
hittable: true,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
test('isSupportedPredicate validates supported predicates', () => {
|
|
18
|
-
assert.equal(isSupportedPredicate('visible'), true);
|
|
19
|
-
assert.equal(isSupportedPredicate('text'), true);
|
|
20
|
-
assert.equal(isSupportedPredicate('checked'), false);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('evaluateIsPredicate visible and hidden', () => {
|
|
24
|
-
const visible = evaluateIsPredicate({
|
|
25
|
-
predicate: 'visible',
|
|
26
|
-
node: baseNode,
|
|
27
|
-
platform: 'ios',
|
|
28
|
-
});
|
|
29
|
-
const hidden = evaluateIsPredicate({
|
|
30
|
-
predicate: 'hidden',
|
|
31
|
-
node: { ...baseNode, rect: { ...baseNode.rect, width: 0 }, hittable: false },
|
|
32
|
-
platform: 'ios',
|
|
33
|
-
});
|
|
34
|
-
assert.equal(visible.pass, true);
|
|
35
|
-
assert.equal(hidden.pass, true);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('evaluateIsPredicate editable and selected', () => {
|
|
39
|
-
const editable = evaluateIsPredicate({
|
|
40
|
-
predicate: 'editable',
|
|
41
|
-
node: baseNode,
|
|
42
|
-
platform: 'ios',
|
|
43
|
-
});
|
|
44
|
-
const selected = evaluateIsPredicate({
|
|
45
|
-
predicate: 'selected',
|
|
46
|
-
node: { ...baseNode, selected: true },
|
|
47
|
-
platform: 'ios',
|
|
48
|
-
});
|
|
49
|
-
assert.equal(editable.pass, true);
|
|
50
|
-
assert.equal(selected.pass, true);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('evaluateIsPredicate text uses equality', () => {
|
|
54
|
-
const match = evaluateIsPredicate({
|
|
55
|
-
predicate: 'text',
|
|
56
|
-
node: baseNode,
|
|
57
|
-
expectedText: 'Email',
|
|
58
|
-
platform: 'ios',
|
|
59
|
-
});
|
|
60
|
-
const mismatch = evaluateIsPredicate({
|
|
61
|
-
predicate: 'text',
|
|
62
|
-
node: baseNode,
|
|
63
|
-
expectedText: 'email',
|
|
64
|
-
platform: 'ios',
|
|
65
|
-
});
|
|
66
|
-
assert.equal(match.pass, true);
|
|
67
|
-
assert.equal(mismatch.pass, false);
|
|
68
|
-
});
|