agent-device-x86sim 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +192 -2
- package/ax-hook/libx86sim-ax.dylib +0 -0
- package/dist/cli.js +127 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +226 -0
- package/dist/start-server-C84E8KRm.js +1182 -0
- package/dist/system-DMZAX-z7.js +203 -0
- package/package.json +59 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wobsoriano
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,193 @@
|
|
|
1
|
-
#
|
|
1
|
+
# agent-device-x86sim
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An [agent-device](https://github.com/callstack/agent-device) plugin that drives an iOS simulator on Linux through [x86Sim](https://github.com/x86sim/x86sim). In this README, "the phone" is the simulated iPhone that x86Sim runs.
|
|
4
|
+
|
|
5
|
+
## How it fits together
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
agent-device + plugin ──HTTP──▶ server ──▶ x86Sim ──▶ the phone
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- agent-device sends its commands to a WebDriver server. The plugin tells agent-device where that server is.
|
|
12
|
+
- The server runs on the Linux machine next to x86Sim. It turns WebDriver requests into x86Sim input and screenshots.
|
|
13
|
+
- The accessibility hook, `libx86sim-ax.dylib`, runs inside the phone. It gives the server the list of elements on the screen. `snapshot -i` prints that list.
|
|
14
|
+
- The package `agent-device-x86sim` has the plugin, the server, the hook, and the `agent-device-x86sim` command.
|
|
15
|
+
|
|
16
|
+
When agent-device runs on the Linux machine, the plugin starts the server and boots the phone for you. When agent-device runs on another machine, you start the server yourself with one command.
|
|
17
|
+
|
|
18
|
+
## Requirements
|
|
19
|
+
|
|
20
|
+
- A Linux machine that meets [x86Sim's requirements](https://github.com/x86sim/x86sim#requirements). It needs x86-64, glibc 2.39 or newer, at least 8 GB of memory, and 45 GB of free disk. Ubuntu 24.04 or newer has the right glibc. x86Sim recommends 16 GB of memory. A GPU is optional. Without one, the phone draws in software and is slower.
|
|
21
|
+
- Node.js 22.18 or newer and Python 3 on the Linux machine.
|
|
22
|
+
- agent-device 0.21.35 or newer, on the Linux machine or on another machine.
|
|
23
|
+
|
|
24
|
+
## Use agent-device on the Linux machine
|
|
25
|
+
|
|
26
|
+
1. Set up x86Sim with its [Quick start](https://github.com/x86sim/x86sim#quick-start).
|
|
27
|
+
|
|
28
|
+
Download the AppImage anywhere and run it. The Setup page of the launcher downloads iOS and creates your first phone. You do not boot the phone, load the hook, or turn on accessibility. The plugin does that for you.
|
|
29
|
+
|
|
30
|
+
Check: the launcher lists a phone.
|
|
31
|
+
|
|
32
|
+
2. Install the plugin.
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
agent-device plugins add agent-device-x86sim
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
If an agent-device daemon is running, stop it so that it loads the plugin.
|
|
39
|
+
|
|
40
|
+
3. Connect.
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
agent-device connect x86sim
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Check: the output says `Connected successfully with x86Sim.` and names your phone.
|
|
47
|
+
|
|
48
|
+
4. Open an app.
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
agent-device open com.apple.Preferences
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The first `open` boots the phone with the hook. That takes up to 6 minutes. Later opens take a few seconds.
|
|
55
|
+
|
|
56
|
+
Check: the output says `Opened: com.apple.Preferences`.
|
|
57
|
+
|
|
58
|
+
5. Read the screen and press a row.
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
agent-device snapshot -i
|
|
62
|
+
agent-device press @e8
|
|
63
|
+
agent-device snapshot -i
|
|
64
|
+
agent-device screenshot ./screen.png
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
A `snapshot -i` in Settings looks like this:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
@e1 [application] "Settings"
|
|
71
|
+
@e2 [navigation-bar] "Settings"
|
|
72
|
+
@e3 [text] "Settings"
|
|
73
|
+
@e4 [collection] "com.apple.settings.sidebar.collectionView"
|
|
74
|
+
[content below collection hidden]
|
|
75
|
+
@e5 [cell] "Apple Account"
|
|
76
|
+
@e6 [button] "Apple Account, Sign in to access your iCloud data, the App Store, Apple services, and more."
|
|
77
|
+
@e7 [cell] "General"
|
|
78
|
+
@e8 [cell] "Accessibility"
|
|
79
|
+
...
|
|
80
|
+
@e17 [search] "Search" [editable]
|
|
81
|
+
@e20 [toolbar] "Toolbar"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The element types and containers are the ones XCTest reports on a Mac, because the hook reads the tree that UIKit builds for XCTest.
|
|
85
|
+
|
|
86
|
+
Check: the second `snapshot -i` lists the rows of the page you pressed.
|
|
87
|
+
|
|
88
|
+
Close the session when you are done.
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
agent-device home
|
|
92
|
+
agent-device close
|
|
93
|
+
agent-device disconnect
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The plugin finds x86Sim in its data folder, `~/.local/share/x86sim`, wherever you saved the AppImage. If you have several phones, it uses the one that runs. When none runs, choose one by the name the launcher shows.
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
agent-device connect x86sim --device "iPhone 17 Pro"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The plugin starts its server only on Linux and only when no server address is set.
|
|
103
|
+
|
|
104
|
+
If the phone was started by the launcher, or runs an older accessibility hook, the plugin restarts it once to load the current hook and turn on accessibility.
|
|
105
|
+
|
|
106
|
+
## Run agent-device on another machine
|
|
107
|
+
|
|
108
|
+
agent-device sends its commands to a WebDriver server that runs next to the simulator. Device clouds such as BrowserStack run that server for you. x86Sim runs on your machine, so on another machine you start the server yourself.
|
|
109
|
+
|
|
110
|
+
1. On the Linux machine, start the server.
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
npx agent-device-x86sim serve
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The command boots the phone if it needs a boot. It prints progress lines to stderr, and a `Ready` line when the server accepts commands. When the phone already runs with the hook, `serve` reaches `Ready` in seconds. Leave it running.
|
|
117
|
+
|
|
118
|
+
Check: the last lines start with `Ready.` and name the commands to run next.
|
|
119
|
+
|
|
120
|
+
2. On the machine that runs agent-device, forward the port.
|
|
121
|
+
|
|
122
|
+
```sh
|
|
123
|
+
ssh -N -L 4723:localhost:4723 linux-box &
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
The plugin uses `http://127.0.0.1:4723`. To use another address, set `X86SIM_WEBDRIVER_ENDPOINT`.
|
|
127
|
+
|
|
128
|
+
3. Install the plugin and connect.
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
agent-device plugins add agent-device-x86sim
|
|
132
|
+
agent-device connect x86sim
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Check: the output says `Connected successfully with x86Sim.` and `x86Sim WebDriver server is ready`.
|
|
136
|
+
|
|
137
|
+
4. Use agent-device as in the section above, from `open` on.
|
|
138
|
+
|
|
139
|
+
`serve` takes these options.
|
|
140
|
+
|
|
141
|
+
| Option | Meaning |
|
|
142
|
+
| -------------------- | --------------------------------------------------------------------------------- |
|
|
143
|
+
| `--appimage PATH` | Use this AppImage instead of the copy in the data folder. Else `X86SIM_APPIMAGE`. |
|
|
144
|
+
| `--device NAME\|DIR` | The phone, by name or folder name. Else the running phone, else the only phone. |
|
|
145
|
+
| `--port PORT` | Default 4723. |
|
|
146
|
+
| `--host HOST` | Default 127.0.0.1. |
|
|
147
|
+
| `--verbose` | Log every request and the output of x86Sim's boot script. |
|
|
148
|
+
|
|
149
|
+
`npx agent-device-x86sim hook-path` prints the path of the accessibility hook that the package ships.
|
|
150
|
+
|
|
151
|
+
## Test your own app
|
|
152
|
+
|
|
153
|
+
Install an arm64 iOS simulator build on the Linux machine, then open it by its bundle id.
|
|
154
|
+
|
|
155
|
+
```sh
|
|
156
|
+
# on the Linux machine, in the folder of the AppImage
|
|
157
|
+
./x86sim-0.5.3-x86_64.AppImage x86sim install ./MyApp.app
|
|
158
|
+
# where agent-device runs
|
|
159
|
+
agent-device open com.example.myapp
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`agent-device install` sends a file path from the machine that runs agent-device. The server looks for that path on the Linux machine. So `install` works only when agent-device runs on the Linux machine.
|
|
163
|
+
|
|
164
|
+
## Notes for agents
|
|
165
|
+
|
|
166
|
+
- Take a new `snapshot -i` after every `press`. Refs such as `@e3` change from one snapshot to the next.
|
|
167
|
+
- The phone shows the result of an input 1 to 15 seconds later, depending on the machine. If the element you expect is missing, wait 2 seconds and take another snapshot. Do not press again.
|
|
168
|
+
- Right after a page opens, the snapshot can still list the previous page. Poll until the element you want appears.
|
|
169
|
+
- `open` takes a bundle id, for example `com.apple.Preferences`. It does not take an app name.
|
|
170
|
+
- The first `open` on the Linux machine boots the phone and can take up to 6 minutes. Do not run it again while it runs.
|
|
171
|
+
- These operations return `UNSUPPORTED_OPERATION`: `fill`, `back`, `orientation`, the keyboard state, and the clipboard.
|
|
172
|
+
- To enter text, press the field, then use `type`. Press only after a snapshot taken a few seconds after the page opened. A press on a page that has not drawn yet reports `Tapped` but does nothing, and `type` then goes nowhere. Check the result with `snapshot`, which shows the typed text as the field's value.
|
|
173
|
+
|
|
174
|
+
## Troubleshooting
|
|
175
|
+
|
|
176
|
+
| Symptom | Cause | Fix |
|
|
177
|
+
| -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------- |
|
|
178
|
+
| `connect x86sim` says the server is not reachable | agent-device runs on another machine, and the server is not running or not forwarded | Run `npx agent-device-x86sim serve` on the Linux machine. Check `curl localhost:4723/status` where agent-device runs. |
|
|
179
|
+
| The plugin or `serve` says x86Sim is not set up | The AppImage never ran on this machine, or it ran with another `X86SIM_DATA` | Follow the [Quick start](https://github.com/x86sim/x86sim#quick-start). Use the same `X86SIM_DATA` for the plugin. |
|
|
180
|
+
| The plugin or `serve` says to pick a phone | There is more than one phone and none runs | Run `agent-device connect x86sim --device "<name>"`, or `serve --device "<name>"`. |
|
|
181
|
+
| `serve` says the port is in use | Another server runs on that port | Stop it, or pass `--port`. |
|
|
182
|
+
| The plugin does not start the server on the Linux machine | `X86SIM_WEBDRIVER_ENDPOINT` is set | Unset the variable. |
|
|
183
|
+
| `snapshot -i` lists only `[application]`, or says `UIKit's accessibility is off` | The hook is not loaded, or accessibility is off | Run `npx agent-device-x86sim serve` again. It stops a phone that lacks the hook and boots it again. |
|
|
184
|
+
| `--provider-app is not supported by x86Sim` | An old plugin sends the bundle id as `--provider-app` | Update the plugin with `agent-device plugins update agent-device-x86sim`, then stop the daemon. |
|
|
185
|
+
| A screenshot shows the screen from before the last `press` | The phone has not drawn the new frame yet | Wait 2 seconds and take the screenshot again. |
|
|
186
|
+
| `connect x86sim` is not a known provider | The daemon started before you installed the plugin | Stop the agent-device daemon and run the command again. |
|
|
187
|
+
|
|
188
|
+
## Limits
|
|
189
|
+
|
|
190
|
+
- Apps must be arm64 iOS simulator builds. App Store builds and device builds do not run.
|
|
191
|
+
- x86Sim has its own gaps, such as no Maps tiles, no Bonjour, no sensors, and no app sandbox. See [x86Sim's status and limitations](https://github.com/x86sim/x86sim#status-and-limitations).
|
|
192
|
+
- `snapshot -i` reads the app in front. System alerts over an app and web content inside an app are not listed yet.
|
|
193
|
+
- x86Sim downloads Apple's iOS simulator runtime to your machine. Apple's license for that runtime covers Apple hardware.
|
|
Binary file
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { r as packagedHookPath, t as startServer } from "./start-server-C84E8KRm.js";
|
|
3
|
+
import { t as discoverTarget } from "./system-DMZAX-z7.js";
|
|
4
|
+
import { hostname } from "node:os";
|
|
5
|
+
import { parseArgs } from "node:util";
|
|
6
|
+
//#region src/cli/args.ts
|
|
7
|
+
/** A mistake in the command line. The CLI prints it with the usage text and exits with 2. */
|
|
8
|
+
var UsageError = class extends Error {};
|
|
9
|
+
const USAGE = `Usage: agent-device-x86sim <command>
|
|
10
|
+
|
|
11
|
+
Commands:
|
|
12
|
+
serve Prepare the phone and run the server that agent-device connects to.
|
|
13
|
+
hook-path Print the path of the accessibility hook this package ships.
|
|
14
|
+
|
|
15
|
+
Options of serve:
|
|
16
|
+
--appimage PATH The x86Sim AppImage. Else $X86SIM_APPIMAGE, else the newest x86sim-*.AppImage
|
|
17
|
+
in ~/x86sim, ~/Applications, ~/Downloads or the current folder.
|
|
18
|
+
--device NAME|DIR The phone, such as device-a64-iphone-17-pro, or its folder. Else the only phone
|
|
19
|
+
x86Sim has created.
|
|
20
|
+
--port PORT Default 4723.
|
|
21
|
+
--host HOST Default 127.0.0.1.
|
|
22
|
+
--verbose Log every request and the output of x86Sim's boot script.
|
|
23
|
+
`;
|
|
24
|
+
function parsePort(text) {
|
|
25
|
+
const port = Number(text);
|
|
26
|
+
if (!/^\d+$/.test(text) || port > 65535) throw new UsageError(`--port must be a number from 0 to 65535, not "${text}".`);
|
|
27
|
+
return port;
|
|
28
|
+
}
|
|
29
|
+
const OPTIONS = {
|
|
30
|
+
appimage: { type: "string" },
|
|
31
|
+
device: { type: "string" },
|
|
32
|
+
host: { type: "string" },
|
|
33
|
+
port: { type: "string" },
|
|
34
|
+
verbose: { type: "boolean" },
|
|
35
|
+
help: {
|
|
36
|
+
type: "boolean",
|
|
37
|
+
short: "h"
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
function scan(argv) {
|
|
41
|
+
try {
|
|
42
|
+
return parseArgs({
|
|
43
|
+
args: [...argv],
|
|
44
|
+
options: OPTIONS,
|
|
45
|
+
allowPositionals: true
|
|
46
|
+
});
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new UsageError(error instanceof Error ? error.message : String(error));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Turns the arguments after `node cli.js` into a command. */
|
|
52
|
+
function parseCli(argv) {
|
|
53
|
+
const { values, positionals } = scan(argv);
|
|
54
|
+
const [command, ...extra] = positionals;
|
|
55
|
+
if (values.help || command === void 0 || command === "help") return { kind: "help" };
|
|
56
|
+
if (extra.length > 0) throw new UsageError(`Unexpected argument "${extra[0]}".`);
|
|
57
|
+
switch (command) {
|
|
58
|
+
case "hook-path": return { kind: "hook-path" };
|
|
59
|
+
case "serve": return {
|
|
60
|
+
kind: "serve",
|
|
61
|
+
options: {
|
|
62
|
+
...values.appimage === void 0 ? {} : { appimage: values.appimage },
|
|
63
|
+
...values.device === void 0 ? {} : { device: values.device },
|
|
64
|
+
host: values.host ?? "127.0.0.1",
|
|
65
|
+
port: parsePort(values.port ?? "4723"),
|
|
66
|
+
verbose: values.verbose ?? false
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
default: throw new UsageError(`Unknown command "${command}".`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/cli/serve.ts
|
|
74
|
+
const log = (line) => process.stderr.write(`${line}\n`);
|
|
75
|
+
/** The lines that tell the user what to run next. */
|
|
76
|
+
function readyMessage(endpoint, device) {
|
|
77
|
+
const port = new URL(endpoint).port;
|
|
78
|
+
return [
|
|
79
|
+
`Ready. The server for the phone ${device} answers at ${endpoint}.`,
|
|
80
|
+
"On the machine that runs agent-device, run:",
|
|
81
|
+
" agent-device plugins add agent-device-x86sim",
|
|
82
|
+
" agent-device connect x86sim",
|
|
83
|
+
`If that is another machine, forward the port first: ssh -N -L ${port}:localhost:${port} <user>@${hostname()}`,
|
|
84
|
+
"Stop the server with Ctrl+C. The phone keeps running."
|
|
85
|
+
].join("\n");
|
|
86
|
+
}
|
|
87
|
+
/** `agent-device-x86sim serve`. Returns when the server is ready. The open server keeps the process alive. */
|
|
88
|
+
async function serve(options) {
|
|
89
|
+
const target = await discoverTarget(options);
|
|
90
|
+
log(`Using ${target.x86sim.label}`);
|
|
91
|
+
log(`Using the phone ${target.deviceName}`);
|
|
92
|
+
const server = await startServer({
|
|
93
|
+
target,
|
|
94
|
+
host: options.host,
|
|
95
|
+
port: options.port,
|
|
96
|
+
verbose: options.verbose,
|
|
97
|
+
log
|
|
98
|
+
});
|
|
99
|
+
log(readyMessage(server.endpoint, target.deviceName));
|
|
100
|
+
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => void server.close().then(() => process.exit(0)));
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/cli.ts
|
|
104
|
+
async function main(argv) {
|
|
105
|
+
const command = parseCli(argv);
|
|
106
|
+
switch (command.kind) {
|
|
107
|
+
case "help":
|
|
108
|
+
process.stdout.write(USAGE);
|
|
109
|
+
return;
|
|
110
|
+
case "hook-path":
|
|
111
|
+
process.stdout.write(`${await packagedHookPath()}\n`);
|
|
112
|
+
return;
|
|
113
|
+
case "serve":
|
|
114
|
+
await serve(command.options);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
main(process.argv.slice(2)).catch((error) => {
|
|
119
|
+
if (error instanceof UsageError) {
|
|
120
|
+
process.stderr.write(`${error.message}\n\n${USAGE}`);
|
|
121
|
+
process.exit(2);
|
|
122
|
+
}
|
|
123
|
+
process.stderr.write(`agent-device-x86sim: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
124
|
+
process.exit(1);
|
|
125
|
+
});
|
|
126
|
+
//#endregion
|
|
127
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AgentDevicePlugin } from "agent-device/plugins";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
export type X86SimOptions = {
|
|
4
|
+
/** The x86sim-webdriver server. Else `X86SIM_WEBDRIVER_ENDPOINT`, else `http://127.0.0.1:4723`. */
|
|
5
|
+
endpoint?: string;
|
|
6
|
+
};
|
|
7
|
+
/** agent-device drives an iOS simulator under x86Sim through its built-in WebDriver engine. */
|
|
8
|
+
export default function x86sim(options?: X86SimOptions): AgentDevicePlugin;
|
|
9
|
+
//#endregion
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { r as NotSetUpError, t as discoverTarget } from "./system-DMZAX-z7.js";
|
|
2
|
+
//#region src/auto-start.ts
|
|
3
|
+
/**
|
|
4
|
+
* The phone to start a server for, when agent-device runs on the machine that has x86Sim. That
|
|
5
|
+
* is a Linux machine where no server address was given and x86Sim is set up. Anything else means
|
|
6
|
+
* a server runs somewhere else, and `undefined` leaves the address alone. A machine that has
|
|
7
|
+
* x86Sim but no phone, or several phones to choose from, is an error that names the fix.
|
|
8
|
+
*/
|
|
9
|
+
async function findAutoTarget(endpoint, env, device, platform = process.platform, discover = discoverTarget) {
|
|
10
|
+
if (endpoint ?? env.X86SIM_WEBDRIVER_ENDPOINT) return void 0;
|
|
11
|
+
if (platform !== "linux") return void 0;
|
|
12
|
+
try {
|
|
13
|
+
return await discover({
|
|
14
|
+
appimage: env.X86SIM_APPIMAGE,
|
|
15
|
+
device
|
|
16
|
+
});
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (error instanceof NotSetUpError) return void 0;
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const loadStartServer = async (options) => (await import("./start-server-C84E8KRm.js").then((n) => n.n)).startServer(options);
|
|
23
|
+
/** One server for the daemon, started on the first session and closed with the plugin. */
|
|
24
|
+
function createAutoServer(start = loadStartServer) {
|
|
25
|
+
let running;
|
|
26
|
+
return {
|
|
27
|
+
async endpoint(target) {
|
|
28
|
+
running ??= start({
|
|
29
|
+
target,
|
|
30
|
+
host: "127.0.0.1",
|
|
31
|
+
port: 0,
|
|
32
|
+
verbose: false,
|
|
33
|
+
log: (line) => process.stderr.write(`${line}\n`)
|
|
34
|
+
});
|
|
35
|
+
try {
|
|
36
|
+
return (await running).endpoint;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
running = void 0;
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
async close() {
|
|
43
|
+
const server = running;
|
|
44
|
+
running = void 0;
|
|
45
|
+
await (await server?.catch(() => void 0))?.close();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/profile-fields.ts
|
|
51
|
+
/**
|
|
52
|
+
* What x86Sim does with each cloud provider profile field. The record is total over the
|
|
53
|
+
* installed `CloudProviderProfileFields` keys, so a field added upstream fails the build here
|
|
54
|
+
* until it is answered. x86Sim is a local simulator, not a cloud: it reads none of them.
|
|
55
|
+
*/
|
|
56
|
+
const X86SIM_PROFILE_FIELDS = {
|
|
57
|
+
provider: "x86sim",
|
|
58
|
+
label: "x86Sim",
|
|
59
|
+
fields: {
|
|
60
|
+
providerApp: "refused",
|
|
61
|
+
providerOsVersion: "refused",
|
|
62
|
+
providerDeviceType: "refused",
|
|
63
|
+
providerProject: "refused",
|
|
64
|
+
providerBuild: "refused",
|
|
65
|
+
providerSessionName: "refused",
|
|
66
|
+
providerDeviceOrientation: "refused",
|
|
67
|
+
providerGeoLocation: "refused",
|
|
68
|
+
providerTimezone: "refused",
|
|
69
|
+
providerAppiumVersion: "refused",
|
|
70
|
+
providerLanguage: "refused",
|
|
71
|
+
providerLocale: "refused",
|
|
72
|
+
providerNetworkProfile: "refused",
|
|
73
|
+
providerCustomNetwork: "refused",
|
|
74
|
+
providerNoResignApp: "refused",
|
|
75
|
+
providerNetworkLogs: "refused",
|
|
76
|
+
providerNetworkHosts: "refused",
|
|
77
|
+
awsProjectArn: "refused",
|
|
78
|
+
awsDeviceArn: "refused",
|
|
79
|
+
awsAppArn: "refused",
|
|
80
|
+
awsRegion: "refused",
|
|
81
|
+
awsInteractionMode: "refused"
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/connection.ts
|
|
86
|
+
const PROVIDER = "x86sim";
|
|
87
|
+
const SERVICE = "x86Sim";
|
|
88
|
+
const DEFAULT_DEVICE = "x86Sim iPhone";
|
|
89
|
+
const STATUS_TIMEOUT_MS = 5e3;
|
|
90
|
+
/** `--device` names an x86Sim phone only when the user set it, because agent-device fills in a default name. */
|
|
91
|
+
const chosenPhone = (device) => typeof device === "string" && device !== "x86Sim iPhone" ? device : void 0;
|
|
92
|
+
/** Options win over the environment, and the environment wins over the local default. */
|
|
93
|
+
function resolveEndpoint(endpoint, env) {
|
|
94
|
+
return endpoint ?? env.X86SIM_WEBDRIVER_ENDPOINT ?? "http://127.0.0.1:4723";
|
|
95
|
+
}
|
|
96
|
+
/** `connect x86sim` takes no provider flags, so a set one is a mistake worth naming. */
|
|
97
|
+
function rejectProviderFlags(flags, host) {
|
|
98
|
+
const set = Object.keys(X86SIM_PROFILE_FIELDS.fields).filter((key) => flags[key] !== void 0);
|
|
99
|
+
if (set.length > 0) throw host.createError("INVALID_ARGS", `${SERVICE} does not use these provider flags: ${set.join(", ")}.`);
|
|
100
|
+
}
|
|
101
|
+
function createConnection(options) {
|
|
102
|
+
return {
|
|
103
|
+
capabilities: {
|
|
104
|
+
leaseKind: "direct-device-provider",
|
|
105
|
+
requiresAppAttachment: false,
|
|
106
|
+
requiresRemoteDaemon: false,
|
|
107
|
+
supportsArtifacts: false,
|
|
108
|
+
supportsDeferredAppSelection: false,
|
|
109
|
+
supportsDirectPortReverse: false,
|
|
110
|
+
usesCloudWebDriverLease: true
|
|
111
|
+
},
|
|
112
|
+
resolve: ({ flags, host }) => {
|
|
113
|
+
rejectProviderFlags(flags, host);
|
|
114
|
+
return { profile: {
|
|
115
|
+
leaseProvider: PROVIDER,
|
|
116
|
+
platform: "ios",
|
|
117
|
+
device: flags.device ?? "x86Sim iPhone"
|
|
118
|
+
} };
|
|
119
|
+
},
|
|
120
|
+
verify: async ({ flags, env, host }) => {
|
|
121
|
+
const target = await findAutoTarget(options.endpoint, env, chosenPhone(flags.device));
|
|
122
|
+
if (target) return {
|
|
123
|
+
provider: PROVIDER,
|
|
124
|
+
service: SERVICE,
|
|
125
|
+
verificationMessage: `${target.x86sim.label} is installed here, and the phone is ${target.deviceName}. The server and the phone start when the first session opens, which can take 1.5 to 6 minutes.`,
|
|
126
|
+
device: {
|
|
127
|
+
status: "verified",
|
|
128
|
+
name: flags.device ?? "x86Sim iPhone",
|
|
129
|
+
platform: "ios"
|
|
130
|
+
},
|
|
131
|
+
app: { status: "deferred" }
|
|
132
|
+
};
|
|
133
|
+
const endpoint = resolveEndpoint(options.endpoint, env);
|
|
134
|
+
const statusUrl = new URL("status", endpoint.endsWith("/") ? endpoint : `${endpoint}/`);
|
|
135
|
+
let ready;
|
|
136
|
+
try {
|
|
137
|
+
const response = await fetch(statusUrl, { signal: AbortSignal.timeout(STATUS_TIMEOUT_MS) });
|
|
138
|
+
const body = await response.json();
|
|
139
|
+
ready = response.ok ? body.value?.ready : void 0;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
throw host.createError("COMMAND_FAILED", `${SERVICE} WebDriver server is not reachable at ${statusUrl.href}. Run \`npx agent-device-x86sim serve\` on the Linux machine that has x86Sim, and forward its port 4723 to this machine. On that Linux machine, install x86Sim and create a phone, and agent-device starts the server by itself.`, { cause: String(error) });
|
|
142
|
+
}
|
|
143
|
+
if (ready !== true) throw host.createError("COMMAND_FAILED", `${SERVICE} WebDriver server at ${statusUrl.href} did not report ready.`);
|
|
144
|
+
return {
|
|
145
|
+
provider: PROVIDER,
|
|
146
|
+
service: SERVICE,
|
|
147
|
+
verificationMessage: `${SERVICE} WebDriver server is ready at ${endpoint}.`,
|
|
148
|
+
device: {
|
|
149
|
+
status: "verified",
|
|
150
|
+
name: flags.device ?? "x86Sim iPhone",
|
|
151
|
+
platform: "ios"
|
|
152
|
+
},
|
|
153
|
+
app: { status: "deferred" }
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/index.ts
|
|
160
|
+
/**
|
|
161
|
+
* The server answers only the routes behind these operations, so the rest are marked
|
|
162
|
+
* unsupported instead of being sent to a route that cannot answer.
|
|
163
|
+
*/
|
|
164
|
+
const CAPABILITY_OVERRIDES = {
|
|
165
|
+
back: {
|
|
166
|
+
support: "unsupported",
|
|
167
|
+
note: "iOS has no back button and the server has no /back route."
|
|
168
|
+
},
|
|
169
|
+
orientation: {
|
|
170
|
+
support: "unsupported",
|
|
171
|
+
note: "The server has no rotation or orientation routes."
|
|
172
|
+
},
|
|
173
|
+
fill: {
|
|
174
|
+
support: "unsupported",
|
|
175
|
+
note: "The server has no element routes, so there is no focus to fill."
|
|
176
|
+
},
|
|
177
|
+
keyboard: {
|
|
178
|
+
support: "unsupported",
|
|
179
|
+
note: "The server does not report or dismiss the keyboard."
|
|
180
|
+
},
|
|
181
|
+
"clipboard.read": {
|
|
182
|
+
support: "unsupported",
|
|
183
|
+
note: "The server has no clipboard access."
|
|
184
|
+
},
|
|
185
|
+
"clipboard.write": {
|
|
186
|
+
support: "unsupported",
|
|
187
|
+
note: "The server has no clipboard access."
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
/** agent-device drives an iOS simulator under x86Sim through its built-in WebDriver engine. */
|
|
191
|
+
function x86sim(options = {}) {
|
|
192
|
+
return {
|
|
193
|
+
apiVersion: 2,
|
|
194
|
+
provider: PROVIDER,
|
|
195
|
+
credentials: { variables: [] },
|
|
196
|
+
connection: createConnection(options),
|
|
197
|
+
setup: (host) => {
|
|
198
|
+
const auto = createAutoServer();
|
|
199
|
+
return {
|
|
200
|
+
webDriver: {
|
|
201
|
+
provider: PROVIDER,
|
|
202
|
+
profileFields: X86SIM_PROFILE_FIELDS,
|
|
203
|
+
platform: "ios",
|
|
204
|
+
deviceName: DEFAULT_DEVICE,
|
|
205
|
+
endpoint: resolveEndpoint(options.endpoint, host.env),
|
|
206
|
+
webdriverCapabilities: {
|
|
207
|
+
platformName: "iOS",
|
|
208
|
+
"appium:automationName": "XCUITest",
|
|
209
|
+
"appium:deviceName": DEFAULT_DEVICE
|
|
210
|
+
},
|
|
211
|
+
capabilityOverrides: CAPABILITY_OVERRIDES,
|
|
212
|
+
prepareSession: async ({ base, req }) => {
|
|
213
|
+
const target = await findAutoTarget(options.endpoint, host.env, chosenPhone(req?.flags?.device));
|
|
214
|
+
return target ? {
|
|
215
|
+
...base,
|
|
216
|
+
endpoint: await auto.endpoint(target)
|
|
217
|
+
} : base;
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
dispose: () => auto.close()
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
//#endregion
|
|
226
|
+
export { x86sim as default };
|