agent-device 0.4.1 → 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 +19 -20
- package/dist/src/797.js +1 -1
- package/dist/src/bin.js +32 -32
- package/dist/src/daemon.js +17 -17
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +8 -2
- package/package.json +7 -9
- package/skills/agent-device/SKILL.md +22 -19
- package/skills/agent-device/references/permissions.md +10 -17
- package/skills/agent-device/references/session-management.md +3 -1
- 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-help.test.ts +0 -102
- package/src/bin.ts +0 -3
- package/src/cli.ts +0 -289
- package/src/core/__tests__/capabilities.test.ts +0 -74
- package/src/core/__tests__/open-target.test.ts +0 -16
- package/src/core/capabilities.ts +0 -57
- package/src/core/dispatch.ts +0 -360
- package/src/core/open-target.ts +0 -13
- package/src/daemon/__tests__/app-state.test.ts +0 -138
- 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/app-state.ts +0 -65
- package/src/daemon/context.ts +0 -48
- package/src/daemon/device-ready.ts +0 -13
- 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 -343
- 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 -1032
- 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 -298
- package/src/daemon/snapshot-processing.ts +0 -131
- package/src/daemon/types.ts +0 -56
- package/src/daemon-client.ts +0 -172
- 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 -157
- package/src/platforms/android/devices.ts +0 -196
- package/src/platforms/android/index.ts +0 -754
- 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 -24
- package/src/platforms/ios/__tests__/runner-client.test.ts +0 -113
- package/src/platforms/ios/ax-snapshot.ts +0 -207
- package/src/platforms/ios/devices.ts +0 -87
- package/src/platforms/ios/index.ts +0 -455
- package/src/platforms/ios/runner-client.ts +0 -938
- package/src/utils/__tests__/args.test.ts +0 -221
- package/src/utils/__tests__/daemon-client.test.ts +0 -78
- 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 -234
- package/src/utils/command-schema.ts +0 -629
- 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/version.ts +0 -26
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { handleSessionCommands } from '../session.ts';
|
|
7
|
-
import { SessionStore } from '../../session-store.ts';
|
|
8
|
-
import type { DaemonRequest, DaemonResponse, SessionState } from '../../types.ts';
|
|
9
|
-
|
|
10
|
-
function makeStore(): SessionStore {
|
|
11
|
-
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-session-reinstall-'));
|
|
12
|
-
return new SessionStore(path.join(tempRoot, 'sessions'));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function makeSession(name: string, device: SessionState['device']): SessionState {
|
|
16
|
-
return {
|
|
17
|
-
name,
|
|
18
|
-
device,
|
|
19
|
-
createdAt: Date.now(),
|
|
20
|
-
actions: [],
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const invoke = async (_req: DaemonRequest): Promise<DaemonResponse> => {
|
|
25
|
-
return { ok: false, error: { code: 'INVALID_ARGS', message: 'invoke should not be called in reinstall tests' } };
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
test('reinstall requires active session or explicit device selector', async () => {
|
|
29
|
-
const sessionStore = makeStore();
|
|
30
|
-
const response = await handleSessionCommands({
|
|
31
|
-
req: {
|
|
32
|
-
token: 't',
|
|
33
|
-
session: 'default',
|
|
34
|
-
command: 'reinstall',
|
|
35
|
-
positionals: ['com.example.app', '/tmp/app.apk'],
|
|
36
|
-
flags: {},
|
|
37
|
-
},
|
|
38
|
-
sessionName: 'default',
|
|
39
|
-
logPath: '/tmp/daemon.log',
|
|
40
|
-
sessionStore,
|
|
41
|
-
invoke,
|
|
42
|
-
});
|
|
43
|
-
assert.ok(response);
|
|
44
|
-
assert.equal(response.ok, false);
|
|
45
|
-
if (!response.ok) {
|
|
46
|
-
assert.equal(response.error.code, 'INVALID_ARGS');
|
|
47
|
-
assert.match(response.error.message, /active session or an explicit device selector/i);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('reinstall validates required args before device operations', async () => {
|
|
52
|
-
const sessionStore = makeStore();
|
|
53
|
-
sessionStore.set(
|
|
54
|
-
'default',
|
|
55
|
-
makeSession('default', {
|
|
56
|
-
platform: 'ios',
|
|
57
|
-
id: 'sim-1',
|
|
58
|
-
name: 'iPhone',
|
|
59
|
-
kind: 'simulator',
|
|
60
|
-
booted: true,
|
|
61
|
-
}),
|
|
62
|
-
);
|
|
63
|
-
const response = await handleSessionCommands({
|
|
64
|
-
req: {
|
|
65
|
-
token: 't',
|
|
66
|
-
session: 'default',
|
|
67
|
-
command: 'reinstall',
|
|
68
|
-
positionals: ['com.example.app'],
|
|
69
|
-
flags: {},
|
|
70
|
-
},
|
|
71
|
-
sessionName: 'default',
|
|
72
|
-
logPath: '/tmp/daemon.log',
|
|
73
|
-
sessionStore,
|
|
74
|
-
invoke,
|
|
75
|
-
});
|
|
76
|
-
assert.ok(response);
|
|
77
|
-
assert.equal(response.ok, false);
|
|
78
|
-
if (!response.ok) {
|
|
79
|
-
assert.equal(response.error.code, 'INVALID_ARGS');
|
|
80
|
-
assert.match(response.error.message, /reinstall <app> <path-to-app-binary>/i);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('reinstall reports unsupported operation on iOS physical devices', async () => {
|
|
85
|
-
const sessionStore = makeStore();
|
|
86
|
-
sessionStore.set(
|
|
87
|
-
'default',
|
|
88
|
-
makeSession('default', {
|
|
89
|
-
platform: 'ios',
|
|
90
|
-
id: 'device-1',
|
|
91
|
-
name: 'iPhone Device',
|
|
92
|
-
kind: 'device',
|
|
93
|
-
booted: true,
|
|
94
|
-
}),
|
|
95
|
-
);
|
|
96
|
-
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-reinstall-binary-'));
|
|
97
|
-
const appPath = path.join(tempRoot, 'Sample.app');
|
|
98
|
-
fs.writeFileSync(appPath, 'placeholder');
|
|
99
|
-
|
|
100
|
-
const response = await handleSessionCommands({
|
|
101
|
-
req: {
|
|
102
|
-
token: 't',
|
|
103
|
-
session: 'default',
|
|
104
|
-
command: 'reinstall',
|
|
105
|
-
positionals: ['com.example.app', appPath],
|
|
106
|
-
flags: {},
|
|
107
|
-
},
|
|
108
|
-
sessionName: 'default',
|
|
109
|
-
logPath: '/tmp/daemon.log',
|
|
110
|
-
sessionStore,
|
|
111
|
-
invoke,
|
|
112
|
-
});
|
|
113
|
-
assert.ok(response);
|
|
114
|
-
assert.equal(response.ok, false);
|
|
115
|
-
if (!response.ok) {
|
|
116
|
-
assert.equal(response.error.code, 'UNSUPPORTED_OPERATION');
|
|
117
|
-
assert.match(response.error.message, /reinstall is not supported/i);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test('reinstall succeeds on active iOS simulator session and records action', async () => {
|
|
122
|
-
const sessionStore = makeStore();
|
|
123
|
-
const session = makeSession('default', {
|
|
124
|
-
platform: 'ios',
|
|
125
|
-
id: 'sim-1',
|
|
126
|
-
name: 'iPhone',
|
|
127
|
-
kind: 'simulator',
|
|
128
|
-
booted: true,
|
|
129
|
-
});
|
|
130
|
-
sessionStore.set('default', session);
|
|
131
|
-
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-reinstall-success-ios-'));
|
|
132
|
-
const appPath = path.join(tempRoot, 'Sample.app');
|
|
133
|
-
fs.writeFileSync(appPath, 'placeholder');
|
|
134
|
-
|
|
135
|
-
const response = await handleSessionCommands({
|
|
136
|
-
req: {
|
|
137
|
-
token: 't',
|
|
138
|
-
session: 'default',
|
|
139
|
-
command: 'reinstall',
|
|
140
|
-
positionals: ['com.example.app', appPath],
|
|
141
|
-
flags: {},
|
|
142
|
-
},
|
|
143
|
-
sessionName: 'default',
|
|
144
|
-
logPath: '/tmp/daemon.log',
|
|
145
|
-
sessionStore,
|
|
146
|
-
invoke,
|
|
147
|
-
reinstallOps: {
|
|
148
|
-
ios: async (_device, app, pathToBinary) => {
|
|
149
|
-
assert.equal(app, 'com.example.app');
|
|
150
|
-
assert.equal(pathToBinary, appPath);
|
|
151
|
-
return { bundleId: 'com.example.app' };
|
|
152
|
-
},
|
|
153
|
-
android: async () => {
|
|
154
|
-
throw new Error('unexpected android reinstall');
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
assert.ok(response);
|
|
160
|
-
assert.equal(response.ok, true);
|
|
161
|
-
if (response.ok) {
|
|
162
|
-
assert.equal(response.data?.platform, 'ios');
|
|
163
|
-
assert.equal(response.data?.appId, 'com.example.app');
|
|
164
|
-
assert.equal(response.data?.bundleId, 'com.example.app');
|
|
165
|
-
assert.equal(response.data?.appPath, appPath);
|
|
166
|
-
}
|
|
167
|
-
assert.equal(session.actions.length, 1);
|
|
168
|
-
assert.equal(session.actions[0]?.command, 'reinstall');
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
test('reinstall succeeds on active Android session with normalized appId', async () => {
|
|
172
|
-
const sessionStore = makeStore();
|
|
173
|
-
sessionStore.set(
|
|
174
|
-
'default',
|
|
175
|
-
makeSession('default', {
|
|
176
|
-
platform: 'android',
|
|
177
|
-
id: 'emulator-5554',
|
|
178
|
-
name: 'Pixel',
|
|
179
|
-
kind: 'emulator',
|
|
180
|
-
booted: true,
|
|
181
|
-
}),
|
|
182
|
-
);
|
|
183
|
-
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-reinstall-success-android-'));
|
|
184
|
-
const appPath = path.join(tempRoot, 'Sample.apk');
|
|
185
|
-
fs.writeFileSync(appPath, 'placeholder');
|
|
186
|
-
|
|
187
|
-
const response = await handleSessionCommands({
|
|
188
|
-
req: {
|
|
189
|
-
token: 't',
|
|
190
|
-
session: 'default',
|
|
191
|
-
command: 'reinstall',
|
|
192
|
-
positionals: ['com.example.app', appPath],
|
|
193
|
-
flags: {},
|
|
194
|
-
},
|
|
195
|
-
sessionName: 'default',
|
|
196
|
-
logPath: '/tmp/daemon.log',
|
|
197
|
-
sessionStore,
|
|
198
|
-
invoke,
|
|
199
|
-
reinstallOps: {
|
|
200
|
-
ios: async () => {
|
|
201
|
-
throw new Error('unexpected ios reinstall');
|
|
202
|
-
},
|
|
203
|
-
android: async (_device, app, pathToBinary) => {
|
|
204
|
-
assert.equal(app, 'com.example.app');
|
|
205
|
-
assert.equal(pathToBinary, appPath);
|
|
206
|
-
return { package: 'com.example.app' };
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
assert.ok(response);
|
|
212
|
-
assert.equal(response.ok, true);
|
|
213
|
-
if (response.ok) {
|
|
214
|
-
assert.equal(response.data?.platform, 'android');
|
|
215
|
-
assert.equal(response.data?.appId, 'com.example.app');
|
|
216
|
-
assert.equal(response.data?.package, 'com.example.app');
|
|
217
|
-
assert.equal(response.data?.appPath, appPath);
|
|
218
|
-
}
|
|
219
|
-
});
|
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { handleSessionCommands } from '../session.ts';
|
|
7
|
-
import { SessionStore } from '../../session-store.ts';
|
|
8
|
-
import type { DaemonRequest, DaemonResponse, SessionState } from '../../types.ts';
|
|
9
|
-
|
|
10
|
-
function makeSessionStore(): SessionStore {
|
|
11
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-session-handler-'));
|
|
12
|
-
return new SessionStore(path.join(root, 'sessions'));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function makeSession(name: string, device: SessionState['device']): SessionState {
|
|
16
|
-
return {
|
|
17
|
-
name,
|
|
18
|
-
device,
|
|
19
|
-
createdAt: Date.now(),
|
|
20
|
-
actions: [],
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const noopInvoke = async (_req: DaemonRequest): Promise<DaemonResponse> => ({ ok: true, data: {} });
|
|
25
|
-
|
|
26
|
-
test('boot requires session or explicit selector', async () => {
|
|
27
|
-
const sessionStore = makeSessionStore();
|
|
28
|
-
const response = await handleSessionCommands({
|
|
29
|
-
req: {
|
|
30
|
-
token: 't',
|
|
31
|
-
session: 'default',
|
|
32
|
-
command: 'boot',
|
|
33
|
-
positionals: [],
|
|
34
|
-
flags: {},
|
|
35
|
-
},
|
|
36
|
-
sessionName: 'default',
|
|
37
|
-
logPath: path.join(os.tmpdir(), 'daemon.log'),
|
|
38
|
-
sessionStore,
|
|
39
|
-
invoke: noopInvoke,
|
|
40
|
-
ensureReady: async () => {},
|
|
41
|
-
});
|
|
42
|
-
assert.ok(response);
|
|
43
|
-
assert.equal(response?.ok, false);
|
|
44
|
-
if (response && !response.ok) {
|
|
45
|
-
assert.equal(response.error.code, 'INVALID_ARGS');
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('boot succeeds for iOS physical devices', async () => {
|
|
50
|
-
const sessionStore = makeSessionStore();
|
|
51
|
-
const sessionName = 'ios-device-session';
|
|
52
|
-
sessionStore.set(
|
|
53
|
-
sessionName,
|
|
54
|
-
makeSession(sessionName, {
|
|
55
|
-
platform: 'ios',
|
|
56
|
-
id: 'ios-device-1',
|
|
57
|
-
name: 'iPhone Device',
|
|
58
|
-
kind: 'device',
|
|
59
|
-
booted: true,
|
|
60
|
-
}),
|
|
61
|
-
);
|
|
62
|
-
let ensureCalls = 0;
|
|
63
|
-
const response = await handleSessionCommands({
|
|
64
|
-
req: {
|
|
65
|
-
token: 't',
|
|
66
|
-
session: sessionName,
|
|
67
|
-
command: 'boot',
|
|
68
|
-
positionals: [],
|
|
69
|
-
flags: {},
|
|
70
|
-
},
|
|
71
|
-
sessionName,
|
|
72
|
-
logPath: path.join(os.tmpdir(), 'daemon.log'),
|
|
73
|
-
sessionStore,
|
|
74
|
-
invoke: noopInvoke,
|
|
75
|
-
ensureReady: async () => {
|
|
76
|
-
ensureCalls += 1;
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
assert.ok(response);
|
|
80
|
-
assert.equal(response?.ok, true);
|
|
81
|
-
assert.equal(ensureCalls, 1);
|
|
82
|
-
if (response && response.ok) {
|
|
83
|
-
assert.equal(response.data?.platform, 'ios');
|
|
84
|
-
assert.equal(response.data?.booted, true);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test('boot succeeds for supported device in session', async () => {
|
|
89
|
-
const sessionStore = makeSessionStore();
|
|
90
|
-
const sessionName = 'android-session';
|
|
91
|
-
sessionStore.set(
|
|
92
|
-
sessionName,
|
|
93
|
-
makeSession(sessionName, {
|
|
94
|
-
platform: 'android',
|
|
95
|
-
id: 'emulator-5554',
|
|
96
|
-
name: 'Pixel Emulator',
|
|
97
|
-
kind: 'emulator',
|
|
98
|
-
booted: true,
|
|
99
|
-
}),
|
|
100
|
-
);
|
|
101
|
-
let ensureCalls = 0;
|
|
102
|
-
const response = await handleSessionCommands({
|
|
103
|
-
req: {
|
|
104
|
-
token: 't',
|
|
105
|
-
session: sessionName,
|
|
106
|
-
command: 'boot',
|
|
107
|
-
positionals: [],
|
|
108
|
-
flags: {},
|
|
109
|
-
},
|
|
110
|
-
sessionName,
|
|
111
|
-
logPath: path.join(os.tmpdir(), 'daemon.log'),
|
|
112
|
-
sessionStore,
|
|
113
|
-
invoke: noopInvoke,
|
|
114
|
-
ensureReady: async () => {
|
|
115
|
-
ensureCalls += 1;
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
assert.ok(response);
|
|
119
|
-
assert.equal(response?.ok, true);
|
|
120
|
-
assert.equal(ensureCalls, 1);
|
|
121
|
-
if (response && response.ok) {
|
|
122
|
-
assert.equal(response.data?.platform, 'android');
|
|
123
|
-
assert.equal(response.data?.booted, true);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test('open URL on existing iOS session clears stale app bundle id', async () => {
|
|
128
|
-
const sessionStore = makeSessionStore();
|
|
129
|
-
const sessionName = 'ios-session';
|
|
130
|
-
sessionStore.set(
|
|
131
|
-
sessionName,
|
|
132
|
-
{
|
|
133
|
-
...makeSession(sessionName, {
|
|
134
|
-
platform: 'ios',
|
|
135
|
-
id: 'sim-1',
|
|
136
|
-
name: 'iPhone 15',
|
|
137
|
-
kind: 'simulator',
|
|
138
|
-
booted: true,
|
|
139
|
-
}),
|
|
140
|
-
appBundleId: 'com.example.old',
|
|
141
|
-
appName: 'Old App',
|
|
142
|
-
},
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
let dispatchedContext: Record<string, unknown> | undefined;
|
|
146
|
-
const response = await handleSessionCommands({
|
|
147
|
-
req: {
|
|
148
|
-
token: 't',
|
|
149
|
-
session: sessionName,
|
|
150
|
-
command: 'open',
|
|
151
|
-
positionals: ['https://example.com/path'],
|
|
152
|
-
flags: {},
|
|
153
|
-
},
|
|
154
|
-
sessionName,
|
|
155
|
-
logPath: path.join(os.tmpdir(), 'daemon.log'),
|
|
156
|
-
sessionStore,
|
|
157
|
-
invoke: noopInvoke,
|
|
158
|
-
dispatch: async (_device, _command, _positionals, _out, context) => {
|
|
159
|
-
dispatchedContext = context as Record<string, unknown> | undefined;
|
|
160
|
-
return {};
|
|
161
|
-
},
|
|
162
|
-
ensureReady: async () => {},
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
assert.ok(response);
|
|
166
|
-
assert.equal(response?.ok, true);
|
|
167
|
-
const updated = sessionStore.get(sessionName);
|
|
168
|
-
assert.equal(updated?.appBundleId, undefined);
|
|
169
|
-
assert.equal(updated?.appName, 'https://example.com/path');
|
|
170
|
-
assert.equal(dispatchedContext?.appBundleId, undefined);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
test('open app on existing iOS session resolves and stores bundle id', async () => {
|
|
174
|
-
const sessionStore = makeSessionStore();
|
|
175
|
-
const sessionName = 'ios-session';
|
|
176
|
-
sessionStore.set(
|
|
177
|
-
sessionName,
|
|
178
|
-
{
|
|
179
|
-
...makeSession(sessionName, {
|
|
180
|
-
platform: 'ios',
|
|
181
|
-
id: 'sim-1',
|
|
182
|
-
name: 'iPhone 15',
|
|
183
|
-
kind: 'simulator',
|
|
184
|
-
booted: true,
|
|
185
|
-
}),
|
|
186
|
-
appBundleId: 'com.example.old',
|
|
187
|
-
appName: 'Old App',
|
|
188
|
-
},
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
let dispatchedContext: Record<string, unknown> | undefined;
|
|
192
|
-
const response = await handleSessionCommands({
|
|
193
|
-
req: {
|
|
194
|
-
token: 't',
|
|
195
|
-
session: sessionName,
|
|
196
|
-
command: 'open',
|
|
197
|
-
positionals: ['settings'],
|
|
198
|
-
flags: {},
|
|
199
|
-
},
|
|
200
|
-
sessionName,
|
|
201
|
-
logPath: path.join(os.tmpdir(), 'daemon.log'),
|
|
202
|
-
sessionStore,
|
|
203
|
-
invoke: noopInvoke,
|
|
204
|
-
dispatch: async (_device, _command, _positionals, _out, context) => {
|
|
205
|
-
dispatchedContext = context as Record<string, unknown> | undefined;
|
|
206
|
-
return {};
|
|
207
|
-
},
|
|
208
|
-
ensureReady: async () => {},
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
assert.ok(response);
|
|
212
|
-
assert.equal(response?.ok, true);
|
|
213
|
-
const updated = sessionStore.get(sessionName);
|
|
214
|
-
assert.equal(updated?.appBundleId, 'com.apple.Preferences');
|
|
215
|
-
assert.equal(updated?.appName, 'settings');
|
|
216
|
-
assert.equal(dispatchedContext?.appBundleId, 'com.apple.Preferences');
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
test('open --relaunch closes and reopens active session app', async () => {
|
|
220
|
-
const sessionStore = makeSessionStore();
|
|
221
|
-
const sessionName = 'android-session';
|
|
222
|
-
sessionStore.set(
|
|
223
|
-
sessionName,
|
|
224
|
-
{
|
|
225
|
-
...makeSession(sessionName, {
|
|
226
|
-
platform: 'android',
|
|
227
|
-
id: 'emulator-5554',
|
|
228
|
-
name: 'Pixel Emulator',
|
|
229
|
-
kind: 'emulator',
|
|
230
|
-
booted: true,
|
|
231
|
-
}),
|
|
232
|
-
appName: 'com.example.app',
|
|
233
|
-
},
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
const calls: Array<{ command: string; positionals: string[] }> = [];
|
|
237
|
-
const response = await handleSessionCommands({
|
|
238
|
-
req: {
|
|
239
|
-
token: 't',
|
|
240
|
-
session: sessionName,
|
|
241
|
-
command: 'open',
|
|
242
|
-
positionals: [],
|
|
243
|
-
flags: { relaunch: true },
|
|
244
|
-
},
|
|
245
|
-
sessionName,
|
|
246
|
-
logPath: path.join(os.tmpdir(), 'daemon.log'),
|
|
247
|
-
sessionStore,
|
|
248
|
-
invoke: noopInvoke,
|
|
249
|
-
dispatch: async (_device, command, positionals) => {
|
|
250
|
-
calls.push({ command, positionals });
|
|
251
|
-
return {};
|
|
252
|
-
},
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
assert.ok(response);
|
|
256
|
-
assert.equal(response?.ok, true);
|
|
257
|
-
assert.equal(calls.length, 2);
|
|
258
|
-
assert.deepEqual(calls[0], { command: 'close', positionals: ['com.example.app'] });
|
|
259
|
-
assert.deepEqual(calls[1], { command: 'open', positionals: ['com.example.app'] });
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
test('open --relaunch rejects URL targets', async () => {
|
|
263
|
-
const sessionStore = makeSessionStore();
|
|
264
|
-
const response = await handleSessionCommands({
|
|
265
|
-
req: {
|
|
266
|
-
token: 't',
|
|
267
|
-
session: 'default',
|
|
268
|
-
command: 'open',
|
|
269
|
-
positionals: ['https://example.com/path'],
|
|
270
|
-
flags: { relaunch: true },
|
|
271
|
-
},
|
|
272
|
-
sessionName: 'default',
|
|
273
|
-
logPath: path.join(os.tmpdir(), 'daemon.log'),
|
|
274
|
-
sessionStore,
|
|
275
|
-
invoke: noopInvoke,
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
assert.ok(response);
|
|
279
|
-
assert.equal(response?.ok, false);
|
|
280
|
-
if (response && !response.ok) {
|
|
281
|
-
assert.equal(response.error.code, 'INVALID_ARGS');
|
|
282
|
-
assert.match(response.error.message, /does not support URL targets/i);
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
test('open --relaunch fails without app when no session exists', async () => {
|
|
287
|
-
const sessionStore = makeSessionStore();
|
|
288
|
-
const response = await handleSessionCommands({
|
|
289
|
-
req: {
|
|
290
|
-
token: 't',
|
|
291
|
-
session: 'default',
|
|
292
|
-
command: 'open',
|
|
293
|
-
positionals: [],
|
|
294
|
-
flags: { relaunch: true },
|
|
295
|
-
},
|
|
296
|
-
sessionName: 'default',
|
|
297
|
-
logPath: path.join(os.tmpdir(), 'daemon.log'),
|
|
298
|
-
sessionStore,
|
|
299
|
-
invoke: noopInvoke,
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
assert.ok(response);
|
|
303
|
-
assert.equal(response?.ok, false);
|
|
304
|
-
if (response && !response.ok) {
|
|
305
|
-
assert.equal(response.error.code, 'INVALID_ARGS');
|
|
306
|
-
assert.match(response.error.message, /requires an app argument/i);
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
test('replay parses open --relaunch flag and replays open with relaunch semantics', async () => {
|
|
311
|
-
const sessionStore = makeSessionStore();
|
|
312
|
-
const replayRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-replay-relaunch-'));
|
|
313
|
-
const replayPath = path.join(replayRoot, 'relaunch.ad');
|
|
314
|
-
fs.writeFileSync(replayPath, 'open "Settings" --relaunch\n');
|
|
315
|
-
|
|
316
|
-
const invoked: DaemonRequest[] = [];
|
|
317
|
-
const response = await handleSessionCommands({
|
|
318
|
-
req: {
|
|
319
|
-
token: 't',
|
|
320
|
-
session: 'default',
|
|
321
|
-
command: 'replay',
|
|
322
|
-
positionals: [replayPath],
|
|
323
|
-
flags: {},
|
|
324
|
-
},
|
|
325
|
-
sessionName: 'default',
|
|
326
|
-
logPath: path.join(os.tmpdir(), 'daemon.log'),
|
|
327
|
-
sessionStore,
|
|
328
|
-
invoke: async (req) => {
|
|
329
|
-
invoked.push(req);
|
|
330
|
-
return { ok: true, data: {} };
|
|
331
|
-
},
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
assert.ok(response);
|
|
335
|
-
assert.equal(response?.ok, true);
|
|
336
|
-
if (response && response.ok) {
|
|
337
|
-
assert.equal(response.data?.replayed, 1);
|
|
338
|
-
}
|
|
339
|
-
assert.equal(invoked.length, 1);
|
|
340
|
-
assert.equal(invoked[0]?.command, 'open');
|
|
341
|
-
assert.deepEqual(invoked[0]?.positionals, ['Settings']);
|
|
342
|
-
assert.equal(invoked[0]?.flags?.relaunch, true);
|
|
343
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { handleSnapshotCommands } from '../snapshot.ts';
|
|
7
|
-
import { SessionStore } from '../../session-store.ts';
|
|
8
|
-
import type { SessionState } from '../../types.ts';
|
|
9
|
-
|
|
10
|
-
function makeSessionStore(): SessionStore {
|
|
11
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-snapshot-handler-'));
|
|
12
|
-
return new SessionStore(path.join(root, 'sessions'));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function makeSession(name: string, device: SessionState['device']): SessionState {
|
|
16
|
-
return {
|
|
17
|
-
name,
|
|
18
|
-
device,
|
|
19
|
-
createdAt: Date.now(),
|
|
20
|
-
actions: [],
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
test('snapshot rejects AX backend on iOS physical devices', async () => {
|
|
25
|
-
const sessionStore = makeSessionStore();
|
|
26
|
-
const sessionName = 'ios-device';
|
|
27
|
-
sessionStore.set(
|
|
28
|
-
sessionName,
|
|
29
|
-
makeSession(sessionName, {
|
|
30
|
-
platform: 'ios',
|
|
31
|
-
id: 'ios-device-1',
|
|
32
|
-
name: 'My iPhone',
|
|
33
|
-
kind: 'device',
|
|
34
|
-
booted: true,
|
|
35
|
-
}),
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const response = await handleSnapshotCommands({
|
|
39
|
-
req: {
|
|
40
|
-
token: 't',
|
|
41
|
-
session: sessionName,
|
|
42
|
-
command: 'snapshot',
|
|
43
|
-
positionals: [],
|
|
44
|
-
flags: { snapshotBackend: 'ax' },
|
|
45
|
-
},
|
|
46
|
-
sessionName,
|
|
47
|
-
logPath: '/tmp/daemon.log',
|
|
48
|
-
sessionStore,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
assert.ok(response);
|
|
52
|
-
assert.equal(response?.ok, false);
|
|
53
|
-
if (response && !response.ok) {
|
|
54
|
-
assert.equal(response.error.code, 'UNSUPPORTED_OPERATION');
|
|
55
|
-
assert.match(response.error.message, /AX snapshot backend is not supported/i);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('settings rejects unsupported iOS physical devices', async () => {
|
|
60
|
-
const sessionStore = makeSessionStore();
|
|
61
|
-
const sessionName = 'ios-device';
|
|
62
|
-
sessionStore.set(
|
|
63
|
-
sessionName,
|
|
64
|
-
makeSession(sessionName, {
|
|
65
|
-
platform: 'ios',
|
|
66
|
-
id: 'ios-device-1',
|
|
67
|
-
name: 'My iPhone',
|
|
68
|
-
kind: 'device',
|
|
69
|
-
booted: true,
|
|
70
|
-
}),
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const response = await handleSnapshotCommands({
|
|
74
|
-
req: {
|
|
75
|
-
token: 't',
|
|
76
|
-
session: sessionName,
|
|
77
|
-
command: 'settings',
|
|
78
|
-
positionals: ['wifi', 'on'],
|
|
79
|
-
flags: {},
|
|
80
|
-
},
|
|
81
|
-
sessionName,
|
|
82
|
-
logPath: '/tmp/daemon.log',
|
|
83
|
-
sessionStore,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
assert.ok(response);
|
|
87
|
-
assert.equal(response?.ok, false);
|
|
88
|
-
if (response && !response.ok) {
|
|
89
|
-
assert.equal(response.error.code, 'UNSUPPORTED_OPERATION');
|
|
90
|
-
assert.match(response.error.message, /settings is not supported/i);
|
|
91
|
-
}
|
|
92
|
-
});
|