spana-test 0.0.2 → 0.2.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/.agents/skills/spana-testing/SKILL.md +304 -0
- package/README.md +308 -88
- package/dist/agent/index.d.ts +110 -0
- package/dist/agent/index.js +25 -0
- package/dist/allure-PTTVORQ6.js +124 -0
- package/dist/allure-PTTVORQ6.js.map +1 -0
- package/dist/android-PAPJJWVN.js +34 -0
- package/dist/android-PAPJJWVN.js.map +1 -0
- package/dist/chunk-3FSZNKEF.js +62 -0
- package/dist/chunk-3FSZNKEF.js.map +1 -0
- package/dist/chunk-3YR4GUGE.js +249 -0
- package/dist/chunk-3YR4GUGE.js.map +1 -0
- package/dist/{discover-XIRJTZ7Z.js → chunk-AEKDFFPJ.js} +12 -5
- package/dist/{discover-XIRJTZ7Z.js.map → chunk-AEKDFFPJ.js.map} +1 -1
- package/dist/chunk-BF37W5EG.js +125 -0
- package/dist/chunk-BF37W5EG.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-EXLUY7KT.js +21 -0
- package/dist/chunk-EXLUY7KT.js.map +1 -0
- package/dist/chunk-FNDOEMOL.js +62 -0
- package/dist/chunk-FNDOEMOL.js.map +1 -0
- package/dist/{chunk-CYEDLQJ4.js → chunk-GZK22EIE.js} +76 -102
- package/dist/chunk-GZK22EIE.js.map +1 -0
- package/dist/chunk-HWFDXIXR.js +183 -0
- package/dist/chunk-HWFDXIXR.js.map +1 -0
- package/dist/chunk-IJIASIX5.js +314 -0
- package/dist/chunk-IJIASIX5.js.map +1 -0
- package/dist/chunk-KJPHH2TW.js +168 -0
- package/dist/chunk-KJPHH2TW.js.map +1 -0
- package/dist/chunk-L7MFJF46.js +137 -0
- package/dist/chunk-L7MFJF46.js.map +1 -0
- package/dist/chunk-MRH7SK52.js +134 -0
- package/dist/chunk-MRH7SK52.js.map +1 -0
- package/dist/chunk-P7JQRLP4.js +114 -0
- package/dist/chunk-P7JQRLP4.js.map +1 -0
- package/dist/chunk-S2XNAKSO.js +1087 -0
- package/dist/chunk-S2XNAKSO.js.map +1 -0
- package/dist/chunk-S4R4OR7T.js +358 -0
- package/dist/chunk-S4R4OR7T.js.map +1 -0
- package/dist/chunk-SFBRFB2N.js +277 -0
- package/dist/chunk-SFBRFB2N.js.map +1 -0
- package/dist/chunk-VNYF5BHX.js +494 -0
- package/dist/chunk-VNYF5BHX.js.map +1 -0
- package/dist/chunk-WBU34APM.js +38 -0
- package/dist/chunk-WBU34APM.js.map +1 -0
- package/dist/chunk-WQ4GXUUE.js +2402 -0
- package/dist/chunk-WQ4GXUUE.js.map +1 -0
- package/dist/chunk-YBZCOQXJ.js +311 -0
- package/dist/chunk-YBZCOQXJ.js.map +1 -0
- package/dist/cli.js +428 -34
- package/dist/cli.js.map +1 -1
- package/dist/compiler-74VGKZO6.js +312 -0
- package/dist/compiler-74VGKZO6.js.map +1 -0
- package/dist/config-loader-BJJ3IJJ7.js +9 -0
- package/dist/config-loader-BJJ3IJJ7.js.map +1 -0
- package/dist/console-XWKUTP3D.js +164 -0
- package/dist/console-XWKUTP3D.js.map +1 -0
- package/dist/coordinator-BbUjvvnX.d.ts +383 -0
- package/dist/discover-KZKXHZZA.js +14 -0
- package/dist/discover-KZKXHZZA.js.map +1 -0
- package/dist/doctor-command-T2UX5RV5.js +732 -0
- package/dist/doctor-command-T2UX5RV5.js.map +1 -0
- package/dist/element-DZ0HyJ3C.d.ts +25 -0
- package/dist/flow-BUC9Mf8W.d.ts +128 -0
- package/dist/gherkin/steps.d.ts +32 -0
- package/dist/gherkin/steps.js +39 -0
- package/dist/gherkin/steps.js.map +1 -0
- package/dist/{html-GRB34S6X.js → html-GE6Q4DCG.js} +76 -22
- package/dist/html-GE6Q4DCG.js.map +1 -0
- package/dist/index.d.ts +159 -144
- package/dist/index.js +39 -165
- package/dist/index.js.map +1 -1
- package/dist/init-command-GVMRXIMY.js +121 -0
- package/dist/init-command-GVMRXIMY.js.map +1 -0
- package/dist/init-flow-command-R76AXF4Z.js +34 -0
- package/dist/init-flow-command-R76AXF4Z.js.map +1 -0
- package/dist/installer-YZJ4DV3F.js +22 -0
- package/dist/installer-YZJ4DV3F.js.map +1 -0
- package/dist/ios-ZW6XVNLG.js +50 -0
- package/dist/ios-ZW6XVNLG.js.map +1 -0
- package/dist/json-KS67BZYU.js +39 -0
- package/dist/json-KS67BZYU.js.map +1 -0
- package/dist/{junit-NAGZJOGQ.js → junit-HLC62MK6.js} +15 -4
- package/dist/junit-HLC62MK6.js.map +1 -0
- package/dist/provider-A57C3MU6.js +12 -0
- package/dist/provider-A57C3MU6.js.map +1 -0
- package/dist/redact-U72BUBBR.js +77 -0
- package/dist/redact-U72BUBBR.js.map +1 -0
- package/dist/runner-UXNHVVGG.js +20 -0
- package/dist/runner-UXNHVVGG.js.map +1 -0
- package/dist/server-W7OA3DDN.js +530 -0
- package/dist/server-W7OA3DDN.js.map +1 -0
- package/dist/session-TMNOKYLG.js +17 -0
- package/dist/session-TMNOKYLG.js.map +1 -0
- package/dist/studio-command-6VHTHDUK.js +24 -0
- package/dist/studio-command-6VHTHDUK.js.map +1 -0
- package/dist/test-command-AHMOZLV4.js +2852 -0
- package/dist/test-command-AHMOZLV4.js.map +1 -0
- package/dist/validator-35624P7S.js +20 -0
- package/dist/validator-35624P7S.js.map +1 -0
- package/package.json +41 -4
- package/studio-dist/assets/index-DC6DIXfl.js +188 -0
- package/studio-dist/assets/index-DDKsnBwD.css +1 -0
- package/studio-dist/index.html +13 -0
- package/dist/chunk-CYEDLQJ4.js.map +0 -1
- package/dist/chunk-PVNNKPBW.js +0 -64
- package/dist/chunk-PVNNKPBW.js.map +0 -1
- package/dist/chunk-VZZH66U5.js +0 -1781
- package/dist/chunk-VZZH66U5.js.map +0 -1
- package/dist/console-GPV3M3PC.js +0 -71
- package/dist/console-GPV3M3PC.js.map +0 -1
- package/dist/html-GRB34S6X.js.map +0 -1
- package/dist/json-FK2NSRGC.js +0 -20
- package/dist/json-FK2NSRGC.js.map +0 -1
- package/dist/junit-NAGZJOGQ.js.map +0 -1
- package/dist/runner-LBQUCG3K.js +0 -12
- package/dist/session-U7VP5J2C.js +0 -122
- package/dist/session-U7VP5J2C.js.map +0 -1
- package/dist/test-command-WPYLJYIK.js +0 -636
- package/dist/test-command-WPYLJYIK.js.map +0 -1
- package/dist/validator-J4YSBB66.js +0 -33
- package/dist/validator-J4YSBB66.js.map +0 -1
- /package/dist/{runner-LBQUCG3K.js.map → agent/index.js.map} +0 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__require
|
|
3
|
+
} from "./chunk-DGUM43GV.js";
|
|
4
|
+
|
|
5
|
+
// src/device/ios.ts
|
|
6
|
+
import { execFileSync, execSync } from "child_process";
|
|
7
|
+
import { readFileSync, unlinkSync } from "fs";
|
|
8
|
+
function listIOSSimulators() {
|
|
9
|
+
try {
|
|
10
|
+
const output = execSync("xcrun simctl list devices -j", { encoding: "utf-8" });
|
|
11
|
+
const data = JSON.parse(output);
|
|
12
|
+
const simulators = [];
|
|
13
|
+
for (const [runtime, devices] of Object.entries(data.devices ?? {})) {
|
|
14
|
+
const runtimeName = runtime.replace("com.apple.CoreSimulator.SimRuntime.", "").replaceAll("-", ".");
|
|
15
|
+
for (const device of devices) {
|
|
16
|
+
simulators.push({
|
|
17
|
+
udid: device.udid,
|
|
18
|
+
name: device.name,
|
|
19
|
+
state: device.state,
|
|
20
|
+
runtime: runtimeName,
|
|
21
|
+
isAvailable: device.isAvailable ?? true
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return simulators;
|
|
26
|
+
} catch {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function listBootedSimulators() {
|
|
31
|
+
return listIOSSimulators().filter((s) => s.state === "Booted" && s.isAvailable);
|
|
32
|
+
}
|
|
33
|
+
function firstIOSSimulator() {
|
|
34
|
+
const booted = listBootedSimulators();
|
|
35
|
+
if (booted.length > 0) return booted[0];
|
|
36
|
+
const available = listIOSSimulators().filter((s) => s.isAvailable);
|
|
37
|
+
return available[0] ?? null;
|
|
38
|
+
}
|
|
39
|
+
function hasAppInstalledOnSimulator(udid, bundleId) {
|
|
40
|
+
if (!bundleId) return false;
|
|
41
|
+
try {
|
|
42
|
+
execSync(`xcrun simctl get_app_container ${udid} ${bundleId} app`, { stdio: "ignore" });
|
|
43
|
+
return true;
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function firstIOSSimulatorWithApp(bundleId) {
|
|
49
|
+
const bootedWithApp = listBootedSimulators().find(
|
|
50
|
+
(sim) => hasAppInstalledOnSimulator(sim.udid, bundleId)
|
|
51
|
+
);
|
|
52
|
+
if (bootedWithApp) return bootedWithApp;
|
|
53
|
+
const availableWithApp = listIOSSimulators().filter((sim) => sim.isAvailable).find((sim) => hasAppInstalledOnSimulator(sim.udid, bundleId));
|
|
54
|
+
if (availableWithApp) return availableWithApp;
|
|
55
|
+
return firstIOSSimulator();
|
|
56
|
+
}
|
|
57
|
+
function ensureIOSSimulator(bundleId) {
|
|
58
|
+
const sim = bundleId ? firstIOSSimulatorWithApp(bundleId) : firstIOSSimulator();
|
|
59
|
+
if (!sim) return null;
|
|
60
|
+
if (sim.state !== "Booted") {
|
|
61
|
+
console.log(`Booting iOS simulator "${sim.name}"...`);
|
|
62
|
+
bootSimulator(sim.udid);
|
|
63
|
+
}
|
|
64
|
+
return sim;
|
|
65
|
+
}
|
|
66
|
+
function bootSimulator(udid) {
|
|
67
|
+
try {
|
|
68
|
+
execSync(`xcrun simctl boot ${udid}`, { stdio: "ignore" });
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function installOnSimulator(udid, appPath) {
|
|
73
|
+
execSync(`xcrun simctl install ${udid} ${appPath}`);
|
|
74
|
+
}
|
|
75
|
+
function launchOnSimulator(udid, bundleId) {
|
|
76
|
+
execSync(`xcrun simctl launch ${udid} ${bundleId}`);
|
|
77
|
+
}
|
|
78
|
+
function launchWithUrlOnSimulator(udid, bundleId, url) {
|
|
79
|
+
execFileSync("xcrun", ["simctl", "launch", udid, bundleId, "--open-url", url]);
|
|
80
|
+
}
|
|
81
|
+
function installedUrlSchemesOnSimulator(udid, bundleId) {
|
|
82
|
+
if (!bundleId) return [];
|
|
83
|
+
try {
|
|
84
|
+
const appPath = execSync(`xcrun simctl get_app_container ${udid} ${bundleId} app`, {
|
|
85
|
+
encoding: "utf-8"
|
|
86
|
+
}).trim();
|
|
87
|
+
const raw = execFileSync(
|
|
88
|
+
"plutil",
|
|
89
|
+
["-extract", "CFBundleURLTypes", "json", "-o", "-", `${appPath}/Info.plist`],
|
|
90
|
+
{
|
|
91
|
+
encoding: "utf-8"
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
const urlTypes = JSON.parse(raw);
|
|
95
|
+
return urlTypes.flatMap((entry) => entry.CFBundleURLSchemes ?? []);
|
|
96
|
+
} catch {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function openUrlOnSimulator(udid, url) {
|
|
101
|
+
execFileSync("xcrun", ["simctl", "openurl", udid, url], { stdio: "ignore" });
|
|
102
|
+
}
|
|
103
|
+
function terminateOnSimulator(udid, bundleId) {
|
|
104
|
+
try {
|
|
105
|
+
execSync(`xcrun simctl terminate ${udid} ${bundleId}`, { stdio: "ignore" });
|
|
106
|
+
} catch {
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function listIOSPhysicalDevices() {
|
|
110
|
+
try {
|
|
111
|
+
const tmpFile = `/tmp/spana-devicectl-${Date.now()}.json`;
|
|
112
|
+
execSync(`xcrun devicectl list devices --json-output ${tmpFile} 2>/dev/null`, {
|
|
113
|
+
timeout: 1e4
|
|
114
|
+
});
|
|
115
|
+
const output = readFileSync(tmpFile, "utf-8");
|
|
116
|
+
try {
|
|
117
|
+
unlinkSync(tmpFile);
|
|
118
|
+
} catch {
|
|
119
|
+
}
|
|
120
|
+
const data = JSON.parse(output);
|
|
121
|
+
const devices = [];
|
|
122
|
+
for (const device of data?.result?.devices ?? []) {
|
|
123
|
+
const deviceType = device.hardwareProperties?.deviceType ?? "";
|
|
124
|
+
const transport = device.connectionProperties?.transportType;
|
|
125
|
+
const state = device.connectionProperties?.tunnelState;
|
|
126
|
+
if ((deviceType === "iPhone" || deviceType === "iPad") && transport && state === "connected") {
|
|
127
|
+
devices.push({
|
|
128
|
+
udid: device.hardwareProperties?.udid ?? device.identifier,
|
|
129
|
+
name: device.deviceProperties?.name ?? "Unknown",
|
|
130
|
+
connectionType: transport === "wired" ? "USB" : transport ?? "unknown"
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return devices;
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
let walkUSB2 = function(items) {
|
|
139
|
+
for (const item of items) {
|
|
140
|
+
if (item.serial_num && /iPhone|iPad|iPod/i.test(item._name ?? "")) {
|
|
141
|
+
devices.push({
|
|
142
|
+
udid: item.serial_num.replaceAll("-", ""),
|
|
143
|
+
name: item._name ?? "iOS Device",
|
|
144
|
+
connectionType: "USB"
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (item._items) walkUSB2(item._items);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
var walkUSB = walkUSB2;
|
|
151
|
+
const output = execSync("system_profiler SPUSBDataType -json 2>/dev/null", {
|
|
152
|
+
encoding: "utf-8",
|
|
153
|
+
timeout: 1e4
|
|
154
|
+
});
|
|
155
|
+
const data = JSON.parse(output);
|
|
156
|
+
const devices = [];
|
|
157
|
+
walkUSB2(data.SPUSBDataType ?? []);
|
|
158
|
+
return devices;
|
|
159
|
+
} catch {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function hasIproxy() {
|
|
164
|
+
try {
|
|
165
|
+
execFileSync("iproxy", ["--help"], { stdio: "ignore" });
|
|
166
|
+
return true;
|
|
167
|
+
} catch {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function firstIOSPhysicalDevice() {
|
|
172
|
+
const devices = listIOSPhysicalDevices();
|
|
173
|
+
return devices[0] ?? null;
|
|
174
|
+
}
|
|
175
|
+
function startIproxy(udid, localPort, devicePort) {
|
|
176
|
+
try {
|
|
177
|
+
execSync("which iproxy", { stdio: "ignore" });
|
|
178
|
+
} catch {
|
|
179
|
+
throw new Error("iproxy not found. Install with: brew install libimobiledevice");
|
|
180
|
+
}
|
|
181
|
+
const { spawn } = __require("child_process");
|
|
182
|
+
const proc = spawn("iproxy", [`${localPort}:${devicePort}`, "-u", udid], {
|
|
183
|
+
stdio: "ignore",
|
|
184
|
+
detached: true
|
|
185
|
+
});
|
|
186
|
+
proc.unref();
|
|
187
|
+
const waitUntil = Date.now() + 1500;
|
|
188
|
+
while (Date.now() < waitUntil) {
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
host: "localhost",
|
|
192
|
+
port: localPort,
|
|
193
|
+
cleanup: () => {
|
|
194
|
+
try {
|
|
195
|
+
proc.kill();
|
|
196
|
+
} catch {
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function connectPhysicalDevice(udid, wdaPort = 8100) {
|
|
202
|
+
const localPort = 8100 + Math.floor(Math.random() * 100);
|
|
203
|
+
return startIproxy(udid, localPort, wdaPort);
|
|
204
|
+
}
|
|
205
|
+
function installOnPhysicalDevice(udid, appPath) {
|
|
206
|
+
try {
|
|
207
|
+
execSync(`xcrun devicectl device install app --device ${udid} ${appPath}`, {
|
|
208
|
+
stdio: "inherit",
|
|
209
|
+
timeout: 12e4
|
|
210
|
+
});
|
|
211
|
+
} catch {
|
|
212
|
+
throw new Error(
|
|
213
|
+
`Failed to install app on device ${udid}. Ensure the app is signed for this device.`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function hasAppOnPhysicalDevice(udid, bundleId) {
|
|
218
|
+
if (!bundleId) return false;
|
|
219
|
+
try {
|
|
220
|
+
const tmpFile = `/tmp/spana-applist-${Date.now()}.json`;
|
|
221
|
+
execSync(
|
|
222
|
+
`xcrun devicectl device info apps --device ${udid} --json-output ${tmpFile} 2>/dev/null`,
|
|
223
|
+
{ timeout: 15e3 }
|
|
224
|
+
);
|
|
225
|
+
const output = readFileSync(tmpFile, "utf-8");
|
|
226
|
+
try {
|
|
227
|
+
unlinkSync(tmpFile);
|
|
228
|
+
} catch {
|
|
229
|
+
}
|
|
230
|
+
return output.includes(bundleId);
|
|
231
|
+
} catch {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function resetSimulatorKeychain(udid) {
|
|
236
|
+
execSync(`xcrun simctl keychain ${udid} reset`, { stdio: "ignore" });
|
|
237
|
+
}
|
|
238
|
+
function ensureAppInstalled(opts) {
|
|
239
|
+
const { udid, bundleId, appPath, isPhysicalDevice } = opts;
|
|
240
|
+
if (isPhysicalDevice) {
|
|
241
|
+
if (!hasAppOnPhysicalDevice(udid, bundleId)) {
|
|
242
|
+
console.log(`Installing ${bundleId} on physical device...`);
|
|
243
|
+
installOnPhysicalDevice(udid, appPath);
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
if (!hasAppInstalledOnSimulator(udid, bundleId)) {
|
|
247
|
+
console.log(`Installing ${bundleId} on simulator...`);
|
|
248
|
+
installOnSimulator(udid, appPath);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export {
|
|
254
|
+
listIOSSimulators,
|
|
255
|
+
listBootedSimulators,
|
|
256
|
+
firstIOSSimulator,
|
|
257
|
+
hasAppInstalledOnSimulator,
|
|
258
|
+
firstIOSSimulatorWithApp,
|
|
259
|
+
ensureIOSSimulator,
|
|
260
|
+
bootSimulator,
|
|
261
|
+
installOnSimulator,
|
|
262
|
+
launchOnSimulator,
|
|
263
|
+
launchWithUrlOnSimulator,
|
|
264
|
+
installedUrlSchemesOnSimulator,
|
|
265
|
+
openUrlOnSimulator,
|
|
266
|
+
terminateOnSimulator,
|
|
267
|
+
listIOSPhysicalDevices,
|
|
268
|
+
hasIproxy,
|
|
269
|
+
firstIOSPhysicalDevice,
|
|
270
|
+
startIproxy,
|
|
271
|
+
connectPhysicalDevice,
|
|
272
|
+
installOnPhysicalDevice,
|
|
273
|
+
hasAppOnPhysicalDevice,
|
|
274
|
+
resetSimulatorKeychain,
|
|
275
|
+
ensureAppInstalled
|
|
276
|
+
};
|
|
277
|
+
//# sourceMappingURL=chunk-SFBRFB2N.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/device/ios.ts"],"sourcesContent":["import { execFileSync, execSync } from \"node:child_process\";\nimport { readFileSync, unlinkSync } from \"node:fs\";\n\nexport interface IOSSimulator {\n udid: string;\n name: string;\n state: \"Booted\" | \"Shutdown\" | string;\n runtime: string; // e.g. \"iOS 17.5\"\n isAvailable: boolean;\n}\n\nexport interface IOSDevice {\n udid: string;\n name: string;\n type: \"simulator\" | \"device\";\n state: string;\n runtime?: string;\n}\n\n/** List iOS simulators */\nexport function listIOSSimulators(): IOSSimulator[] {\n try {\n const output = execSync(\"xcrun simctl list devices -j\", { encoding: \"utf-8\" });\n const data = JSON.parse(output);\n const simulators: IOSSimulator[] = [];\n\n for (const [runtime, devices] of Object.entries(data.devices ?? {})) {\n // runtime looks like \"com.apple.CoreSimulator.SimRuntime.iOS-17-5\"\n const runtimeName = runtime\n .replace(\"com.apple.CoreSimulator.SimRuntime.\", \"\")\n .replaceAll(\"-\", \".\");\n\n for (const device of devices as any[]) {\n simulators.push({\n udid: device.udid,\n name: device.name,\n state: device.state,\n runtime: runtimeName,\n isAvailable: device.isAvailable ?? true,\n });\n }\n }\n\n return simulators;\n } catch {\n return [];\n }\n}\n\n/** List booted iOS simulators */\nexport function listBootedSimulators(): IOSSimulator[] {\n return listIOSSimulators().filter((s) => s.state === \"Booted\" && s.isAvailable);\n}\n\n/** Get first booted simulator, or first available if none booted */\nexport function firstIOSSimulator(): IOSSimulator | null {\n const booted = listBootedSimulators();\n if (booted.length > 0) return booted[0]!;\n\n const available = listIOSSimulators().filter((s) => s.isAvailable);\n return available[0] ?? null;\n}\n\n/** Check whether an app is installed on a simulator */\nexport function hasAppInstalledOnSimulator(udid: string, bundleId: string): boolean {\n if (!bundleId) return false;\n\n try {\n execSync(`xcrun simctl get_app_container ${udid} ${bundleId} app`, { stdio: \"ignore\" });\n return true;\n } catch {\n return false;\n }\n}\n\n/** Prefer a simulator that already has the requested app installed */\nexport function firstIOSSimulatorWithApp(bundleId: string): IOSSimulator | null {\n const bootedWithApp = listBootedSimulators().find((sim) =>\n hasAppInstalledOnSimulator(sim.udid, bundleId),\n );\n if (bootedWithApp) return bootedWithApp;\n\n const availableWithApp = listIOSSimulators()\n .filter((sim) => sim.isAvailable)\n .find((sim) => hasAppInstalledOnSimulator(sim.udid, bundleId));\n if (availableWithApp) return availableWithApp;\n\n return firstIOSSimulator();\n}\n\n/**\n * Ensure an iOS simulator is available and booted.\n * If none booted, boots the first available simulator (preferring one with the app installed).\n * Returns the simulator or null if none available.\n */\nexport function ensureIOSSimulator(bundleId?: string): IOSSimulator | null {\n const sim = bundleId ? firstIOSSimulatorWithApp(bundleId) : firstIOSSimulator();\n if (!sim) return null;\n\n if (sim.state !== \"Booted\") {\n console.log(`Booting iOS simulator \"${sim.name}\"...`);\n bootSimulator(sim.udid);\n }\n\n return sim;\n}\n\n/** Boot a simulator by UDID */\nexport function bootSimulator(udid: string): void {\n try {\n execSync(`xcrun simctl boot ${udid}`, { stdio: \"ignore\" });\n } catch {\n // May already be booted — ignore\n }\n}\n\n/** Install app on simulator */\nexport function installOnSimulator(udid: string, appPath: string): void {\n execSync(`xcrun simctl install ${udid} ${appPath}`);\n}\n\n/** Launch app on simulator */\nexport function launchOnSimulator(udid: string, bundleId: string): void {\n execSync(`xcrun simctl launch ${udid} ${bundleId}`);\n}\n\n/** Launch app on simulator with a deep link URL (bypasses system confirmation dialog) */\nexport function launchWithUrlOnSimulator(udid: string, bundleId: string, url: string): void {\n execFileSync(\"xcrun\", [\"simctl\", \"launch\", udid, bundleId, \"--open-url\", url]);\n}\n\n/** List URL schemes registered by the installed app on simulator */\nexport function installedUrlSchemesOnSimulator(udid: string, bundleId: string): string[] {\n if (!bundleId) return [];\n\n try {\n const appPath = execSync(`xcrun simctl get_app_container ${udid} ${bundleId} app`, {\n encoding: \"utf-8\",\n }).trim();\n\n const raw = execFileSync(\n \"plutil\",\n [\"-extract\", \"CFBundleURLTypes\", \"json\", \"-o\", \"-\", `${appPath}/Info.plist`],\n {\n encoding: \"utf-8\",\n },\n );\n\n const urlTypes = JSON.parse(raw) as Array<{\n CFBundleURLSchemes?: string[];\n }>;\n\n return urlTypes.flatMap((entry) => entry.CFBundleURLSchemes ?? []);\n } catch {\n return [];\n }\n}\n\n/** Open a URL or deep link on simulator */\nexport function openUrlOnSimulator(udid: string, url: string): void {\n execFileSync(\"xcrun\", [\"simctl\", \"openurl\", udid, url], { stdio: \"ignore\" });\n}\n\n/** Terminate app on simulator */\nexport function terminateOnSimulator(udid: string, bundleId: string): void {\n try {\n execSync(`xcrun simctl terminate ${udid} ${bundleId}`, { stdio: \"ignore\" });\n } catch {\n // May not be running\n }\n}\n\n// ---------------------------------------------------------------------------\n// Physical device support\n// ---------------------------------------------------------------------------\n\nexport interface IOSPhysicalDevice {\n udid: string;\n name: string;\n connectionType: \"USB\" | \"Wi-Fi\" | string;\n}\n\n/**\n * List connected physical iOS devices using xcrun devicectl (Xcode 15+).\n * Falls back to system_profiler if devicectl is unavailable.\n */\nexport function listIOSPhysicalDevices(): IOSPhysicalDevice[] {\n // Try xcrun devicectl first (Xcode 15+)\n try {\n const tmpFile = `/tmp/spana-devicectl-${Date.now()}.json`;\n execSync(`xcrun devicectl list devices --json-output ${tmpFile} 2>/dev/null`, {\n timeout: 10_000,\n });\n const output = readFileSync(tmpFile, \"utf-8\");\n try {\n unlinkSync(tmpFile);\n } catch {\n /* cleanup */\n }\n\n const data = JSON.parse(output);\n const devices: IOSPhysicalDevice[] = [];\n\n for (const device of data?.result?.devices ?? []) {\n const deviceType = device.hardwareProperties?.deviceType ?? \"\";\n const transport = device.connectionProperties?.transportType;\n const state = device.connectionProperties?.tunnelState;\n\n // Only treat iPhones/iPads with an active tunnel as available physical\n // devices. devicectl can report remembered Wi-Fi devices with a transport\n // but tunnelState \"disconnected\", which should not trigger a device-first\n // test run attempt.\n if (\n (deviceType === \"iPhone\" || deviceType === \"iPad\") &&\n transport &&\n state === \"connected\"\n ) {\n devices.push({\n udid: device.hardwareProperties?.udid ?? device.identifier,\n name: device.deviceProperties?.name ?? \"Unknown\",\n connectionType: transport === \"wired\" ? \"USB\" : (transport ?? \"unknown\"),\n });\n }\n }\n\n return devices;\n } catch {\n // Fall back to system_profiler for older Xcode\n }\n\n try {\n const output = execSync(\"system_profiler SPUSBDataType -json 2>/dev/null\", {\n encoding: \"utf-8\",\n timeout: 10_000,\n });\n const data = JSON.parse(output);\n const devices: IOSPhysicalDevice[] = [];\n\n function walkUSB(items: any[]): void {\n for (const item of items) {\n // iOS devices have serial_num and contain \"iPhone\" or \"iPad\" in name\n if (item.serial_num && /iPhone|iPad|iPod/i.test(item._name ?? \"\")) {\n devices.push({\n udid: item.serial_num.replaceAll(\"-\", \"\"),\n name: item._name ?? \"iOS Device\",\n connectionType: \"USB\",\n });\n }\n if (item._items) walkUSB(item._items);\n }\n }\n\n walkUSB(data.SPUSBDataType ?? []);\n return devices;\n } catch {\n return [];\n }\n}\n\nexport function hasIproxy(): boolean {\n try {\n execFileSync(\"iproxy\", [\"--help\"], { stdio: \"ignore\" });\n return true;\n } catch {\n return false;\n }\n}\n\n/** Get first connected physical iOS device */\nexport function firstIOSPhysicalDevice(): IOSPhysicalDevice | null {\n const devices = listIOSPhysicalDevices();\n return devices[0] ?? null;\n}\n\n/**\n * Start iproxy to tunnel a port from localhost to a physical device via USB.\n * Requires libimobiledevice (`brew install libimobiledevice`).\n *\n * @returns A cleanup function to kill the iproxy process.\n */\nexport function startIproxy(\n udid: string,\n localPort: number,\n devicePort: number,\n): { host: string; port: number; cleanup: () => void } {\n // Check iproxy is available\n try {\n execSync(\"which iproxy\", { stdio: \"ignore\" });\n } catch {\n throw new Error(\"iproxy not found. Install with: brew install libimobiledevice\");\n }\n\n const { spawn } = require(\"node:child_process\") as typeof import(\"node:child_process\");\n const proc = spawn(\"iproxy\", [`${localPort}:${devicePort}`, \"-u\", udid], {\n stdio: \"ignore\",\n detached: true,\n });\n proc.unref();\n\n // Give iproxy a moment to bind\n const waitUntil = Date.now() + 1500;\n while (Date.now() < waitUntil) {\n /* busy wait */\n }\n\n return {\n host: \"localhost\",\n port: localPort,\n cleanup: () => {\n try {\n proc.kill();\n } catch {\n // already dead\n }\n },\n };\n}\n\n/**\n * Connect to a physical iOS device for testing.\n * Sets up iproxy tunnel and returns connection info for WDA.\n *\n * WDA must be pre-installed and running on the device.\n * Install with: xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner\n * -destination \"id=<UDID>\" test\n */\nexport function connectPhysicalDevice(\n udid: string,\n wdaPort = 8100,\n): { host: string; port: number; cleanup: () => void } {\n const localPort = 8100 + Math.floor(Math.random() * 100);\n return startIproxy(udid, localPort, wdaPort);\n}\n\n/**\n * Install an app on a physical iOS device using xcrun devicectl (Xcode 15+).\n * Accepts .app bundles or .ipa files.\n */\nexport function installOnPhysicalDevice(udid: string, appPath: string): void {\n try {\n execSync(`xcrun devicectl device install app --device ${udid} ${appPath}`, {\n stdio: \"inherit\",\n timeout: 120_000,\n });\n } catch {\n throw new Error(\n `Failed to install app on device ${udid}. Ensure the app is signed for this device.`,\n );\n }\n}\n\n/**\n * Check if an app is installed on a physical device.\n */\nexport function hasAppOnPhysicalDevice(udid: string, bundleId: string): boolean {\n if (!bundleId) return false;\n try {\n const tmpFile = `/tmp/spana-applist-${Date.now()}.json`;\n execSync(\n `xcrun devicectl device info apps --device ${udid} --json-output ${tmpFile} 2>/dev/null`,\n { timeout: 15_000 },\n );\n const output = readFileSync(tmpFile, \"utf-8\");\n try {\n unlinkSync(tmpFile);\n } catch {\n /* cleanup */\n }\n return output.includes(bundleId);\n } catch {\n return false;\n }\n}\n\n/** Reset simulator keychain (removes all stored passwords and certificates) */\nexport function resetSimulatorKeychain(udid: string): void {\n execSync(`xcrun simctl keychain ${udid} reset`, { stdio: \"ignore\" });\n}\n\n/**\n * Ensure an app is installed on the target device (simulator or physical).\n * Installs from appPath if not already present.\n */\nexport function ensureAppInstalled(opts: {\n udid: string;\n bundleId: string;\n appPath: string;\n isPhysicalDevice: boolean;\n}): void {\n const { udid, bundleId, appPath, isPhysicalDevice } = opts;\n\n if (isPhysicalDevice) {\n if (!hasAppOnPhysicalDevice(udid, bundleId)) {\n console.log(`Installing ${bundleId} on physical device...`);\n installOnPhysicalDevice(udid, appPath);\n }\n } else {\n if (!hasAppInstalledOnSimulator(udid, bundleId)) {\n console.log(`Installing ${bundleId} on simulator...`);\n installOnSimulator(udid, appPath);\n }\n }\n}\n"],"mappings":";;;;;AAAA,SAAS,cAAc,gBAAgB;AACvC,SAAS,cAAc,kBAAkB;AAmBlC,SAAS,oBAAoC;AAClD,MAAI;AACF,UAAM,SAAS,SAAS,gCAAgC,EAAE,UAAU,QAAQ,CAAC;AAC7E,UAAM,OAAO,KAAK,MAAM,MAAM;AAC9B,UAAM,aAA6B,CAAC;AAEpC,eAAW,CAAC,SAAS,OAAO,KAAK,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,GAAG;AAEnE,YAAM,cAAc,QACjB,QAAQ,uCAAuC,EAAE,EACjD,WAAW,KAAK,GAAG;AAEtB,iBAAW,UAAU,SAAkB;AACrC,mBAAW,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