@testver/testver 1.2.4 → 1.2.6
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/dist/index.js +941 -196
- package/dist/py-agent/testver_appium.py +553 -535
- package/dist/wdio-attach-service/index.cjs +236 -215
- package/dist/wdio-bootstrap/bootstrap.cjs +687 -666
- package/package.json +1 -1
- package/src/ui/static/assets/{index-B5ex4vcf.js → index-CdvPhYu6.js} +621 -621
- package/src/ui/static/assets/{index-C5li84-E.js → index-D8o46FhP.js} +1 -1
- package/src/ui/static/index.html +1 -1
package/dist/index.js
CHANGED
|
@@ -7520,7 +7520,9 @@ __export(local_mobile_tools_exports, {
|
|
|
7520
7520
|
resolveAdb: () => resolveAdb,
|
|
7521
7521
|
resolveLocalDeviceKey: () => resolveLocalDeviceKey,
|
|
7522
7522
|
startAvd: () => startAvd,
|
|
7523
|
+
startIosSimulator: () => startIosSimulator,
|
|
7523
7524
|
stopEmulator: () => stopEmulator,
|
|
7525
|
+
stopIosSimulator: () => stopIosSimulator,
|
|
7524
7526
|
wdaLocalPortFor: () => wdaLocalPortFor
|
|
7525
7527
|
});
|
|
7526
7528
|
import { spawn } from "child_process";
|
|
@@ -7845,7 +7847,7 @@ async function resolveLocalDeviceKey(deviceKey, explicitAdbPath) {
|
|
|
7845
7847
|
if (!deviceKey.startsWith(AVD_KEY_PREFIX)) return deviceKey;
|
|
7846
7848
|
return startAvd(deviceKey.slice(AVD_KEY_PREFIX.length), explicitAdbPath);
|
|
7847
7849
|
}
|
|
7848
|
-
async function captureAndroidScreenshotViaAdb(serial, explicitAdbPath) {
|
|
7850
|
+
async function captureAndroidScreenshotViaAdb(serial, explicitAdbPath, opts = {}) {
|
|
7849
7851
|
if (!serial) return null;
|
|
7850
7852
|
const adbPath = await findAdb(explicitAdbPath);
|
|
7851
7853
|
if (!adbPath) return null;
|
|
@@ -7860,7 +7862,7 @@ async function captureAndroidScreenshotViaAdb(serial, explicitAdbPath) {
|
|
|
7860
7862
|
} catch {
|
|
7861
7863
|
}
|
|
7862
7864
|
resolve35(null);
|
|
7863
|
-
}, 5e3);
|
|
7865
|
+
}, opts.timeoutMs ?? 5e3);
|
|
7864
7866
|
child2.stdout?.on("data", (b) => chunks.push(b));
|
|
7865
7867
|
child2.stderr?.on("data", (b) => {
|
|
7866
7868
|
err5 += b.toString("utf-8");
|
|
@@ -8076,6 +8078,38 @@ async function listIosSimulatorsUncached() {
|
|
|
8076
8078
|
if (!res.ok) return [];
|
|
8077
8079
|
return parseSimctlDevices(res.stdout);
|
|
8078
8080
|
}
|
|
8081
|
+
async function findIosSimulator(udid) {
|
|
8082
|
+
if (process.platform !== "darwin") throw new Error("iOS simulators run only on a Mac.");
|
|
8083
|
+
if (!isIosSimulatorUdid(udid)) throw new Error("Give the simulator UDID.");
|
|
8084
|
+
const sim = (await listIosSimulatorsUncached()).find((s) => s.serial.toUpperCase() === udid.toUpperCase());
|
|
8085
|
+
if (!sim) throw new Error("No iOS simulator with that UDID on this Mac.");
|
|
8086
|
+
return sim;
|
|
8087
|
+
}
|
|
8088
|
+
async function startIosSimulator(udid, opts = {}) {
|
|
8089
|
+
const sim = await findIosSimulator(udid);
|
|
8090
|
+
const label3 = simulatorLabel(sim);
|
|
8091
|
+
if (!sim.booted) {
|
|
8092
|
+
const boot = await run("xcrun", ["simctl", "boot", udid], { timeoutMs: 6e4 });
|
|
8093
|
+
if (!boot.ok && !/current state: Booted/i.test(boot.stderr)) {
|
|
8094
|
+
throw new Error(`The simulator "${label3}" did not start: ${(boot.stderr || boot.error || "").trim().split("\n")[0]}`);
|
|
8095
|
+
}
|
|
8096
|
+
}
|
|
8097
|
+
await run("open", ["-a", "Simulator", "--args", "-CurrentDeviceUDID", udid], { timeoutMs: 15e3 });
|
|
8098
|
+
const timeoutMs = opts.timeoutMs ?? 18e4;
|
|
8099
|
+
const ready = await run("xcrun", ["simctl", "bootstatus", udid], { timeoutMs });
|
|
8100
|
+
simulatorCache = null;
|
|
8101
|
+
if (!ready.ok) {
|
|
8102
|
+
throw new Error(`The simulator "${label3}" started but had not finished booting after ${Math.round(timeoutMs / 1e3)} s \u2014 wait for its home screen, then try again.`);
|
|
8103
|
+
}
|
|
8104
|
+
}
|
|
8105
|
+
async function stopIosSimulator(udid) {
|
|
8106
|
+
const sim = await findIosSimulator(udid);
|
|
8107
|
+
const r = await run("xcrun", ["simctl", "shutdown", udid], { timeoutMs: 3e4 });
|
|
8108
|
+
simulatorCache = null;
|
|
8109
|
+
if (!r.ok && !/current state: Shutdown/i.test(r.stderr)) {
|
|
8110
|
+
throw new Error(`Couldn't close "${simulatorLabel(sim)}": ${(r.stderr || r.error || "").trim().split("\n")[0]}`);
|
|
8111
|
+
}
|
|
8112
|
+
}
|
|
8079
8113
|
function parseSimctlDevices(stdout) {
|
|
8080
8114
|
try {
|
|
8081
8115
|
const parsed = JSON.parse(stdout);
|
|
@@ -8091,14 +8125,14 @@ function parseSimctlDevices(stdout) {
|
|
|
8091
8125
|
serial: sim.udid,
|
|
8092
8126
|
kind: "simulator",
|
|
8093
8127
|
// Label carries "(Simulator)" so every picker shows it without
|
|
8094
|
-
// needing its own kind-awareness
|
|
8095
|
-
|
|
8096
|
-
name: `${sim.name ?? "iOS Simulator"} (Simulator${booted ? ", booted" : ""})`,
|
|
8128
|
+
// needing its own kind-awareness.
|
|
8129
|
+
name: `${sim.name ?? "iOS Simulator"} (Simulator)`,
|
|
8097
8130
|
manufacturer: "Apple",
|
|
8098
8131
|
platformVersion: version,
|
|
8099
|
-
// 'connected' even when shutdown — XCUITest auto-boots by UDID,
|
|
8100
|
-
//
|
|
8101
|
-
//
|
|
8132
|
+
// 'connected' even when shutdown — XCUITest auto-boots by UDID, so
|
|
8133
|
+
// a saved run naming it still works. `booted` tells the two apart
|
|
8134
|
+
// for Settings (Start / Close, the count) and the device pickers
|
|
8135
|
+
// (running simulators only).
|
|
8102
8136
|
state: "connected",
|
|
8103
8137
|
booted
|
|
8104
8138
|
});
|
|
@@ -8264,7 +8298,7 @@ async function detectLocalMobileStatusNow(input) {
|
|
|
8264
8298
|
appium
|
|
8265
8299
|
};
|
|
8266
8300
|
}
|
|
8267
|
-
var ADB_HIT_CACHE_MS, ADB_MISS_CACHE_MS, adbCache, savedSdkCache, avdListCache, AVD_KEY_PREFIX, IOS_SHOT_FAIL_SKIP_MS, iosShotFailedAt, adbVersionCache, simulatorCache, xcodeCache, driversCache, driversInFlight, WEBVIEW_HINT, statusInFlight;
|
|
8301
|
+
var ADB_HIT_CACHE_MS, ADB_MISS_CACHE_MS, adbCache, savedSdkCache, avdListCache, AVD_KEY_PREFIX, IOS_SHOT_FAIL_SKIP_MS, iosShotFailedAt, adbVersionCache, simulatorCache, simulatorLabel, xcodeCache, driversCache, driversInFlight, WEBVIEW_HINT, statusInFlight;
|
|
8268
8302
|
var init_local_mobile_tools = __esm({
|
|
8269
8303
|
"src/mobile/local-mobile-tools.ts"() {
|
|
8270
8304
|
"use strict";
|
|
@@ -8278,10 +8312,12 @@ var init_local_mobile_tools = __esm({
|
|
|
8278
8312
|
iosShotFailedAt = /* @__PURE__ */ new Map();
|
|
8279
8313
|
adbVersionCache = /* @__PURE__ */ new Map();
|
|
8280
8314
|
simulatorCache = null;
|
|
8315
|
+
simulatorLabel = (sim) => (sim.name ?? sim.serial).replace(/\s*\(Simulator[^)]*\)$/, "");
|
|
8281
8316
|
xcodeCache = null;
|
|
8282
8317
|
driversCache = null;
|
|
8283
8318
|
driversInFlight = null;
|
|
8284
|
-
WEBVIEW_HINT =
|
|
8319
|
+
WEBVIEW_HINT = // Appium 3 (and 2.13+) refuses a feature name without its driver scope.
|
|
8320
|
+
"Hybrid apps (webviews): start Appium with `appium --allow-insecure uiautomator2:chromedriver_autodownload` (Appium before 2.13: `--allow-insecure chromedriver_autodownload`) so Android webview automation gets a matching chromedriver automatically. The app must also call setWebContentsDebuggingEnabled(true) (debug builds) \u2014 without it the webview never registers a WEBVIEW_* context and only native-tree automation of its content is possible.";
|
|
8285
8321
|
statusInFlight = null;
|
|
8286
8322
|
}
|
|
8287
8323
|
});
|
|
@@ -9271,6 +9307,10 @@ var init_local_appium = __esm({
|
|
|
9271
9307
|
* show them with a "Tap to authorize" / "Offline" badge instead of
|
|
9272
9308
|
* silently dropping them — the user wants to know their device is
|
|
9273
9309
|
* plugged in even when something's wrong.
|
|
9310
|
+
*
|
|
9311
|
+
* Only devices that are on: emulators that aren't running and shut-down
|
|
9312
|
+
* simulators are left out (start them in Settings → Connectors → Local
|
|
9313
|
+
* Devices). A saved run that names one still starts it.
|
|
9274
9314
|
*/
|
|
9275
9315
|
async listDevices(creds) {
|
|
9276
9316
|
const out = [];
|
|
@@ -9280,23 +9320,12 @@ var init_local_appium = __esm({
|
|
|
9280
9320
|
for (const d of android.devices) {
|
|
9281
9321
|
out.push(probeToMobileDevice(d, "android"));
|
|
9282
9322
|
}
|
|
9283
|
-
for (const avd of android.avds ?? []) {
|
|
9284
|
-
if (avd.running) continue;
|
|
9285
|
-
out.push({
|
|
9286
|
-
id: `local-appium:${AVD_KEY_PREFIX}${avd.name}`,
|
|
9287
|
-
providerId: "local-appium",
|
|
9288
|
-
platform: "android",
|
|
9289
|
-
name: `${avd.name.replace(/_/g, " ")} (Emulator, starts when picked)`,
|
|
9290
|
-
os: "Android",
|
|
9291
|
-
realMobile: false,
|
|
9292
|
-
rawDeviceKey: `${AVD_KEY_PREFIX}${avd.name}`
|
|
9293
|
-
});
|
|
9294
|
-
}
|
|
9295
9323
|
const ios = await detectIosStatus(creds.iosToolsPath).catch((err5) => {
|
|
9296
9324
|
throw err5;
|
|
9297
9325
|
});
|
|
9298
9326
|
if (ios.available) {
|
|
9299
9327
|
for (const d of ios.devices) {
|
|
9328
|
+
if (d.kind === "simulator" && !d.booted) continue;
|
|
9300
9329
|
out.push(probeToMobileDevice(d, "ios"));
|
|
9301
9330
|
}
|
|
9302
9331
|
}
|
|
@@ -9342,8 +9371,14 @@ var init_local_appium = __esm({
|
|
|
9342
9371
|
// at once would otherwise both use 8100); a real device also gets
|
|
9343
9372
|
// the WebDriverAgent signing from Settings when it's filled in.
|
|
9344
9373
|
...isIos ? iosSessionCaps(creds, opts.deviceKey) : {},
|
|
9345
|
-
//
|
|
9346
|
-
|
|
9374
|
+
// No Appium idle timeout (0) for Testver's own local sessions: Testver
|
|
9375
|
+
// ends them itself (tab closed → 2 min, idle → 10 min, End session,
|
|
9376
|
+
// shutdown). The timeout was dangerous here — a session whose
|
|
9377
|
+
// UiAutomator2 server another session on the device had restarted
|
|
9378
|
+
// timed out 600 s later, and that cleanup force-stopped the device's
|
|
9379
|
+
// server, crashing whatever session was live then. Cloud providers
|
|
9380
|
+
// keep theirs (each session has its own vendor device).
|
|
9381
|
+
"appium:newCommandTimeout": 0,
|
|
9347
9382
|
"appium:noReset": false,
|
|
9348
9383
|
"appium:fullReset": false,
|
|
9349
9384
|
// Android launch-verification hardening. UiAutomator2 polls for
|
|
@@ -10793,8 +10828,15 @@ var init_cloud_bridge = __esm({
|
|
|
10793
10828
|
// src/mobile/reuse-ticket-store.ts
|
|
10794
10829
|
var reuse_ticket_store_exports = {};
|
|
10795
10830
|
__export(reuse_ticket_store_exports, {
|
|
10831
|
+
liveSessionMatches: () => liveSessionMatches,
|
|
10796
10832
|
reuseTicketStore: () => reuseTicketStore
|
|
10797
10833
|
});
|
|
10834
|
+
function liveSessionMatches(live, run2) {
|
|
10835
|
+
if (!live || live.providerId !== run2.providerId) return false;
|
|
10836
|
+
if (run2.deviceName && live.deviceName && String(live.deviceName).toLowerCase() !== String(run2.deviceName).toLowerCase()) return false;
|
|
10837
|
+
if (run2.appId && live.appId && String(live.appId) !== String(run2.appId)) return false;
|
|
10838
|
+
return true;
|
|
10839
|
+
}
|
|
10798
10840
|
var logger10, DEFAULT_TTL_MS, ReuseTicketStore, reuseTicketStore;
|
|
10799
10841
|
var init_reuse_ticket_store = __esm({
|
|
10800
10842
|
"src/mobile/reuse-ticket-store.ts"() {
|
|
@@ -10817,6 +10859,7 @@ var init_reuse_ticket_store = __esm({
|
|
|
10817
10859
|
deviceName: capabilities.deviceName,
|
|
10818
10860
|
platformName: capabilities.platformName,
|
|
10819
10861
|
platformVersion: capabilities.platformVersion,
|
|
10862
|
+
...capabilities.appId ? { appId: capabilities.appId } : {},
|
|
10820
10863
|
liveViewUrl: info.liveViewUrl,
|
|
10821
10864
|
dashboardUrl: info.dashboardUrl,
|
|
10822
10865
|
expiresAt: Date.now() + ttlMs,
|
|
@@ -10924,6 +10967,7 @@ __export(appium_project_exports, {
|
|
|
10924
10967
|
appiumTestFiles: () => appiumTestFiles,
|
|
10925
10968
|
deleteWebDriverSession: () => deleteWebDriverSession,
|
|
10926
10969
|
endLocalAppiumSessions: () => endLocalAppiumSessions,
|
|
10970
|
+
localRunSessionIds: () => localRunSessionIds,
|
|
10927
10971
|
usesAppiumClient: () => usesAppiumClient
|
|
10928
10972
|
});
|
|
10929
10973
|
import { readFileSync as readFileSync11, readdirSync as readdirSync5 } from "fs";
|
|
@@ -10975,6 +11019,18 @@ async function deleteWebDriverSession(hubUrl, sessionId) {
|
|
|
10975
11019
|
});
|
|
10976
11020
|
}
|
|
10977
11021
|
async function endLocalAppiumSessions(o) {
|
|
11022
|
+
const base = o.appiumUrl.replace(/\/+$/, "");
|
|
11023
|
+
let ended = 0;
|
|
11024
|
+
for (const id of await localRunSessionIds(o)) {
|
|
11025
|
+
try {
|
|
11026
|
+
await deleteWebDriverSession(base, id);
|
|
11027
|
+
ended++;
|
|
11028
|
+
} catch {
|
|
11029
|
+
}
|
|
11030
|
+
}
|
|
11031
|
+
return ended;
|
|
11032
|
+
}
|
|
11033
|
+
async function localRunSessionIds(o) {
|
|
10978
11034
|
const base = o.appiumUrl.replace(/\/+$/, "");
|
|
10979
11035
|
let sessions = [];
|
|
10980
11036
|
for (const path2 of ["/appium/sessions", "/sessions"]) {
|
|
@@ -10988,19 +11044,15 @@ async function endLocalAppiumSessions(o) {
|
|
|
10988
11044
|
} catch {
|
|
10989
11045
|
}
|
|
10990
11046
|
}
|
|
10991
|
-
|
|
11047
|
+
const ids = [];
|
|
10992
11048
|
for (const s of sessions) {
|
|
10993
11049
|
if (!s?.id || s.id === o.keep || typeof s.created !== "number" || s.created < o.since - 2e3) continue;
|
|
10994
11050
|
const caps = s.capabilities ?? {};
|
|
10995
11051
|
const device = String(caps.udid ?? caps["appium:udid"] ?? caps.deviceUDID ?? caps.deviceName ?? caps["appium:deviceName"] ?? "");
|
|
10996
11052
|
if (o.udid && device && device !== o.udid) continue;
|
|
10997
|
-
|
|
10998
|
-
await deleteWebDriverSession(base, s.id);
|
|
10999
|
-
ended++;
|
|
11000
|
-
} catch {
|
|
11001
|
-
}
|
|
11053
|
+
ids.push(s.id);
|
|
11002
11054
|
}
|
|
11003
|
-
return
|
|
11055
|
+
return ids;
|
|
11004
11056
|
}
|
|
11005
11057
|
function appRefRejected(output, ref) {
|
|
11006
11058
|
if (!ref || !/^(bs|lt|storage):/i.test(ref)) return false;
|
|
@@ -11250,7 +11302,7 @@ var init_request_guard = __esm({
|
|
|
11250
11302
|
|
|
11251
11303
|
// src/ui/routes/request-schemas.ts
|
|
11252
11304
|
import { z } from "zod";
|
|
11253
|
-
var text, optText, password, name, email, code, token, setupBody, loginBody, login2faBody, challengeBody, forgotPasswordBody, resetPasswordBody, changePasswordBody, confirmPasswordBody, profileBody, createUserBody, updateUserBody, adminResetPasswordBody, stringOrList, envMap, runBody, runCommandsBody, region2, stringMap, cloudProviderBody, cloudTestBody, llmTestBody, llmActiveModelBody, mcpServerBody, outputFolderBody;
|
|
11305
|
+
var text, optText, password, name, email, code, token, setupBody, loginBody, login2faBody, challengeBody, forgotPasswordBody, resetPasswordBody, changePasswordBody, confirmPasswordBody, profileBody, createUserBody, updateUserBody, adminResetPasswordBody, stringOrList, envMap, deviceSessionBody, runBody, runCommandsBody, region2, stringMap, cloudProviderBody, cloudTestBody, llmTestBody, llmActiveModelBody, mcpServerBody, outputFolderBody;
|
|
11254
11306
|
var init_request_schemas = __esm({
|
|
11255
11307
|
"src/ui/routes/request-schemas.ts"() {
|
|
11256
11308
|
"use strict";
|
|
@@ -11287,6 +11339,7 @@ var init_request_schemas = __esm({
|
|
|
11287
11339
|
adminResetPasswordBody = z.looseObject({ newPassword: password });
|
|
11288
11340
|
stringOrList = z.union([text(5e6), z.array(text(1e5)).max(1e5)]).nullish();
|
|
11289
11341
|
envMap = z.record(text(1e4), z.union([text(1e5), z.number(), z.boolean()])).nullish();
|
|
11342
|
+
deviceSessionBody = z.looseObject({ runId: optText(200), token: optText(200), sessionId: optText(200) });
|
|
11290
11343
|
runBody = z.looseObject({
|
|
11291
11344
|
command: optText(5e6),
|
|
11292
11345
|
files: stringOrList,
|
|
@@ -23071,6 +23124,7 @@ __export(auto_heal_webdriver_exports, {
|
|
|
23071
23124
|
onWdFailureSignal: () => onWdFailureSignal,
|
|
23072
23125
|
onWdRunExit: () => onWdRunExit,
|
|
23073
23126
|
registerCdpPort: () => registerCdpPort,
|
|
23127
|
+
registerSessionSource: () => registerSessionSource,
|
|
23074
23128
|
registerWdRun: () => registerWdRun,
|
|
23075
23129
|
runOwningClientPort: () => runOwningClientPort,
|
|
23076
23130
|
wdCaptureGaps: () => wdCaptureGaps,
|
|
@@ -23135,7 +23189,7 @@ async function shadowTick(runId, entry2) {
|
|
|
23135
23189
|
entry2.capturing = false;
|
|
23136
23190
|
}
|
|
23137
23191
|
}
|
|
23138
|
-
if (entry2.endpoints.length === 0 && entry2.remoteSessions.length === 0 && entry2.cdpPorts.length === 0) return;
|
|
23192
|
+
if (entry2.endpoints.length === 0 && entry2.remoteSessions.length === 0 && entry2.cdpPorts.length === 0 && !entry2.sessionSource) return;
|
|
23139
23193
|
entry2.capturing = true;
|
|
23140
23194
|
try {
|
|
23141
23195
|
await captureAll(entry2, false);
|
|
@@ -23144,6 +23198,12 @@ async function shadowTick(runId, entry2) {
|
|
|
23144
23198
|
entry2.capturing = false;
|
|
23145
23199
|
}
|
|
23146
23200
|
}
|
|
23201
|
+
function registerSessionSource(runId, list) {
|
|
23202
|
+
const entry2 = runs.get(runId);
|
|
23203
|
+
if (!entry2 || !entry2.capture || entry2.endedAt) return;
|
|
23204
|
+
entry2.sessionSource = list;
|
|
23205
|
+
console.log(`[auto-heal] shadow capture watching the local Appium server (run ${runId})`);
|
|
23206
|
+
}
|
|
23147
23207
|
function registerCdpPort(runId, port) {
|
|
23148
23208
|
const entry2 = runs.get(runId);
|
|
23149
23209
|
if (!entry2 || entry2.cdpPorts.includes(port)) return;
|
|
@@ -23198,7 +23258,7 @@ function stopPolling(entry2) {
|
|
|
23198
23258
|
function onWdFailureSignal(runId) {
|
|
23199
23259
|
const entry2 = runs.get(runId);
|
|
23200
23260
|
if (!entry2 || !entry2.capture || entry2.capturing) return;
|
|
23201
|
-
if (entry2.endpoints.length === 0 && entry2.remoteSessions.length === 0 && entry2.cdpPorts.length === 0) return;
|
|
23261
|
+
if (entry2.endpoints.length === 0 && entry2.remoteSessions.length === 0 && entry2.cdpPorts.length === 0 && !entry2.sessionSource) return;
|
|
23202
23262
|
const now = Date.now();
|
|
23203
23263
|
if (now - entry2.lastAttempt < CAPTURE_THROTTLE_MS) return;
|
|
23204
23264
|
entry2.lastAttempt = now;
|
|
@@ -23218,7 +23278,7 @@ function onWdRunExit(runId, exitCode) {
|
|
|
23218
23278
|
if (!entry2) return;
|
|
23219
23279
|
entry2.endedAt = Date.now();
|
|
23220
23280
|
stopPolling(entry2);
|
|
23221
|
-
if (entry2.capture && exitCode !== 0 && (entry2.endpoints.length > 0 || entry2.remoteSessions.length > 0 || entry2.cdpPorts.length > 0) && !entry2.capturing) {
|
|
23281
|
+
if (entry2.capture && exitCode !== 0 && (entry2.endpoints.length > 0 || entry2.remoteSessions.length > 0 || entry2.cdpPorts.length > 0 || !!entry2.sessionSource) && !entry2.capturing) {
|
|
23222
23282
|
entry2.capturing = true;
|
|
23223
23283
|
void captureAll(entry2, true).catch(() => {
|
|
23224
23284
|
}).finally(() => {
|
|
@@ -23284,6 +23344,14 @@ async function captureAll(entry2, failure) {
|
|
|
23284
23344
|
for (const id of await listSessions(endpoint)) targets.push({ endpoint, id });
|
|
23285
23345
|
}
|
|
23286
23346
|
targets.push(...entry2.remoteSessions);
|
|
23347
|
+
if (entry2.sessionSource) {
|
|
23348
|
+
try {
|
|
23349
|
+
for (const t of await entry2.sessionSource()) {
|
|
23350
|
+
if (!targets.some((x) => x.id === t.id)) targets.push(t);
|
|
23351
|
+
}
|
|
23352
|
+
} catch {
|
|
23353
|
+
}
|
|
23354
|
+
}
|
|
23287
23355
|
for (const port of entry2.cdpPorts) {
|
|
23288
23356
|
const capture = await captureCdp(port, failure);
|
|
23289
23357
|
if (capture) storeCapture(entry2, capture);
|
|
@@ -25429,6 +25497,7 @@ function buildSiteMatchers(b) {
|
|
|
25429
25497
|
};
|
|
25430
25498
|
switch (b.strategy) {
|
|
25431
25499
|
case "id": {
|
|
25500
|
+
const short = androidIdName(b.raw);
|
|
25432
25501
|
const ctx = [
|
|
25433
25502
|
`\\b(?:Appium|Mobile)?By\\.(?:id|Id)${OPEN}`,
|
|
25434
25503
|
`\\b(?:Appium|Mobile)?By\\.ID${S},${S}`,
|
|
@@ -25445,7 +25514,15 @@ function buildSiteMatchers(b) {
|
|
|
25445
25514
|
...quotedForms([""], `#${b.raw}`, "css #id"),
|
|
25446
25515
|
...nativeForms(b.raw, "resourceId|resourceIdMatches", "UiSelector resourceId")
|
|
25447
25516
|
],
|
|
25448
|
-
...tail(b.raw)
|
|
25517
|
+
...tail(b.raw).slice(0, 2),
|
|
25518
|
+
// An Android resource-id the code builds from its short name —
|
|
25519
|
+
// byId('sign-in') → `id=com.shop:id/${name}`: the helper call holds
|
|
25520
|
+
// only the name, so only a bare new name may go in (replacementFor).
|
|
25521
|
+
...short ? [
|
|
25522
|
+
quotedForms([HELPER_CALL], short, "resource-id helper", FIRST_ARG_END, "hint"),
|
|
25523
|
+
quotedForms([HELPER_ANY_ARG], short, "resource-id helper (argument)", FIRST_ARG_END, "hint")
|
|
25524
|
+
] : [],
|
|
25525
|
+
...tail(b.raw).slice(2)
|
|
25449
25526
|
];
|
|
25450
25527
|
}
|
|
25451
25528
|
case "name": {
|
|
@@ -25593,7 +25670,15 @@ function renderSite(site, newValue) {
|
|
|
25593
25670
|
const v = site.encode === "xml" ? xmlEsc(newValue) : site.quoted ? escFor(newValue, site.quote) : newValue;
|
|
25594
25671
|
return site.find.slice(0, site.valueStart) + v + site.find.slice(site.valueEnd);
|
|
25595
25672
|
}
|
|
25673
|
+
function androidIdName(raw) {
|
|
25674
|
+
return /^[\w.]+:id\/(.+)$/.exec(raw)?.[1];
|
|
25675
|
+
}
|
|
25596
25676
|
function replacementFor(site, b, p2) {
|
|
25677
|
+
if (site.holds === "hint" && b.strategy === "id" && androidIdName(b.raw)) {
|
|
25678
|
+
const pkg = b.raw.slice(0, b.raw.indexOf(":id/"));
|
|
25679
|
+
const name2 = p2.value.startsWith(`${pkg}:id/`) ? androidIdName(p2.value) : !p2.value.includes(":id/") && /^[\w.-]+$/.test(p2.value) ? p2.value : void 0;
|
|
25680
|
+
return p2.valueIsName && name2 ? renderSite(site, name2) : site.find;
|
|
25681
|
+
}
|
|
25597
25682
|
if (site.holds === "hint") {
|
|
25598
25683
|
return p2.valueIsName ? renderSite(site, p2.value) : site.find;
|
|
25599
25684
|
}
|
|
@@ -32731,6 +32816,7 @@ import { spawn as spawn4 } from "child_process";
|
|
|
32731
32816
|
import { existsSync as existsSync53, unlinkSync as unlinkSync6, mkdirSync as mkdirSync19, writeFileSync as writeFileSync17, readdirSync as readdirSync30, readFileSync as readFileSync48, statSync as statSync25, rmSync as rmSync3 } from "fs";
|
|
32732
32817
|
import { dirname as dirname22, isAbsolute as isAbsolute14, join as join53, relative as relative22, resolve as resolvePath9 } from "path";
|
|
32733
32818
|
import { cpus } from "os";
|
|
32819
|
+
import { randomBytes as randomBytes5, timingSafeEqual as timingSafeEqual3 } from "crypto";
|
|
32734
32820
|
import { createServer as createNetServer } from "net";
|
|
32735
32821
|
function redactGridSecrets(text2) {
|
|
32736
32822
|
let out = text2;
|
|
@@ -32909,6 +32995,22 @@ function mountRunnerRoutes(app, wss, scanner, options, resultsStore4, cloudConfi
|
|
|
32909
32995
|
res.status(500).json({ error: error instanceof Error ? error.message : String(error) });
|
|
32910
32996
|
}
|
|
32911
32997
|
});
|
|
32998
|
+
app.post("/api/runner/device-session", validateBody(deviceSessionBody), (req, res) => {
|
|
32999
|
+
const b = req.body || {};
|
|
33000
|
+
const runId = String(b.runId || "");
|
|
33001
|
+
const sessionId = String(b.sessionId || "");
|
|
33002
|
+
const local = localDeviceRuns.get(runId);
|
|
33003
|
+
const given = Buffer.from(String(b.token || ""));
|
|
33004
|
+
const want = Buffer.from(local?.token || "");
|
|
33005
|
+
if (!local || given.length !== want.length || !timingSafeEqual3(given, want)) {
|
|
33006
|
+
return res.status(404).json({ error: "No local device run with this id and token." });
|
|
33007
|
+
}
|
|
33008
|
+
if (!/^[\w.-]{1,128}$/.test(sessionId)) return res.status(400).json({ error: "sessionId is not a WebDriver session id." });
|
|
33009
|
+
if (!local.sessionIds.includes(sessionId)) local.sessionIds.push(sessionId);
|
|
33010
|
+
Promise.resolve().then(() => (init_auto_heal_webdriver(), auto_heal_webdriver_exports)).then(({ attachRelaySession: attachRelaySession2 }) => attachRelaySession2(local.appiumUrl, sessionId, void 0, runId)).catch(() => {
|
|
33011
|
+
});
|
|
33012
|
+
res.status(204).end();
|
|
33013
|
+
});
|
|
32912
33014
|
app.post("/api/runner/run", validateBody(runBody), async (req, res) => {
|
|
32913
33015
|
let cleanupOnThrow;
|
|
32914
33016
|
try {
|
|
@@ -33183,9 +33285,9 @@ function mountRunnerRoutes(app, wss, scanner, options, resultsStore4, cloudConfi
|
|
|
33183
33285
|
code: "GRID_UNSUPPORTED_FRAMEWORK"
|
|
33184
33286
|
});
|
|
33185
33287
|
}
|
|
33186
|
-
const { reuseTicketStore: reuseTicketStore2 } = await Promise.resolve().then(() => (init_reuse_ticket_store(), reuse_ticket_store_exports));
|
|
33288
|
+
const { reuseTicketStore: reuseTicketStore2, liveSessionMatches: liveSessionMatches2 } = await Promise.resolve().then(() => (init_reuse_ticket_store(), reuse_ticket_store_exports));
|
|
33187
33289
|
const live = clientHeader ? reuseTicketStore2.peek(clientHeader) : null;
|
|
33188
|
-
const sameTarget =
|
|
33290
|
+
const sameTarget = liveSessionMatches2(live, { providerId: cloudProvider, deviceName, appId });
|
|
33189
33291
|
const claimedTicket = clientHeader && sameTarget ? reuseTicketStore2.claim(clientHeader) : null;
|
|
33190
33292
|
mobileBridgeClientId = clientHeader || void 0;
|
|
33191
33293
|
mobileBridgeClaimedSessionId = claimedTicket ? claimedTicket.sessionId : void 0;
|
|
@@ -33273,8 +33375,26 @@ function mountRunnerRoutes(app, wss, scanner, options, resultsStore4, cloudConfi
|
|
|
33273
33375
|
mobileBridgeUsedOverlay = true;
|
|
33274
33376
|
mobileWdioResults = placement.wdioResultsFile;
|
|
33275
33377
|
}
|
|
33378
|
+
const runDeviceSerial = isLocalAppium ? plan.env.TESTVER_DEVICE_UDID || deviceName : void 0;
|
|
33379
|
+
if (runDeviceSerial && !effectiveReuseId && options.mobileSessionPool) {
|
|
33380
|
+
try {
|
|
33381
|
+
await options.mobileSessionPool.releaseLocalDevice(runDeviceSerial, {
|
|
33382
|
+
exceptClientId: clientHeader || void 0,
|
|
33383
|
+
reason: `A test run started on ${runDeviceSerial}, so this session was closed \u2014 a local device runs one session at a time.`
|
|
33384
|
+
});
|
|
33385
|
+
} catch (err5) {
|
|
33386
|
+
console.warn(`[testver] Freeing ${runDeviceSerial} before the run failed:`, err5.message);
|
|
33387
|
+
}
|
|
33388
|
+
}
|
|
33276
33389
|
if (isLocalAppium && plan.env.APPIUM_URL) {
|
|
33277
33390
|
localAppiumTarget = { appiumUrl: plan.env.APPIUM_URL, udid: plan.env.TESTVER_DEVICE_UDID, since: Date.now(), keep: effectiveReuseId };
|
|
33391
|
+
if (options.port) {
|
|
33392
|
+
const token2 = randomBytes5(24).toString("hex");
|
|
33393
|
+
localDeviceRuns.set(runId, { token: token2, appiumUrl: plan.env.APPIUM_URL.replace(/\/+$/, ""), sessionIds: [] });
|
|
33394
|
+
runEnv.TESTVER_SESSION_REPORT_URL = `http://127.0.0.1:${options.port}/api/runner/device-session`;
|
|
33395
|
+
runEnv.TESTVER_SESSION_REPORT_TOKEN = token2;
|
|
33396
|
+
runEnv.TESTVER_RUN_ID = runId;
|
|
33397
|
+
}
|
|
33278
33398
|
}
|
|
33279
33399
|
if (options.port && clientHeader) {
|
|
33280
33400
|
runEnv.TESTVER_REPORTBACK_URL = `http://localhost:${options.port}`;
|
|
@@ -33356,15 +33476,16 @@ function mountRunnerRoutes(app, wss, scanner, options, resultsStore4, cloudConfi
|
|
|
33356
33476
|
console.warn("[testver] cloud session poller start failed:", err5.message);
|
|
33357
33477
|
}
|
|
33358
33478
|
}
|
|
33359
|
-
|
|
33479
|
+
const targetPlatform = plan.env.TESTVER_PLATFORM_NAME || platformName;
|
|
33480
|
+
if (cloudConfigStore && deviceName && targetPlatform && (isLocalAppium ? appId : plan.env.TESTVER_PLATFORM_VERSION)) {
|
|
33360
33481
|
try {
|
|
33361
33482
|
cloudConfigStore.setLastMobileTarget({
|
|
33362
33483
|
provider: cloudProvider,
|
|
33363
33484
|
appId: appId || void 0,
|
|
33364
|
-
appRef: plan.appUrl,
|
|
33485
|
+
appRef: isLocalAppium ? void 0 : plan.appUrl,
|
|
33365
33486
|
deviceName,
|
|
33366
|
-
platformName:
|
|
33367
|
-
platformVersion: plan.env.TESTVER_PLATFORM_VERSION,
|
|
33487
|
+
platformName: /ios/i.test(String(targetPlatform)) ? "iOS" : "Android",
|
|
33488
|
+
platformVersion: plan.env.TESTVER_PLATFORM_VERSION || "",
|
|
33368
33489
|
setAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
33369
33490
|
});
|
|
33370
33491
|
} catch (err5) {
|
|
@@ -33949,7 +34070,12 @@ function mountRunnerRoutes(app, wss, scanner, options, resultsStore4, cloudConfi
|
|
|
33949
34070
|
// AI Assistant's live session this run reused).
|
|
33950
34071
|
...mobileBridgeRun ? {
|
|
33951
34072
|
endSessions: async (reported) => {
|
|
34073
|
+
const local = localDeviceRuns.get(runId);
|
|
33952
34074
|
if (localAppiumTarget) await endLocalAppiumSessions(localAppiumTarget).catch(() => 0);
|
|
34075
|
+
for (const id of local?.sessionIds ?? []) {
|
|
34076
|
+
if (id === localAppiumTarget?.keep) continue;
|
|
34077
|
+
await deleteWebDriverSession(local.appiumUrl, id).catch(() => void 0);
|
|
34078
|
+
}
|
|
33953
34079
|
for (const s of reported) {
|
|
33954
34080
|
if (s.providerId === "local-appium" || !s.hubUrl || s.sessionId === mobileBridgeClaimedSessionId) continue;
|
|
33955
34081
|
await deleteWebDriverSession(s.hubUrl, s.sessionId).catch(() => void 0);
|
|
@@ -33985,10 +34111,18 @@ function mountRunnerRoutes(app, wss, scanner, options, resultsStore4, cloudConfi
|
|
|
33985
34111
|
Promise.all([
|
|
33986
34112
|
Promise.resolve().then(() => (init_auto_heal_webdriver(), auto_heal_webdriver_exports)),
|
|
33987
34113
|
Promise.resolve().then(() => (init_auto_heal_service(), auto_heal_service_exports))
|
|
33988
|
-
]).then(async ([{ registerWdRun: registerWdRun2, registerCdpPort: registerCdpPort2 }, { couldHealRun: couldHealRun2 }]) => {
|
|
34114
|
+
]).then(async ([{ registerWdRun: registerWdRun2, registerCdpPort: registerCdpPort2, registerSessionSource: registerSessionSource2 }, { couldHealRun: couldHealRun2 }]) => {
|
|
33989
34115
|
const capture = await couldHealRun2({ origin: reqOrigin, parentRunId: reqParentRunId }).catch(() => true);
|
|
33990
34116
|
registerWdRun2(runId, proc.pid, fw || "", { capture });
|
|
33991
34117
|
if (capture && cypressCdpPort) registerCdpPort2(runId, cypressCdpPort);
|
|
34118
|
+
if (capture && localAppiumTarget) {
|
|
34119
|
+
const target2 = localAppiumTarget;
|
|
34120
|
+
const endpoint = target2.appiumUrl.replace(/\/+$/, "");
|
|
34121
|
+
registerSessionSource2(runId, async () => [
|
|
34122
|
+
...target2.keep ? [target2.keep] : [],
|
|
34123
|
+
...await localRunSessionIds(target2)
|
|
34124
|
+
].map((id) => ({ endpoint, id })));
|
|
34125
|
+
}
|
|
33992
34126
|
}).catch(() => {
|
|
33993
34127
|
});
|
|
33994
34128
|
let estimatedDuration;
|
|
@@ -34489,6 +34623,7 @@ ${closing.stderr}`, mobileAppRef)) {
|
|
|
34489
34623
|
broadcast(wss, { type: "complete", runId, exitCode: code2 ?? 1, duration, passed: parsedPassed, failed: parsedFailed, user: triggeredBy });
|
|
34490
34624
|
pushActivity?.({ type: "complete", runId, exitCode: code2 ?? 1, duration, passed: parsedPassed, failed: parsedFailed, user: triggeredBy, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
34491
34625
|
activeRuns.delete(runId);
|
|
34626
|
+
localDeviceRuns.delete(runId);
|
|
34492
34627
|
gridAccepted.delete(runId);
|
|
34493
34628
|
releaseGridHold();
|
|
34494
34629
|
runHistory.unshift(result);
|
|
@@ -34512,6 +34647,7 @@ ${closing.stderr}`, mobileAppRef)) {
|
|
|
34512
34647
|
cancelledRunIds.delete(runId);
|
|
34513
34648
|
cancelledSessions.delete(runId);
|
|
34514
34649
|
activeRuns.delete(runId);
|
|
34650
|
+
localDeviceRuns.delete(runId);
|
|
34515
34651
|
gridAccepted.delete(runId);
|
|
34516
34652
|
runHistory.unshift(result);
|
|
34517
34653
|
if (runHistory.length > MAX_HISTORY2) runHistory.pop();
|
|
@@ -34649,6 +34785,7 @@ ${closing.stderr}`, mobileAppRef)) {
|
|
|
34649
34785
|
active.result.status = "cancelled";
|
|
34650
34786
|
active.result.endTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
34651
34787
|
activeRuns.delete(runId);
|
|
34788
|
+
localDeviceRuns.delete(runId);
|
|
34652
34789
|
runHistory.unshift(active.result);
|
|
34653
34790
|
audit(req, "run.cancel", { resourceType: "test-run", resourceId: runId });
|
|
34654
34791
|
res.json({ runId, status: "cancelled" });
|
|
@@ -35523,7 +35660,7 @@ function broadcast(wss, message) {
|
|
|
35523
35660
|
}
|
|
35524
35661
|
}
|
|
35525
35662
|
}
|
|
35526
|
-
var GRID_SECRET_PATTERNS, GRID_CEILING_RE, gridAccepted, gridPreflightChain, gridRefusals, activeRuns, startingRuns, cancelBeforeStart, cancelledRunIds, cancelledSessions, STARTING_TTL_MS, WAITING_FOR_VENDOR_TURN, WAITING_FOR_REPORT_TURN, waitingRuns, headlessNoted, runHistory, MAX_HISTORY2, MAX_RUN_BUFFER_CHARS, cypressProgress, robotProgress, ReportTurnCancelled, reportTurns, PW_RUN_DIR_MAX_AGE_MS, PLAYWRIGHT_SWITCHES, PROVIDER_LABELS, BROWSERSTACK_NODE_SDK_VERSION, BROWSERSTACK_CYPRESS_CLI_VERSION, LAMBDATEST_CYPRESS_CLI_VERSION;
|
|
35663
|
+
var GRID_SECRET_PATTERNS, GRID_CEILING_RE, gridAccepted, gridPreflightChain, gridRefusals, activeRuns, localDeviceRuns, startingRuns, cancelBeforeStart, cancelledRunIds, cancelledSessions, STARTING_TTL_MS, WAITING_FOR_VENDOR_TURN, WAITING_FOR_REPORT_TURN, waitingRuns, headlessNoted, runHistory, MAX_HISTORY2, MAX_RUN_BUFFER_CHARS, cypressProgress, robotProgress, ReportTurnCancelled, reportTurns, PW_RUN_DIR_MAX_AGE_MS, PLAYWRIGHT_SWITCHES, PROVIDER_LABELS, BROWSERSTACK_NODE_SDK_VERSION, BROWSERSTACK_CYPRESS_CLI_VERSION, LAMBDATEST_CYPRESS_CLI_VERSION;
|
|
35527
35664
|
var init_api_runner = __esm({
|
|
35528
35665
|
"src/ui/routes/api-runner.ts"() {
|
|
35529
35666
|
"use strict";
|
|
@@ -35570,6 +35707,7 @@ var init_api_runner = __esm({
|
|
|
35570
35707
|
gridPreflightChain = Promise.resolve();
|
|
35571
35708
|
gridRefusals = /* @__PURE__ */ new Map();
|
|
35572
35709
|
activeRuns = /* @__PURE__ */ new Map();
|
|
35710
|
+
localDeviceRuns = /* @__PURE__ */ new Map();
|
|
35573
35711
|
startingRuns = /* @__PURE__ */ new Map();
|
|
35574
35712
|
cancelBeforeStart = /* @__PURE__ */ new Set();
|
|
35575
35713
|
cancelledRunIds = /* @__PURE__ */ new Set();
|
|
@@ -35738,6 +35876,16 @@ async function wrapAiRunForCloud(opts) {
|
|
|
35738
35876
|
throw new AiRunSetupError(resolvedProvider, err5.message);
|
|
35739
35877
|
}
|
|
35740
35878
|
const deviceSerial = isLocalAppium && plan.env.TESTVER_DEVICE_UDID || deviceName;
|
|
35879
|
+
if (isLocalAppium && !reuseSessionId && sessionPool && deviceSerial) {
|
|
35880
|
+
try {
|
|
35881
|
+
await sessionPool.releaseLocalDevice(deviceSerial, {
|
|
35882
|
+
exceptClientId: clientId,
|
|
35883
|
+
reason: `A test run started on ${deviceSerial}, so this session was closed \u2014 a local device runs one session at a time.`
|
|
35884
|
+
});
|
|
35885
|
+
} catch (err5) {
|
|
35886
|
+
logger16.warn(`Freeing ${deviceSerial} before the run failed: ${err5.message}`);
|
|
35887
|
+
}
|
|
35888
|
+
}
|
|
35741
35889
|
if (opts.uiPort && clientId) {
|
|
35742
35890
|
plan.env = {
|
|
35743
35891
|
...plan.env,
|
|
@@ -37520,7 +37668,7 @@ ${snap.tree}`;
|
|
|
37520
37668
|
|
|
37521
37669
|
${NOT_FOUND_HINTS}${tree}`;
|
|
37522
37670
|
}
|
|
37523
|
-
var VALID_STRATEGIES, NOT_FOUND_HINTS, mobileLaunchApp, mobileTap, mobileType, mobileSwipe, mobileScrollTo, mobileWaitFor, mobilePressKey, mobileAlert, mobileTapAt, mobileListContexts, mobileSwitchContext, mobileOrientation, mobileScreenshot, mobileSnapshot, mobileWait, mobileTools;
|
|
37671
|
+
var VALID_STRATEGIES, NOT_FOUND_HINTS, mobileLaunchApp, mobileTap, mobileType, mobileSwipe, mobileDrag, mobileScrollTo, mobileWaitFor, mobilePressKey, mobileAlert, mobileTapAt, mobileListContexts, mobileSwitchContext, mobileOrientation, mobileScreenshot, mobileSnapshot, mobileWait, mobileTools;
|
|
37524
37672
|
var init_mobile = __esm({
|
|
37525
37673
|
"src/core/tools/mobile.ts"() {
|
|
37526
37674
|
"use strict";
|
|
@@ -37538,18 +37686,21 @@ var init_mobile = __esm({
|
|
|
37538
37686
|
category: "mobile",
|
|
37539
37687
|
definition: {
|
|
37540
37688
|
name: "mobile_launch_app",
|
|
37541
|
-
description:
|
|
37689
|
+
description: 'Start the mobile automation session against the device and app the user already selected in the Mobile picker. Returns the session info and an accessibility snapshot of the current screen. Call it first when no session is running (the "Mobile session" note in the message says). When a session is already running it brings the app back to the front \u2014 use it to recover after the app crashed or closed.',
|
|
37542
37690
|
parameters: { type: "object", properties: {} }
|
|
37543
37691
|
},
|
|
37544
37692
|
handler: async (_args, ctx) => {
|
|
37545
37693
|
const manager = getManager(ctx);
|
|
37546
37694
|
try {
|
|
37695
|
+
const before = manager.isActive() ? manager.getSessionInfo()?.sessionId : void 0;
|
|
37547
37696
|
const info = await manager.start();
|
|
37697
|
+
const reused = !!before && before === info.sessionId;
|
|
37698
|
+
if (reused) await manager.reopenApp();
|
|
37548
37699
|
const adapter = manager.getAdapter();
|
|
37549
37700
|
const tree = await freshTree(adapter);
|
|
37550
37701
|
step(ctx, "mobile_launch_app", "ok", `${info.providerId}/${info.device}`);
|
|
37551
37702
|
return [
|
|
37552
|
-
|
|
37703
|
+
reused ? "Mobile session already running \u2014 the app is in front." : "Mobile session started.",
|
|
37553
37704
|
`Provider: ${info.providerId}`,
|
|
37554
37705
|
`Device: ${info.device}`,
|
|
37555
37706
|
`Platform: ${info.platform}`,
|
|
@@ -37635,21 +37786,36 @@ var init_mobile = __esm({
|
|
|
37635
37786
|
category: "mobile",
|
|
37636
37787
|
definition: {
|
|
37637
37788
|
name: "mobile_swipe",
|
|
37638
|
-
description: "Swipe
|
|
37789
|
+
description: "Swipe \u2014 for dismissing cards, carousels, or custom gestures. **Give the element** (`strategy` + `value`) and a `direction`: Testver finds where it is and swipes across it \u2014 the tree has no coordinates, so never measure screenshots or call adb for bounds. Coordinates (`fromX`/`fromY`/`toX`/`toY`, device pixels) only for a swipe that belongs to no element. **To reach an off-screen element, prefer mobile_scroll_to \u2014 it scrolls natively and verifies arrival.** Returns the settled accessibility tree after the swipe.",
|
|
37639
37790
|
parameters: {
|
|
37640
37791
|
type: "object",
|
|
37641
37792
|
properties: {
|
|
37793
|
+
strategy: { type: "string", enum: VALID_STRATEGIES, description: "Locator strategy of the element to swipe on. Default: accessibility-id." },
|
|
37794
|
+
value: { type: "string", description: "Locator value of the element to swipe on." },
|
|
37795
|
+
direction: { type: "string", enum: ["left", "right", "up", "down"], description: "Direction the finger moves, with an element." },
|
|
37642
37796
|
fromX: { type: "number" },
|
|
37643
37797
|
fromY: { type: "number" },
|
|
37644
37798
|
toX: { type: "number" },
|
|
37645
37799
|
toY: { type: "number" },
|
|
37646
|
-
durationMs: { type: "number", description: "Swipe duration. Default 400." }
|
|
37647
|
-
}
|
|
37648
|
-
required: ["fromX", "fromY", "toX", "toY"]
|
|
37800
|
+
durationMs: { type: "number", description: "Swipe duration. Default 300 on an element, 400 between coordinates." }
|
|
37801
|
+
}
|
|
37649
37802
|
}
|
|
37650
37803
|
},
|
|
37651
37804
|
handler: async (args2, ctx) => {
|
|
37652
37805
|
const adapter = getAdapter(ctx);
|
|
37806
|
+
if (args2.value) {
|
|
37807
|
+
const loc = parseLocator(args2);
|
|
37808
|
+
const direction = String(args2.direction || "left");
|
|
37809
|
+
if (!["left", "right", "up", "down"].includes(direction)) throw new Error("direction must be left, right, up or down.");
|
|
37810
|
+
if (!adapter.swipeElement) throw new Error("Swiping on an element is not supported by the active mobile adapter \u2014 use coordinates.");
|
|
37811
|
+
const res2 = await adapter.swipeElement(loc, direction, args2.durationMs ? Number(args2.durationMs) : void 0);
|
|
37812
|
+
step(ctx, "mobile_swipe", res2.success ? "ok" : "fail", `${direction} on ${loc.strategy}=${loc.value}`, loc.value, res2.error);
|
|
37813
|
+
if (!res2.success) return await failWithTree(adapter, `Swipe FAILED on ${loc.strategy}=${loc.value}: ${res2.error || "unknown"}`);
|
|
37814
|
+
return `Swiped ${direction} on ${loc.value}.${await freshTree(adapter)}`;
|
|
37815
|
+
}
|
|
37816
|
+
if ([args2.fromX, args2.fromY, args2.toX, args2.toY].some((v) => v === void 0 || Number.isNaN(Number(v)))) {
|
|
37817
|
+
throw new Error("Give the element to swipe on (strategy + value + direction), or all four coordinates.");
|
|
37818
|
+
}
|
|
37653
37819
|
const res = await adapter.swipe(
|
|
37654
37820
|
{ x: Number(args2.fromX), y: Number(args2.fromY) },
|
|
37655
37821
|
{ x: Number(args2.toX), y: Number(args2.toY) },
|
|
@@ -37665,6 +37831,34 @@ var init_mobile = __esm({
|
|
|
37665
37831
|
return `Swiped.${await freshTree(adapter)}`;
|
|
37666
37832
|
}
|
|
37667
37833
|
};
|
|
37834
|
+
mobileDrag = {
|
|
37835
|
+
category: "mobile",
|
|
37836
|
+
definition: {
|
|
37837
|
+
name: "mobile_drag",
|
|
37838
|
+
description: "Drag one element onto another \u2014 drag and drop, reordering a list, moving a slider handle onto a mark. Give both elements by locator; Testver finds where they are, presses the first, holds so the drag starts, moves onto the second and releases. No coordinates needed. Returns the settled accessibility tree after the drop.",
|
|
37839
|
+
parameters: {
|
|
37840
|
+
type: "object",
|
|
37841
|
+
properties: {
|
|
37842
|
+
fromStrategy: { type: "string", enum: VALID_STRATEGIES, description: "Locator strategy of the element to drag. Default: accessibility-id." },
|
|
37843
|
+
fromValue: { type: "string", description: "Locator value of the element to drag." },
|
|
37844
|
+
toStrategy: { type: "string", enum: VALID_STRATEGIES, description: "Locator strategy of the drop target. Default: accessibility-id." },
|
|
37845
|
+
toValue: { type: "string", description: "Locator value of the drop target." },
|
|
37846
|
+
durationMs: { type: "number", description: "How long the move takes. Default 1000 (slow enough for drag-and-drop)." }
|
|
37847
|
+
},
|
|
37848
|
+
required: ["fromValue", "toValue"]
|
|
37849
|
+
}
|
|
37850
|
+
},
|
|
37851
|
+
handler: async (args2, ctx) => {
|
|
37852
|
+
const adapter = getAdapter(ctx);
|
|
37853
|
+
if (!adapter.drag) throw new Error("Drag is not supported by the active mobile adapter.");
|
|
37854
|
+
const from = parseLocator({ strategy: args2.fromStrategy, value: args2.fromValue });
|
|
37855
|
+
const to = parseLocator({ strategy: args2.toStrategy, value: args2.toValue });
|
|
37856
|
+
const res = await adapter.drag(from, to, args2.durationMs ? Number(args2.durationMs) : void 0);
|
|
37857
|
+
step(ctx, "mobile_drag", res.success ? "ok" : "fail", `${from.value} \u2192 ${to.value}`, from.value, res.error);
|
|
37858
|
+
if (!res.success) return await failWithTree(adapter, `Drag FAILED from ${from.strategy}=${from.value} to ${to.strategy}=${to.value}: ${res.error || "unknown"}`);
|
|
37859
|
+
return `Dragged ${from.value} onto ${to.value}.${await freshTree(adapter)}`;
|
|
37860
|
+
}
|
|
37861
|
+
};
|
|
37668
37862
|
mobileScrollTo = {
|
|
37669
37863
|
category: "mobile",
|
|
37670
37864
|
definition: {
|
|
@@ -37938,6 +38132,7 @@ var init_mobile = __esm({
|
|
|
37938
38132
|
mobileTap,
|
|
37939
38133
|
mobileType,
|
|
37940
38134
|
mobileSwipe,
|
|
38135
|
+
mobileDrag,
|
|
37941
38136
|
mobileScrollTo,
|
|
37942
38137
|
mobileWaitFor,
|
|
37943
38138
|
mobilePressKey,
|
|
@@ -38160,22 +38355,22 @@ var init_ai_cloud_run = __esm({
|
|
|
38160
38355
|
|
|
38161
38356
|
// src/core/tools/test-runner.ts
|
|
38162
38357
|
import { spawn as spawn6 } from "child_process";
|
|
38163
|
-
import { existsSync as existsSync54, readFileSync as readFileSync49 } from "fs";
|
|
38358
|
+
import { existsSync as existsSync54, readFileSync as readFileSync49, rmSync as rmSync4 } from "fs";
|
|
38164
38359
|
import { isAbsolute as isAbsolute15, join as join55, relative as relative24, resolve as resolve13 } from "path";
|
|
38165
38360
|
function runCmd(command, cwd, timeout, extraEnv = {}, onCloseHook, meta) {
|
|
38166
38361
|
return new Promise((resolve35, reject) => {
|
|
38167
|
-
const treeKill = !!meta?.onTimeoutKill;
|
|
38168
38362
|
const proc = spawn6(command, [], {
|
|
38169
38363
|
cwd,
|
|
38170
|
-
...treeKill ? {} : { timeout },
|
|
38171
38364
|
env: { ...process.env, ...extraEnv },
|
|
38172
38365
|
stdio: ["pipe", "pipe", "pipe"],
|
|
38173
38366
|
shell: true
|
|
38174
38367
|
});
|
|
38175
|
-
|
|
38368
|
+
let timedOut = false;
|
|
38369
|
+
const timer = setTimeout(() => {
|
|
38370
|
+
timedOut = true;
|
|
38176
38371
|
void (async () => {
|
|
38177
38372
|
try {
|
|
38178
|
-
await meta
|
|
38373
|
+
await meta?.onTimeoutKill?.();
|
|
38179
38374
|
} catch {
|
|
38180
38375
|
}
|
|
38181
38376
|
if (proc.pid) await killTree(proc.pid).catch(() => false);
|
|
@@ -38186,7 +38381,7 @@ function runCmd(command, cwd, timeout, extraEnv = {}, onCloseHook, meta) {
|
|
|
38186
38381
|
}
|
|
38187
38382
|
}
|
|
38188
38383
|
})();
|
|
38189
|
-
}, timeout)
|
|
38384
|
+
}, timeout);
|
|
38190
38385
|
const runId = `ai-${generateId()}`;
|
|
38191
38386
|
if (meta?.track) {
|
|
38192
38387
|
try {
|
|
@@ -38203,11 +38398,11 @@ function runCmd(command, cwd, timeout, extraEnv = {}, onCloseHook, meta) {
|
|
|
38203
38398
|
stderr += data.toString();
|
|
38204
38399
|
});
|
|
38205
38400
|
proc.on("error", (err5) => {
|
|
38206
|
-
|
|
38401
|
+
clearTimeout(timer);
|
|
38207
38402
|
reject(err5);
|
|
38208
38403
|
});
|
|
38209
38404
|
proc.on("close", async (code2) => {
|
|
38210
|
-
|
|
38405
|
+
clearTimeout(timer);
|
|
38211
38406
|
if (meta?.track) {
|
|
38212
38407
|
try {
|
|
38213
38408
|
runClosed(runId);
|
|
@@ -38219,7 +38414,7 @@ function runCmd(command, cwd, timeout, extraEnv = {}, onCloseHook, meta) {
|
|
|
38219
38414
|
${stderr}` });
|
|
38220
38415
|
} catch {
|
|
38221
38416
|
}
|
|
38222
|
-
resolve35({ stdout, stderr, exitCode: code2 ?? 1 });
|
|
38417
|
+
resolve35({ stdout, stderr, exitCode: code2 ?? 1, ...timedOut ? { timedOut } : {} });
|
|
38223
38418
|
});
|
|
38224
38419
|
});
|
|
38225
38420
|
}
|
|
@@ -38433,7 +38628,7 @@ var init_test_runner = __esm({
|
|
|
38433
38628
|
},
|
|
38434
38629
|
cloud_provider: {
|
|
38435
38630
|
type: "string",
|
|
38436
|
-
description: "Leave this out for normal runs \u2014 tests run locally, and `browser` / `environment` pick the target (an environment such as \"Staging\" is NOT a cloud provider). Set it ONLY when the user asked to run on that cloud and it is set up in Settings: browserstack, lambdatest, saucelabs, or testver-grid. The ONLY way to execute tests on a cloud provider \u2014 dispatches through Testver's runner (cloud env injection, SDK attach, session watch) and returns the run's ground-truth cloudExecution verdict. Never try to reach cloud grids via shell commands, the testver CLI, or Testver's HTTP API."
|
|
38631
|
+
description: "Leave this out for normal runs \u2014 tests run locally, and `browser` / `environment` pick the target (an environment such as \"Staging\" is NOT a cloud provider). Set it ONLY when the user asked to run on that cloud and it is set up in Settings: browserstack, lambdatest, saucelabs, or testver-grid. A Local Devices (local-appium) session is NOT a cloud \u2014 leave this out and the run uses that device. The ONLY way to execute tests on a cloud provider \u2014 dispatches through Testver's runner (cloud env injection, SDK attach, session watch) and returns the run's ground-truth cloudExecution verdict. Never try to reach cloud grids via shell commands, the testver CLI, or Testver's HTTP API."
|
|
38437
38632
|
}
|
|
38438
38633
|
}
|
|
38439
38634
|
}
|
|
@@ -38528,7 +38723,8 @@ var init_test_runner = __esm({
|
|
|
38528
38723
|
if (inserted === command) inserted = insertCypressArgs(command, targets.args, cwd) ?? command;
|
|
38529
38724
|
command = inserted !== command ? inserted : `${command} ${targets.args}`;
|
|
38530
38725
|
}
|
|
38531
|
-
const
|
|
38726
|
+
const rawProvider = String(args2.cloud_provider || "").trim().toLowerCase();
|
|
38727
|
+
const cloudProvider = /^(local|local[-_ ]?appium|local[-_ ]?devices?)$/.test(rawProvider) ? "" : rawProvider;
|
|
38532
38728
|
if (cloudProvider) {
|
|
38533
38729
|
if (!["browserstack", "lambdatest", "saucelabs", "testver-grid"].includes(cloudProvider)) {
|
|
38534
38730
|
throw new Error(`Unknown cloud_provider "${cloudProvider}" \u2014 use browserstack, lambdatest, saucelabs, or testver-grid.`);
|
|
@@ -38581,7 +38777,14 @@ var init_test_runner = __esm({
|
|
|
38581
38777
|
const finalCommand = wrap2?.command ?? command;
|
|
38582
38778
|
const secretsEnv = getRecordedSecretsEnv(ctx.workingDirectory);
|
|
38583
38779
|
const extraEnv = { ...secretsEnv, ...targets.env, ...wrap2?.env ?? {} };
|
|
38584
|
-
|
|
38780
|
+
for (const stale of [".testver-results.json", ".testver-results.json.parts"]) {
|
|
38781
|
+
try {
|
|
38782
|
+
rmSync4(join55(cwd, stale), { recursive: true, force: true });
|
|
38783
|
+
} catch {
|
|
38784
|
+
}
|
|
38785
|
+
}
|
|
38786
|
+
const timeoutMs = wrap2 ? 20 * 6e4 : 5 * 6e4;
|
|
38787
|
+
const result = await runCmd(finalCommand, cwd, timeoutMs, extraEnv, wrap2?.onComplete, {
|
|
38585
38788
|
framework,
|
|
38586
38789
|
track: !wrap2,
|
|
38587
38790
|
// a cloud device run: on timeout end its vendor sessions, then kill the whole tree
|
|
@@ -38610,6 +38813,9 @@ Errors:
|
|
|
38610
38813
|
${result.stderr.trim()}` : "",
|
|
38611
38814
|
`
|
|
38612
38815
|
Exit code: ${result.exitCode}`,
|
|
38816
|
+
result.timedOut ? `
|
|
38817
|
+
|
|
38818
|
+
TIMED OUT: the run was stopped after ${timeoutMs / 6e4} minutes (the run_tests time limit) and its processes were ended \u2014 the exit code and any missing results come from that, not from the tests. Run fewer tests at a time (one spec, or a name filter) so each run finishes in time.` : "",
|
|
38613
38819
|
zeroWarning ? `
|
|
38614
38820
|
|
|
38615
38821
|
${zeroWarning}` : ""
|
|
@@ -39765,6 +39971,7 @@ function classifyRole(file, isTestFile3) {
|
|
|
39765
39971
|
const p2 = file.replace(/\\/g, "/").toLowerCase();
|
|
39766
39972
|
if (/(^|\/)(step[-_]?def|step_definitions|steps)(\/|$)/.test(p2) || /_steps?\.|\.steps?\./.test(p2)) return "step";
|
|
39767
39973
|
if (/(^|\/)(pages?|page[-_]?objects?|pom)(\/|$)/.test(p2) || /page\.[a-z]+$|page_[a-z]/.test(p2) || /[a-z]page\./.test(p2)) return "page";
|
|
39974
|
+
if (/(^|\/)(screens?|screen[-_]?objects?)(\/|$)/.test(p2) || /screen\.[a-z]+$|screen_[a-z]/.test(p2)) return "page";
|
|
39768
39975
|
if (/conftest\.py$/.test(p2) || /(^|\/)fixtures?(\/|$)/.test(p2) || /fixture/.test(p2)) return "fixture";
|
|
39769
39976
|
if (/(^|\/)(helpers?|utils?|support|lib|common|core|shared)(\/|$)/.test(p2)) return "helper";
|
|
39770
39977
|
return "source";
|
|
@@ -42637,7 +42844,7 @@ async function buildFetchOptions(request, vars, baseDir = process.cwd()) {
|
|
|
42637
42844
|
const resolvedKey = resolveVariables(field.key, vars);
|
|
42638
42845
|
if (field.fieldType === "file" && field.filePath) {
|
|
42639
42846
|
const { readFileSync: readFileSync101 } = await import("fs");
|
|
42640
|
-
const { resolve: resolve35, basename:
|
|
42847
|
+
const { resolve: resolve35, basename: basename31 } = await import("path");
|
|
42641
42848
|
const rel = resolveVariables(String(field.filePath), vars);
|
|
42642
42849
|
let buffer;
|
|
42643
42850
|
try {
|
|
@@ -42645,7 +42852,7 @@ async function buildFetchOptions(request, vars, baseDir = process.cwd()) {
|
|
|
42645
42852
|
} catch (err5) {
|
|
42646
42853
|
throw new Error(`Cannot read upload file "${rel}": ${err5.message}`);
|
|
42647
42854
|
}
|
|
42648
|
-
const fileName = field.fileName ||
|
|
42855
|
+
const fileName = field.fileName || basename31(rel);
|
|
42649
42856
|
const contentType = field.contentType;
|
|
42650
42857
|
form.append(resolvedKey, buffer, contentType ? { filename: fileName, contentType } : { filename: fileName });
|
|
42651
42858
|
} else if (field.fieldType === "file" && field.value) {
|
|
@@ -45090,11 +45297,11 @@ async function send(method, url, headers, body, auth, timeout) {
|
|
|
45090
45297
|
}
|
|
45091
45298
|
async function writeReport(workingDirectory2, rel, fallbackName, data) {
|
|
45092
45299
|
const { mkdir: mkdir8, writeFile: writeFile11 } = await import("fs/promises");
|
|
45093
|
-
const { resolve: resolve35, dirname:
|
|
45300
|
+
const { resolve: resolve35, dirname: dirname34, relative: relative43 } = await import("path");
|
|
45094
45301
|
const target2 = resolve35(workingDirectory2, rel || `.testver/contracts/${fallbackName}`);
|
|
45095
45302
|
const relPath = relative43(workingDirectory2, target2);
|
|
45096
45303
|
if (relPath.startsWith("..")) return null;
|
|
45097
|
-
await mkdir8(
|
|
45304
|
+
await mkdir8(dirname34(target2), { recursive: true });
|
|
45098
45305
|
await writeFile11(target2, JSON.stringify(data, null, 2), "utf-8");
|
|
45099
45306
|
return relPath.replace(/\\/g, "/");
|
|
45100
45307
|
}
|
|
@@ -72388,7 +72595,7 @@ var init_testver2 = __esm({
|
|
|
72388
72595
|
|
|
72389
72596
|
// src/core/tools/send-email.ts
|
|
72390
72597
|
import { readFileSync as readFileSync53, statSync as statSync28 } from "fs";
|
|
72391
|
-
import { createHash as createHash9, randomBytes as
|
|
72598
|
+
import { createHash as createHash9, randomBytes as randomBytes6 } from "crypto";
|
|
72392
72599
|
import { basename as basename19 } from "path";
|
|
72393
72600
|
function initSendEmailTool(store4, projectPath2, opts) {
|
|
72394
72601
|
tmStore2 = store4;
|
|
@@ -72423,7 +72630,7 @@ function mintConfirmToken(hash3, owner) {
|
|
|
72423
72630
|
if (oldest === void 0) break;
|
|
72424
72631
|
pendingConfirms.delete(oldest);
|
|
72425
72632
|
}
|
|
72426
|
-
const token2 =
|
|
72633
|
+
const token2 = randomBytes6(16).toString("hex");
|
|
72427
72634
|
pendingConfirms.set(token2, { hash: hash3, expires: now + CONFIRM_TTL_MS, owner });
|
|
72428
72635
|
return token2;
|
|
72429
72636
|
}
|
|
@@ -75771,7 +75978,7 @@ __export(report_store_exports, {
|
|
|
75771
75978
|
canAccessRecord: () => canAccessRecord
|
|
75772
75979
|
});
|
|
75773
75980
|
import { readFileSync as readFileSync54, mkdirSync as mkdirSync21, existsSync as existsSync63 } from "fs";
|
|
75774
|
-
import { randomBytes as
|
|
75981
|
+
import { randomBytes as randomBytes7 } from "crypto";
|
|
75775
75982
|
import { join as join64 } from "path";
|
|
75776
75983
|
function canAccessRecord(record, user) {
|
|
75777
75984
|
if (record.ownerEmail === user.id) return true;
|
|
@@ -75843,7 +76050,7 @@ var init_report_store = __esm({
|
|
|
75843
76050
|
...input.pinned != null ? { pinned: input.pinned } : {}
|
|
75844
76051
|
}, input.templateId);
|
|
75845
76052
|
}
|
|
75846
|
-
const id = !input.id || existing ? `rpt_${Date.now().toString(36)}_${
|
|
76053
|
+
const id = !input.id || existing ? `rpt_${Date.now().toString(36)}_${randomBytes7(4).toString("hex")}` : input.id;
|
|
75847
76054
|
const report = {
|
|
75848
76055
|
...input,
|
|
75849
76056
|
id,
|
|
@@ -75893,7 +76100,7 @@ var init_report_store = __esm({
|
|
|
75893
76100
|
createShareToken(id, opts) {
|
|
75894
76101
|
const report = this.get(id);
|
|
75895
76102
|
if (!report) return null;
|
|
75896
|
-
report.shareToken =
|
|
76103
|
+
report.shareToken = randomBytes7(24).toString("hex");
|
|
75897
76104
|
report.shareCreatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
75898
76105
|
const days = Number(opts?.expiresInDays);
|
|
75899
76106
|
if (Number.isFinite(days) && days >= 1 && days <= 365) {
|
|
@@ -76159,7 +76366,7 @@ __export(report_schedules_exports, {
|
|
|
76159
76366
|
isScheduleFormat: () => isScheduleFormat,
|
|
76160
76367
|
updateSchedule: () => updateSchedule
|
|
76161
76368
|
});
|
|
76162
|
-
import { randomBytes as
|
|
76369
|
+
import { randomBytes as randomBytes8 } from "crypto";
|
|
76163
76370
|
function isPlausibleEmail(s) {
|
|
76164
76371
|
return typeof s === "string" && /^[^\s@,;<>]+@[^\s@,;<>]+\.[^\s@,;<>]+$/.test(s.trim());
|
|
76165
76372
|
}
|
|
@@ -76204,7 +76411,7 @@ function createSchedule(store4, user, input) {
|
|
|
76204
76411
|
if (!canAccessRecord(source, user)) return { error: "Cannot schedule another user's report", status: 403 };
|
|
76205
76412
|
const cron = String(input.cron).trim();
|
|
76206
76413
|
const schedule = store4.createSchedule({
|
|
76207
|
-
id: `sched_${Date.now().toString(36)}_${
|
|
76414
|
+
id: `sched_${Date.now().toString(36)}_${randomBytes8(3).toString("hex")}`,
|
|
76208
76415
|
ownerEmail: user.id,
|
|
76209
76416
|
title: input.title.trim().slice(0, 200),
|
|
76210
76417
|
sourceReportId: input.sourceReportId,
|
|
@@ -78083,6 +78290,7 @@ function lastRunOf(testName) {
|
|
|
78083
78290
|
return automatedResult(testName);
|
|
78084
78291
|
}
|
|
78085
78292
|
function whereOf(h) {
|
|
78293
|
+
if (h.cloudProvider === "local-appium") return "local device";
|
|
78086
78294
|
return h.source === "cloud" ? h.cloudProvider ? `cloud (${h.cloudProvider})` : "cloud" : "local";
|
|
78087
78295
|
}
|
|
78088
78296
|
function median(xs) {
|
|
@@ -82257,7 +82465,9 @@ author: testver
|
|
|
82257
82465
|
## When asked to CREATE / SCAFFOLD a framework \u2014 gather requirements first
|
|
82258
82466
|
This section applies ONLY when the user is asking you to create or scaffold a test framework \u2014 ignore it entirely for any other request. When they ARE asking to build a framework: do NOT create files, scaffold, or run anything until you have BOTH items below. If either is missing, ASK the user and WAIT. NEVER assume app/device details:
|
|
82259
82467
|
1. The app under test AND a device/platform. App format must match the platform: **Android = .apk/.aab \xB7 iOS real device / cloud = .ipa \xB7 iOS local simulator = .app bundle (macOS only)**. Testver aborts a run up front on a mismatch, so ask rather than guess.
|
|
82260
|
-
2. The first scenario to automate (e.g. "launch the app and see the home screen"). If not given, PROPOSE one and confirm.
|
|
82468
|
+
2. The first scenario to automate (e.g. "launch the app and see the home screen"). If not given, PROPOSE one and WAIT for the user to confirm it \u2014 before creating any file.
|
|
82469
|
+
A live Mobile session (the AI Assistant's Mobile mode) already tells you the app and the device: that settles item 1 only. Item 2 still needs the user's answer, so ask for it even when a session is running.
|
|
82470
|
+
Also ask ONCE, without waiting on it, whether there are other environments to run against. For an app these are usually separate builds of it (e.g. a Dev and a Staging build talking to different back ends): tell the user to upload each one in Settings \u2192 General \u2192 App Builds under the environment's name, so it can be picked per run in the device/app pickers \u2014 the framework then needs no change, because the picked build arrives as TESTVER_APP_URL. When environments are builds, the build decides the environment: a test must NOT switch it inside the app (no steps on an in-app environment or server picker, no extra environment variable for it), or a run on the Staging build would quietly end up on Dev. An empty provider ref for a build is normal \u2014 Testver installs or uploads each build the first time a run uses it. Do not register Browsers/Environments with configure_run_targets for a mobile project (a Mobile workspace has no such settings).
|
|
82261
82471
|
Only once you have both do you scaffold: put the app path and capabilities in configuration (capabilities file or env, never hardcoded), implement that one scenario as the smoke test, and run it to verify.
|
|
82262
82472
|
|
|
82263
82473
|
## Runner per language (all five are first-class in Testver)
|
|
@@ -82268,7 +82478,7 @@ Only once you have both do you scaffold: put the app path and capabilities in co
|
|
|
82268
82478
|
| Java | TestNG (Maven/Gradle) | \`src/test/java/ screens/ pom.xml\` | \`mvn test\` |
|
|
82269
82479
|
| C# | NUnit | \`Tests/ Screens/ *.csproj\` | \`dotnet test\` |
|
|
82270
82480
|
| Ruby | RSpec | \`spec/ screens/ Gemfile\` | \`bundle exec rspec\` |
|
|
82271
|
-
Testver's AI Record writes generated mobile
|
|
82481
|
+
Testver's AI Record writes a generated mobile spec next to the project's existing specs (\`tests/mobile/\` only when there are none yet) \u2014 keep ONE specs folder, and make sure the runner's config finds it.
|
|
82272
82482
|
|
|
82273
82483
|
## Install + detection deps (Testver classifies the project by these \u2014 get them in the manifest)
|
|
82274
82484
|
- **WDIO:** \`npm i -D @wdio/cli @wdio/appium-service appium\` (+ \`appium driver install uiautomator2\` and/or \`xcuitest\`). Detection needs \`@wdio/appium-service\` (or \`appium\`+\`webdriverio\`) in package.json plus a \`wdio.conf.*\`.
|
|
@@ -82316,7 +82526,7 @@ Runner-native logging (\`@wdio/logger\`, Python \`logging\`, SLF4J, RSpec output
|
|
|
82316
82526
|
## Verify the setup (do this, then stop)
|
|
82317
82527
|
- If the user did NOT give the app (in the format matching the platform) and a device/platform, ASK first \u2014 do not assume.
|
|
82318
82528
|
- Put the app path and capabilities in CONFIGURATION (capabilities file or the env contract) \u2014 NEVER hardcode app/device details inside a test.
|
|
82319
|
-
- Create exactly ONE
|
|
82529
|
+
- Create exactly ONE smoke test: the scenario the user confirmed (only when they explicitly leave it to you: launch the app and assert the first screen renders). Run it to confirm install, drivers, config and result capture all work. Do not generate a full suite unless the user asks.
|
|
82320
82530
|
`,
|
|
82321
82531
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
82322
82532
|
// 12. EXPLORE & AUTOMATE (web)
|
|
@@ -89243,6 +89453,9 @@ function ofFile(entries, file) {
|
|
|
89243
89453
|
return !f || f === want || f.endsWith(`/${want}`) || want.endsWith(`/${f}`);
|
|
89244
89454
|
});
|
|
89245
89455
|
}
|
|
89456
|
+
function ranOnCloud(r) {
|
|
89457
|
+
return r.source === "cloud" && r.cloudProvider !== "local-appium";
|
|
89458
|
+
}
|
|
89246
89459
|
var MAX_RUNS, MAX_HISTORY_PER_TEST, STATUS_RANK, TestResultsStore;
|
|
89247
89460
|
var init_test_results_store = __esm({
|
|
89248
89461
|
"src/ui/store/test-results-store.ts"() {
|
|
@@ -89392,9 +89605,7 @@ var init_test_results_store = __esm({
|
|
|
89392
89605
|
list = list.filter((r) => r.status === filter.status);
|
|
89393
89606
|
}
|
|
89394
89607
|
if (filter?.source && filter.source !== "all") {
|
|
89395
|
-
list = list.filter(
|
|
89396
|
-
(r) => filter.source === "cloud" ? r.source === "cloud" : r.source !== "cloud"
|
|
89397
|
-
);
|
|
89608
|
+
list = list.filter((r) => filter.source === "cloud" === ranOnCloud(r));
|
|
89398
89609
|
}
|
|
89399
89610
|
return {
|
|
89400
89611
|
runs: list.slice(offset, offset + limit),
|
|
@@ -93854,7 +94065,7 @@ var init_git_cache_store = __esm({
|
|
|
93854
94065
|
});
|
|
93855
94066
|
|
|
93856
94067
|
// src/ui/auth/token-manager.ts
|
|
93857
|
-
import { createHmac, randomBytes as
|
|
94068
|
+
import { createHmac, randomBytes as randomBytes9, timingSafeEqual as timingSafeEqual4 } from "crypto";
|
|
93858
94069
|
import { readFileSync as readFileSync67, writeFileSync as writeFileSync21, existsSync as existsSync77, mkdirSync as mkdirSync31 } from "fs";
|
|
93859
94070
|
import { join as join80 } from "path";
|
|
93860
94071
|
import { scryptSync } from "crypto";
|
|
@@ -93866,7 +94077,7 @@ function base64UrlDecode(str2) {
|
|
|
93866
94077
|
return Buffer.from(str2, "base64url").toString("utf-8");
|
|
93867
94078
|
}
|
|
93868
94079
|
function hashPassword(password2) {
|
|
93869
|
-
const salt =
|
|
94080
|
+
const salt = randomBytes9(16).toString("hex");
|
|
93870
94081
|
const hash3 = scryptSync(password2, salt, 64).toString("hex");
|
|
93871
94082
|
return `${salt}:${hash3}`;
|
|
93872
94083
|
}
|
|
@@ -93876,7 +94087,7 @@ function verifyPassword(password2, stored) {
|
|
|
93876
94087
|
const [salt, hash3] = parts;
|
|
93877
94088
|
try {
|
|
93878
94089
|
const test = scryptSync(password2, salt, 64);
|
|
93879
|
-
return
|
|
94090
|
+
return timingSafeEqual4(Buffer.from(hash3, "hex"), test);
|
|
93880
94091
|
} catch {
|
|
93881
94092
|
return false;
|
|
93882
94093
|
}
|
|
@@ -93898,7 +94109,7 @@ var init_token_manager = __esm({
|
|
|
93898
94109
|
const hex2 = readFileSync67(secretPath, "utf-8").trim();
|
|
93899
94110
|
this.secret = Buffer.from(hex2, "hex");
|
|
93900
94111
|
} else {
|
|
93901
|
-
this.secret =
|
|
94112
|
+
this.secret = randomBytes9(64);
|
|
93902
94113
|
writeFileSync21(secretPath, this.secret.toString("hex"), "utf-8");
|
|
93903
94114
|
}
|
|
93904
94115
|
}
|
|
@@ -93923,7 +94134,7 @@ var init_token_manager = __esm({
|
|
|
93923
94134
|
if (signature.length !== expectedSig.length) return null;
|
|
93924
94135
|
const sigBuf = Buffer.from(signature, "utf-8");
|
|
93925
94136
|
const expectedBuf = Buffer.from(expectedSig, "utf-8");
|
|
93926
|
-
if (!
|
|
94137
|
+
if (!timingSafeEqual4(sigBuf, expectedBuf)) return null;
|
|
93927
94138
|
const payload = JSON.parse(base64UrlDecode(body));
|
|
93928
94139
|
const now = Math.floor(Date.now() / 1e3);
|
|
93929
94140
|
if (payload.exp && payload.exp < now) return null;
|
|
@@ -93944,7 +94155,7 @@ var user_store_exports = {};
|
|
|
93944
94155
|
__export(user_store_exports, {
|
|
93945
94156
|
UserStore: () => UserStore
|
|
93946
94157
|
});
|
|
93947
|
-
import { createHash as createHash11, randomBytes as
|
|
94158
|
+
import { createHash as createHash11, randomBytes as randomBytes10 } from "crypto";
|
|
93948
94159
|
import Database2 from "better-sqlite3";
|
|
93949
94160
|
import { existsSync as existsSync78, mkdirSync as mkdirSync32 } from "fs";
|
|
93950
94161
|
import { join as join81 } from "path";
|
|
@@ -94198,7 +94409,7 @@ var init_user_store = __esm({
|
|
|
94198
94409
|
}
|
|
94199
94410
|
/** Issue a single-use reset token (older ones for the user are voided). */
|
|
94200
94411
|
createPasswordReset(userId, ttlMs = 60 * 60 * 1e3) {
|
|
94201
|
-
const token2 =
|
|
94412
|
+
const token2 = randomBytes10(32).toString("base64url");
|
|
94202
94413
|
const now = Date.now();
|
|
94203
94414
|
const expiresAt = now + ttlMs;
|
|
94204
94415
|
this.db.prepare("DELETE FROM password_resets WHERE user_id = ? OR expires_at < ?").run(userId, now);
|
|
@@ -94282,7 +94493,7 @@ var init_user_store = __esm({
|
|
|
94282
94493
|
// ── Trusted browsers ("Trust this browser") ─────────────────────────────────
|
|
94283
94494
|
/** Remember a browser for `days`; the raw token goes to the browser, only its hash is kept. */
|
|
94284
94495
|
createTrustedBrowser(userId, days, ipAddress, userAgent) {
|
|
94285
|
-
const token2 =
|
|
94496
|
+
const token2 = randomBytes10(32).toString("base64url");
|
|
94286
94497
|
const id = generateId("tb");
|
|
94287
94498
|
const now = Date.now();
|
|
94288
94499
|
const expiresAt = now + days * 24 * 36e5;
|
|
@@ -94661,9 +94872,10 @@ var init_permissions2 = __esm({
|
|
|
94661
94872
|
{ method: "PUT", pathPrefix: "/api/connectors", minRole: "admin" },
|
|
94662
94873
|
{ method: "DELETE", pathPrefix: "/api/connectors", minRole: "admin" },
|
|
94663
94874
|
{ method: "POST", pathPrefix: "/api/mobile/local/config", minRole: "admin" },
|
|
94664
|
-
// Starting / closing an Android emulator
|
|
94665
|
-
// Settings change — open to whoever can run tests.
|
|
94875
|
+
// Starting / closing an Android emulator or iOS simulator is running a
|
|
94876
|
+
// device, not a Settings change — open to whoever can run tests.
|
|
94666
94877
|
{ method: "POST", pathPrefix: "/api/mobile/local/emulator", minRole: "tester" },
|
|
94878
|
+
{ method: "POST", pathPrefix: "/api/mobile/local/simulator", minRole: "tester" },
|
|
94667
94879
|
{ method: "POST", pathPrefix: "/api/tests/ownership/config", minRole: "admin" },
|
|
94668
94880
|
// ── Tester (write operations) ─────────────────────────────────
|
|
94669
94881
|
// AI Test Gen — generation / reverse-engineer / review. Expensive LLM
|
|
@@ -94877,6 +95089,7 @@ function isPublicPath(path2, req) {
|
|
|
94877
95089
|
if (path2 === "/api/askpass") return true;
|
|
94878
95090
|
if (path2 === "/api/mobile/session/register-external" && isLocalRequest(req)) return true;
|
|
94879
95091
|
if (path2 === "/api/mobile/session/unregister-external" && isLocalRequest(req)) return true;
|
|
95092
|
+
if (path2 === "/api/runner/device-session" && isLocalRequest(req)) return true;
|
|
94880
95093
|
if (path2 === "/api/system/app-mode" && req?.method === "GET") return true;
|
|
94881
95094
|
return false;
|
|
94882
95095
|
}
|
|
@@ -95157,7 +95370,7 @@ var init_connector_registry = __esm({
|
|
|
95157
95370
|
});
|
|
95158
95371
|
|
|
95159
95372
|
// src/ui/local-browser-tokens.ts
|
|
95160
|
-
import { randomBytes as
|
|
95373
|
+
import { randomBytes as randomBytes11 } from "crypto";
|
|
95161
95374
|
function getLocalBrowserTokenStore() {
|
|
95162
95375
|
if (!_store) _store = new LocalBrowserTokenStore();
|
|
95163
95376
|
return _store;
|
|
@@ -95184,7 +95397,7 @@ var init_local_browser_tokens = __esm({
|
|
|
95184
95397
|
userTokens.sort((a, b) => a.createdAt - b.createdAt);
|
|
95185
95398
|
this.byToken.delete(userTokens[0].token);
|
|
95186
95399
|
}
|
|
95187
|
-
const token2 = `lbt_${
|
|
95400
|
+
const token2 = `lbt_${randomBytes11(24).toString("base64url")}`;
|
|
95188
95401
|
const now = Date.now();
|
|
95189
95402
|
this.byToken.set(token2, {
|
|
95190
95403
|
token: token2,
|
|
@@ -99014,6 +99227,8 @@ var init_session_manager = __esm({
|
|
|
99014
99227
|
MobileSessionManager = class _MobileSessionManager {
|
|
99015
99228
|
adapter = null;
|
|
99016
99229
|
desired = null;
|
|
99230
|
+
/** start() calls in progress. */
|
|
99231
|
+
starting = 0;
|
|
99017
99232
|
disconnectCallbacks = [];
|
|
99018
99233
|
startedCallbacks = [];
|
|
99019
99234
|
lostCallbacks = [];
|
|
@@ -99045,6 +99260,18 @@ var init_session_manager = __esm({
|
|
|
99045
99260
|
setAdapterFactory(factory) {
|
|
99046
99261
|
this.adapterFactory = factory;
|
|
99047
99262
|
}
|
|
99263
|
+
/**
|
|
99264
|
+
* Runs before every NEW device session (never when start() hands back
|
|
99265
|
+
* the live one). The pool uses it to make a local device exclusive: a
|
|
99266
|
+
* second session on the same Android device restarts its UiAutomator2
|
|
99267
|
+
* server and breaks the first. May throw to refuse the start; the
|
|
99268
|
+
* returned function (if any) is called once the new session is up or
|
|
99269
|
+
* has failed.
|
|
99270
|
+
*/
|
|
99271
|
+
beforeNewSession = null;
|
|
99272
|
+
setBeforeNewSession(hook) {
|
|
99273
|
+
this.beforeNewSession = hook;
|
|
99274
|
+
}
|
|
99048
99275
|
/** Caller (route handler / UI) sets the device+app the LLM should target. */
|
|
99049
99276
|
setDesiredSession(desired) {
|
|
99050
99277
|
this.desired = desired;
|
|
@@ -99054,9 +99281,29 @@ var init_session_manager = __esm({
|
|
|
99054
99281
|
}
|
|
99055
99282
|
/** Start (or re-attach to) the underlying Appium session. Idempotent. */
|
|
99056
99283
|
async start() {
|
|
99284
|
+
this.starting++;
|
|
99285
|
+
try {
|
|
99286
|
+
return await this.startOrReuse();
|
|
99287
|
+
} finally {
|
|
99288
|
+
this.starting--;
|
|
99289
|
+
}
|
|
99290
|
+
}
|
|
99291
|
+
/**
|
|
99292
|
+
* A start() is in progress — a fresh session being opened, possibly in
|
|
99293
|
+
* place of one that died. The session bar keeps showing the session
|
|
99294
|
+
* meanwhile instead of offering "Start session".
|
|
99295
|
+
*/
|
|
99296
|
+
isStarting() {
|
|
99297
|
+
return this.starting > 0;
|
|
99298
|
+
}
|
|
99299
|
+
async startOrReuse() {
|
|
99057
99300
|
if (this.adapter && this.adapter.isActive()) {
|
|
99058
99301
|
const before = this.adapter.getSessionInfo()?.sessionId;
|
|
99059
|
-
|
|
99302
|
+
let alive = this.adapter.ping ? await this.adapter.ping().catch(() => false) : true;
|
|
99303
|
+
if (!alive && this.adapter.isActive() && await this.reopenApp()) {
|
|
99304
|
+
alive = this.adapter.ping ? await this.adapter.ping().catch(() => false) : true;
|
|
99305
|
+
if (alive) logger26.info("MobileSession: the app was not running \u2014 reopened it in the same session.");
|
|
99306
|
+
}
|
|
99060
99307
|
if (alive) {
|
|
99061
99308
|
const info2 = this.adapter.getSessionInfo();
|
|
99062
99309
|
if (info2) return info2;
|
|
@@ -99092,8 +99339,17 @@ var init_session_manager = __esm({
|
|
|
99092
99339
|
}
|
|
99093
99340
|
this.adapter = null;
|
|
99094
99341
|
}
|
|
99095
|
-
this.
|
|
99096
|
-
|
|
99342
|
+
const done2 = this.beforeNewSession ? await this.beforeNewSession(this.desired) : void 0;
|
|
99343
|
+
let info;
|
|
99344
|
+
try {
|
|
99345
|
+
this.adapter = this.adapterFactory(this.desired);
|
|
99346
|
+
info = await this.adapter.startSession(this.desired);
|
|
99347
|
+
} finally {
|
|
99348
|
+
try {
|
|
99349
|
+
done2?.();
|
|
99350
|
+
} catch {
|
|
99351
|
+
}
|
|
99352
|
+
}
|
|
99097
99353
|
logger26.info(`MobileSession started (provider=${info.providerId} device=${info.device})`);
|
|
99098
99354
|
for (const cb of this.startedCallbacks) {
|
|
99099
99355
|
try {
|
|
@@ -99103,6 +99359,26 @@ var init_session_manager = __esm({
|
|
|
99103
99359
|
}
|
|
99104
99360
|
return info;
|
|
99105
99361
|
}
|
|
99362
|
+
/**
|
|
99363
|
+
* Bring the app under test to the foreground in the current session —
|
|
99364
|
+
* starts it again after a crash, a no-op when it's already in front.
|
|
99365
|
+
* The app is the one Appium installed for the session (bundleId /
|
|
99366
|
+
* appPackage from the session's capabilities). False when there's no
|
|
99367
|
+
* session or no app id to go by.
|
|
99368
|
+
*/
|
|
99369
|
+
async reopenApp() {
|
|
99370
|
+
const adapter = this.adapter;
|
|
99371
|
+
if (!adapter || !adapter.isActive()) return false;
|
|
99372
|
+
const caps = adapter.getResolvedCapabilities?.() ?? null;
|
|
99373
|
+
const pick = (k) => {
|
|
99374
|
+
const v = caps?.[k] ?? caps?.[`appium:${k}`];
|
|
99375
|
+
return typeof v === "string" && v ? v : void 0;
|
|
99376
|
+
};
|
|
99377
|
+
const appId = this.desired?.platform === "android" ? pick("appPackage") ?? pick("bundleId") : pick("bundleId") ?? pick("appPackage");
|
|
99378
|
+
if (!appId) return false;
|
|
99379
|
+
const res = await adapter.activateApp(appId).catch(() => null);
|
|
99380
|
+
return !!res?.success;
|
|
99381
|
+
}
|
|
99106
99382
|
/**
|
|
99107
99383
|
* Told each time a NEW device session starts here — the first one, or a
|
|
99108
99384
|
* fresh one replacing a session that died (mobile_launch_app) — never when
|
|
@@ -99435,6 +99711,11 @@ var init_appium_client = __esm({
|
|
|
99435
99711
|
const res = await this.request("GET", `/element/${elementId}/text`);
|
|
99436
99712
|
return res.value || "";
|
|
99437
99713
|
}
|
|
99714
|
+
/** An element's position and size in device pixels (W3C element rect). */
|
|
99715
|
+
async getElementRect(elementId) {
|
|
99716
|
+
const res = await this.request("GET", `/element/${elementId}/rect`);
|
|
99717
|
+
return { x: res.value?.x ?? 0, y: res.value?.y ?? 0, width: res.value?.width ?? 0, height: res.value?.height ?? 0 };
|
|
99718
|
+
}
|
|
99438
99719
|
async takeScreenshot() {
|
|
99439
99720
|
const res = await this.request("GET", `/screenshot`);
|
|
99440
99721
|
return res.value;
|
|
@@ -99594,6 +99875,10 @@ function translateForWebview(loc) {
|
|
|
99594
99875
|
return { strategy: STRATEGY_MAP[loc.strategy], value: loc.value };
|
|
99595
99876
|
}
|
|
99596
99877
|
}
|
|
99878
|
+
function isAppNotRunningError(err5) {
|
|
99879
|
+
const msg = (err5 instanceof Error ? err5.message : String(err5 ?? "")).toLowerCase();
|
|
99880
|
+
return msg.includes("possibly crashed") || /application under test .* is not running/.test(msg);
|
|
99881
|
+
}
|
|
99597
99882
|
function detectSystemDialog(xml, platform4) {
|
|
99598
99883
|
const markers = platform4 === "ios" ? [/<XCUIElementTypeAlert/i] : [
|
|
99599
99884
|
/permissioncontroller/i,
|
|
@@ -99776,7 +100061,7 @@ ${out}`;
|
|
|
99776
100061
|
}
|
|
99777
100062
|
return out;
|
|
99778
100063
|
}
|
|
99779
|
-
var logger28, STRATEGY_MAP, ANDROID_KEYCODE, RemoteAppiumAdapter, HTML_VOID_TAGS, HTML_SKIP_TAGS, HTML_INTERACTIVE_TAGS;
|
|
100064
|
+
var logger28, STRATEGY_MAP, ANDROID_KEYCODE, RemoteAppiumAdapter, APP_NOT_RUNNING_HINT, HTML_VOID_TAGS, HTML_SKIP_TAGS, HTML_INTERACTIVE_TAGS;
|
|
99780
100065
|
var init_remote_appium_adapter = __esm({
|
|
99781
100066
|
"src/mobile/remote-appium-adapter.ts"() {
|
|
99782
100067
|
"use strict";
|
|
@@ -100185,6 +100470,64 @@ ${tree}`;
|
|
|
100185
100470
|
return { success: true, message: `long-pressed ${locator.strategy}=${locator.value} (${durationMs}ms, W3C)`, elementId: id };
|
|
100186
100471
|
});
|
|
100187
100472
|
}
|
|
100473
|
+
/**
|
|
100474
|
+
* Swipe across an element. The AI's tree carries no coordinates, so the
|
|
100475
|
+
* element is resolved here: the driver's own swipe gesture first, then a
|
|
100476
|
+
* W3C swipe through the element's rect (85% of its width / height).
|
|
100477
|
+
*/
|
|
100478
|
+
async swipeElement(locator, direction, durationMs = 300) {
|
|
100479
|
+
return this.guarded(async () => {
|
|
100480
|
+
if (!this.session) throw new Error("No active mobile session");
|
|
100481
|
+
const id = await this.findElement(locator);
|
|
100482
|
+
try {
|
|
100483
|
+
if (this.session.platform === "android") {
|
|
100484
|
+
await this.client.executeMobileCommand("mobile: swipeGesture", [{ elementId: id, direction, percent: 0.85 }]);
|
|
100485
|
+
} else {
|
|
100486
|
+
await this.client.executeMobileCommand("mobile: swipe", [{ elementId: id, direction }]);
|
|
100487
|
+
}
|
|
100488
|
+
return { success: true, message: `swiped ${direction} on ${locator.strategy}=${locator.value}`, elementId: id };
|
|
100489
|
+
} catch (err5) {
|
|
100490
|
+
logger28.debug(`swipe extension failed, falling back to W3C: ${err5.message}`);
|
|
100491
|
+
}
|
|
100492
|
+
const r = await this.client.getElementRect(id);
|
|
100493
|
+
const cx = Math.round(r.x + r.width / 2);
|
|
100494
|
+
const cy = Math.round(r.y + r.height / 2);
|
|
100495
|
+
const [dx, dy] = [Math.round(r.width * 0.425), Math.round(r.height * 0.425)];
|
|
100496
|
+
const [from, to] = direction === "left" ? [{ x: cx + dx, y: cy }, { x: cx - dx, y: cy }] : direction === "right" ? [{ x: cx - dx, y: cy }, { x: cx + dx, y: cy }] : direction === "up" ? [{ x: cx, y: cy + dy }, { x: cx, y: cy - dy }] : [{ x: cx, y: cy - dy }, { x: cx, y: cy + dy }];
|
|
100497
|
+
const res = await this.swipe(from, to, durationMs);
|
|
100498
|
+
return res.success ? { ...res, message: `swiped ${direction} on ${locator.strategy}=${locator.value} (W3C)`, elementId: id } : res;
|
|
100499
|
+
});
|
|
100500
|
+
}
|
|
100501
|
+
/**
|
|
100502
|
+
* Drag one element onto another: press the source, hold so drag-and-drop
|
|
100503
|
+
* starts (a quick move reads as a fling), move to the target's centre,
|
|
100504
|
+
* release. W3C actions — the same gesture on Android and iOS.
|
|
100505
|
+
*/
|
|
100506
|
+
async drag(from, to, durationMs = 1e3) {
|
|
100507
|
+
return this.guarded(async () => {
|
|
100508
|
+
if (!this.session) throw new Error("No active mobile session");
|
|
100509
|
+
const src = await this.client.getElementRect(await this.findElement(from));
|
|
100510
|
+
const dst = await this.client.getElementRect(await this.findElement(to));
|
|
100511
|
+
const centre = (r) => ({ x: Math.round(r.x + r.width / 2), y: Math.round(r.y + r.height / 2) });
|
|
100512
|
+
const [a, b] = [centre(src), centre(dst)];
|
|
100513
|
+
await this.client.performActions([
|
|
100514
|
+
{
|
|
100515
|
+
type: "pointer",
|
|
100516
|
+
id: "finger1",
|
|
100517
|
+
parameters: { pointerType: "touch" },
|
|
100518
|
+
actions: [
|
|
100519
|
+
{ type: "pointerMove", duration: 0, x: a.x, y: a.y },
|
|
100520
|
+
{ type: "pointerDown", button: 0 },
|
|
100521
|
+
{ type: "pause", duration: 600 },
|
|
100522
|
+
{ type: "pointerMove", duration: Math.min(5e3, Math.max(300, durationMs)), x: b.x, y: b.y },
|
|
100523
|
+
{ type: "pause", duration: 200 },
|
|
100524
|
+
{ type: "pointerUp", button: 0 }
|
|
100525
|
+
]
|
|
100526
|
+
}
|
|
100527
|
+
]);
|
|
100528
|
+
return { success: true, message: `dragged ${from.strategy}=${from.value} onto ${to.strategy}=${to.value}` };
|
|
100529
|
+
});
|
|
100530
|
+
}
|
|
100188
100531
|
/**
|
|
100189
100532
|
* Accept/dismiss the current system alert or permission dialog.
|
|
100190
100533
|
* W3C alert endpoints first (XCUITest handles these well); Android
|
|
@@ -100296,6 +100639,7 @@ ${tree}`;
|
|
|
100296
100639
|
`The device automation session has crashed (UiAutomator2/WebDriverAgent instrumentation is no longer running on the device). This commonly happens after the app is cleared or force-stopped. Call mobile_launch_app to start a fresh session, then retry. (original: ${err5.message})`
|
|
100297
100640
|
);
|
|
100298
100641
|
}
|
|
100642
|
+
if (isAppNotRunningError(err5)) throw new Error(`${err5.message}${APP_NOT_RUNNING_HINT}`);
|
|
100299
100643
|
throw err5;
|
|
100300
100644
|
}
|
|
100301
100645
|
}
|
|
@@ -100364,13 +100708,15 @@ ${tree}`;
|
|
|
100364
100708
|
error: `Device automation session crashed \u2014 call mobile_launch_app to start a fresh session, then retry. (original: ${err5.message})`
|
|
100365
100709
|
};
|
|
100366
100710
|
}
|
|
100711
|
+
const hint = isAppNotRunningError(err5) ? APP_NOT_RUNNING_HINT : "";
|
|
100367
100712
|
if (err5 instanceof AppiumApiError) {
|
|
100368
|
-
return { success: false, error: `${err5.code}: ${err5.message}` };
|
|
100713
|
+
return { success: false, error: `${err5.code}: ${err5.message}${hint}` };
|
|
100369
100714
|
}
|
|
100370
|
-
return { success: false, error: err5.message };
|
|
100715
|
+
return { success: false, error: `${err5.message}${hint}` };
|
|
100371
100716
|
}
|
|
100372
100717
|
}
|
|
100373
100718
|
};
|
|
100719
|
+
APP_NOT_RUNNING_HINT = " \u2014 the app crashed or closed: call mobile_launch_app to reopen it in this session.";
|
|
100374
100720
|
HTML_VOID_TAGS = /* @__PURE__ */ new Set([
|
|
100375
100721
|
"area",
|
|
100376
100722
|
"base",
|
|
@@ -100418,17 +100764,22 @@ ${tree}`;
|
|
|
100418
100764
|
// src/mobile/session-pool.ts
|
|
100419
100765
|
var session_pool_exports = {};
|
|
100420
100766
|
__export(session_pool_exports, {
|
|
100767
|
+
LocalDeviceBusyError: () => LocalDeviceBusyError,
|
|
100421
100768
|
MobileSessionPool: () => MobileSessionPool
|
|
100422
100769
|
});
|
|
100423
100770
|
function defaultMaxLifetimeMs() {
|
|
100424
100771
|
const m = Number(process.env.TESTVER_MOBILE_SESSION_MAX_MINUTES);
|
|
100425
100772
|
return (Number.isFinite(m) && m > 0 ? m : 180) * 60 * 1e3;
|
|
100426
100773
|
}
|
|
100774
|
+
function localDeviceOf(manager) {
|
|
100775
|
+
const d = manager.getDesiredSession?.();
|
|
100776
|
+
return d && d.providerId === "local-appium" && d.deviceKey ? d.deviceKey : void 0;
|
|
100777
|
+
}
|
|
100427
100778
|
function isCloudSession(manager) {
|
|
100428
100779
|
const desired = manager.getDesiredSession?.();
|
|
100429
100780
|
return !!desired && desired.providerId !== "local-appium";
|
|
100430
100781
|
}
|
|
100431
|
-
var logger29, EXPIRY_WARNING_MS, HEARTBEAT_INTERVAL_MS, MobileSessionPool;
|
|
100782
|
+
var logger29, EXPIRY_WARNING_MS, HEARTBEAT_INTERVAL_MS, LocalDeviceBusyError, MobileSessionPool;
|
|
100432
100783
|
var init_session_pool = __esm({
|
|
100433
100784
|
"src/mobile/session-pool.ts"() {
|
|
100434
100785
|
"use strict";
|
|
@@ -100440,6 +100791,12 @@ var init_session_pool = __esm({
|
|
|
100440
100791
|
logger29 = createLogger("mobile-session-pool");
|
|
100441
100792
|
EXPIRY_WARNING_MS = 90 * 1e3;
|
|
100442
100793
|
HEARTBEAT_INTERVAL_MS = 60 * 1e3;
|
|
100794
|
+
LocalDeviceBusyError = class extends Error {
|
|
100795
|
+
constructor(device, owner) {
|
|
100796
|
+
super(`${device} is in use by "${owner}" in another tab. Wait for that run to finish, or pick another device.`);
|
|
100797
|
+
this.name = "LocalDeviceBusyError";
|
|
100798
|
+
}
|
|
100799
|
+
};
|
|
100443
100800
|
MobileSessionPool = class {
|
|
100444
100801
|
constructor(options, ttlMs = 10 * 60 * 1e3) {
|
|
100445
100802
|
this.options = options;
|
|
@@ -100452,6 +100809,10 @@ var init_session_pool = __esm({
|
|
|
100452
100809
|
}
|
|
100453
100810
|
options;
|
|
100454
100811
|
pool = /* @__PURE__ */ new Map();
|
|
100812
|
+
/** Why Testver closed a tab's session — handed to onManagerDisconnect once. */
|
|
100813
|
+
closeReasons = /* @__PURE__ */ new Map();
|
|
100814
|
+
/** New sessions on one local device start one at a time (device → tail of the queue). */
|
|
100815
|
+
deviceStarts = /* @__PURE__ */ new Map();
|
|
100455
100816
|
cleanupTimer = null;
|
|
100456
100817
|
ttlMs;
|
|
100457
100818
|
maxLifetimeMs;
|
|
@@ -100467,10 +100828,13 @@ var init_session_pool = __esm({
|
|
|
100467
100828
|
}
|
|
100468
100829
|
const manager = new MobileSessionManager();
|
|
100469
100830
|
manager.setAdapterFactory((desired) => this.buildAdapter(desired));
|
|
100831
|
+
manager.setBeforeNewSession((desired) => this.claimLocalDevice(desired, key2));
|
|
100470
100832
|
manager.onDisconnect(() => {
|
|
100471
100833
|
this.pool.delete(key2);
|
|
100834
|
+
const reason = this.closeReasons.get(key2);
|
|
100835
|
+
this.closeReasons.delete(key2);
|
|
100472
100836
|
try {
|
|
100473
|
-
this.options.onManagerDisconnect?.(clientId);
|
|
100837
|
+
this.options.onManagerDisconnect?.(clientId, reason);
|
|
100474
100838
|
} catch {
|
|
100475
100839
|
}
|
|
100476
100840
|
});
|
|
@@ -100482,6 +100846,10 @@ var init_session_pool = __esm({
|
|
|
100482
100846
|
manager.onSessionStarted((info) => {
|
|
100483
100847
|
reuseTicketStore.moveTo(clientId, info, isCloudSession(manager) ? this.ttlMs : void 0, withdrawn);
|
|
100484
100848
|
withdrawn = null;
|
|
100849
|
+
try {
|
|
100850
|
+
this.options.onSessionStarted?.(clientId, info);
|
|
100851
|
+
} catch {
|
|
100852
|
+
}
|
|
100485
100853
|
});
|
|
100486
100854
|
}
|
|
100487
100855
|
this.pool.set(key2, { manager, lastTouchedAt: Date.now(), createdAt: Date.now() });
|
|
@@ -100524,16 +100892,81 @@ var init_session_pool = __esm({
|
|
|
100524
100892
|
} catch {
|
|
100525
100893
|
}
|
|
100526
100894
|
}
|
|
100527
|
-
/**
|
|
100528
|
-
|
|
100895
|
+
/**
|
|
100896
|
+
* Free a LOCAL device for a new session: end every other tab's Testver
|
|
100897
|
+
* session on it first, while those sessions are still healthy.
|
|
100898
|
+
*
|
|
100899
|
+
* Why: an Android device runs ONE UiAutomator2 server. A new session
|
|
100900
|
+
* restarts it, so an older session on the device dies — and Appium keeps
|
|
100901
|
+
* listing it. Testver can't DELETE it afterwards (deleting a UiAutomator2
|
|
100902
|
+
* session force-stops the device's server, which by then belongs to the
|
|
100903
|
+
* NEW session), so the old one used to sit until Appium's
|
|
100904
|
+
* newCommandTimeout, whose cleanup force-stopped the server and crashed
|
|
100905
|
+
* whatever session was live at that moment. Ending it BEFORE the new one
|
|
100906
|
+
* starts is the only safe moment.
|
|
100907
|
+
*
|
|
100908
|
+
* A session a test run is driving is never closed under the run:
|
|
100909
|
+
* `refuseIfRunning` throws LocalDeviceBusyError instead (a new interactive
|
|
100910
|
+
* session); otherwise it is left alone. Returns how many were closed.
|
|
100911
|
+
*/
|
|
100912
|
+
async releaseLocalDevice(device, opts) {
|
|
100913
|
+
if (!device) return 0;
|
|
100914
|
+
const others = [...this.pool.entries()].filter(([id, e]) => id !== opts.exceptClientId && localDeviceOf(e.manager) === device && e.manager.isActive());
|
|
100915
|
+
let closed = 0;
|
|
100916
|
+
for (const [id, e] of others) {
|
|
100917
|
+
if (e.manager.isLockedForRun?.()) {
|
|
100918
|
+
if (opts.refuseIfRunning) throw new LocalDeviceBusyError(device, e.manager.getLockInfo()?.ownerLabel || "a test run");
|
|
100919
|
+
continue;
|
|
100920
|
+
}
|
|
100921
|
+
if (await this.evict(id, opts.reason)) closed++;
|
|
100922
|
+
}
|
|
100923
|
+
if (closed > 0) logger29.info(`Closed ${closed} other session(s) on local device ${device} before a new one`);
|
|
100924
|
+
return closed;
|
|
100925
|
+
}
|
|
100926
|
+
/**
|
|
100927
|
+
* beforeNewSession hook: new sessions on one local device start one at a
|
|
100928
|
+
* time, and each first frees the device (releaseLocalDevice). Cloud
|
|
100929
|
+
* sessions each get their own vendor device — nothing to do.
|
|
100930
|
+
*/
|
|
100931
|
+
async claimLocalDevice(desired, clientKey) {
|
|
100932
|
+
if (desired.providerId !== "local-appium" || !desired.deviceKey) return;
|
|
100933
|
+
const device = desired.deviceKey;
|
|
100934
|
+
const prev = this.deviceStarts.get(device) ?? Promise.resolve();
|
|
100935
|
+
let release4;
|
|
100936
|
+
const mine = new Promise((resolve35) => {
|
|
100937
|
+
release4 = resolve35;
|
|
100938
|
+
});
|
|
100939
|
+
const tail = prev.then(() => mine);
|
|
100940
|
+
this.deviceStarts.set(device, tail);
|
|
100941
|
+
const done2 = () => {
|
|
100942
|
+
release4();
|
|
100943
|
+
if (this.deviceStarts.get(device) === tail) this.deviceStarts.delete(device);
|
|
100944
|
+
};
|
|
100945
|
+
await prev;
|
|
100946
|
+
try {
|
|
100947
|
+
await this.releaseLocalDevice(device, {
|
|
100948
|
+
exceptClientId: clientKey,
|
|
100949
|
+
reason: `Another tab started a session on ${device}, so this one was closed \u2014 a local device runs one session at a time.`,
|
|
100950
|
+
refuseIfRunning: true
|
|
100951
|
+
});
|
|
100952
|
+
} catch (err5) {
|
|
100953
|
+
done2();
|
|
100954
|
+
throw err5;
|
|
100955
|
+
}
|
|
100956
|
+
return done2;
|
|
100957
|
+
}
|
|
100958
|
+
/** Explicit eviction — closes the live session. `reason` reaches the tab. */
|
|
100959
|
+
async evict(clientId, reason) {
|
|
100529
100960
|
const entry2 = this.pool.get(clientId);
|
|
100530
100961
|
if (!entry2) return false;
|
|
100962
|
+
if (reason) this.closeReasons.set(clientId, reason);
|
|
100531
100963
|
this.pool.delete(clientId);
|
|
100532
100964
|
try {
|
|
100533
100965
|
await entry2.manager.stop();
|
|
100534
100966
|
} catch (err5) {
|
|
100535
100967
|
logger29.debug(`evict() stop error: ${err5.message}`);
|
|
100536
100968
|
}
|
|
100969
|
+
this.closeReasons.delete(clientId);
|
|
100537
100970
|
logger29.info(`Evicted MobileSessionManager for clientId=${clientId}`);
|
|
100538
100971
|
return true;
|
|
100539
100972
|
}
|
|
@@ -101166,7 +101599,7 @@ var askpass_service_exports = {};
|
|
|
101166
101599
|
__export(askpass_service_exports, {
|
|
101167
101600
|
AskPassService: () => AskPassService
|
|
101168
101601
|
});
|
|
101169
|
-
import { randomBytes as
|
|
101602
|
+
import { randomBytes as randomBytes12 } from "crypto";
|
|
101170
101603
|
import { tmpdir as tmpdir4 } from "os";
|
|
101171
101604
|
import { join as join85, sep as sep7 } from "path";
|
|
101172
101605
|
import {
|
|
@@ -101174,7 +101607,7 @@ import {
|
|
|
101174
101607
|
mkdirSync as mkdirSync35,
|
|
101175
101608
|
writeFileSync as writeFileSync22,
|
|
101176
101609
|
chmodSync,
|
|
101177
|
-
rmSync as
|
|
101610
|
+
rmSync as rmSync5
|
|
101178
101611
|
} from "fs";
|
|
101179
101612
|
import { execPath } from "process";
|
|
101180
101613
|
var AskPassService, HELPER_SCRIPT;
|
|
@@ -101243,7 +101676,7 @@ var init_askpass_service = __esm({
|
|
|
101243
101676
|
this.sessionCache.clear();
|
|
101244
101677
|
if (!this.helperDir) return;
|
|
101245
101678
|
try {
|
|
101246
|
-
|
|
101679
|
+
rmSync5(this.helperDir, { recursive: true, force: true });
|
|
101247
101680
|
} catch {
|
|
101248
101681
|
}
|
|
101249
101682
|
this.helperDir = null;
|
|
@@ -101256,7 +101689,7 @@ var init_askpass_service = __esm({
|
|
|
101256
101689
|
*/
|
|
101257
101690
|
register(opts) {
|
|
101258
101691
|
if (!this.helperPath) this.initialize();
|
|
101259
|
-
const token2 =
|
|
101692
|
+
const token2 = randomBytes12(32).toString("hex");
|
|
101260
101693
|
this.contexts.set(token2, {
|
|
101261
101694
|
clientId: opts.clientId,
|
|
101262
101695
|
userId: opts.userId,
|
|
@@ -101316,7 +101749,7 @@ var init_askpass_service = __esm({
|
|
|
101316
101749
|
}
|
|
101317
101750
|
return Promise.resolve({ cancelled: true });
|
|
101318
101751
|
}
|
|
101319
|
-
const requestId =
|
|
101752
|
+
const requestId = randomBytes12(12).toString("hex");
|
|
101320
101753
|
return new Promise((resolve35) => {
|
|
101321
101754
|
const closeDialog = () => this.broadcast(ctx.clientId, ctx.userId, { type: "askpass-closed", requestId });
|
|
101322
101755
|
const timer = setTimeout(() => {
|
|
@@ -102539,7 +102972,7 @@ var init_login_throttle = __esm({
|
|
|
102539
102972
|
});
|
|
102540
102973
|
|
|
102541
102974
|
// src/ui/auth/two-factor-challenges.ts
|
|
102542
|
-
import { createHash as createHash12, randomBytes as
|
|
102975
|
+
import { createHash as createHash12, randomBytes as randomBytes13 } from "crypto";
|
|
102543
102976
|
var MAX_CHALLENGE_ATTEMPTS, TTL, PENDING_TTL, hash2, TwoFactorChallenges;
|
|
102544
102977
|
var init_two_factor_challenges = __esm({
|
|
102545
102978
|
"src/ui/auth/two-factor-challenges.ts"() {
|
|
@@ -102558,7 +102991,7 @@ var init_two_factor_challenges = __esm({
|
|
|
102558
102991
|
/** Start a challenge; the raw token goes to the browser. Older challenges of the user are dropped. */
|
|
102559
102992
|
create(userId, purpose) {
|
|
102560
102993
|
for (const [k, c2] of this.challenges) if (c2.userId === userId) this.challenges.delete(k);
|
|
102561
|
-
const raw =
|
|
102994
|
+
const raw = randomBytes13(32).toString("base64url");
|
|
102562
102995
|
this.challenges.set(hash2(raw), { userId, purpose, expiresAt: this.now() + TTL[purpose], attempts: 0 });
|
|
102563
102996
|
this.prune();
|
|
102564
102997
|
return raw;
|
|
@@ -102611,7 +103044,7 @@ var init_two_factor_challenges = __esm({
|
|
|
102611
103044
|
});
|
|
102612
103045
|
|
|
102613
103046
|
// src/ui/auth/two-factor-crypto.ts
|
|
102614
|
-
import { createCipheriv as createCipheriv2, createDecipheriv as createDecipheriv2, createHash as createHash13, randomBytes as
|
|
103047
|
+
import { createCipheriv as createCipheriv2, createDecipheriv as createDecipheriv2, createHash as createHash13, randomBytes as randomBytes14 } from "crypto";
|
|
102615
103048
|
import { existsSync as existsSync86, mkdirSync as mkdirSync38, readFileSync as readFileSync72, writeFileSync as writeFileSync24 } from "fs";
|
|
102616
103049
|
import { join as join88 } from "path";
|
|
102617
103050
|
function twoFactorKeyPath() {
|
|
@@ -102630,7 +103063,7 @@ function loadKey(create) {
|
|
|
102630
103063
|
const dir = getTestverDir();
|
|
102631
103064
|
if (!existsSync86(dir)) mkdirSync38(dir, { recursive: true });
|
|
102632
103065
|
try {
|
|
102633
|
-
writeFileSync24(path2,
|
|
103066
|
+
writeFileSync24(path2, randomBytes14(32).toString("hex"), { encoding: "utf-8", mode: 384, flag: "wx" });
|
|
102634
103067
|
} catch (e) {
|
|
102635
103068
|
if (e.code !== "EEXIST") throw e;
|
|
102636
103069
|
}
|
|
@@ -102655,7 +103088,7 @@ function previousFileKey() {
|
|
|
102655
103088
|
}
|
|
102656
103089
|
function encryptTotpSecret(secret) {
|
|
102657
103090
|
const loaded = loadKey(true);
|
|
102658
|
-
const iv =
|
|
103091
|
+
const iv = randomBytes14(12);
|
|
102659
103092
|
const cipher = createCipheriv2("aes-256-gcm", loaded.key, iv);
|
|
102660
103093
|
const data = Buffer.concat([cipher.update(secret, "utf8"), cipher.final()]);
|
|
102661
103094
|
const tag2 = cipher.getAuthTag();
|
|
@@ -102695,7 +103128,7 @@ var init_two_factor_crypto = __esm({
|
|
|
102695
103128
|
});
|
|
102696
103129
|
|
|
102697
103130
|
// src/ui/auth/totp.ts
|
|
102698
|
-
import { createHmac as createHmac2, randomBytes as
|
|
103131
|
+
import { createHmac as createHmac2, randomBytes as randomBytes15, timingSafeEqual as timingSafeEqual5 } from "crypto";
|
|
102699
103132
|
function base32Encode(buf) {
|
|
102700
103133
|
let bits = 0;
|
|
102701
103134
|
let value = 0;
|
|
@@ -102729,7 +103162,7 @@ function base32Decode(input) {
|
|
|
102729
103162
|
return Buffer.from(out);
|
|
102730
103163
|
}
|
|
102731
103164
|
function generateTotpSecret() {
|
|
102732
|
-
return base32Encode(
|
|
103165
|
+
return base32Encode(randomBytes15(20));
|
|
102733
103166
|
}
|
|
102734
103167
|
function timeStep(nowMs) {
|
|
102735
103168
|
return Math.floor(nowMs / 1e3 / TOTP_STEP_SECONDS);
|
|
@@ -102783,7 +103216,7 @@ function generateRecoveryCodes(count = RECOVERY_CODE_COUNT) {
|
|
|
102783
103216
|
while (codes.size < count) {
|
|
102784
103217
|
let s = "";
|
|
102785
103218
|
while (s.length < 10) {
|
|
102786
|
-
for (const b of
|
|
103219
|
+
for (const b of randomBytes15(16)) {
|
|
102787
103220
|
if (b < limit && s.length < 10) s += RECOVERY_ALPHABET[b % RECOVERY_ALPHABET.length];
|
|
102788
103221
|
}
|
|
102789
103222
|
}
|
|
@@ -102804,7 +103237,7 @@ var init_totp = __esm({
|
|
|
102804
103237
|
TOTP_WINDOW = 1;
|
|
102805
103238
|
DRIFT_SEARCH = 10;
|
|
102806
103239
|
B32 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
102807
|
-
same3 = (a, b) => a.length === b.length &&
|
|
103240
|
+
same3 = (a, b) => a.length === b.length && timingSafeEqual5(Buffer.from(a), Buffer.from(b));
|
|
102808
103241
|
RECOVERY_ALPHABET = "abcdefghjkmnpqrstvwxyz23456789";
|
|
102809
103242
|
RECOVERY_CODE_COUNT = 10;
|
|
102810
103243
|
}
|
|
@@ -107268,7 +107701,7 @@ var api_auth_exports = {};
|
|
|
107268
107701
|
__export(api_auth_exports, {
|
|
107269
107702
|
mountAuthRoutes: () => mountAuthRoutes
|
|
107270
107703
|
});
|
|
107271
|
-
import { createHash as createHash14, timingSafeEqual as
|
|
107704
|
+
import { createHash as createHash14, timingSafeEqual as timingSafeEqual6 } from "crypto";
|
|
107272
107705
|
function mountAuthRoutes(app, userStore2, tokenManager, auditLogStore, systemConfigStore) {
|
|
107273
107706
|
const throttle = new LoginThrottle();
|
|
107274
107707
|
const challenges = new TwoFactorChallenges();
|
|
@@ -108613,7 +109046,7 @@ var init_api_auth = __esm({
|
|
|
108613
109046
|
if (typeof given !== "string" || !given) return false;
|
|
108614
109047
|
const a = createHash14("sha256").update(expected).digest();
|
|
108615
109048
|
const b = createHash14("sha256").update(given).digest();
|
|
108616
|
-
return
|
|
109049
|
+
return timingSafeEqual6(a, b);
|
|
108617
109050
|
};
|
|
108618
109051
|
}
|
|
108619
109052
|
});
|
|
@@ -109813,6 +110246,48 @@ var init_chat_sources = __esm({
|
|
|
109813
110246
|
}
|
|
109814
110247
|
});
|
|
109815
110248
|
|
|
110249
|
+
// src/mobile/session-prompt.ts
|
|
110250
|
+
import { basename as basename26 } from "path";
|
|
110251
|
+
function appLabel(appRef) {
|
|
110252
|
+
if (!appRef) return void 0;
|
|
110253
|
+
return /^[a-z][a-z0-9+.-]*:\/\//i.test(appRef) ? appRef : basename26(appRef);
|
|
110254
|
+
}
|
|
110255
|
+
function appIdOf(manager) {
|
|
110256
|
+
const caps = manager.getAdapter()?.getResolvedCapabilities?.() ?? null;
|
|
110257
|
+
for (const k of ["bundleId", "appPackage"]) {
|
|
110258
|
+
const v = caps?.[k] ?? caps?.[`appium:${k}`];
|
|
110259
|
+
if (typeof v === "string" && v) return v;
|
|
110260
|
+
}
|
|
110261
|
+
return void 0;
|
|
110262
|
+
}
|
|
110263
|
+
function describeMobileSession(manager, now = Date.now()) {
|
|
110264
|
+
const desired = manager?.getDesiredSession() ?? null;
|
|
110265
|
+
const info = manager?.isActive() ? manager.getSessionInfo() : null;
|
|
110266
|
+
if (info) {
|
|
110267
|
+
const app = appLabel(desired?.appRef);
|
|
110268
|
+
const appId = appIdOf(manager);
|
|
110269
|
+
const mins = Math.max(0, Math.round((now - info.startedAt) / 6e4));
|
|
110270
|
+
const details = [
|
|
110271
|
+
`device ${info.device} (${info.platform === "ios" ? "iOS" : "Android"}${desired?.osVersion ? ` ${desired.osVersion}` : ""}, ${info.providerId})`,
|
|
110272
|
+
app ? `app ${app}${appId ? ` (${appId})` : ""}` : appId ? `app ${appId}` : null,
|
|
110273
|
+
`started ${mins === 0 ? "just now" : `${mins} min ago`}`
|
|
110274
|
+
].filter(Boolean).join(", ");
|
|
110275
|
+
return `## Mobile session
|
|
110276
|
+
A device session is ALREADY RUNNING \u2014 ${details}. Do not call mobile_launch_app to start it: begin with mobile_snapshot to read the current screen. Call mobile_launch_app only to recover \u2014 when a mobile_* result says the session crashed or the app is not running (it reopens the app, or opens a fresh session).`;
|
|
110277
|
+
}
|
|
110278
|
+
if (desired) {
|
|
110279
|
+
const app = appLabel(desired.appRef);
|
|
110280
|
+
return `## Mobile session
|
|
110281
|
+
No session is running yet. The user picked device ${desired.deviceKey} (${desired.platform === "ios" ? "iOS" : "Android"} ${desired.osVersion}, ${desired.providerId})${app ? ` and app ${app}` : ""} \u2014 call mobile_launch_app first to start it.`;
|
|
110282
|
+
}
|
|
110283
|
+
return "## Mobile session\nNo device session is running and no device or app is picked. mobile_* tools need one: ask the user to pick a device and an app in the Mobile session bar above the chat and click Start session. Until then, work from the code and the run output (run_tests still runs on the device and build the last run used) \u2014 do NOT reach the device another way: no adb commands, no unpacking the app build, no scripts that dump its ids.";
|
|
110284
|
+
}
|
|
110285
|
+
var init_session_prompt = __esm({
|
|
110286
|
+
"src/mobile/session-prompt.ts"() {
|
|
110287
|
+
"use strict";
|
|
110288
|
+
}
|
|
110289
|
+
});
|
|
110290
|
+
|
|
109816
110291
|
// src/ui/services/knowledge-inventory.ts
|
|
109817
110292
|
var knowledge_inventory_exports = {};
|
|
109818
110293
|
__export(knowledge_inventory_exports, {
|
|
@@ -111151,7 +111626,10 @@ ${sourcesBlock}` : "") + mcpHint;
|
|
|
111151
111626
|
fileContext: effectiveMode === "ask" ? [] : fileContext || [],
|
|
111152
111627
|
uploadedFiles: resolvedUploads,
|
|
111153
111628
|
projectPath: options.projectPath,
|
|
111154
|
-
browserBreadcrumb: includeBreadcrumb ? browserBreadcrumb : void 0
|
|
111629
|
+
browserBreadcrumb: includeBreadcrumb ? browserBreadcrumb : void 0,
|
|
111630
|
+
// Mobile: whether this tab already has a device session, so the AI
|
|
111631
|
+
// reads the screen instead of starting one (or knows it must).
|
|
111632
|
+
mobileSession: effectiveMode === "mobile" ? describeMobileSession(typeof clientId === "string" ? options.mobileSessionPool?.peek(clientId) : void 0) : void 0
|
|
111155
111633
|
});
|
|
111156
111634
|
const modeTools = tabOrchestrator.getToolRegistry().getDefinitions().filter((d) => !excludedToolNames.has(d.name));
|
|
111157
111635
|
const modeSystemPrompt = buildModeSystemPromptForChat(effectiveMode, options.projectPath, modeTools);
|
|
@@ -111879,6 +112357,7 @@ function buildModeSystemPromptForChat(mode, projectPath2, tools) {
|
|
|
111879
112357
|
}
|
|
111880
112358
|
function buildChatUserMessage(ctx) {
|
|
111881
112359
|
const parts = [];
|
|
112360
|
+
if (ctx.mobileSession) parts.push(ctx.mobileSession);
|
|
111882
112361
|
if (ctx.browserBreadcrumb) {
|
|
111883
112362
|
parts.push(
|
|
111884
112363
|
`${ctx.browserBreadcrumb}
|
|
@@ -111962,6 +112441,7 @@ var init_api_ai = __esm({
|
|
|
111962
112441
|
init_tool_action_kinds();
|
|
111963
112442
|
init_test_scanner();
|
|
111964
112443
|
init_test_run_command();
|
|
112444
|
+
init_session_prompt();
|
|
111965
112445
|
ALL_BROWSER_TOOLS = [
|
|
111966
112446
|
"browser_launch",
|
|
111967
112447
|
"browser_navigate",
|
|
@@ -112034,6 +112514,7 @@ var init_api_ai = __esm({
|
|
|
112034
112514
|
"mobile_tap",
|
|
112035
112515
|
"mobile_type",
|
|
112036
112516
|
"mobile_swipe",
|
|
112517
|
+
"mobile_drag",
|
|
112037
112518
|
"mobile_scroll_to",
|
|
112038
112519
|
"mobile_wait_for",
|
|
112039
112520
|
"mobile_alert",
|
|
@@ -112218,11 +112699,13 @@ Focus: native Android & iOS apps via Appium (cloud or USB-connected local device
|
|
|
112218
112699
|
MOBILE_DOMAIN_SECTION = `## Mobile Automation Strategy
|
|
112219
112700
|
The user already picked the device + app. Drive the live device with \`mobile_*\` tools over a native accessibility tree.
|
|
112220
112701
|
|
|
112221
|
-
**Launch \u2192 read \u2192 act:** call \`mobile_launch_app\` ONCE first (
|
|
112702
|
+
**Launch \u2192 read \u2192 act:** the "Mobile session" note in the message says whether a session is already running. Running \u2192 start with \`mobile_snapshot\`; not running \u2192 call \`mobile_launch_app\` ONCE first. After a crash, \`mobile_launch_app\` reopens the app (or a fresh session when the old one died). Read the accessibility tree it returns; \`mobile_snapshot\` re-reads the current screen. Every action returns the SETTLED tree of the resulting screen \u2014 read that instead of an extra snapshot. Use \`mobile_screenshot\` only when you truly need pixels.
|
|
112222
112703
|
|
|
112223
112704
|
**Native locators (never CSS/web refs), in order:** accessibility-id (\`content-desc\`/\`accessibilityIdentifier\`) > id (Android \`resource-id\`, iOS \`name\`) > \`-android-uiautomator\` / \`-ios-class-chain\` > xpath (last resort). Read exact values from the tree \u2014 never invent them.
|
|
112224
112705
|
|
|
112225
|
-
**Gestures:** \`mobile_tap\` (add \`longPressMs\` for long-press), \`mobile_type\`, \`mobile_press_key\`, \`mobile_orientation\`; \`mobile_tap_at\` is a last resort for system UI without locators. **Off-screen element \u2192 \`mobile_scroll_to\`** (scrolls natively and verifies), not coordinate math; reserve \`mobile_swipe\` for carousels/dismiss gestures.
|
|
112706
|
+
**Gestures:** \`mobile_tap\` (add \`longPressMs\` for long-press), \`mobile_type\`, \`mobile_press_key\`, \`mobile_orientation\`; \`mobile_tap_at\` is a last resort for system UI without locators. **Off-screen element \u2192 \`mobile_scroll_to\`** (scrolls natively and verifies), not coordinate math; reserve \`mobile_swipe\` for carousels/dismiss gestures \u2014 give it the element and a \`direction\`, not coordinates; \`mobile_drag\` drags one element onto another. The tree has no coordinates: never measure screenshots or call adb / Appium yourself to find element bounds.
|
|
112707
|
+
|
|
112708
|
+
**The device only through mobile_* tools:** no adb shell, no unpacking the app build (dex / resources), no scripts that dump ids or press keys \u2014 and no scratch scripts left in the project. If you need to see the app and no session can start (nothing picked), say so and ask the user to start one in the Mobile session bar.
|
|
112226
112709
|
|
|
112227
112710
|
**Element state is in the tree:** (checked)/(unchecked), (disabled), (selected), (focused), (scrollable) \u2014 read it, don't re-probe.
|
|
112228
112711
|
|
|
@@ -112230,7 +112713,7 @@ The user already picked the device + app. Drive the live device with \`mobile_*\
|
|
|
112230
112713
|
|
|
112231
112714
|
**Interrupts:** a \`\u26A0 SYSTEM DIALOG/ALERT DETECTED\` banner \u2192 handle FIRST with \`mobile_alert\` accept|dismiss. A \`\u26A0 FOREGROUND CHANGED\` banner \u2192 the action switched apps/screens; the tree below is the NEW screen. Missing on-screen element in a hybrid app \u2192 it's in a webview: \`mobile_list_contexts\` \u2192 \`mobile_switch_context\` "WEBVIEW_\u2026" (a \`[hybrid screen \u2014 a WebView is present]\` banner in the tree is the tell). Inside a webview locate with \`css\` or \`xpath\` ONLY (native strategies don't exist in the HTML DOM); coordinate taps still use physical screen pixels. Switch back to "NATIVE_APP" when done. Truncated tree \u2192 \`mobile_snapshot\` query="<text or id>".
|
|
112232
112715
|
|
|
112233
|
-
**Recover:** failed actions include the current tree + hints \u2014 read them (exact accId/id, scroll_to, wait_for, alert, context switch). If the session shows crashed, \`mobile_launch_app\` to
|
|
112716
|
+
**Recover:** failed actions include the current tree + hints \u2014 read them (exact accId/id, scroll_to, wait_for, alert, context switch). If the session or the app shows crashed ("not running"), call \`mobile_launch_app\` to recover.
|
|
112234
112717
|
|
|
112235
112718
|
**Run against the picked device:** Testver injects the device + Appium connection automatically \u2014 do not hardcode a different hub or device in your run command.`;
|
|
112236
112719
|
API_IDENTITY = (projectPath2) => `You are an expert AI assistant for the API TESTING track of the project at: ${projectPath2}
|
|
@@ -113514,9 +113997,7 @@ function mountResultsRoutes(app, resultsStore4, artifactFetcher, projectRoot = p
|
|
|
113514
113997
|
const sourceRaw = typeof req.query.source === "string" ? req.query.source : void 0;
|
|
113515
113998
|
const sourceFilter = sourceRaw === "cloud" || sourceRaw === "local" ? sourceRaw : void 0;
|
|
113516
113999
|
const { runs: allRuns } = resultsStore4.getRunHistory(Number.MAX_SAFE_INTEGER, 0);
|
|
113517
|
-
const scoped = sourceFilter ? allRuns.filter(
|
|
113518
|
-
(r) => sourceFilter === "cloud" ? r.source === "cloud" : r.source !== "cloud"
|
|
113519
|
-
) : allRuns;
|
|
114000
|
+
const scoped = sourceFilter ? allRuns.filter((r) => sourceFilter === "cloud" === ranOnCloud(r)) : allRuns;
|
|
113520
114001
|
const status = { all: scoped.length, completed: 0, failed: 0, running: 0, cancelled: 0 };
|
|
113521
114002
|
const source = { all: allRuns.length, local: 0, cloud: 0 };
|
|
113522
114003
|
let totalPassRate = 0;
|
|
@@ -113537,7 +114018,7 @@ function mountResultsRoutes(app, resultsStore4, artifactFetcher, projectRoot = p
|
|
|
113537
114018
|
}
|
|
113538
114019
|
}
|
|
113539
114020
|
for (const r of allRuns) {
|
|
113540
|
-
if (r
|
|
114021
|
+
if (ranOnCloud(r)) source.cloud++;
|
|
113541
114022
|
else source.local++;
|
|
113542
114023
|
}
|
|
113543
114024
|
res.json({
|
|
@@ -113715,15 +114196,15 @@ function mountResultsRoutes(app, resultsStore4, artifactFetcher, projectRoot = p
|
|
|
113715
114196
|
const { scanAllTests: scanAllTests2 } = await Promise.resolve().then(() => (init_test_scanner(), test_scanner_exports));
|
|
113716
114197
|
const { generateHumanSteps: generateHumanSteps2 } = await Promise.resolve().then(() => (init_step_generator(), step_generator_exports));
|
|
113717
114198
|
const { readFileSync: readFileSync101, existsSync: existsSync124 } = await import("fs");
|
|
113718
|
-
const { resolve: resolve35, basename:
|
|
114199
|
+
const { resolve: resolve35, basename: basename31 } = await import("path");
|
|
113719
114200
|
const scanResult = scanAllTests2(run2.projectPath);
|
|
113720
114201
|
const allScannedTests = scanResult.suites.flatMap((s) => s.tests);
|
|
113721
114202
|
for (const t of run2.tests || []) {
|
|
113722
114203
|
if (t.steps && t.steps.length > 0) continue;
|
|
113723
114204
|
if (!t.file) continue;
|
|
113724
|
-
const fileBasename =
|
|
114205
|
+
const fileBasename = basename31(t.file);
|
|
113725
114206
|
const matchedTest = allScannedTests.find(
|
|
113726
|
-
(st) => st.name === t.name && (st.file === t.file ||
|
|
114207
|
+
(st) => st.name === t.name && (st.file === t.file || basename31(st.file) === fileBasename || st.file.endsWith(t.file) || t.file.endsWith(st.file))
|
|
113727
114208
|
);
|
|
113728
114209
|
if (matchedTest?.line) {
|
|
113729
114210
|
const fullPath = resolve35(run2.projectPath, matchedTest.file);
|
|
@@ -114093,6 +114574,7 @@ var init_api_results = __esm({
|
|
|
114093
114574
|
"src/ui/routes/api-results.ts"() {
|
|
114094
114575
|
"use strict";
|
|
114095
114576
|
init_artifact_path();
|
|
114577
|
+
init_test_results_store();
|
|
114096
114578
|
init_export_service();
|
|
114097
114579
|
init_cloud_secrets();
|
|
114098
114580
|
}
|
|
@@ -114513,7 +114995,7 @@ __export(api_explorer_exports, {
|
|
|
114513
114995
|
mountExplorerRoutes: () => mountExplorerRoutes
|
|
114514
114996
|
});
|
|
114515
114997
|
import { readFileSync as readFileSync81, existsSync as existsSync97 } from "fs";
|
|
114516
|
-
import { resolve as resolve27, basename as
|
|
114998
|
+
import { resolve as resolve27, basename as basename27 } from "path";
|
|
114517
114999
|
function mountExplorerRoutes(app, _scanner, options, resultsStore4) {
|
|
114518
115000
|
const { projectPath: projectPath2 } = options;
|
|
114519
115001
|
app.get("/api/tests/lifecycle", (_req, res) => {
|
|
@@ -114649,11 +115131,11 @@ function mountExplorerRoutes(app, _scanner, options, resultsStore4) {
|
|
|
114649
115131
|
}
|
|
114650
115132
|
} else if (testName) {
|
|
114651
115133
|
const scanResult = scanAllTests(projectPath2);
|
|
114652
|
-
const fileBasename =
|
|
115134
|
+
const fileBasename = basename27(file);
|
|
114653
115135
|
const allScanned = scanResult.suites.flatMap((s) => s.tests);
|
|
114654
115136
|
const norm6 = (n) => n.replace(/\[.*\]$/, "").trim();
|
|
114655
115137
|
const wantName = norm6(testName);
|
|
114656
|
-
const fileMatches = (t) => t.file === file ||
|
|
115138
|
+
const fileMatches = (t) => t.file === file || basename27(t.file) === fileBasename || t.file.endsWith(file) || file.endsWith(t.file);
|
|
114657
115139
|
const nameMatches2 = (t) => t.name === testName || norm6(t.name) === wantName;
|
|
114658
115140
|
const matchedTest = allScanned.find((t) => nameMatches2(t) && fileMatches(t) && t.line) || allScanned.find((t) => nameMatches2(t) && t.line);
|
|
114659
115141
|
if (!matchedTest || !matchedTest.line) {
|
|
@@ -117427,11 +117909,11 @@ var init_selectors = __esm({
|
|
|
117427
117909
|
});
|
|
117428
117910
|
|
|
117429
117911
|
// src/recorder/recorder.ts
|
|
117430
|
-
import { randomBytes as
|
|
117912
|
+
import { randomBytes as randomBytes16 } from "crypto";
|
|
117431
117913
|
function tokenFor2(page) {
|
|
117432
117914
|
let t = pageTokens.get(page);
|
|
117433
117915
|
if (!t) {
|
|
117434
|
-
t =
|
|
117916
|
+
t = randomBytes16(16).toString("hex");
|
|
117435
117917
|
pageTokens.set(page, t);
|
|
117436
117918
|
}
|
|
117437
117919
|
return t;
|
|
@@ -130275,7 +130757,7 @@ function publicAutoHeal(cfg) {
|
|
|
130275
130757
|
}
|
|
130276
130758
|
function isMcpUiEnabled() {
|
|
130277
130759
|
const raw = (process.env.TESTVER_MCP_ENABLED ?? "").trim().toLowerCase();
|
|
130278
|
-
return
|
|
130760
|
+
return raw === "true" || raw === "1" || raw === "yes" || raw === "on";
|
|
130279
130761
|
}
|
|
130280
130762
|
function mountSystemRoutes(app, systemConfigStore, projectPath2, onRemoteUpdatesChanged) {
|
|
130281
130763
|
app.get("/api/system/app-mode", (_req, res) => {
|
|
@@ -131411,6 +131893,30 @@ function mountAutoHealRoutes(app, resultsStore4, options, systemConfig) {
|
|
|
131411
131893
|
}
|
|
131412
131894
|
return true;
|
|
131413
131895
|
};
|
|
131896
|
+
const codeLinesOf = (pairs, fileCache) => {
|
|
131897
|
+
if (!pairs?.length) return void 0;
|
|
131898
|
+
const out = [];
|
|
131899
|
+
for (const p2 of pairs) {
|
|
131900
|
+
if (p2.find.includes("\n") || p2.replace.includes("\n")) return void 0;
|
|
131901
|
+
let content = fileCache.get(p2.file);
|
|
131902
|
+
if (content === void 0) {
|
|
131903
|
+
try {
|
|
131904
|
+
content = readTextFile(join103(options.projectPath, p2.file)).text;
|
|
131905
|
+
} catch {
|
|
131906
|
+
content = null;
|
|
131907
|
+
}
|
|
131908
|
+
fileCache.set(p2.file, content);
|
|
131909
|
+
}
|
|
131910
|
+
if (!content) return void 0;
|
|
131911
|
+
const lineOf = (text2) => content.split(/\r?\n/).find((l) => l.includes(text2));
|
|
131912
|
+
const withFind = lineOf(p2.find);
|
|
131913
|
+
const withReplace = withFind === void 0 ? lineOf(p2.replace) : void 0;
|
|
131914
|
+
if (withFind !== void 0) out.push({ file: p2.file, before: withFind.trim(), after: withFind.replace(p2.find, p2.replace).trim() });
|
|
131915
|
+
else if (withReplace !== void 0) out.push({ file: p2.file, before: withReplace.replace(p2.replace, p2.find).trim(), after: withReplace.trim() });
|
|
131916
|
+
else return void 0;
|
|
131917
|
+
}
|
|
131918
|
+
return out;
|
|
131919
|
+
};
|
|
131414
131920
|
const allRuns = (limit) => {
|
|
131415
131921
|
const { runs: runs3 } = resultsStore4.getRunHistory(limit, 0);
|
|
131416
131922
|
const out = [];
|
|
@@ -131482,7 +131988,8 @@ function mountAutoHealRoutes(app, resultsStore4, options, systemConfig) {
|
|
|
131482
131988
|
actionable,
|
|
131483
131989
|
staleReason,
|
|
131484
131990
|
partialNote: s.partialNote,
|
|
131485
|
-
chain: s.chain
|
|
131991
|
+
chain: s.chain,
|
|
131992
|
+
codeLines: codeLinesOf(s.pairs, fileCache)
|
|
131486
131993
|
});
|
|
131487
131994
|
}
|
|
131488
131995
|
}
|
|
@@ -131714,16 +132221,31 @@ function contains(b, x, y) {
|
|
|
131714
132221
|
function area(b) {
|
|
131715
132222
|
return Math.max(0, b.x2 - b.x1) * Math.max(0, b.y2 - b.y1);
|
|
131716
132223
|
}
|
|
131717
|
-
function
|
|
131718
|
-
|
|
132224
|
+
function hasIdentity(node, platform4) {
|
|
132225
|
+
if (platform4 === "ios") return !!(node.attrs["name"] || node.attrs["accessibilityIdentifier"] || "").trim();
|
|
132226
|
+
const rid = node.attrs["resource-id"] || "";
|
|
132227
|
+
return rid.includes(":id/") && !rid.startsWith("android:") || !!(node.attrs["content-desc"] || "").trim();
|
|
132228
|
+
}
|
|
132229
|
+
function findTapTargetAt(pageSource, x, y, platform4) {
|
|
132230
|
+
const under = [];
|
|
132231
|
+
let screen = 0;
|
|
131719
132232
|
for (const node of walkElements(pageSource)) {
|
|
131720
132233
|
if (!node.bounds) continue;
|
|
131721
|
-
|
|
131722
|
-
if (
|
|
131723
|
-
best = node;
|
|
131724
|
-
}
|
|
132234
|
+
screen = Math.max(screen, area(node.bounds));
|
|
132235
|
+
if (contains(node.bounds, x, y)) under.push(node);
|
|
131725
132236
|
}
|
|
131726
|
-
|
|
132237
|
+
let inner = null;
|
|
132238
|
+
for (const node of under) {
|
|
132239
|
+
if (!inner || node.depth > inner.depth || node.depth === inner.depth && area(node.bounds) < area(inner.bounds)) inner = node;
|
|
132240
|
+
}
|
|
132241
|
+
if (!inner) return null;
|
|
132242
|
+
if (hasIdentity(inner, platform4)) return { target: inner, inner };
|
|
132243
|
+
const ancestors = under.filter((n) => n !== inner && n.depth < inner.depth && n.depth >= inner.depth - 4 && inner.path.startsWith(n.path + "/")).sort((a, b) => b.depth - a.depth);
|
|
132244
|
+
for (const a of ancestors) {
|
|
132245
|
+
if (screen && area(a.bounds) > screen * 0.4) break;
|
|
132246
|
+
if (hasIdentity(a, platform4) || a.attrs["clickable"] === "true") return { target: a, inner };
|
|
132247
|
+
}
|
|
132248
|
+
return { target: inner, inner };
|
|
131727
132249
|
}
|
|
131728
132250
|
function findWebviewAt(pageSource, x, y) {
|
|
131729
132251
|
let best = null;
|
|
@@ -131965,7 +132487,8 @@ function generateLocators(node, pageSource, platform4) {
|
|
|
131965
132487
|
return { primary, ranked: unique, label: label3 };
|
|
131966
132488
|
}
|
|
131967
132489
|
function describeElement2(node, platform4) {
|
|
131968
|
-
const
|
|
132490
|
+
const editable = /EditText|XCUIElementType(TextField|SecureTextField|TextView|SearchField)/i.test(node.attrs["class"] || node.tag || "");
|
|
132491
|
+
const text2 = platform4 === "android" ? (editable ? "" : node.attrs["text"]) || node.attrs["content-desc"] : (editable ? "" : node.attrs["label"]) || node.attrs["name"];
|
|
131969
132492
|
if (text2 && text2.trim()) return `"${text2.slice(0, 40)}"`;
|
|
131970
132493
|
const rid = node.attrs["resource-id"];
|
|
131971
132494
|
if (rid) {
|
|
@@ -132421,6 +132944,10 @@ return { locator: loc, tag: tag, text: text };
|
|
|
132421
132944
|
* field. Fixes the late-poll race where the first source poll already
|
|
132422
132945
|
* sees the typed text and mistakes it for the baseline. */
|
|
132423
132946
|
typingSeed = null;
|
|
132947
|
+
/** Text the recorder just typed itself (the "Type text" box): it is
|
|
132948
|
+
* already a step, so the typing detector takes the field's new value
|
|
132949
|
+
* as its baseline instead of recording the same text a second time. */
|
|
132950
|
+
explicitType = null;
|
|
132424
132951
|
/** Faster source-poll cadence while a field is focused (catches typing
|
|
132425
132952
|
* before the user navigates away). Restored to the idle cadence after. */
|
|
132426
132953
|
static TOUCH_PRIME_IDLE_MS = 1500;
|
|
@@ -132481,6 +133008,14 @@ return { locator: loc, tag: tag, text: text };
|
|
|
132481
133008
|
* Fire-and-forget — failures just mean the next tap fetches fresh.
|
|
132482
133009
|
*/
|
|
132483
133010
|
async primeSource() {
|
|
133011
|
+
if (this.primeInFlight) return this.primeInFlight;
|
|
133012
|
+
this.primeInFlight = this.doPrimeSource().finally(() => {
|
|
133013
|
+
this.primeInFlight = null;
|
|
133014
|
+
});
|
|
133015
|
+
return this.primeInFlight;
|
|
133016
|
+
}
|
|
133017
|
+
primeInFlight = null;
|
|
133018
|
+
async doPrimeSource() {
|
|
132484
133019
|
if (!this.recording) return;
|
|
132485
133020
|
const adapter = this.manager.getAdapter();
|
|
132486
133021
|
if (!adapter || !adapter.isActive()) return;
|
|
@@ -132539,7 +133074,7 @@ return { locator: loc, tag: tag, text: text };
|
|
|
132539
133074
|
const seed = this.typingSeed;
|
|
132540
133075
|
const b = focused.node.bounds;
|
|
132541
133076
|
const seedMatches = seed && Date.now() - seed.at < 8e3 && b && seed.x >= b.x1 && seed.x <= b.x2 && seed.y >= b.y1 && seed.y <= b.y2;
|
|
132542
|
-
const baseline = seedMatches ? seed.baseline : focused.text;
|
|
133077
|
+
const baseline = seedMatches && !this.absorbsExplicitType(focused) ? seed.baseline : focused.text;
|
|
132543
133078
|
this.typingSeed = null;
|
|
132544
133079
|
logger38.info(`Typing detected: field focused (baseline ${baseline.length} chars, current ${focused.text.length} chars).`);
|
|
132545
133080
|
this.pendingType = {
|
|
@@ -132560,12 +133095,24 @@ return { locator: loc, tag: tag, text: text };
|
|
|
132560
133095
|
if (focused.text !== this.pendingType.text) {
|
|
132561
133096
|
this.pendingType.text = focused.text;
|
|
132562
133097
|
this.pendingType.changedAt = Date.now();
|
|
133098
|
+
if (this.absorbsExplicitType(focused)) this.pendingType.baseline = focused.text;
|
|
132563
133099
|
return;
|
|
132564
133100
|
}
|
|
132565
133101
|
if (this.pendingType.text !== this.pendingType.baseline && Date.now() - this.pendingType.changedAt > 1e3) {
|
|
132566
133102
|
this.commitPendingType();
|
|
132567
133103
|
}
|
|
132568
133104
|
}
|
|
133105
|
+
/** Is the focused field showing text the recorder typed itself a moment
|
|
133106
|
+
* ago? (A password field shows dots, so any text there counts.) */
|
|
133107
|
+
absorbsExplicitType(focused) {
|
|
133108
|
+
const e = this.explicitType;
|
|
133109
|
+
if (!e || Date.now() - e.at > 6e3) return false;
|
|
133110
|
+
if (focused.text === e.text || isSecureNode(focused.node) && focused.text.length > 0) {
|
|
133111
|
+
this.explicitType = null;
|
|
133112
|
+
return true;
|
|
133113
|
+
}
|
|
133114
|
+
return false;
|
|
133115
|
+
}
|
|
132569
133116
|
/** Emit the pending typed text as a 'type' action (capture-only). */
|
|
132570
133117
|
commitPendingType() {
|
|
132571
133118
|
const p2 = this.pendingType;
|
|
@@ -132695,7 +133242,7 @@ return { locator: loc, tag: tag, text: text };
|
|
|
132695
133242
|
if (g.type === "tap") {
|
|
132696
133243
|
const src = this.cachedSource?.xml;
|
|
132697
133244
|
const platform4 = (this.sessionSnapshot ?? this.manager.getSessionInfo())?.platform;
|
|
132698
|
-
const node = src && platform4 ?
|
|
133245
|
+
const node = src && platform4 ? findTapTargetAt(src, g.x, g.y, platform4)?.target ?? null : null;
|
|
132699
133246
|
if (this.textFieldFocused && !node) return;
|
|
132700
133247
|
if (this.textFieldFocused || this.pendingType) {
|
|
132701
133248
|
await this.primeSource();
|
|
@@ -132819,8 +133366,15 @@ return { locator: loc, tag: tag, text: text };
|
|
|
132819
133366
|
}
|
|
132820
133367
|
this.cachedSource = null;
|
|
132821
133368
|
let locators = null;
|
|
132822
|
-
const
|
|
132823
|
-
|
|
133369
|
+
const hit = source ? findTapTargetAt(source, x, y, platform4) : null;
|
|
133370
|
+
const node = hit?.target ?? null;
|
|
133371
|
+
if (node && source) {
|
|
133372
|
+
locators = generateLocators(node, source, platform4);
|
|
133373
|
+
if (hit && hit.inner !== hit.target && !locators.label.startsWith('"')) {
|
|
133374
|
+
const innerLabel = generateLocators(hit.inner, source, platform4).label;
|
|
133375
|
+
if (innerLabel.startsWith('"')) locators = { ...locators, label: innerLabel };
|
|
133376
|
+
}
|
|
133377
|
+
}
|
|
132824
133378
|
const axContext = node && source ? getAccessibilityContext(source, node, 2) : null;
|
|
132825
133379
|
const webviewNode = source ? findWebviewAt(source, x, y) : null;
|
|
132826
133380
|
let webCapture = null;
|
|
@@ -133002,6 +133556,7 @@ return { locator: loc, tag: tag, text: text };
|
|
|
133002
133556
|
const res2 = await adapter.type(target2.primary, text2, true);
|
|
133003
133557
|
if (!res2.success) throw new Error(`Type failed: ${res2.error}`);
|
|
133004
133558
|
this.cachedSource = null;
|
|
133559
|
+
this.absorbTyping(text2);
|
|
133005
133560
|
let secretEnv;
|
|
133006
133561
|
if (target2.secure) secretEnv = this.secretSink?.(target2.label || "password", text2) || void 0;
|
|
133007
133562
|
const shown2 = target2.secure ? SECRET_MASK2 : text2;
|
|
@@ -133028,6 +133583,7 @@ return { locator: loc, tag: tag, text: text };
|
|
|
133028
133583
|
throw new Error(`Type failed: ${res.error || "no focused element to receive text"}. Tap an input field first.`);
|
|
133029
133584
|
}
|
|
133030
133585
|
this.cachedSource = null;
|
|
133586
|
+
this.absorbTyping(text2);
|
|
133031
133587
|
const action = {
|
|
133032
133588
|
index: this.nextIndex++,
|
|
133033
133589
|
type: "type",
|
|
@@ -133040,6 +133596,13 @@ return { locator: loc, tag: tag, text: text };
|
|
|
133040
133596
|
this.actions.push(action);
|
|
133041
133597
|
return action;
|
|
133042
133598
|
}
|
|
133599
|
+
/** The recorder typed `text` itself: drop what the typing detector was
|
|
133600
|
+
* tracking and let it absorb the field's new value (see explicitType). */
|
|
133601
|
+
absorbTyping(text2) {
|
|
133602
|
+
this.pendingType = null;
|
|
133603
|
+
this.typingSeed = null;
|
|
133604
|
+
this.explicitType = { text: text2, at: Date.now() };
|
|
133605
|
+
}
|
|
133043
133606
|
async recordSwipe(from, to, durationMs, thumbnail, screenshot, screenshotSize, perform = true) {
|
|
133044
133607
|
if (!this.recording) throw new Error("Recorder is not active.");
|
|
133045
133608
|
const adapter = this.manager.getAdapter();
|
|
@@ -133070,6 +133633,10 @@ return { locator: loc, tag: tag, text: text };
|
|
|
133070
133633
|
this.actions.push(action);
|
|
133071
133634
|
return action;
|
|
133072
133635
|
}
|
|
133636
|
+
/** The screen changed through something that isn't recorded (a tap or key while paused): drop the primed source. */
|
|
133637
|
+
screenChanged() {
|
|
133638
|
+
this.cachedSource = null;
|
|
133639
|
+
}
|
|
133073
133640
|
async recordPressKey(key2, thumbnail, screenshot, screenshotSize) {
|
|
133074
133641
|
if (!this.recording) throw new Error("Recorder is not active.");
|
|
133075
133642
|
const adapter = this.manager.getAdapter();
|
|
@@ -134581,7 +135148,7 @@ var init_recording_history_store = __esm({
|
|
|
134581
135148
|
|
|
134582
135149
|
// src/mobile/ai-codegen.ts
|
|
134583
135150
|
import { existsSync as existsSync108, readdirSync as readdirSync43, readFileSync as readFileSync89, statSync as statSync44 } from "fs";
|
|
134584
|
-
import { join as join105, relative as relative40 } from "path";
|
|
135151
|
+
import { dirname as dirname31, join as join105, relative as relative40 } from "path";
|
|
134585
135152
|
function readSample(fullPath, maxBytes = 3500) {
|
|
134586
135153
|
try {
|
|
134587
135154
|
if (!existsSync108(fullPath)) return null;
|
|
@@ -134711,6 +135278,13 @@ function inspectProject(projectPath2) {
|
|
|
134711
135278
|
allTestFiles.push(...findFiles2(join105(projectPath2, dir), /\.(spec|test)\.(ts|js|py|java|cs)$|^test_.+\.py$|_test\.py$|(Test|Tests|IT)\.(java|kt|cs)$/));
|
|
134712
135279
|
}
|
|
134713
135280
|
hints.sampleTestPaths = [...new Set(allTestFiles)].slice(0, 8);
|
|
135281
|
+
const dirCount = /* @__PURE__ */ new Map();
|
|
135282
|
+
for (const f of new Set(allTestFiles)) {
|
|
135283
|
+
const d = relative40(projectPath2, dirname31(f)).replace(/\\/g, "/");
|
|
135284
|
+
dirCount.set(d, (dirCount.get(d) || 0) + 1);
|
|
135285
|
+
}
|
|
135286
|
+
const topDir = [...dirCount.entries()].sort((a, b) => b[1] - a[1] || a[0].length - b[0].length)[0];
|
|
135287
|
+
if (topDir && topDir[0]) hints.testDir = topDir[0];
|
|
134714
135288
|
const embedTest = pickSmallest(allTestFiles.slice(0, 12));
|
|
134715
135289
|
if (embedTest) {
|
|
134716
135290
|
const sample = readSample(embedTest);
|
|
@@ -134718,7 +135292,24 @@ function inspectProject(projectPath2) {
|
|
|
134718
135292
|
hints.embeddedTestSample = { path: relative40(projectPath2, embedTest), ...sample };
|
|
134719
135293
|
}
|
|
134720
135294
|
}
|
|
134721
|
-
const pageDirs = [
|
|
135295
|
+
const pageDirs = [
|
|
135296
|
+
"tests/mobile/pages",
|
|
135297
|
+
"tests/pages",
|
|
135298
|
+
"tests/mobile/pageobjects",
|
|
135299
|
+
"src/pages",
|
|
135300
|
+
"src/pageobjects",
|
|
135301
|
+
"pages",
|
|
135302
|
+
"pageobjects",
|
|
135303
|
+
"tests/support/pages",
|
|
135304
|
+
"tests/mobile/screens",
|
|
135305
|
+
"tests/screens",
|
|
135306
|
+
"test/screens",
|
|
135307
|
+
"test/pages",
|
|
135308
|
+
"test/pageobjects",
|
|
135309
|
+
"src/screens",
|
|
135310
|
+
"screens"
|
|
135311
|
+
];
|
|
135312
|
+
const PAGE_FILE = /Page\.(ts|js|py|java|cs|kt)$|_page\.(ts|js|py)$|Screen\.(ts|js|py|java|cs|kt)$|\.screen\.(ts|js)$|_screen\.py$/;
|
|
134722
135313
|
for (const d of pageDirs) {
|
|
134723
135314
|
if (existsSync108(join105(projectPath2, d))) {
|
|
134724
135315
|
hints.pageObjectDir = d;
|
|
@@ -134727,10 +135318,10 @@ function inspectProject(projectPath2) {
|
|
|
134727
135318
|
}
|
|
134728
135319
|
let pageObjectCandidates = [];
|
|
134729
135320
|
if (hints.pageObjectDir) {
|
|
134730
|
-
pageObjectCandidates = findFiles2(join105(projectPath2, hints.pageObjectDir),
|
|
135321
|
+
pageObjectCandidates = findFiles2(join105(projectPath2, hints.pageObjectDir), PAGE_FILE);
|
|
134731
135322
|
} else {
|
|
134732
135323
|
for (const dir of testCandidates) {
|
|
134733
|
-
pageObjectCandidates.push(...findFiles2(join105(projectPath2, dir),
|
|
135324
|
+
pageObjectCandidates.push(...findFiles2(join105(projectPath2, dir), PAGE_FILE, 4, 10));
|
|
134734
135325
|
}
|
|
134735
135326
|
}
|
|
134736
135327
|
pageObjectCandidates = [...new Set(pageObjectCandidates)];
|
|
@@ -134740,7 +135331,7 @@ function inspectProject(projectPath2) {
|
|
|
134740
135331
|
const sample = readSample(embedPage);
|
|
134741
135332
|
if (sample) hints.embeddedPageObject = { path: relative40(projectPath2, embedPage), ...sample };
|
|
134742
135333
|
}
|
|
134743
|
-
const helperDirs = ["tests/mobile/helpers", "tests/helpers", "tests/support", "tests/fixtures", "tests/mobile/fixtures", "src/helpers", "src/support", "helpers", "support"];
|
|
135334
|
+
const helperDirs = ["tests/mobile/helpers", "tests/helpers", "tests/support", "tests/fixtures", "tests/mobile/fixtures", "test/support", "test/helpers", "test/fixtures", "src/helpers", "src/support", "helpers", "support"];
|
|
134744
135335
|
for (const d of helperDirs) {
|
|
134745
135336
|
if (existsSync108(join105(projectPath2, d))) {
|
|
134746
135337
|
hints.helperDir = d;
|
|
@@ -134784,6 +135375,14 @@ function formatActionForPrompt(a, n) {
|
|
|
134784
135375
|
if (a.from && a.to) parts.push(`swipe ${a.from.x},${a.from.y} \u2192 ${a.to.x},${a.to.y}`);
|
|
134785
135376
|
if (a.assertType) parts.push(`assert=${a.assertType}${a.expectedValue ? `="${a.expectedValue}"` : ""}`);
|
|
134786
135377
|
if (a.userIntent) parts.push(`intent="${a.userIntent}"`);
|
|
135378
|
+
const ea = a.elementAttrs;
|
|
135379
|
+
if (ea) {
|
|
135380
|
+
const bits = ["class", "text", "content-desc", "label", "name"].filter((k) => ea[k] && String(ea[k]).trim() && !(k === "text" && a.secretEnv)).map((k) => `${k}=${JSON.stringify(String(ea[k]).slice(0, 60))}`);
|
|
135381
|
+
if (bits.length) parts.push(`element{${bits.join(", ")}}`);
|
|
135382
|
+
}
|
|
135383
|
+
if ((a.type === "annotation" || a.type === "assertion") && a.axContext) {
|
|
135384
|
+
parts.push(`screen context (recorded): ${a.axContext.replace(/\s+/g, " ").slice(0, 700)}`);
|
|
135385
|
+
}
|
|
134787
135386
|
if (a.inWebview) {
|
|
134788
135387
|
parts.push(
|
|
134789
135388
|
a.webLocator ? `WEBVIEW step: DOM locator ${a.webLocator.strategy}:${a.webLocator.value}${a.webContext ? ` (context ${a.webContext})` : ""} \u2014 wrap in a switchContext pair` : `WEBVIEW step (no DOM locator captured): the locator above is the NATIVE accessibility projection \u2014 use it in NATIVE_APP context, do NOT switch`
|
|
@@ -134807,7 +135406,7 @@ function readMergeTarget(projectPath2, relPath) {
|
|
|
134807
135406
|
function buildMobileCodegenPrompt(input) {
|
|
134808
135407
|
const { actions, session, testName, projectPath: projectPath2 } = input;
|
|
134809
135408
|
const hints = inspectProject(projectPath2);
|
|
134810
|
-
const targetDir =
|
|
135409
|
+
const targetDir = hints.testDir || "tests/mobile";
|
|
134811
135410
|
const langChoice = input.preferredLanguage || (hints.detectedFramework === "pytest" ? "python" : hints.detectedFramework === "testng" || hints.detectedFramework === "junit" ? "java" : hints.detectedFramework === "nunit" || hints.detectedFramework === "xunit" || hints.detectedFramework === "mstest" ? "csharp" : "typescript");
|
|
134812
135411
|
const lines = [];
|
|
134813
135412
|
if (input.mergeMode && input.targetTestFile) {
|
|
@@ -134857,7 +135456,7 @@ function buildMobileCodegenPrompt(input) {
|
|
|
134857
135456
|
lines.push(`## Page-object convention detected`);
|
|
134858
135457
|
lines.push(`This project uses a page-object pattern under \`${hints.pageObjectDir}\`. EXTEND that pattern:`);
|
|
134859
135458
|
lines.push(` \u2022 If a page object already exists for the screen the recording targets, REUSE it (read with \`read_file\`, import, call its methods).`);
|
|
134860
|
-
lines.push(` \u2022 If not, CREATE a new
|
|
135459
|
+
lines.push(` \u2022 If not, CREATE a new one \u2014 same folder, same naming and shape as the sample below \u2014 before writing the spec.`);
|
|
134861
135460
|
if (hints.embeddedPageObject) {
|
|
134862
135461
|
lines.push(`### Sample page object \u2014 \`${hints.embeddedPageObject.path}\`${hints.embeddedPageObject.truncated ? " (truncated)" : ""}`);
|
|
134863
135462
|
lines.push("```");
|
|
@@ -134899,6 +135498,7 @@ function buildMobileCodegenPrompt(input) {
|
|
|
134899
135498
|
}
|
|
134900
135499
|
lines.push(`## Recorded actions (1-indexed)`);
|
|
134901
135500
|
actions.forEach((a, i) => lines.push(`- ${formatActionForPrompt(a, i + 1)}`));
|
|
135501
|
+
lines.push(`This list is the whole recording \u2014 locators, elements, values and screen context. Don't read Testver's own files under \`.testver/\` for it.`);
|
|
134902
135502
|
lines.push("");
|
|
134903
135503
|
lines.push(`## Locator guidance`);
|
|
134904
135504
|
lines.push(`- Each tap/type carries the PRIMARY locator we resolved \u2014 use it verbatim (validated against the live page source at record time).`);
|
|
@@ -135143,6 +135743,7 @@ var init_ai_codegen = __esm({
|
|
|
135143
135743
|
var api_mobile_exports = {};
|
|
135144
135744
|
__export(api_mobile_exports, {
|
|
135145
135745
|
cancelMobileClientGone: () => cancelMobileClientGone,
|
|
135746
|
+
ensureAdbPump: () => ensureAdbPump,
|
|
135146
135747
|
mountMobileRoutes: () => mountMobileRoutes,
|
|
135147
135748
|
scheduleMobileClientGone: () => scheduleMobileClientGone,
|
|
135148
135749
|
setMobileClientOwners: () => setMobileClientOwners
|
|
@@ -135202,6 +135803,44 @@ function startExternalFramePump(clientId) {
|
|
|
135202
135803
|
latestExternalFrames.delete(clientId);
|
|
135203
135804
|
})();
|
|
135204
135805
|
}
|
|
135806
|
+
function ensureAdbPump(clientId, serial, adbPath) {
|
|
135807
|
+
const existing = adbPumps.get(clientId);
|
|
135808
|
+
if (existing && !existing.stop && existing.serial === serial) {
|
|
135809
|
+
existing.wantedAt = Date.now();
|
|
135810
|
+
return existing;
|
|
135811
|
+
}
|
|
135812
|
+
if (existing) existing.stop = true;
|
|
135813
|
+
let signal;
|
|
135814
|
+
const pump = {
|
|
135815
|
+
serial,
|
|
135816
|
+
adbPath,
|
|
135817
|
+
wantedAt: Date.now(),
|
|
135818
|
+
stop: false,
|
|
135819
|
+
nextFrame: new Promise((r) => {
|
|
135820
|
+
signal = r;
|
|
135821
|
+
})
|
|
135822
|
+
};
|
|
135823
|
+
adbPumps.set(clientId, pump);
|
|
135824
|
+
void (async () => {
|
|
135825
|
+
const { captureAndroidScreenshotViaAdb: captureAndroidScreenshotViaAdb2 } = await Promise.resolve().then(() => (init_local_mobile_tools(), local_mobile_tools_exports));
|
|
135826
|
+
const { getLocalPreviewTarget: getLocalPreviewTarget2 } = await Promise.resolve().then(() => (init_local_preview_registry(), local_preview_registry_exports));
|
|
135827
|
+
while (!pump.stop) {
|
|
135828
|
+
if (getLocalPreviewTarget2(clientId)?.serial !== serial || Date.now() - pump.wantedAt > ADB_PUMP_IDLE_STOP_MS) break;
|
|
135829
|
+
const image = await captureAndroidScreenshotViaAdb2(serial, adbPath, { timeoutMs: ADB_PUMP_CAPTURE_TIMEOUT_MS }).catch(() => null);
|
|
135830
|
+
if (image) pump.latest = { image, capturedAt: Date.now() };
|
|
135831
|
+
const done2 = signal;
|
|
135832
|
+
pump.nextFrame = new Promise((r) => {
|
|
135833
|
+
signal = r;
|
|
135834
|
+
});
|
|
135835
|
+
done2();
|
|
135836
|
+
await new Promise((r) => setTimeout(r, image ? 150 : 1e3));
|
|
135837
|
+
}
|
|
135838
|
+
pump.stop = true;
|
|
135839
|
+
signal();
|
|
135840
|
+
if (adbPumps.get(clientId) === pump) adbPumps.delete(clientId);
|
|
135841
|
+
})();
|
|
135842
|
+
return pump;
|
|
135843
|
+
}
|
|
135205
135844
|
function extractClientId2(req) {
|
|
135206
135845
|
const h = req.headers["x-client-id"];
|
|
135207
135846
|
if (typeof h === "string" && h.length > 0) return h;
|
|
@@ -135709,7 +136348,8 @@ function mountMobileRoutes(app, options, wss) {
|
|
|
135709
136348
|
reuseTicketStore.issue(clientId, info, {
|
|
135710
136349
|
deviceName: info.device,
|
|
135711
136350
|
platformName: info.platform === "ios" ? "iOS" : "Android",
|
|
135712
|
-
platformVersion: osVersion
|
|
136351
|
+
platformVersion: osVersion,
|
|
136352
|
+
appId
|
|
135713
136353
|
});
|
|
135714
136354
|
} catch (err5) {
|
|
135715
136355
|
logger41.warn(`reuseTicketStore.issue (start) failed: ${err5.message}`);
|
|
@@ -135747,7 +136387,8 @@ function mountMobileRoutes(app, options, wss) {
|
|
|
135747
136387
|
res.json({ session: info });
|
|
135748
136388
|
} catch (err5) {
|
|
135749
136389
|
logger41.error(`session start failed: ${err5.message}`);
|
|
135750
|
-
|
|
136390
|
+
const busy2 = err5.name === "LocalDeviceBusyError";
|
|
136391
|
+
res.status(busy2 ? 409 : 500).json({ error: err5.message, ...busy2 ? { code: "LOCAL_DEVICE_BUSY" } : {} });
|
|
135751
136392
|
}
|
|
135752
136393
|
});
|
|
135753
136394
|
app.get("/api/mobile/session", (req, res) => {
|
|
@@ -135758,7 +136399,7 @@ function mountMobileRoutes(app, options, wss) {
|
|
|
135758
136399
|
const manager = pool.peek(clientId);
|
|
135759
136400
|
if (!manager) return res.json({ session: null, desired: null, context: null });
|
|
135760
136401
|
const context = manager.getAdapter()?.getCachedContext?.() ?? null;
|
|
135761
|
-
res.json({ session: manager.getSessionInfo(), desired: manager.getDesiredSession(), context });
|
|
136402
|
+
res.json({ session: manager.getSessionInfo(), desired: manager.getDesiredSession(), context, starting: manager.isStarting() });
|
|
135762
136403
|
});
|
|
135763
136404
|
app.post("/api/mobile/session/keepalive", (req, res) => {
|
|
135764
136405
|
const pool = mobilePool();
|
|
@@ -135778,13 +136419,32 @@ function mountMobileRoutes(app, options, wss) {
|
|
|
135778
136419
|
const { getLocalPreviewTarget: getLocalPreviewTarget2 } = await Promise.resolve().then(() => (init_local_preview_registry(), local_preview_registry_exports));
|
|
135779
136420
|
const target2 = getLocalPreviewTarget2(clientId);
|
|
135780
136421
|
if (target2 && target2.platform === "android") {
|
|
135781
|
-
const
|
|
135782
|
-
|
|
135783
|
-
|
|
136422
|
+
const pump = ensureAdbPump(clientId, target2.serial, target2.adbPath);
|
|
136423
|
+
if (!pump.latest) {
|
|
136424
|
+
await Promise.race([pump.nextFrame, new Promise((r) => setTimeout(r, ADB_FIRST_FRAME_WAIT_MS))]);
|
|
136425
|
+
}
|
|
136426
|
+
const since = Number(req.query.since) || 0;
|
|
136427
|
+
if (since && pump.latest && pump.latest.capturedAt <= since) {
|
|
136428
|
+
await Promise.race([pump.nextFrame, new Promise((r) => setTimeout(r, ADB_UNCHANGED_WAIT_MS))]);
|
|
136429
|
+
if (pump.latest && pump.latest.capturedAt <= since) {
|
|
136430
|
+
reuseTicketStore.refresh(clientId);
|
|
136431
|
+
res.json({ unchanged: true, capturedAt: pump.latest.capturedAt });
|
|
136432
|
+
return;
|
|
136433
|
+
}
|
|
136434
|
+
}
|
|
136435
|
+
const frame = pump.latest;
|
|
136436
|
+
if (frame) {
|
|
135784
136437
|
reuseTicketStore.refresh(clientId);
|
|
135785
|
-
res.json({ image, capturedAt: Date.now() });
|
|
136438
|
+
res.json({ image: frame.image, capturedAt: frame.capturedAt, ...Date.now() - frame.capturedAt > ADB_FRESH_MS ? { delayed: true } : {} });
|
|
136439
|
+
return;
|
|
136440
|
+
}
|
|
136441
|
+
const cachedExt = latestExternalFrames.get(clientId);
|
|
136442
|
+
if (cachedExt && Date.now() - cachedExt.capturedAt < 5e3) {
|
|
136443
|
+
res.json({ image: cachedExt.image, capturedAt: cachedExt.capturedAt, delayed: true });
|
|
135786
136444
|
return;
|
|
135787
136445
|
}
|
|
136446
|
+
res.status(503).json({ error: "Waiting for the device's first frame \u2014 it is busy with the test run.", code: "FRAME_PENDING" });
|
|
136447
|
+
return;
|
|
135788
136448
|
} else if (target2 && target2.platform === "ios") {
|
|
135789
136449
|
const { captureIosScreenshot: captureIosScreenshot2 } = await Promise.resolve().then(() => (init_local_mobile_tools(), local_mobile_tools_exports));
|
|
135790
136450
|
const image = await captureIosScreenshot2(target2.serial, target2.iosToolsPath);
|
|
@@ -136214,6 +136874,46 @@ function mountMobileRoutes(app, options, wss) {
|
|
|
136214
136874
|
}
|
|
136215
136875
|
const r = await adapter.swipe(from, to, durationMs);
|
|
136216
136876
|
if (!r.success) return res.status(500).json({ error: r.error || "swipe failed" });
|
|
136877
|
+
recorderPool()?.getFor(clientId).screenChanged();
|
|
136878
|
+
res.json({ ok: true });
|
|
136879
|
+
} catch (err5) {
|
|
136880
|
+
res.status(500).json({ error: err5.message });
|
|
136881
|
+
}
|
|
136882
|
+
});
|
|
136883
|
+
app.post("/api/mobile/session/tap", async (req, res) => {
|
|
136884
|
+
const mPool = mobilePool();
|
|
136885
|
+
if (!mPool) return res.status(500).json({ error: "Mobile session pool not initialized." });
|
|
136886
|
+
const clientId = extractClientId2(req);
|
|
136887
|
+
if (!clientId) return res.status(400).json({ error: "Missing X-Client-Id header." });
|
|
136888
|
+
if (rejectIfLocked(req, res, clientId)) return;
|
|
136889
|
+
const x = Number(req.body?.x);
|
|
136890
|
+
const y = Number(req.body?.y);
|
|
136891
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return res.status(400).json({ error: "Body must include numeric x and y." });
|
|
136892
|
+
try {
|
|
136893
|
+
const adapter = mPool.getFor(clientId).getAdapter();
|
|
136894
|
+
if (!adapter || !adapter.isActive()) return res.status(400).json({ error: "No active mobile session." });
|
|
136895
|
+
const r = await adapter.tapAt({ x, y });
|
|
136896
|
+
if (!r.success) return res.status(500).json({ error: r.error || "tap failed" });
|
|
136897
|
+
recorderPool()?.getFor(clientId).screenChanged();
|
|
136898
|
+
res.json({ ok: true });
|
|
136899
|
+
} catch (err5) {
|
|
136900
|
+
res.status(500).json({ error: err5.message });
|
|
136901
|
+
}
|
|
136902
|
+
});
|
|
136903
|
+
app.post("/api/mobile/session/press-key", async (req, res) => {
|
|
136904
|
+
const mPool = mobilePool();
|
|
136905
|
+
if (!mPool) return res.status(500).json({ error: "Mobile session pool not initialized." });
|
|
136906
|
+
const clientId = extractClientId2(req);
|
|
136907
|
+
if (!clientId) return res.status(400).json({ error: "Missing X-Client-Id header." });
|
|
136908
|
+
if (rejectIfLocked(req, res, clientId)) return;
|
|
136909
|
+
const key2 = String(req.body?.key ?? "");
|
|
136910
|
+
if (!key2) return res.status(400).json({ error: "Body must include key." });
|
|
136911
|
+
try {
|
|
136912
|
+
const adapter = mPool.getFor(clientId).getAdapter();
|
|
136913
|
+
if (!adapter || !adapter.isActive()) return res.status(400).json({ error: "No active mobile session." });
|
|
136914
|
+
const r = await adapter.pressKey(key2);
|
|
136915
|
+
if (!r.success) return res.status(500).json({ error: r.error || "key press failed" });
|
|
136916
|
+
recorderPool()?.getFor(clientId).screenChanged();
|
|
136217
136917
|
res.json({ ok: true });
|
|
136218
136918
|
} catch (err5) {
|
|
136219
136919
|
res.status(500).json({ error: err5.message });
|
|
@@ -136264,7 +136964,9 @@ function mountMobileRoutes(app, options, wss) {
|
|
|
136264
136964
|
reuseTicketStore.issue(clientId, liveInfo, {
|
|
136265
136965
|
deviceName: liveInfo.device,
|
|
136266
136966
|
platformName: liveInfo.platform === "ios" ? "iOS" : "Android",
|
|
136267
|
-
platformVersion: ""
|
|
136967
|
+
platformVersion: "",
|
|
136968
|
+
// Same session, same build: keep the app the session started with.
|
|
136969
|
+
appId: reuseTicketStore.peek(clientId)?.appId
|
|
136268
136970
|
});
|
|
136269
136971
|
} catch (err5) {
|
|
136270
136972
|
console.warn("[testver] reuseTicketStore.issue (stop) failed:", err5.message);
|
|
@@ -136960,7 +137662,7 @@ ${previousContext}`);
|
|
|
136960
137662
|
}
|
|
136961
137663
|
});
|
|
136962
137664
|
}
|
|
136963
|
-
var latestExternalFrames, externalFramePumps, FRAME_PUMP_INTERVAL_MS, logger41, MOBILE_PROVIDER_IDS, EXCLUDED_TOOLS_FOR_MOBILE_RECORDER, mobileClientOwnersRef, clientGoneTimers, onClientGone;
|
|
137665
|
+
var latestExternalFrames, externalFramePumps, FRAME_PUMP_INTERVAL_MS, adbPumps, ADB_PUMP_CAPTURE_TIMEOUT_MS, ADB_PUMP_IDLE_STOP_MS, ADB_FIRST_FRAME_WAIT_MS, ADB_FRESH_MS, ADB_UNCHANGED_WAIT_MS, logger41, MOBILE_PROVIDER_IDS, EXCLUDED_TOOLS_FOR_MOBILE_RECORDER, mobileClientOwnersRef, clientGoneTimers, onClientGone;
|
|
136964
137666
|
var init_api_mobile = __esm({
|
|
136965
137667
|
"src/ui/routes/api-mobile.ts"() {
|
|
136966
137668
|
"use strict";
|
|
@@ -136987,6 +137689,12 @@ var init_api_mobile = __esm({
|
|
|
136987
137689
|
latestExternalFrames = /* @__PURE__ */ new Map();
|
|
136988
137690
|
externalFramePumps = /* @__PURE__ */ new Map();
|
|
136989
137691
|
FRAME_PUMP_INTERVAL_MS = 800;
|
|
137692
|
+
adbPumps = /* @__PURE__ */ new Map();
|
|
137693
|
+
ADB_PUMP_CAPTURE_TIMEOUT_MS = 45e3;
|
|
137694
|
+
ADB_PUMP_IDLE_STOP_MS = 15e3;
|
|
137695
|
+
ADB_FIRST_FRAME_WAIT_MS = 4e3;
|
|
137696
|
+
ADB_FRESH_MS = 3e3;
|
|
137697
|
+
ADB_UNCHANGED_WAIT_MS = 2500;
|
|
136990
137698
|
logger41 = createLogger("api-mobile");
|
|
136991
137699
|
MOBILE_PROVIDER_IDS = ["browserstack", "saucelabs", "lambdatest", "local-appium"];
|
|
136992
137700
|
EXCLUDED_TOOLS_FOR_MOBILE_RECORDER = /* @__PURE__ */ new Set([
|
|
@@ -136995,6 +137703,14 @@ var init_api_mobile = __esm({
|
|
|
136995
137703
|
"mobile_tap",
|
|
136996
137704
|
"mobile_type",
|
|
136997
137705
|
"mobile_swipe",
|
|
137706
|
+
"mobile_drag",
|
|
137707
|
+
"mobile_scroll_to",
|
|
137708
|
+
"mobile_wait_for",
|
|
137709
|
+
"mobile_alert",
|
|
137710
|
+
"mobile_tap_at",
|
|
137711
|
+
"mobile_list_contexts",
|
|
137712
|
+
"mobile_switch_context",
|
|
137713
|
+
"mobile_orientation",
|
|
136998
137714
|
"mobile_press_key",
|
|
136999
137715
|
"mobile_screenshot",
|
|
137000
137716
|
"mobile_snapshot",
|
|
@@ -137110,6 +137826,26 @@ function mountLocalMobileRoutes(app, options) {
|
|
|
137110
137826
|
if (!ok6) return res.status(400).json({ error: `Couldn't close ${serial} \u2014 it may have closed already.` });
|
|
137111
137827
|
res.json({ stopped: true });
|
|
137112
137828
|
});
|
|
137829
|
+
app.post("/api/mobile/local/simulator/start", async (req, res) => {
|
|
137830
|
+
const udid = typeof req.body?.udid === "string" ? req.body.udid.trim() : "";
|
|
137831
|
+
if (!isIosSimulatorUdid(udid)) return res.status(400).json({ error: "Give the simulator UDID." });
|
|
137832
|
+
try {
|
|
137833
|
+
await startIosSimulator(udid);
|
|
137834
|
+
res.json({ started: true });
|
|
137835
|
+
} catch (err5) {
|
|
137836
|
+
res.status(400).json({ error: err5.message });
|
|
137837
|
+
}
|
|
137838
|
+
});
|
|
137839
|
+
app.post("/api/mobile/local/simulator/stop", async (req, res) => {
|
|
137840
|
+
const udid = typeof req.body?.udid === "string" ? req.body.udid.trim() : "";
|
|
137841
|
+
if (!isIosSimulatorUdid(udid)) return res.status(400).json({ error: "Give the simulator UDID." });
|
|
137842
|
+
try {
|
|
137843
|
+
await stopIosSimulator(udid);
|
|
137844
|
+
res.json({ stopped: true });
|
|
137845
|
+
} catch (err5) {
|
|
137846
|
+
res.status(400).json({ error: err5.message });
|
|
137847
|
+
}
|
|
137848
|
+
});
|
|
137113
137849
|
app.get("/api/mobile/local/config", (_req, res) => {
|
|
137114
137850
|
res.json({ config: store4.get() });
|
|
137115
137851
|
});
|
|
@@ -137156,7 +137892,7 @@ __export(remote_updates_service_exports, {
|
|
|
137156
137892
|
RemoteUpdatesService: () => RemoteUpdatesService
|
|
137157
137893
|
});
|
|
137158
137894
|
import { existsSync as existsSync110, readFileSync as readFileSync90, mkdirSync as mkdirSync49 } from "fs";
|
|
137159
|
-
import { join as join107, basename as
|
|
137895
|
+
import { join as join107, basename as basename28 } from "path";
|
|
137160
137896
|
var FIRST_CHECK_DELAY_MS, RemoteUpdatesService;
|
|
137161
137897
|
var init_remote_updates_service = __esm({
|
|
137162
137898
|
"src/ui/services/remote-updates-service.ts"() {
|
|
@@ -137286,7 +138022,7 @@ var init_remote_updates_service = __esm({
|
|
|
137286
138022
|
if (!_RemoteUpdatesService.shouldNotify(check, cfg, this.persisted.notified?.[branch])) return;
|
|
137287
138023
|
this.persisted.notified = { ...this.persisted.notified ?? {}, [branch]: check.upstreamSha };
|
|
137288
138024
|
try {
|
|
137289
|
-
await this.deps.notify(check, cfg,
|
|
138025
|
+
await this.deps.notify(check, cfg, basename28(this.deps.projectPath));
|
|
137290
138026
|
} catch (err5) {
|
|
137291
138027
|
console.error("[remote-updates] notify failed:", err5.message);
|
|
137292
138028
|
}
|
|
@@ -137912,7 +138648,7 @@ var init_skills_chat_history_store = __esm({
|
|
|
137912
138648
|
|
|
137913
138649
|
// src/ui/workflows/workflow-store.ts
|
|
137914
138650
|
import { readFileSync as readFileSync92, mkdirSync as mkdirSync52, existsSync as existsSync113, unlinkSync as unlinkSync12 } from "fs";
|
|
137915
|
-
import { randomBytes as
|
|
138651
|
+
import { randomBytes as randomBytes17 } from "crypto";
|
|
137916
138652
|
import { join as join110 } from "path";
|
|
137917
138653
|
var EMPTY_DATA, MAX_WORKFLOWS, WorkflowStore;
|
|
137918
138654
|
var init_workflow_store = __esm({
|
|
@@ -138037,8 +138773,8 @@ var init_workflow_store = __esm({
|
|
|
138037
138773
|
const workflow = this.data.workflows[workflowId];
|
|
138038
138774
|
if (!workflow) return void 0;
|
|
138039
138775
|
const config = {
|
|
138040
|
-
webhookId:
|
|
138041
|
-
secret:
|
|
138776
|
+
webhookId: randomBytes17(12).toString("hex"),
|
|
138777
|
+
secret: randomBytes17(32).toString("hex"),
|
|
138042
138778
|
name: options?.name,
|
|
138043
138779
|
enabled: true,
|
|
138044
138780
|
variableMapping: options?.variableMapping,
|
|
@@ -140668,7 +141404,7 @@ var api_workflows_exports = {};
|
|
|
140668
141404
|
__export(api_workflows_exports, {
|
|
140669
141405
|
mountWorkflowRoutes: () => mountWorkflowRoutes
|
|
140670
141406
|
});
|
|
140671
|
-
import { timingSafeEqual as
|
|
141407
|
+
import { timingSafeEqual as timingSafeEqual7 } from "crypto";
|
|
140672
141408
|
function broadcast5(wss, data) {
|
|
140673
141409
|
const msg = JSON.stringify(data);
|
|
140674
141410
|
for (const client of wss.clients) {
|
|
@@ -141338,7 +142074,7 @@ function matchesCronField2(field, value) {
|
|
|
141338
142074
|
function safeCompare(a, b) {
|
|
141339
142075
|
if (a.length !== b.length) return false;
|
|
141340
142076
|
try {
|
|
141341
|
-
return
|
|
142077
|
+
return timingSafeEqual7(Buffer.from(a, "utf-8"), Buffer.from(b, "utf-8"));
|
|
141342
142078
|
} catch {
|
|
141343
142079
|
return false;
|
|
141344
142080
|
}
|
|
@@ -145492,13 +146228,13 @@ var init_streaming_json = __esm({
|
|
|
145492
146228
|
});
|
|
145493
146229
|
|
|
145494
146230
|
// src/ui/util/script-framework-detect.ts
|
|
145495
|
-
function
|
|
146231
|
+
function basename29(filePath3) {
|
|
145496
146232
|
const norm6 = filePath3.replace(/\\/g, "/");
|
|
145497
146233
|
const idx = norm6.lastIndexOf("/");
|
|
145498
146234
|
return idx >= 0 ? norm6.slice(idx + 1) : norm6;
|
|
145499
146235
|
}
|
|
145500
146236
|
function detectScriptFramework(filePath3, content) {
|
|
145501
|
-
const name2 =
|
|
146237
|
+
const name2 = basename29(filePath3).toLowerCase();
|
|
145502
146238
|
const c2 = content || "";
|
|
145503
146239
|
if (name2.endsWith(".cy.ts") || name2.endsWith(".cy.js")) return "cypress";
|
|
145504
146240
|
if (name2.endsWith(".feature")) return "cucumber";
|
|
@@ -150420,7 +151156,7 @@ __export(api_output_exports, {
|
|
|
150420
151156
|
});
|
|
150421
151157
|
import { existsSync as existsSync118, statSync as statSync46, readdirSync as readdirSync45, readFileSync as readFileSync96, createReadStream as createReadStream2 } from "fs";
|
|
150422
151158
|
import { resolve as resolve32, extname as extname20, join as join115, relative as relative41, isAbsolute as isAbsolute24 } from "path";
|
|
150423
|
-
import { randomBytes as
|
|
151159
|
+
import { randomBytes as randomBytes18 } from "crypto";
|
|
150424
151160
|
import { watch } from "chokidar";
|
|
150425
151161
|
function normalizePath(p2) {
|
|
150426
151162
|
return p2.replace(/\\/g, "/");
|
|
@@ -150435,7 +151171,7 @@ function issueViewTicket(folderId, path2) {
|
|
|
150435
151171
|
const now = Date.now();
|
|
150436
151172
|
for (const [k, v] of viewTickets) if (v.expires < now) viewTickets.delete(k);
|
|
150437
151173
|
while (viewTickets.size >= 500) viewTickets.delete(viewTickets.keys().next().value);
|
|
150438
|
-
const ticket =
|
|
151174
|
+
const ticket = randomBytes18(24).toString("base64url");
|
|
150439
151175
|
viewTickets.set(ticket, { folderId, path: path2, expires: now + VIEW_TICKET_MS });
|
|
150440
151176
|
return ticket;
|
|
150441
151177
|
}
|
|
@@ -151449,7 +152185,7 @@ __export(api_documents_exports, {
|
|
|
151449
152185
|
sandboxActiveContent: () => sandboxActiveContent
|
|
151450
152186
|
});
|
|
151451
152187
|
import { existsSync as existsSync119, mkdirSync as mkdirSync56, writeFileSync as writeFileSync29, readFileSync as readFileSync97 } from "fs";
|
|
151452
|
-
import { join as join116, basename as
|
|
152188
|
+
import { join as join116, basename as basename30 } from "path";
|
|
151453
152189
|
function sandboxActiveContent(res) {
|
|
151454
152190
|
res.setHeader(
|
|
151455
152191
|
"Content-Security-Policy",
|
|
@@ -151556,7 +152292,7 @@ function mountDocumentRoutes(app, tmStore5, projectPath2) {
|
|
|
151556
152292
|
try {
|
|
151557
152293
|
const filename = req.params.filename;
|
|
151558
152294
|
const filePath3 = resolveDocumentPath(filename, projectPath2);
|
|
151559
|
-
if (!filePath3 ||
|
|
152295
|
+
if (!filePath3 || basename30(filePath3) !== filename) {
|
|
151560
152296
|
res.status(404).json({ error: "File not found" });
|
|
151561
152297
|
return;
|
|
151562
152298
|
}
|
|
@@ -152316,10 +153052,10 @@ __export(trace_viewer_exports, {
|
|
|
152316
153052
|
traceViewerCandidates: () => traceViewerCandidates,
|
|
152317
153053
|
traceViewerHandler: () => traceViewerHandler
|
|
152318
153054
|
});
|
|
152319
|
-
import { existsSync as existsSync120, mkdirSync as mkdirSync57, readdirSync as readdirSync46, readFileSync as readFileSync98, renameSync as renameSync6, rmSync as
|
|
153055
|
+
import { existsSync as existsSync120, mkdirSync as mkdirSync57, readdirSync as readdirSync46, readFileSync as readFileSync98, renameSync as renameSync6, rmSync as rmSync6, writeFileSync as writeFileSync30 } from "fs";
|
|
152320
153056
|
import { createRequire as createRequire4 } from "module";
|
|
152321
153057
|
import { homedir as homedir4 } from "os";
|
|
152322
|
-
import { dirname as
|
|
153058
|
+
import { dirname as dirname32, join as join117 } from "path";
|
|
152323
153059
|
function compareVersions(a, b) {
|
|
152324
153060
|
const parse = (v) => {
|
|
152325
153061
|
const [core = "", pre] = v.split("-", 2);
|
|
@@ -152347,7 +153083,7 @@ function fromPackageRoot(root, source) {
|
|
|
152347
153083
|
}
|
|
152348
153084
|
function resolvePackage(fromFile, name2) {
|
|
152349
153085
|
try {
|
|
152350
|
-
return
|
|
153086
|
+
return dirname32(createRequire4(fromFile).resolve(`${name2}/package.json`));
|
|
152351
153087
|
} catch {
|
|
152352
153088
|
return void 0;
|
|
152353
153089
|
}
|
|
@@ -152460,7 +153196,7 @@ function extractJavaTraceViewer(jar, dest) {
|
|
|
152460
153196
|
if (!index) return false;
|
|
152461
153197
|
const pkg = index.name.slice(0, index.name.indexOf("lib/vite/traceViewer/"));
|
|
152462
153198
|
const prefix = `${pkg}lib/vite/traceViewer/`;
|
|
152463
|
-
|
|
153199
|
+
rmSync6(tmp, { recursive: true, force: true });
|
|
152464
153200
|
for (const x of zip.entries) {
|
|
152465
153201
|
let rel;
|
|
152466
153202
|
if (x.name === `${pkg}package.json`) rel = "package.json";
|
|
@@ -152468,17 +153204,17 @@ function extractJavaTraceViewer(jar, dest) {
|
|
|
152468
153204
|
else continue;
|
|
152469
153205
|
if (/[\\:]/.test(rel) || rel.split("/").some((seg) => seg === "" || seg === "." || seg === "..")) continue;
|
|
152470
153206
|
const out = join117(tmp, ...rel.split("/"));
|
|
152471
|
-
mkdirSync57(
|
|
153207
|
+
mkdirSync57(dirname32(out), { recursive: true });
|
|
152472
153208
|
writeFileSync30(out, zip.read(x, MAX_VIEWER_FILE));
|
|
152473
153209
|
}
|
|
152474
153210
|
if (!existsSync120(join117(tmp, "lib", "vite", "traceViewer", "index.html")) || !existsSync120(join117(tmp, "package.json"))) throw new Error("no viewer");
|
|
152475
|
-
mkdirSync57(
|
|
152476
|
-
|
|
153211
|
+
mkdirSync57(dirname32(dest), { recursive: true });
|
|
153212
|
+
rmSync6(dest, { recursive: true, force: true });
|
|
152477
153213
|
renameSync6(tmp, dest);
|
|
152478
153214
|
return true;
|
|
152479
153215
|
} catch {
|
|
152480
153216
|
try {
|
|
152481
|
-
|
|
153217
|
+
rmSync6(tmp, { recursive: true, force: true });
|
|
152482
153218
|
} catch {
|
|
152483
153219
|
}
|
|
152484
153220
|
return false;
|
|
@@ -152566,7 +153302,7 @@ var init_client_resume = __esm({
|
|
|
152566
153302
|
|
|
152567
153303
|
// src/ui/server.ts
|
|
152568
153304
|
import { createServer as createServer3 } from "http";
|
|
152569
|
-
import { join as join118, dirname as
|
|
153305
|
+
import { join as join118, dirname as dirname33, relative as relative42 } from "path";
|
|
152570
153306
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
152571
153307
|
import { existsSync as existsSync121, readFileSync as readFileSync99, mkdirSync as mkdirSync58, unlinkSync as unlinkSync13 } from "fs";
|
|
152572
153308
|
async function createUIServer(options) {
|
|
@@ -152684,10 +153420,10 @@ async function createUIServer(options) {
|
|
|
152684
153420
|
if (!cfg || !cfg.enabled || !cfg.username || !cfg.accessKey) return null;
|
|
152685
153421
|
return { username: cfg.username, accessKey: cfg.accessKey, region: cfg.region };
|
|
152686
153422
|
},
|
|
152687
|
-
onManagerDisconnect: async (clientId) => {
|
|
153423
|
+
onManagerDisconnect: async (clientId, reason) => {
|
|
152688
153424
|
try {
|
|
152689
153425
|
const { sendTo: sendTo3 } = await Promise.resolve().then(() => (init_shared_streaming(), shared_streaming_exports));
|
|
152690
|
-
sendTo3(wss, clientId, { type: "mobile-session-closed" });
|
|
153426
|
+
sendTo3(wss, clientId, { type: "mobile-session-closed", ...reason ? { reason } : {} });
|
|
152691
153427
|
} catch {
|
|
152692
153428
|
}
|
|
152693
153429
|
try {
|
|
@@ -152698,6 +153434,15 @@ async function createUIServer(options) {
|
|
|
152698
153434
|
} catch {
|
|
152699
153435
|
}
|
|
152700
153436
|
},
|
|
153437
|
+
// A new session for a tab — also one the AI opened after the old one
|
|
153438
|
+
// died — so its session bar and live view show it.
|
|
153439
|
+
onSessionStarted: async (clientId, info) => {
|
|
153440
|
+
try {
|
|
153441
|
+
const { sendTo: sendTo3 } = await Promise.resolve().then(() => (init_shared_streaming(), shared_streaming_exports));
|
|
153442
|
+
sendTo3(wss, clientId, { type: "mobile-session-started", session: info });
|
|
153443
|
+
} catch {
|
|
153444
|
+
}
|
|
153445
|
+
},
|
|
152701
153446
|
// A cloud session closes soon (idle, or at its maximum lifetime) — warn
|
|
152702
153447
|
// its tab, which can keep an idle one open.
|
|
152703
153448
|
onSessionExpiring: async (clientId, info) => {
|
|
@@ -153217,7 +153962,7 @@ async function createUIServer(options) {
|
|
|
153217
153962
|
});
|
|
153218
153963
|
function getServerPackageVersion() {
|
|
153219
153964
|
try {
|
|
153220
|
-
const dir =
|
|
153965
|
+
const dir = dirname33(fileURLToPath4(import.meta.url));
|
|
153221
153966
|
return JSON.parse(readFileSync99(join118(dir, "..", "package.json"), "utf-8")).version || "0.0.0";
|
|
153222
153967
|
} catch {
|
|
153223
153968
|
return "0.0.0";
|
|
@@ -153255,7 +154000,7 @@ async function createUIServer(options) {
|
|
|
153255
154000
|
const req = createRequire5(import.meta.url);
|
|
153256
154001
|
let testverCoreRoot;
|
|
153257
154002
|
try {
|
|
153258
|
-
testverCoreRoot =
|
|
154003
|
+
testverCoreRoot = dirname33(req.resolve("playwright-core/package.json"));
|
|
153259
154004
|
} catch {
|
|
153260
154005
|
}
|
|
153261
154006
|
const { traceViewerHandler: traceViewerHandler2 } = await Promise.resolve().then(() => (init_trace_viewer(), trace_viewer_exports));
|
|
@@ -153506,7 +154251,7 @@ async function createUIServer(options) {
|
|
|
153506
154251
|
scheduler.stop();
|
|
153507
154252
|
remoteUpdatesService?.stop();
|
|
153508
154253
|
try {
|
|
153509
|
-
await mobileSessionPool.shutdown(1e4
|
|
154254
|
+
await mobileSessionPool.shutdown(1e4);
|
|
153510
154255
|
} catch {
|
|
153511
154256
|
}
|
|
153512
154257
|
clearInterval(wsHeartbeatInterval);
|
|
@@ -153614,7 +154359,7 @@ var init_server = __esm({
|
|
|
153614
154359
|
init_route_errors();
|
|
153615
154360
|
init_utils();
|
|
153616
154361
|
init_atomic_write();
|
|
153617
|
-
__dirname =
|
|
154362
|
+
__dirname = dirname33(fileURLToPath4(import.meta.url));
|
|
153618
154363
|
}
|
|
153619
154364
|
});
|
|
153620
154365
|
|
|
@@ -156042,11 +156787,11 @@ if (args[0] === "deploy") {
|
|
|
156042
156787
|
const deployDir = join122(workingDirectory, ".testver-deploy");
|
|
156043
156788
|
const ensureDeployEnvSafety = async () => {
|
|
156044
156789
|
const { readFileSync: readFileSync101, appendFileSync: appendFileSync2 } = await import("fs");
|
|
156045
|
-
const { randomBytes:
|
|
156790
|
+
const { randomBytes: randomBytes19 } = await import("crypto");
|
|
156046
156791
|
const { ensureTwoFactorKeyLine: ensureTwoFactorKeyLine2, ensureGitignoreLine: ensureGitignoreLine2 } = await Promise.resolve().then(() => (init_deploy_env(), deploy_env_exports));
|
|
156047
156792
|
const envFile = join122(deployDir, ".env");
|
|
156048
156793
|
const envText = existsSync124(envFile) ? readFileSync101(envFile, "utf-8") : "";
|
|
156049
|
-
const addition = ensureTwoFactorKeyLine2(envText, () =>
|
|
156794
|
+
const addition = ensureTwoFactorKeyLine2(envText, () => randomBytes19(32).toString("hex"));
|
|
156050
156795
|
if (addition) {
|
|
156051
156796
|
appendFileSync2(envFile, addition);
|
|
156052
156797
|
console.log(" \u2705 TESTVER_2FA_KEY added to .testver-deploy/.env \u2014 it keeps two-factor sign-in working across container rebuilds; back this file up and never change the value");
|
|
@@ -156569,7 +157314,7 @@ server {
|
|
|
156569
157314
|
}
|
|
156570
157315
|
} else if (subcommand === "pm2") {
|
|
156571
157316
|
const { realpathSync: realpathSync3 } = await import("fs");
|
|
156572
|
-
const { basename:
|
|
157317
|
+
const { basename: basename31 } = await import("path");
|
|
156573
157318
|
const pmFlag = (name2) => {
|
|
156574
157319
|
const i = args.indexOf(`--${name2}`);
|
|
156575
157320
|
if (i !== -1 && args[i + 1] && !args[i + 1].startsWith("-")) return args[i + 1];
|
|
@@ -156579,7 +157324,7 @@ server {
|
|
|
156579
157324
|
const pmHas = (name2) => args.includes(`--${name2}`);
|
|
156580
157325
|
const port = pmFlag("port") || process.env.TESTVER_PORT || "3700";
|
|
156581
157326
|
const host = pmFlag("host") || "";
|
|
156582
|
-
const appName = (pmFlag("name") ||
|
|
157327
|
+
const appName = (pmFlag("name") || basename31(workingDirectory) || "testver").replace(/[^A-Za-z0-9._-]/g, "-");
|
|
156583
157328
|
const outName = "testver.pm2.config.js";
|
|
156584
157329
|
const outPath = join122(workingDirectory, outName);
|
|
156585
157330
|
let scriptPath = process.argv[1] || "testver";
|