rnxsim 0.0.0 → 0.1.313
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +512 -0
- package/detox/colors.ts +54 -0
- package/detox/config-loader.ts +135 -0
- package/detox/element-types.ts +39 -0
- package/detox/expectations.ts +537 -0
- package/detox/gestures.ts +480 -0
- package/detox/index.ts +2118 -0
- package/detox/jest-preset.cjs +51 -0
- package/detox/jest-setup-after-env.cjs +18 -0
- package/detox/matchers.ts +30 -0
- package/detox/motion-change.cjs +109 -0
- package/detox/motion-change.d.cts +35 -0
- package/detox/navigation.ts +43 -0
- package/detox/screenshots/animated-color-test-rest-norngh.png +0 -0
- package/detox/screenshots/color-test-after-drag-norngh.png +0 -0
- package/detox/screenshots/color-test-rest-norngh.png +0 -0
- package/detox/screenshots/theme-blue-toggle.png +0 -0
- package/detox/screenshots/theme-blue.png +0 -0
- package/detox/screenshots/theme-red-toggle.png +0 -0
- package/detox/screenshots/theme-red.png +0 -0
- package/dist-cli/bin.js +15 -0
- package/dist-cli/chunks/agent-XZ2KTPCU.js +48 -0
- package/dist-cli/chunks/agent-wrapper-JJYYW2WH.js +17 -0
- package/dist-cli/chunks/app-fonts-IXRNQG6B.js +4 -0
- package/dist-cli/chunks/assert-54T5SK5F.js +49 -0
- package/dist-cli/chunks/auth-FI5UDI45.js +12 -0
- package/dist-cli/chunks/beta-JV6UKADW.js +4 -0
- package/dist-cli/chunks/camera-VL73YIKP.js +22 -0
- package/dist-cli/chunks/chunk-2D2UPBBR.js +4 -0
- package/dist-cli/chunks/chunk-2YR5BGA5.js +5 -0
- package/dist-cli/chunks/chunk-3NV2NCNX.js +4 -0
- package/dist-cli/chunks/chunk-46EUUFJ5.js +4 -0
- package/dist-cli/chunks/chunk-4NPPOV2N.js +5 -0
- package/dist-cli/chunks/chunk-5DHC6KHQ.js +7 -0
- package/dist-cli/chunks/chunk-5TEF3ET3.js +74 -0
- package/dist-cli/chunks/chunk-5TPRP5QT.js +4 -0
- package/dist-cli/chunks/chunk-5YJCOWCH.js +4 -0
- package/dist-cli/chunks/chunk-7GN3LVWB.js +4 -0
- package/dist-cli/chunks/chunk-BBULZ7CG.js +568 -0
- package/dist-cli/chunks/chunk-BTWORNNG.js +71 -0
- package/dist-cli/chunks/chunk-D4FFVGI5.js +5 -0
- package/dist-cli/chunks/chunk-DCEMHR2Y.js +4 -0
- package/dist-cli/chunks/chunk-DZS6WPUI.js +4 -0
- package/dist-cli/chunks/chunk-F5ZRSS3C.js +3 -0
- package/dist-cli/chunks/chunk-FSUYIVJ6.js +9 -0
- package/dist-cli/chunks/chunk-G2WW6L2C.js +23 -0
- package/dist-cli/chunks/chunk-GASE6UBA.js +4 -0
- package/dist-cli/chunks/chunk-GGRX24GF.js +142 -0
- package/dist-cli/chunks/chunk-HI5TFJWN.js +5 -0
- package/dist-cli/chunks/chunk-IJ5CAZZC.js +5 -0
- package/dist-cli/chunks/chunk-IJO63TDP.js +4 -0
- package/dist-cli/chunks/chunk-KTHV3RUS.js +26 -0
- package/dist-cli/chunks/chunk-LF2ZVT7O.js +6 -0
- package/dist-cli/chunks/chunk-MJRLLB4R.js +38 -0
- package/dist-cli/chunks/chunk-NFK7T35W.js +4 -0
- package/dist-cli/chunks/chunk-NMF2ZMZQ.js +15 -0
- package/dist-cli/chunks/chunk-OHAZNXLK.js +4 -0
- package/dist-cli/chunks/chunk-OVFJFXUD.js +101 -0
- package/dist-cli/chunks/chunk-OZSSI4WN.js +28 -0
- package/dist-cli/chunks/chunk-QKDWYITG.js +25 -0
- package/dist-cli/chunks/chunk-RSZWCKNT.js +30 -0
- package/dist-cli/chunks/chunk-RTN5C5RL.js +4 -0
- package/dist-cli/chunks/chunk-TIVZIMMW.js +4 -0
- package/dist-cli/chunks/chunk-TZFFR3SD.js +7 -0
- package/dist-cli/chunks/chunk-UC6U3MML.js +5 -0
- package/dist-cli/chunks/chunk-VFCMSYZK.js +6 -0
- package/dist-cli/chunks/chunk-VNQEB4L7.js +5 -0
- package/dist-cli/chunks/chunk-VZXWHRUZ.js +983 -0
- package/dist-cli/chunks/chunk-W6K4EFPH.js +107 -0
- package/dist-cli/chunks/chunk-WEXDAC74.js +4 -0
- package/dist-cli/chunks/chunk-WF3T4SVI.js +14 -0
- package/dist-cli/chunks/chunk-WINYQ44O.js +4 -0
- package/dist-cli/chunks/chunk-WMIIKMGK.js +10 -0
- package/dist-cli/chunks/chunk-WUSWBCWA.js +507 -0
- package/dist-cli/chunks/chunk-WWZIXIRD.js +4 -0
- package/dist-cli/chunks/chunk-XEVZYVIW.js +766 -0
- package/dist-cli/chunks/chunk-YDGQTMQL.js +4 -0
- package/dist-cli/chunks/chunk-YIFT42WN.js +4 -0
- package/dist-cli/chunks/chunk-ZMJD5GEC.js +125 -0
- package/dist-cli/chunks/cleanup-P27PA6JI.js +25 -0
- package/dist-cli/chunks/cli-version-WWLPBDQ7.js +4 -0
- package/dist-cli/chunks/compat-ZD65FED3.js +20 -0
- package/dist-cli/chunks/config-XMJRNM2A.js +13 -0
- package/dist-cli/chunks/control-KMIQT3QP.js +4 -0
- package/dist-cli/chunks/daemon-G2ME7NLB.js +4 -0
- package/dist-cli/chunks/debug-PT4HOP7N.js +200 -0
- package/dist-cli/chunks/desktop-S3FG72AK.js +31 -0
- package/dist-cli/chunks/detox-B3D4IFCN.js +52 -0
- package/dist-cli/chunks/device-XBNDSB2R.js +18 -0
- package/dist-cli/chunks/diagnose-HMQXJE5N.js +43 -0
- package/dist-cli/chunks/disk-cleanup-BLCZ5BSZ.js +4 -0
- package/dist-cli/chunks/drivers-LDECZGP2.js +4 -0
- package/dist-cli/chunks/film-BJGTBYZB.js +74 -0
- package/dist-cli/chunks/flow-UEQNVTU7.js +4 -0
- package/dist-cli/chunks/help-T5FYSVGB.js +4 -0
- package/dist-cli/chunks/hidden-runtime-alias-ANOYADHM.js +4 -0
- package/dist-cli/chunks/home-paths-GT3LFNOR.js +4 -0
- package/dist-cli/chunks/inspect-ZA6XF5LD.js +4 -0
- package/dist-cli/chunks/install-desktop-TIMUDHPL.js +4 -0
- package/dist-cli/chunks/login-FJ737MWG.js +28 -0
- package/dist-cli/chunks/logout-ZCNMMHMY.js +4 -0
- package/dist-cli/chunks/maestro-SZTNKLDF.js +104 -0
- package/dist-cli/chunks/maestro-generate-DCFAIZ4H.js +36 -0
- package/dist-cli/chunks/mode-GRMQCRXR.js +26 -0
- package/dist-cli/chunks/optional-demo-registry-W36EWFFB.js +4 -0
- package/dist-cli/chunks/perf-QYBAAUZG.js +48 -0
- package/dist-cli/chunks/permissions-3QCQ6VF4.js +13 -0
- package/dist-cli/chunks/record-QPPC2S4E.js +72 -0
- package/dist-cli/chunks/report-issue-7NMFP4HK.js +29 -0
- package/dist-cli/chunks/runtime-XOAXMSTU.js +4 -0
- package/dist-cli/chunks/screenshot-command-67AECJFB.js +159 -0
- package/dist-cli/chunks/screenshot-layers-ASWBYPJL.js +20 -0
- package/dist-cli/chunks/screenshots-capture-PXA3HFQK.js +42 -0
- package/dist-cli/chunks/serve-BI2NBAXG.js +44 -0
- package/dist-cli/chunks/setup-7DWPMRSB.js +32 -0
- package/dist-cli/chunks/skills-S3Y22TUA.js +50 -0
- package/dist-cli/chunks/storage-XUIMJWAJ.js +37 -0
- package/dist-cli/chunks/store-JTHEJLAZ.js +4 -0
- package/dist-cli/chunks/telemetry-ZYJGD2DB.js +4 -0
- package/dist-cli/chunks/timeline-TMPLQPSP.js +24 -0
- package/dist-cli/chunks/upgrade-7HDSIM7K.js +7 -0
- package/dist-cli/chunks/upload-GMSZPWM6.js +4 -0
- package/dist-cli/chunks/version-HOCHZ37L.js +6 -0
- package/dist-cli/chunks/web-DG3WBYD3.js +4 -0
- package/dist-cli/chunks/what-happened-XFVUTZR7.js +25 -0
- package/dist-lib/agent-daemon-client.cjs +468 -0
- package/dist-lib/agent-events.cjs +48 -0
- package/dist-lib/agent-identity.cjs +53 -0
- package/dist-lib/agent-sessions.cjs +725 -0
- package/dist-lib/attached-projects.cjs +526 -0
- package/dist-lib/auth/shared-session.cjs +195 -0
- package/dist-lib/backend-origin.cjs +70 -0
- package/dist-lib/beta.cjs +41 -0
- package/dist-lib/beta.mjs +13 -0
- package/dist-lib/bridge-constants.cjs +161 -0
- package/dist-lib/cli-constants.cjs +32 -0
- package/dist-lib/config.cjs +96 -0
- package/dist-lib/detox/index.cjs +2863 -0
- package/dist-lib/detox/jest-preset.cjs +51 -0
- package/dist-lib/dev-bundle-resolution.cjs +223 -0
- package/dist-lib/home-paths.cjs +421 -0
- package/dist-lib/host/bridge-host.cjs +5600 -0
- package/dist-lib/host/fetch-proxy-handler.cjs +373 -0
- package/dist-lib/host/fetch-proxy-overrides.cjs +63 -0
- package/dist-lib/host/fetch-proxy-overrides.mjs +37 -0
- package/dist-lib/host/websocket-proxy.cjs +214 -0
- package/dist-lib/index.cjs +513 -0
- package/dist-lib/jump-to-source-babel.cjs +93 -0
- package/dist-lib/menu.cjs +620 -0
- package/dist-lib/menu.mjs +581 -0
- package/dist-lib/metro.cjs +297 -0
- package/dist-lib/profiles.cjs +246 -0
- package/dist-lib/public-brand.cjs +39 -0
- package/dist-lib/render-mode.cjs +54 -0
- package/dist-lib/scripts/dev-server-scanner.cjs +1034 -0
- package/dist-lib/sdk.cjs +2333 -0
- package/dist-lib/sdk.mjs +2240 -0
- package/dist-lib/skills.cjs +23922 -0
- package/dist-lib/vite.cjs +358 -0
- package/package.json +189 -18
- package/scripts/dev-server-scanner.ts +941 -0
- package/scripts/optional-demo-registry.ts +113 -0
- package/scripts/postinstall.cjs +3 -0
- package/scripts/preuninstall.cjs +118 -0
- package/skills/contrast/SKILL.md +171 -0
- package/skills/rnx-debug/SKILL.md +425 -0
- package/skills/rnx-perf/SKILL.md +295 -0
- package/skills/rnx-setup/SKILL.md +160 -0
- package/skills/rnx-test/SKILL.md +292 -0
- package/skills/rnx-visual/SKILL.md +122 -0
- package/src/agent-daemon-client.ts +410 -0
- package/src/agent-events.ts +71 -0
- package/src/agent-identity.ts +23 -0
- package/src/agent-prompt.ts +71 -0
- package/src/agent-sessions.ts +573 -0
- package/src/attached-projects.ts +539 -0
- package/src/auth/shared-session.ts +204 -0
- package/src/backend-origin.ts +49 -0
- package/src/beta.ts +19 -0
- package/src/bridge-constants.ts +171 -0
- package/src/browser-cache.ts +16 -0
- package/src/cli-constants.ts +1 -0
- package/src/cli-version.ts +32 -0
- package/src/codex-client.ts +215 -0
- package/src/config.ts +134 -0
- package/src/dev-bundle-resolution.ts +236 -0
- package/src/disk-cleanup.ts +466 -0
- package/src/home-paths.ts +552 -0
- package/src/host/agent-host.ts +666 -0
- package/src/host/bridge-host.ts +2626 -0
- package/src/host/fetch-proxy-handler.ts +397 -0
- package/src/host/fetch-proxy-overrides.ts +51 -0
- package/src/host/open-url.ts +89 -0
- package/src/host/websocket-proxy.ts +210 -0
- package/src/index.ts +12 -705
- package/src/jump-to-source-babel.ts +135 -0
- package/src/menu.ts +734 -0
- package/src/metro-plugin.ts +139 -0
- package/src/native-dev-bundle-url.ts +96 -0
- package/src/native-seam-manifest.ts +341 -0
- package/src/plist.ts +27 -0
- package/src/poll-until.ts +92 -0
- package/src/profiles.ts +179 -0
- package/src/public-brand.ts +9 -0
- package/src/render-mode.ts +27 -0
- package/src/runtime-assets.ts +228 -0
- package/src/runtime-delivery.ts +54 -0
- package/src/screenshots/compose.ts +422 -0
- package/src/screenshots/frame-compose.ts +454 -0
- package/src/screenshots/orchestrate.ts +256 -0
- package/src/screenshots/org-deck.ts +91 -0
- package/src/screenshots/registry.ts +58 -0
- package/src/screenshots/schema.ts +364 -0
- package/src/sdk.ts +7 -0
- package/src/settings-bundle.ts +418 -0
- package/src/skills/builtin/a11y-review.ts +132 -0
- package/src/skills/builtin/compat-check.ts +71 -0
- package/src/skills/builtin/maestro-test.ts +121 -0
- package/src/skills/builtin/perf-profile.ts +90 -0
- package/src/skills/builtin/screenshot-all.ts +52 -0
- package/src/skills/builtin/visual-diff.ts +100 -0
- package/src/skills/registry.ts +107 -0
- package/src/skills/types.ts +41 -0
- package/src/team-machine-prompt.ts +73 -0
- package/src/vite-plugin-one.ts +190 -0
- package/src/vite-plugin.ts +1750 -0
- package/src/worklets-babel.ts +134 -0
package/dist-lib/sdk.cjs
ADDED
|
@@ -0,0 +1,2333 @@
|
|
|
1
|
+
/*! rnx v0.1.313 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
|
+
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
|
+
"use strict";
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/sdk.ts
|
|
23
|
+
var sdk_exports = {};
|
|
24
|
+
__export(sdk_exports, {
|
|
25
|
+
DEBUG_CHANNELS: () => DEBUG_CHANNELS,
|
|
26
|
+
LAYOUT_GET_NATIVE_EVAL: () => LAYOUT_GET_NATIVE_EVAL,
|
|
27
|
+
MERGED_CONSOLE_COUNT_EVAL: () => MERGED_CONSOLE_COUNT_EVAL,
|
|
28
|
+
NOISY_TIMELINE_KINDS: () => NOISY_TIMELINE_KINDS,
|
|
29
|
+
READY_CONTENT_NODE_FLOOR: () => READY_CONTENT_NODE_FLOOR,
|
|
30
|
+
READY_NODE_STABLE_MS: () => READY_NODE_STABLE_MS,
|
|
31
|
+
READY_PROBE_POLL_MS: () => READY_PROBE_POLL_MS,
|
|
32
|
+
WAIT_READY_PROBE: () => WAIT_READY_PROBE,
|
|
33
|
+
WAIT_READY_PROGRESS_INTERVAL_MS: () => WAIT_READY_PROGRESS_INTERVAL_MS,
|
|
34
|
+
clearConsole: () => clearConsole,
|
|
35
|
+
clearLogs: () => clearLogs,
|
|
36
|
+
clearRequests: () => clearRequests,
|
|
37
|
+
detectOpenNativeUI: () => detectOpenNativeUI,
|
|
38
|
+
filterLogEntries: () => filterLogEntries,
|
|
39
|
+
formatLayoutElements: () => formatLayoutElements,
|
|
40
|
+
formatTimelineEvent: () => formatTimelineEvent,
|
|
41
|
+
formatTimelineEvents: () => formatTimelineEvents,
|
|
42
|
+
formatTimelinePayload: () => formatTimelinePayload,
|
|
43
|
+
formatTimelineSummary: () => formatTimelineSummary,
|
|
44
|
+
getShellState: () => getShellState,
|
|
45
|
+
inspectAccessibilityTree: () => inspectAccessibilityTree,
|
|
46
|
+
inspectDebugFind: () => inspectDebugFind,
|
|
47
|
+
inspectDebugFlags: () => inspectDebugFlags,
|
|
48
|
+
inspectDebugRecent: () => inspectDebugRecent,
|
|
49
|
+
inspectDebugStatus: () => inspectDebugStatus,
|
|
50
|
+
inspectDescribe: () => inspectDescribe,
|
|
51
|
+
inspectErrors: () => inspectErrors,
|
|
52
|
+
inspectFind: () => inspectFind,
|
|
53
|
+
inspectGetLayout: () => inspectGetLayout,
|
|
54
|
+
inspectKeyboard: () => inspectKeyboard,
|
|
55
|
+
inspectLogs: () => inspectLogs,
|
|
56
|
+
inspectMemory: () => inspectMemory,
|
|
57
|
+
inspectNodeCount: () => inspectNodeCount,
|
|
58
|
+
inspectRequests: () => inspectRequests,
|
|
59
|
+
inspectScreens: () => inspectScreens,
|
|
60
|
+
inspectScrollStateAt: () => inspectScrollStateAt,
|
|
61
|
+
inspectTimelineAdvanceCursor: () => inspectTimelineAdvanceCursor,
|
|
62
|
+
inspectTimelineRecent: () => inspectTimelineRecent,
|
|
63
|
+
inspectTimelineSummary: () => inspectTimelineSummary,
|
|
64
|
+
inspectTree: () => inspectTree,
|
|
65
|
+
inspectUrl: () => inspectUrl,
|
|
66
|
+
inspectWaitReady: () => inspectWaitReady,
|
|
67
|
+
inspectWaitSelector: () => inspectWaitSelector,
|
|
68
|
+
inspectWarnings: () => inspectWarnings,
|
|
69
|
+
isInspectModeActive: () => isInspectModeActive,
|
|
70
|
+
isInspectPickCommand: () => isInspectPickCommand,
|
|
71
|
+
isShellCommandUnavailable: () => isShellCommandUnavailable,
|
|
72
|
+
isTapSuccess: () => isTapSuccess,
|
|
73
|
+
layoutGetNativeEval: () => layoutGetNativeEval,
|
|
74
|
+
rankInteractive: () => rankInteractive,
|
|
75
|
+
readyProbeHasContent: () => readyProbeHasContent,
|
|
76
|
+
readyProbeHasTargetContent: () => readyProbeHasTargetContent,
|
|
77
|
+
resolveFindMode: () => resolveFindMode,
|
|
78
|
+
resolveMaxMsFlag: () => resolveMaxMsFlag,
|
|
79
|
+
scoreInteractive: () => scoreInteractive,
|
|
80
|
+
scoreLayoutTextContrast: () => scoreLayoutTextContrast,
|
|
81
|
+
setDebugChannels: () => setDebugChannels,
|
|
82
|
+
shouldSkipAutoSettleForInspectPick: () => shouldSkipAutoSettleForInspectPick,
|
|
83
|
+
tapBest: () => tapBest,
|
|
84
|
+
tapById: () => tapById,
|
|
85
|
+
tapByText: () => tapByText,
|
|
86
|
+
tapCommandForNode: () => tapCommandForNode,
|
|
87
|
+
tapCoordinates: () => tapCoordinates,
|
|
88
|
+
tapResolvedTarget: () => tapResolvedTarget,
|
|
89
|
+
tapTargetFromPayload: () => tapTargetFromPayload,
|
|
90
|
+
waitForSootsimIdle: () => waitForSootsimIdle,
|
|
91
|
+
waitReadyReason: () => waitReadyReason
|
|
92
|
+
});
|
|
93
|
+
module.exports = __toCommonJS(sdk_exports);
|
|
94
|
+
|
|
95
|
+
// cli/commands/inspect/core.ts
|
|
96
|
+
function resolveMaxMsFlag(args, fallbackMs) {
|
|
97
|
+
const aliases = ["--max-ms", "--maxMs", "--maxms", "--max_ms"];
|
|
98
|
+
for (const flag of aliases) {
|
|
99
|
+
const i = args.indexOf(flag);
|
|
100
|
+
if (i >= 0 && args[i + 1]) {
|
|
101
|
+
const n = Number(args[i + 1]);
|
|
102
|
+
if (Number.isFinite(n)) return Math.max(100, n);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return fallbackMs;
|
|
106
|
+
}
|
|
107
|
+
var INSPECT_PICK_COMMANDS = /* @__PURE__ */ new Set([
|
|
108
|
+
"tap",
|
|
109
|
+
"double-tap",
|
|
110
|
+
"tap-text",
|
|
111
|
+
"tap-id",
|
|
112
|
+
"long-press",
|
|
113
|
+
"touch"
|
|
114
|
+
]);
|
|
115
|
+
function isInspectPickCommand(subcommand) {
|
|
116
|
+
return typeof subcommand === "string" && INSPECT_PICK_COMMANDS.has(subcommand);
|
|
117
|
+
}
|
|
118
|
+
async function isInspectModeActive(bridge) {
|
|
119
|
+
const active = await bridge.send({
|
|
120
|
+
type: "evaluate",
|
|
121
|
+
code: "window.__sootsimEngineState?.inspectActive === true"
|
|
122
|
+
});
|
|
123
|
+
return active === true;
|
|
124
|
+
}
|
|
125
|
+
async function shouldSkipAutoSettleForInspectPick(bridge, subcommand) {
|
|
126
|
+
if (!isInspectPickCommand(subcommand)) return false;
|
|
127
|
+
try {
|
|
128
|
+
return await isInspectModeActive(bridge);
|
|
129
|
+
} catch {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function inspectNodeCount(bridge) {
|
|
134
|
+
const count = await bridge.send({
|
|
135
|
+
type: "evaluate",
|
|
136
|
+
code: "(async () => await window.__sootsimTest.getNodeCount())()"
|
|
137
|
+
});
|
|
138
|
+
return { nodes: typeof count === "number" ? count : 0 };
|
|
139
|
+
}
|
|
140
|
+
async function inspectTree(bridge, depth = 5, opts) {
|
|
141
|
+
const optsArg = opts?.format ? `, ${JSON.stringify(opts)}` : "";
|
|
142
|
+
const tree = await bridge.send({
|
|
143
|
+
type: "evaluate",
|
|
144
|
+
code: `(async () => await window.__sootsimTest.dumpTree(${depth}${optsArg}))()`
|
|
145
|
+
});
|
|
146
|
+
if (opts?.format === "boxes" && typeof tree === "string") {
|
|
147
|
+
try {
|
|
148
|
+
return { depth, tree: JSON.parse(tree) };
|
|
149
|
+
} catch {
|
|
150
|
+
return { depth, tree };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return { depth, tree };
|
|
154
|
+
}
|
|
155
|
+
async function inspectUrl(bridge) {
|
|
156
|
+
const url = await bridge.send({ type: "evaluate", code: "window.location.href" });
|
|
157
|
+
return { url: typeof url === "string" ? url : "" };
|
|
158
|
+
}
|
|
159
|
+
async function inspectDescribe(bridge, dumpOpts) {
|
|
160
|
+
const code = `(async () => {
|
|
161
|
+
const t = window.__sootsimTest
|
|
162
|
+
const mainShell = window.SootSim?.bridges?.mainShell
|
|
163
|
+
const kb = window.__sootsimKeyboard
|
|
164
|
+
if (!t) return { error: 'no test bridge' }
|
|
165
|
+
|
|
166
|
+
let shell = null
|
|
167
|
+
try {
|
|
168
|
+
shell = typeof mainShell?.getState === 'function' ? await mainShell.getState() : null
|
|
169
|
+
} catch {}
|
|
170
|
+
|
|
171
|
+
const opts = ${JSON.stringify(dumpOpts)}
|
|
172
|
+
const needsRecursiveDump = opts.verbose || opts.subtreeRoot || opts.includeOccluded
|
|
173
|
+
const globToRegex = (glob) => {
|
|
174
|
+
const escaped = String(glob).replace(/[.+^$(){}|[\\]\\\\]/g, '\\\\$&')
|
|
175
|
+
const body = escaped.replace(/\\*/g, '.*').replace(/\\?/g, '.')
|
|
176
|
+
return new RegExp('^' + body + '$', 'i')
|
|
177
|
+
}
|
|
178
|
+
// clipping a describe line is a DISPLAY decision. opts.fullText (set by
|
|
179
|
+
// \`describe --json\`) keeps the real string, so a bundle-eval stack or a
|
|
180
|
+
// red-box message reaches the caller whole instead of ending in an
|
|
181
|
+
// ellipsis nothing downstream can undo.
|
|
182
|
+
const clipForDisplay = (value, max) => {
|
|
183
|
+
const text = typeof value === 'string' ? value.replace(/\\s+/g, ' ').trim() : ''
|
|
184
|
+
if (opts.fullText || text.length <= max) return text
|
|
185
|
+
return text.slice(0, max - 1).trimEnd() + '\u2026'
|
|
186
|
+
}
|
|
187
|
+
const formatInspectableTree = async () => {
|
|
188
|
+
if (typeof t.listInspectable !== 'function') return null
|
|
189
|
+
const list = await t.listInspectable({})
|
|
190
|
+
if (!Array.isArray(list)) return null
|
|
191
|
+
const filter = typeof opts.filter === 'string' ? opts.filter.toLowerCase() : ''
|
|
192
|
+
const testIdRegex = opts.testIdLike ? globToRegex(opts.testIdLike) : null
|
|
193
|
+
const onlyRegex = opts.onlyGlob ? globToRegex(opts.onlyGlob) : null
|
|
194
|
+
const lines = []
|
|
195
|
+
let matched = 0
|
|
196
|
+
for (const node of list) {
|
|
197
|
+
const testID = node?.testID || node?.testId || ''
|
|
198
|
+
const role = node?.role || ''
|
|
199
|
+
const label = node?.accessibilityLabel || node?.label || ''
|
|
200
|
+
const text = node?.text || ''
|
|
201
|
+
if (testIdRegex && !testIdRegex.test(testID)) continue
|
|
202
|
+
const joined = [role, label, text, testID].filter(Boolean).join(' ')
|
|
203
|
+
if (onlyRegex && !onlyRegex.test(joined)) continue
|
|
204
|
+
if (filter && !joined.toLowerCase().includes(filter)) continue
|
|
205
|
+
matched++
|
|
206
|
+
|
|
207
|
+
const type = String(node?.type || 'node').toLowerCase()
|
|
208
|
+
const handlers = Array.isArray(node?.handlers) ? node.handlers : []
|
|
209
|
+
const parts = []
|
|
210
|
+
if (role) parts.push('[' + role + ']')
|
|
211
|
+
else if (handlers.length > 0) parts.push('[tap]')
|
|
212
|
+
else parts.push('<' + type + '>')
|
|
213
|
+
const visibleText = clipForDisplay(text, 50)
|
|
214
|
+
if (visibleText) parts.push(JSON.stringify(visibleText))
|
|
215
|
+
if (testID) parts.push('#' + testID)
|
|
216
|
+
if (label && label !== text) {
|
|
217
|
+
parts.push('label=' + JSON.stringify(clipForDisplay(label, 50)))
|
|
218
|
+
}
|
|
219
|
+
if (!opts.hideXy) {
|
|
220
|
+
const abs = node?.absolute || {}
|
|
221
|
+
const layout = node?.layout || {}
|
|
222
|
+
const x = Math.round(Number(abs.x) || 0)
|
|
223
|
+
const y = Math.round(Number(abs.y) || 0)
|
|
224
|
+
const w = Math.round(Number(layout.width) || 0)
|
|
225
|
+
const h = Math.round(Number(layout.height) || 0)
|
|
226
|
+
parts.push('@(' + x + ',' + y + ') ' + w + 'x' + h)
|
|
227
|
+
}
|
|
228
|
+
if (handlers.length > 0) parts.push('(tap)')
|
|
229
|
+
lines.push(' ' + parts.join(' '))
|
|
230
|
+
}
|
|
231
|
+
return { tree: lines.join('\\n'), matched }
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
let tree = ''
|
|
235
|
+
const compactResult = needsRecursiveDump ? null : await formatInspectableTree()
|
|
236
|
+
if (compactResult) {
|
|
237
|
+
tree = compactResult.tree
|
|
238
|
+
} else {
|
|
239
|
+
tree = await t.dumpTree(12, opts)
|
|
240
|
+
}
|
|
241
|
+
const nodeCount = (await t.getNodeCount?.()) || 0
|
|
242
|
+
const keyboard = kb && typeof kb.getLayout === 'function' ? kb.getLayout() : null
|
|
243
|
+
return { tree, shell, nodeCount, keyboard }
|
|
244
|
+
})()`;
|
|
245
|
+
const result = await bridge.send({ type: "evaluate", code });
|
|
246
|
+
return result ?? {};
|
|
247
|
+
}
|
|
248
|
+
function scoreLayoutTextContrast(input) {
|
|
249
|
+
const required = input.fontSize >= 18 || input.fontSize >= 14 && (input.fontWeight ?? 400) >= 700 ? 3 : 4.5;
|
|
250
|
+
const { normal, background } = input;
|
|
251
|
+
if (normal.width <= 0 || normal.height <= 0 || normal.width !== background.width || normal.height !== background.height) {
|
|
252
|
+
return { ratio: null, required, reason: "capture dimensions do not match" };
|
|
253
|
+
}
|
|
254
|
+
const left = Math.max(0, Math.floor(input.box.x));
|
|
255
|
+
const top = Math.max(0, Math.floor(input.box.y));
|
|
256
|
+
const right = Math.min(normal.width, Math.ceil(input.box.x + input.box.w));
|
|
257
|
+
const bottom = Math.min(normal.height, Math.ceil(input.box.y + input.box.h));
|
|
258
|
+
if (right <= left || bottom <= top) {
|
|
259
|
+
return { ratio: null, required, reason: "text is outside the captured frame" };
|
|
260
|
+
}
|
|
261
|
+
const linear = (value) => {
|
|
262
|
+
const channel = value / 255;
|
|
263
|
+
return channel <= 0.04045 ? channel / 12.92 : Math.pow((channel + 0.055) / 1.055, 2.4);
|
|
264
|
+
};
|
|
265
|
+
const ratioOf = (foreground, behind) => {
|
|
266
|
+
const foregroundLuminance = 0.2126 * linear(foreground[0]) + 0.7152 * linear(foreground[1]) + 0.0722 * linear(foreground[2]);
|
|
267
|
+
const backgroundLuminance = 0.2126 * linear(behind[0]) + 0.7152 * linear(behind[1]) + 0.0722 * linear(behind[2]);
|
|
268
|
+
return (Math.max(foregroundLuminance, backgroundLuminance) + 0.05) / (Math.min(foregroundLuminance, backgroundLuminance) + 0.05);
|
|
269
|
+
};
|
|
270
|
+
const hex = (color) => `#${color.slice(0, 3).map((value) => Math.round(value).toString(16).padStart(2, "0")).join("")}`;
|
|
271
|
+
const area = (right - left) * (bottom - top);
|
|
272
|
+
const step = Math.max(1, Math.floor(Math.sqrt(area / 12e3)));
|
|
273
|
+
const offsetAt = (x, y) => (y * normal.width + x) * 4;
|
|
274
|
+
const deltaAt = (offset) => Math.max(
|
|
275
|
+
Math.abs(normal.data[offset] - background.data[offset]),
|
|
276
|
+
Math.abs(normal.data[offset + 1] - background.data[offset + 1]),
|
|
277
|
+
Math.abs(normal.data[offset + 2] - background.data[offset + 2])
|
|
278
|
+
);
|
|
279
|
+
let strongestDelta = 0;
|
|
280
|
+
let strongestForeground = null;
|
|
281
|
+
let opaqueBackground = null;
|
|
282
|
+
for (let y = top; y < bottom; y += step) {
|
|
283
|
+
for (let x = left; x < right; x += step) {
|
|
284
|
+
const offset = offsetAt(x, y);
|
|
285
|
+
if (background.data[offset + 3] < 250) continue;
|
|
286
|
+
const behind = [
|
|
287
|
+
background.data[offset],
|
|
288
|
+
background.data[offset + 1],
|
|
289
|
+
background.data[offset + 2]
|
|
290
|
+
];
|
|
291
|
+
opaqueBackground ??= behind;
|
|
292
|
+
const delta = deltaAt(offset);
|
|
293
|
+
if (delta <= strongestDelta) continue;
|
|
294
|
+
strongestDelta = delta;
|
|
295
|
+
strongestForeground = [
|
|
296
|
+
normal.data[offset],
|
|
297
|
+
normal.data[offset + 1],
|
|
298
|
+
normal.data[offset + 2]
|
|
299
|
+
];
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
let bestRatio = Infinity;
|
|
303
|
+
let bestForeground = null;
|
|
304
|
+
let bestBackground = null;
|
|
305
|
+
const consider = (foreground, behind) => {
|
|
306
|
+
const ratio = ratioOf(foreground, behind);
|
|
307
|
+
if (ratio >= bestRatio) return;
|
|
308
|
+
bestRatio = ratio;
|
|
309
|
+
bestForeground = foreground;
|
|
310
|
+
bestBackground = behind;
|
|
311
|
+
};
|
|
312
|
+
if (strongestDelta >= 2 && strongestForeground) {
|
|
313
|
+
for (let y = top; y < bottom; y += step) {
|
|
314
|
+
for (let x = left; x < right; x += step) {
|
|
315
|
+
const offset = offsetAt(x, y);
|
|
316
|
+
if (background.data[offset + 3] < 250 || deltaAt(offset) < 2) {
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
consider(strongestForeground, [
|
|
320
|
+
background.data[offset],
|
|
321
|
+
background.data[offset + 1],
|
|
322
|
+
background.data[offset + 2]
|
|
323
|
+
]);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
} else if (opaqueBackground) {
|
|
327
|
+
consider(opaqueBackground, opaqueBackground);
|
|
328
|
+
}
|
|
329
|
+
if (!bestForeground || !bestBackground || !Number.isFinite(bestRatio)) {
|
|
330
|
+
return {
|
|
331
|
+
ratio: null,
|
|
332
|
+
required,
|
|
333
|
+
reason: "could not isolate opaque rendered text pixels"
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
return {
|
|
337
|
+
ratio: Math.round(bestRatio * 100) / 100,
|
|
338
|
+
required,
|
|
339
|
+
foreground: hex(bestForeground),
|
|
340
|
+
background: hex(bestBackground)
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function layoutGetNativeEval(opts = {}) {
|
|
344
|
+
const includeStyle = opts.styling === true;
|
|
345
|
+
const filter = opts.filter?.trim().toLowerCase() ?? "";
|
|
346
|
+
return `(async () => {
|
|
347
|
+
const t = window.__sootsimTest
|
|
348
|
+
if (!t || typeof t.listInspectable !== 'function') return []
|
|
349
|
+
const list = await t.listInspectable({})
|
|
350
|
+
if (!Array.isArray(list)) return []
|
|
351
|
+
const includeStyle = ${JSON.stringify(includeStyle)}
|
|
352
|
+
const scoreContrast = ${scoreLayoutTextContrast.toString()}
|
|
353
|
+
// narrows by ELEMENT, not by style field: fewer rows, full detail on each.
|
|
354
|
+
const filter = ${JSON.stringify(filter)}
|
|
355
|
+
const matchesFilter = (n, text) => {
|
|
356
|
+
if (!filter) return true
|
|
357
|
+
const fields = [text, n.testID || n.testId, n.accessibilityRole || n.role, n.type]
|
|
358
|
+
return fields.some((f) => typeof f === 'string' && f.toLowerCase().includes(filter))
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : 0)
|
|
362
|
+
const round = (v) => Math.round(num(v))
|
|
363
|
+
|
|
364
|
+
// borderRadius can be authored as a string ("12px") or split per-corner;
|
|
365
|
+
// prefer the uniform borderRadius, else the largest corner radius present.
|
|
366
|
+
const radiusOf = (style) => {
|
|
367
|
+
if (!style) return 0
|
|
368
|
+
const keys = ['borderRadius','borderTopLeftRadius','borderTopRightRadius','borderBottomLeftRadius','borderBottomRightRadius']
|
|
369
|
+
let max = 0
|
|
370
|
+
for (const k of keys) {
|
|
371
|
+
const raw = style[k]
|
|
372
|
+
const n = typeof raw === 'number' ? raw : (typeof raw === 'string' ? parseFloat(raw) : NaN)
|
|
373
|
+
if (Number.isFinite(n)) max = Math.max(max, n)
|
|
374
|
+
}
|
|
375
|
+
return Math.round(max)
|
|
376
|
+
}
|
|
377
|
+
const fontSizeOf = (style) => {
|
|
378
|
+
if (!style) return 0
|
|
379
|
+
const raw = style.fontSize
|
|
380
|
+
const n = typeof raw === 'number' ? raw : (typeof raw === 'string' ? parseFloat(raw) : NaN)
|
|
381
|
+
return Number.isFinite(n) ? Math.round(n) : 0
|
|
382
|
+
}
|
|
383
|
+
// styling extractors \u2014 omit boring defaults so the agent only sees notable
|
|
384
|
+
// styling (low opacity, struck text, clipping, a real border/color).
|
|
385
|
+
const colorStr = (v) => {
|
|
386
|
+
if (v == null) return undefined
|
|
387
|
+
const s = String(v).split(' ').join('')
|
|
388
|
+
return s && s !== 'transparent' && s !== 'rgba(0,0,0,0)' ? s : undefined
|
|
389
|
+
}
|
|
390
|
+
const opacityOf = (style) => {
|
|
391
|
+
const o = style && style.opacity
|
|
392
|
+
const n = typeof o === 'number' ? o : (typeof o === 'string' ? parseFloat(o) : NaN)
|
|
393
|
+
return Number.isFinite(n) && n < 1 ? Math.round(n * 100) / 100 : undefined
|
|
394
|
+
}
|
|
395
|
+
const weightOf = (style) => {
|
|
396
|
+
const w = style && style.fontWeight
|
|
397
|
+
const n = w === 'bold' ? 700 : (typeof w === 'number' ? w : (typeof w === 'string' ? parseInt(w, 10) : NaN))
|
|
398
|
+
return Number.isFinite(n) && n >= 600 ? n : undefined
|
|
399
|
+
}
|
|
400
|
+
const decoOf = (style) => {
|
|
401
|
+
const d = style && (style.textDecorationLine || style.textDecoration)
|
|
402
|
+
return d && d !== 'none' && d !== 'normal' ? String(d).split(' ')[0] : undefined
|
|
403
|
+
}
|
|
404
|
+
const overflowOf = (style) => (style && style.overflow === 'hidden' ? 'hidden' : undefined)
|
|
405
|
+
const borderWOf = (style) => {
|
|
406
|
+
if (!style) return undefined
|
|
407
|
+
const keys = ['borderWidth','borderTopWidth','borderBottomWidth','borderLeftWidth','borderRightWidth']
|
|
408
|
+
let max = 0
|
|
409
|
+
for (const k of keys) {
|
|
410
|
+
const r = style[k]
|
|
411
|
+
const n = typeof r === 'number' ? r : (typeof r === 'string' ? parseFloat(r) : NaN)
|
|
412
|
+
if (Number.isFinite(n)) max = Math.max(max, n)
|
|
413
|
+
}
|
|
414
|
+
return max > 0 ? Math.round(max) : undefined
|
|
415
|
+
}
|
|
416
|
+
// only meaningful alongside a real border width, so it is resolved by the
|
|
417
|
+
// caller below rather than on its own.
|
|
418
|
+
const borderColorOf = (style) => {
|
|
419
|
+
if (!style) return undefined
|
|
420
|
+
const keys = ['borderColor','borderTopColor','borderBottomColor','borderLeftColor','borderRightColor']
|
|
421
|
+
for (const k of keys) {
|
|
422
|
+
const c = colorStr(style[k])
|
|
423
|
+
if (c) return c
|
|
424
|
+
}
|
|
425
|
+
return undefined
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const isVisible = (n) => {
|
|
429
|
+
const layout = n && n.layout
|
|
430
|
+
if (!layout || layout.width <= 0 || layout.height <= 0) return false
|
|
431
|
+
const abs = (n && (n.absolute || n.absolutePosition)) || null
|
|
432
|
+
if (!abs) return true
|
|
433
|
+
const device = (n && n.device) || {}
|
|
434
|
+
const screenW = Number(device.width) || window.innerWidth || 0
|
|
435
|
+
const screenH = Number(device.height) || window.innerHeight || 0
|
|
436
|
+
if (!screenW || !screenH) return true
|
|
437
|
+
return abs.x + layout.width > 0 && abs.y + layout.height > 0 && abs.x < screenW && abs.y < screenH
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const elements = list.filter(isVisible).filter((n) => {
|
|
441
|
+
const t = typeof n.text === 'string' && n.text.trim() ? n.text.trim() : undefined
|
|
442
|
+
return matchesFilter(n, t)
|
|
443
|
+
}).map((n) => {
|
|
444
|
+
const layout = n.layout || { x: 0, y: 0, width: 0, height: 0 }
|
|
445
|
+
const abs = n.absolute || n.absolutePosition || { x: layout.x, y: layout.y }
|
|
446
|
+
const text = typeof n.text === 'string' && n.text.trim() ? n.text.trim() : undefined
|
|
447
|
+
const base = {
|
|
448
|
+
...(typeof n.nodeId === 'number'
|
|
449
|
+
? {
|
|
450
|
+
nodeId: n.nodeId,
|
|
451
|
+
ancestorIds: Array.isArray(n.ancestors)
|
|
452
|
+
? n.ancestors.map((ancestor) => ancestor && ancestor.nodeId).filter((id) => typeof id === 'number')
|
|
453
|
+
: [],
|
|
454
|
+
}
|
|
455
|
+
: {}),
|
|
456
|
+
testID: n.testID || n.testId || undefined,
|
|
457
|
+
role: n.accessibilityRole || n.role || undefined,
|
|
458
|
+
type: typeof n.type === 'string' ? n.type : 'node',
|
|
459
|
+
text,
|
|
460
|
+
box: { x: round(abs.x), y: round(abs.y), w: round(layout.width), h: round(layout.height) },
|
|
461
|
+
borderRadius: 0,
|
|
462
|
+
padding: { t: 0, r: 0, b: 0, l: 0 },
|
|
463
|
+
fontSize: 0,
|
|
464
|
+
}
|
|
465
|
+
if (!includeStyle) return base
|
|
466
|
+
// computedStyle has the resolved values; style is the curated subset \u2014
|
|
467
|
+
// fall back across both so radius/fontSize survive either shape.
|
|
468
|
+
const style = Object.assign({}, n.style || {}, n.computedStyle || {})
|
|
469
|
+
const pad = (n.boxModel && n.boxModel.padding) || {}
|
|
470
|
+
const borderWidth = borderWOf(style)
|
|
471
|
+
return {
|
|
472
|
+
...base,
|
|
473
|
+
borderRadius: radiusOf(style),
|
|
474
|
+
padding: { t: round(pad.top), r: round(pad.right), b: round(pad.bottom), l: round(pad.left) },
|
|
475
|
+
fontSize: text ? (fontSizeOf(style) || 14) : 0,
|
|
476
|
+
color: text ? colorStr(style.color) : undefined,
|
|
477
|
+
bg: colorStr(style.backgroundColor),
|
|
478
|
+
opacity: opacityOf(style),
|
|
479
|
+
fontWeight: weightOf(style),
|
|
480
|
+
textDecoration: decoOf(style),
|
|
481
|
+
overflow: overflowOf(style),
|
|
482
|
+
borderWidth,
|
|
483
|
+
borderColor: borderWidth ? borderColorOf(style) : undefined,
|
|
484
|
+
}
|
|
485
|
+
})
|
|
486
|
+
const textElements = elements.filter((element) => element.text && element.fontSize > 0)
|
|
487
|
+
if (!includeStyle || textElements.length === 0) return elements
|
|
488
|
+
|
|
489
|
+
const screenshot = window.SootSim && window.SootSim.bridges && window.SootSim.bridges.screenshot
|
|
490
|
+
if (typeof screenshot !== 'function') {
|
|
491
|
+
throw new Error('styled native layout requires the rnx capture bridge')
|
|
492
|
+
}
|
|
493
|
+
const device = list.find((node) => node && node.device)?.device || {}
|
|
494
|
+
const width = Math.round(Number(device.width) || window.innerWidth || 0)
|
|
495
|
+
const height = Math.round(Number(device.height) || window.innerHeight || 0)
|
|
496
|
+
if (!width || !height) throw new Error('native layout has no capture dimensions')
|
|
497
|
+
const capture = async (suppressText) => {
|
|
498
|
+
const dataUrl = await screenshot({
|
|
499
|
+
format: 'png',
|
|
500
|
+
outputWidth: width,
|
|
501
|
+
outputHeight: height,
|
|
502
|
+
...(suppressText ? { suppressText: true } : {}),
|
|
503
|
+
})
|
|
504
|
+
const image = await new Promise((resolve, reject) => {
|
|
505
|
+
const next = new Image()
|
|
506
|
+
next.onload = () => resolve(next)
|
|
507
|
+
next.onerror = () => reject(new Error('could not decode native layout pixels'))
|
|
508
|
+
next.src = dataUrl
|
|
509
|
+
})
|
|
510
|
+
const canvas = document.createElement('canvas')
|
|
511
|
+
canvas.width = image.naturalWidth
|
|
512
|
+
canvas.height = image.naturalHeight
|
|
513
|
+
const context = canvas.getContext('2d', { willReadFrequently: true })
|
|
514
|
+
if (!context) throw new Error('could not read native layout pixels')
|
|
515
|
+
context.drawImage(image, 0, 0)
|
|
516
|
+
return context.getImageData(0, 0, canvas.width, canvas.height)
|
|
517
|
+
}
|
|
518
|
+
const normal = await capture(false)
|
|
519
|
+
const background = await capture(true)
|
|
520
|
+
for (const element of textElements) {
|
|
521
|
+
element.contrast = scoreContrast({
|
|
522
|
+
normal,
|
|
523
|
+
background,
|
|
524
|
+
box: element.box,
|
|
525
|
+
fontSize: element.fontSize,
|
|
526
|
+
fontWeight: element.fontWeight,
|
|
527
|
+
})
|
|
528
|
+
}
|
|
529
|
+
return elements
|
|
530
|
+
})()`;
|
|
531
|
+
}
|
|
532
|
+
var LAYOUT_GET_NATIVE_EVAL = layoutGetNativeEval();
|
|
533
|
+
async function inspectGetLayout(bridge, opts = {}) {
|
|
534
|
+
const raw = await bridge.send({
|
|
535
|
+
type: "evaluate",
|
|
536
|
+
code: layoutGetNativeEval(opts)
|
|
537
|
+
});
|
|
538
|
+
return Array.isArray(raw) ? raw : [];
|
|
539
|
+
}
|
|
540
|
+
function formatLayoutElements(elements, opts) {
|
|
541
|
+
if (elements.length === 0) return " no visible elements found";
|
|
542
|
+
const lines = elements.map((el) => {
|
|
543
|
+
const ident = el.testID ? `#${el.testID}` : el.selector ? el.selector : el.role ? `[${el.role}]` : `<${el.type}>`;
|
|
544
|
+
const parts = [ident, `@(${el.box.x},${el.box.y})`, `${el.box.w}x${el.box.h}`];
|
|
545
|
+
if (el.borderRadius > 0) parts.push(`radius:${el.borderRadius}`);
|
|
546
|
+
const p = el.padding;
|
|
547
|
+
if (p.t || p.r || p.b || p.l) {
|
|
548
|
+
const uniform = p.t === p.r && p.r === p.b && p.b === p.l;
|
|
549
|
+
parts.push(uniform ? `pad:${p.t}` : `pad:${p.t},${p.r},${p.b},${p.l}`);
|
|
550
|
+
}
|
|
551
|
+
if (el.fontSize > 0) parts.push(`font:${el.fontSize}`);
|
|
552
|
+
if (opts?.styling) {
|
|
553
|
+
if (el.fontWeight) parts.push(`weight:${el.fontWeight}`);
|
|
554
|
+
if (el.color) parts.push(`color:${el.color}`);
|
|
555
|
+
if (el.bg) parts.push(`bg:${el.bg}`);
|
|
556
|
+
if (el.contrast) {
|
|
557
|
+
const score = el.contrast.ratio == null ? `?/${el.contrast.required}` : `${el.contrast.ratio}/${el.contrast.required}${el.contrast.ratio < el.contrast.required ? " FAIL" : ""}`;
|
|
558
|
+
parts.push(`contrast:${score}`);
|
|
559
|
+
if (el.contrast.background) parts.push(`on:${el.contrast.background}`);
|
|
560
|
+
}
|
|
561
|
+
if (el.opacity != null) parts.push(`opacity:${el.opacity}`);
|
|
562
|
+
if (el.textDecoration) parts.push(`deco:${el.textDecoration}`);
|
|
563
|
+
if (el.overflow) parts.push(`overflow:${el.overflow}`);
|
|
564
|
+
if (el.borderWidth) {
|
|
565
|
+
parts.push(
|
|
566
|
+
el.borderColor ? `border:${el.borderWidth}/${el.borderColor}` : `border:${el.borderWidth}`
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
if (el.text) {
|
|
571
|
+
const text = el.text.length > 40 ? `${el.text.slice(0, 39)}\u2026` : el.text;
|
|
572
|
+
parts.push(`"${text}"`);
|
|
573
|
+
}
|
|
574
|
+
return ` ${parts.join(" ")}`;
|
|
575
|
+
});
|
|
576
|
+
return lines.join("\n");
|
|
577
|
+
}
|
|
578
|
+
var INSPECT_A11Y_CODE = `(async () => {
|
|
579
|
+
const t = window.__sootsimTest
|
|
580
|
+
if (!t) return []
|
|
581
|
+
|
|
582
|
+
const readLayout = (n) => n?.layout || null
|
|
583
|
+
const readAbs = (n) => n?.absolutePosition || n?.absolute || null
|
|
584
|
+
const readRole = (n) => n?.accessibilityRole || n?.role || null
|
|
585
|
+
const readLabel = (n) => n?.accessibilityLabel || n?.label || n?.text || null
|
|
586
|
+
const readHint = (n) => n?.accessibilityHint || n?.hint || null
|
|
587
|
+
const readState = (n) => n?.accessibilityState || n?.state || null
|
|
588
|
+
const readTestId = (n) => n?.testID || n?.testId || null
|
|
589
|
+
const readType = (n) => typeof n?.type === 'string' ? n.type.toLowerCase() : n?.type
|
|
590
|
+
const readPressable = (n) => {
|
|
591
|
+
if (n?.pressable) return true
|
|
592
|
+
const handlers = Array.isArray(n?.handlers) ? n.handlers : []
|
|
593
|
+
const role = readRole(n)
|
|
594
|
+
return handlers.length > 0 || role === 'button' || role === 'link' || role === 'tab'
|
|
595
|
+
}
|
|
596
|
+
const isTextInput = (n) => n?.isTextInput === true
|
|
597
|
+
const isTextNode = (n) => readType(n) === 'text'
|
|
598
|
+
const isVisibleTarget = (n) => {
|
|
599
|
+
const layout = readLayout(n)
|
|
600
|
+
if (!layout || layout.width <= 0 || layout.height <= 0) return false
|
|
601
|
+
const abs = readAbs(n)
|
|
602
|
+
if (!abs) return true
|
|
603
|
+
const device = n?.device || {}
|
|
604
|
+
const screenW = Number(device.width) || window.innerWidth || 0
|
|
605
|
+
const screenH = Number(device.height) || window.innerHeight || 0
|
|
606
|
+
return (
|
|
607
|
+
abs.x + layout.width > 0 &&
|
|
608
|
+
abs.y + layout.height > 0 &&
|
|
609
|
+
abs.x < screenW &&
|
|
610
|
+
abs.y < screenH
|
|
611
|
+
)
|
|
612
|
+
}
|
|
613
|
+
const hasAccessibleSignal = (n) => {
|
|
614
|
+
const role = readRole(n)
|
|
615
|
+
const label = readLabel(n)
|
|
616
|
+
const hint = readHint(n)
|
|
617
|
+
if (role) return true
|
|
618
|
+
if (hint) return true
|
|
619
|
+
if (isTextInput(n)) return true
|
|
620
|
+
if (readPressable(n)) return true
|
|
621
|
+
if (isTextNode(n) && n?.text) return true
|
|
622
|
+
if (typeof label === 'string' && label.length <= 30 && label !== n?.text) return true
|
|
623
|
+
return false
|
|
624
|
+
}
|
|
625
|
+
const normalize = (n) => {
|
|
626
|
+
const layout = readLayout(n)
|
|
627
|
+
const abs = readAbs(n)
|
|
628
|
+
const role = readRole(n) || (readPressable(n) ? 'button' : isTextInput(n) ? 'textfield' : isTextNode(n) ? 'statictext' : 'none')
|
|
629
|
+
return {
|
|
630
|
+
role,
|
|
631
|
+
label: readLabel(n),
|
|
632
|
+
hint: readHint(n),
|
|
633
|
+
state: readState(n),
|
|
634
|
+
testID: readTestId(n),
|
|
635
|
+
position: abs ? { x: Math.round(abs.x), y: Math.round(abs.y) } : null,
|
|
636
|
+
size: layout ? { w: Math.round(layout.width), h: Math.round(layout.height) } : null,
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
if (typeof t.listInspectable === 'function') {
|
|
641
|
+
const list = await t.listInspectable({})
|
|
642
|
+
if (Array.isArray(list)) {
|
|
643
|
+
return list.filter(n => isVisibleTarget(n) && hasAccessibleSignal(n)).map(normalize)
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
const all = await t.queryAll({ pruneHidden: true })
|
|
648
|
+
return all
|
|
649
|
+
.filter(n => isVisibleTarget(n) && hasAccessibleSignal(n))
|
|
650
|
+
.map(normalize)
|
|
651
|
+
})()`;
|
|
652
|
+
async function inspectAccessibilityTree(bridge) {
|
|
653
|
+
const nodes = await bridge.send({ type: "evaluate", code: INSPECT_A11Y_CODE });
|
|
654
|
+
return Array.isArray(nodes) ? nodes : [];
|
|
655
|
+
}
|
|
656
|
+
var FIND_INSPECTABLE_TARGETS = `
|
|
657
|
+
const fromInspectable = async () => {
|
|
658
|
+
if (typeof t.listInspectable !== 'function') return null
|
|
659
|
+
const list = await t.listInspectable({})
|
|
660
|
+
if (!Array.isArray(list)) return null
|
|
661
|
+
return list.map((n) => {
|
|
662
|
+
const role = n.accessibilityRole ?? n.role
|
|
663
|
+
const label = n.accessibilityLabel ?? n.label
|
|
664
|
+
const layout = n.layout
|
|
665
|
+
const absolutePosition = n.absolutePosition ?? n.absolute
|
|
666
|
+
const screenW = Number(n.device?.width) || window.innerWidth || 0
|
|
667
|
+
const screenH = Number(n.device?.height) || window.innerHeight || 0
|
|
668
|
+
const visibleFrame = layout && absolutePosition
|
|
669
|
+
? {
|
|
670
|
+
x: Math.max(0, absolutePosition.x),
|
|
671
|
+
y: Math.max(0, absolutePosition.y),
|
|
672
|
+
width: Math.max(
|
|
673
|
+
0,
|
|
674
|
+
Math.min(screenW, absolutePosition.x + layout.width) -
|
|
675
|
+
Math.max(0, absolutePosition.x),
|
|
676
|
+
),
|
|
677
|
+
height: Math.max(
|
|
678
|
+
0,
|
|
679
|
+
Math.min(screenH, absolutePosition.y + layout.height) -
|
|
680
|
+
Math.max(0, absolutePosition.y),
|
|
681
|
+
),
|
|
682
|
+
}
|
|
683
|
+
: null
|
|
684
|
+
const handlers = Array.isArray(n.handlers) ? n.handlers : []
|
|
685
|
+
const pressable =
|
|
686
|
+
handlers.length > 0 ||
|
|
687
|
+
role === 'button' ||
|
|
688
|
+
role === 'link' ||
|
|
689
|
+
role === 'tab'
|
|
690
|
+
return {
|
|
691
|
+
type: typeof n.type === 'string' ? n.type.toLowerCase() : n.type,
|
|
692
|
+
id: n.id ?? n.nodeId,
|
|
693
|
+
nodeId: n.nodeId,
|
|
694
|
+
testID: n.testID ?? n.testId,
|
|
695
|
+
text: n.text,
|
|
696
|
+
layout,
|
|
697
|
+
absolutePosition,
|
|
698
|
+
visibleFrame,
|
|
699
|
+
style: n.computedStyle ?? n.style ?? {},
|
|
700
|
+
childCount: n.childCount ?? 0,
|
|
701
|
+
pressed: n.pressed ?? false,
|
|
702
|
+
pressable,
|
|
703
|
+
isTextInput: n.isTextInput ?? false,
|
|
704
|
+
accessible: n.accessible ?? true,
|
|
705
|
+
accessibilityLabel: label,
|
|
706
|
+
accessibilityRole: role,
|
|
707
|
+
accessibilityHint: n.accessibilityHint,
|
|
708
|
+
accessibilityState: n.accessibilityState,
|
|
709
|
+
accessibilityValue: n.accessibilityValue,
|
|
710
|
+
}
|
|
711
|
+
})
|
|
712
|
+
}
|
|
713
|
+
const isVisibleTarget = (n) => {
|
|
714
|
+
if (!n?.layout) return false
|
|
715
|
+
const frame = n.visibleFrame
|
|
716
|
+
if (frame) return frame.width > 0 && frame.height > 0
|
|
717
|
+
const abs = n.absolutePosition
|
|
718
|
+
if (!abs) return n.layout.width > 0 && n.layout.height > 0
|
|
719
|
+
const screenW = window.innerWidth || 0
|
|
720
|
+
const screenH = window.innerHeight || 0
|
|
721
|
+
return (
|
|
722
|
+
abs.x + n.layout.width > 0 &&
|
|
723
|
+
abs.y + n.layout.height > 0 &&
|
|
724
|
+
abs.x < screenW &&
|
|
725
|
+
abs.y < screenH
|
|
726
|
+
)
|
|
727
|
+
}
|
|
728
|
+
`;
|
|
729
|
+
function resolveFindMode(q) {
|
|
730
|
+
if (q.testId) {
|
|
731
|
+
return {
|
|
732
|
+
mode: "testid",
|
|
733
|
+
code: `(async () => {
|
|
734
|
+
const t = window.__sootsimTest
|
|
735
|
+
if (!t) return null
|
|
736
|
+
return (await t.findByTestId(${JSON.stringify(q.testId)})) || (await t.findById(${JSON.stringify(q.testId)}))
|
|
737
|
+
})()`
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
if (q.role) {
|
|
741
|
+
return {
|
|
742
|
+
mode: "role",
|
|
743
|
+
code: `(async () => {
|
|
744
|
+
const t = window.__sootsimTest
|
|
745
|
+
if (!t) return []
|
|
746
|
+
return await t.queryAll({ hasRole: ${JSON.stringify(q.role)}, pruneHidden: true })
|
|
747
|
+
})()`
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
if (q.type) {
|
|
751
|
+
return {
|
|
752
|
+
mode: "type",
|
|
753
|
+
code: `(async () => {
|
|
754
|
+
const t = window.__sootsimTest
|
|
755
|
+
if (!t) return []
|
|
756
|
+
return await t.queryAll({ type: ${JSON.stringify(q.type)}, pruneHidden: true })
|
|
757
|
+
})()`
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
if (q.pressable) {
|
|
761
|
+
return {
|
|
762
|
+
mode: "pressable",
|
|
763
|
+
code: `(async () => {
|
|
764
|
+
const t = window.__sootsimTest
|
|
765
|
+
if (!t) return []
|
|
766
|
+
${FIND_INSPECTABLE_TARGETS}
|
|
767
|
+
const inspectable = await fromInspectable()
|
|
768
|
+
if (inspectable) return inspectable.filter(n => n.pressable && isVisibleTarget(n))
|
|
769
|
+
const all = await t.queryAll({ pruneHidden: true })
|
|
770
|
+
return all.filter(n => n.pressable && isVisibleTarget(n))
|
|
771
|
+
})()`
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
if (q.interactive) {
|
|
775
|
+
return {
|
|
776
|
+
mode: "interactive-targets",
|
|
777
|
+
code: `(async () => {
|
|
778
|
+
const t = window.__sootsimTest
|
|
779
|
+
if (!t) return []
|
|
780
|
+
${FIND_INSPECTABLE_TARGETS}
|
|
781
|
+
const inspectable = await fromInspectable()
|
|
782
|
+
if (inspectable) {
|
|
783
|
+
return inspectable.filter(n => n.pressable && isVisibleTarget(n))
|
|
784
|
+
}
|
|
785
|
+
const all = await t.queryAll({ pruneHidden: true })
|
|
786
|
+
return all.filter(n => n.pressable && isVisibleTarget(n))
|
|
787
|
+
})()`
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
if (q.visible) {
|
|
791
|
+
return {
|
|
792
|
+
mode: "visible",
|
|
793
|
+
code: `(async () => {
|
|
794
|
+
const t = window.__sootsimTest
|
|
795
|
+
if (!t) return []
|
|
796
|
+
const all = await t.queryAll({ pruneHidden: true })
|
|
797
|
+
return all.filter(n => n.layout && n.layout.width > 0 && n.layout.height > 0)
|
|
798
|
+
})()`
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
if (q.text) {
|
|
802
|
+
return {
|
|
803
|
+
mode: "text",
|
|
804
|
+
code: `(async () => {
|
|
805
|
+
const t = window.__sootsimTest
|
|
806
|
+
if (!t) return null
|
|
807
|
+
return await t.findByText(${JSON.stringify(q.text)})
|
|
808
|
+
})()`
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
return null;
|
|
812
|
+
}
|
|
813
|
+
async function inspectFind(bridge, q) {
|
|
814
|
+
const resolved = resolveFindMode(q);
|
|
815
|
+
if (!resolved) return null;
|
|
816
|
+
const result = await bridge.send({ type: "evaluate", code: resolved.code });
|
|
817
|
+
return { mode: resolved.mode, result };
|
|
818
|
+
}
|
|
819
|
+
function rankInteractive(nodes) {
|
|
820
|
+
return [...nodes].sort((a, b) => scoreInteractive(b) - scoreInteractive(a));
|
|
821
|
+
}
|
|
822
|
+
function scoreInteractive(n) {
|
|
823
|
+
let score = 0;
|
|
824
|
+
if (n.testID) score += 100;
|
|
825
|
+
if (typeof n.text === "string" && n.text.trim().length > 0) score += 60;
|
|
826
|
+
if (typeof n.accessibilityLabel === "string" && n.accessibilityLabel.trim().length > 0) {
|
|
827
|
+
score += 30;
|
|
828
|
+
}
|
|
829
|
+
if (n.accessibilityRole) score += 15;
|
|
830
|
+
const w = n.layout?.width ?? 0;
|
|
831
|
+
const h = n.layout?.height ?? 0;
|
|
832
|
+
const area = w * h;
|
|
833
|
+
if (area >= 400 && area <= 6e4) score += 25;
|
|
834
|
+
else if (area > 6e4) score -= 20;
|
|
835
|
+
const y = n.absolutePosition?.y ?? 0;
|
|
836
|
+
if (y < 0) score -= 30;
|
|
837
|
+
return score;
|
|
838
|
+
}
|
|
839
|
+
function tapCommandForNode(n) {
|
|
840
|
+
if (n.testID) return `rnxsim do tap-id ${shellEscape(n.testID)}`;
|
|
841
|
+
const text = typeof n.text === "string" ? n.text.trim() : "";
|
|
842
|
+
if (text.length > 0 && text.length <= 80)
|
|
843
|
+
return `rnxsim do tap-text ${shellEscape(text)}`;
|
|
844
|
+
const x = Math.round(((n.absolutePosition?.x ?? 0) + (n.layout?.width ?? 0) / 2) * 10) / 10;
|
|
845
|
+
const y = Math.round(((n.absolutePosition?.y ?? 0) + (n.layout?.height ?? 0) / 2) * 10) / 10;
|
|
846
|
+
return `rnxsim do tap ${x} ${y}`;
|
|
847
|
+
}
|
|
848
|
+
function shellEscape(value) {
|
|
849
|
+
if (/^[A-Za-z0-9_./@:-]+$/.test(value)) return value;
|
|
850
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
851
|
+
}
|
|
852
|
+
var WAIT_READY_PROBE = `(async () => {
|
|
853
|
+
const t = window.__sootsimTest
|
|
854
|
+
let nodes = 0
|
|
855
|
+
try { nodes = (await t?.getNodeCount?.()) || 0 } catch {}
|
|
856
|
+
let targets = 0
|
|
857
|
+
let liveFrameActive = false
|
|
858
|
+
let liveFrameChannels = 0
|
|
859
|
+
let liveFramePublishes = 0
|
|
860
|
+
let loadingText = ''
|
|
861
|
+
const cleanText = (value) =>
|
|
862
|
+
typeof value === 'string' ? value.replace(/\\s+/g, ' ').trim() : ''
|
|
863
|
+
const loadingSignal = (value) => {
|
|
864
|
+
const text = cleanText(value)
|
|
865
|
+
if (!text) return ''
|
|
866
|
+
return /^(opening app\\b|looking for your app\\b|building bundle\\b|preparing rnxsim runtime\\b|loading native bundle\\b|loading rnx stubs\\b|loading bundle loader\\b|loading native stubs\\b|loading compat bridge\\b|loading react-native shim\\b|loading react bridge\\b|loading reconciler\\b|loading replacement modules\\b|injecting rnx modules\\b|warming sqlite engine\\b|capturing root component\\b|reloading app\\b|loading(?:[.!\u2026]*)?$|connecting(?:[.!\u2026]*)?$)/i.test(text)
|
|
867
|
+
? text
|
|
868
|
+
: ''
|
|
869
|
+
}
|
|
870
|
+
try {
|
|
871
|
+
const loading = window.__sootsimConnectRNLoading
|
|
872
|
+
if (loading && loading.active === true) {
|
|
873
|
+
loadingText = [loading.title, loading.detail].map(cleanText).filter(Boolean).join(' ')
|
|
874
|
+
}
|
|
875
|
+
} catch {}
|
|
876
|
+
try {
|
|
877
|
+
if (typeof t?.listInspectable === 'function') {
|
|
878
|
+
const list = await t.listInspectable({})
|
|
879
|
+
if (Array.isArray(list)) {
|
|
880
|
+
const screenW = window.innerWidth || 0
|
|
881
|
+
const screenH = window.innerHeight || 0
|
|
882
|
+
const isVisible = (n) => {
|
|
883
|
+
const layout = n?.layout
|
|
884
|
+
if (!layout || layout.width <= 0 || layout.height <= 0) return false
|
|
885
|
+
const abs = n?.absolutePosition || n?.absolute
|
|
886
|
+
if (!abs) return true
|
|
887
|
+
const device = n?.device || {}
|
|
888
|
+
const w = Number(device.width) || screenW
|
|
889
|
+
const h = Number(device.height) || screenH
|
|
890
|
+
return (
|
|
891
|
+
abs.x + layout.width > 0 &&
|
|
892
|
+
abs.y + layout.height > 0 &&
|
|
893
|
+
abs.x < w &&
|
|
894
|
+
abs.y < h
|
|
895
|
+
)
|
|
896
|
+
}
|
|
897
|
+
const hasContentSignal = (n) => {
|
|
898
|
+
const role = n?.accessibilityRole || n?.role
|
|
899
|
+
const label = cleanText(n?.accessibilityLabel || n?.label)
|
|
900
|
+
const handlers = Array.isArray(n?.handlers) ? n.handlers : []
|
|
901
|
+
const text = cleanText(n?.text)
|
|
902
|
+
const testID = cleanText(n?.testID || n?.testId)
|
|
903
|
+
const loading = loadingSignal(text) || loadingSignal(label) || loadingSignal(testID)
|
|
904
|
+
if (!loadingText && loading) {
|
|
905
|
+
loadingText = loading
|
|
906
|
+
}
|
|
907
|
+
if (handlers.length > 0) return true
|
|
908
|
+
if (role) return true
|
|
909
|
+
if (n?.isTextInput) return true
|
|
910
|
+
if (text) return true
|
|
911
|
+
if (label) return true
|
|
912
|
+
if (testID && !/^splash|loading/i.test(testID)) return true
|
|
913
|
+
return false
|
|
914
|
+
}
|
|
915
|
+
targets = list.filter(n => isVisible(n) && hasContentSignal(n)).length
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
} catch {}
|
|
919
|
+
try {
|
|
920
|
+
const stats = await t?.getImageLoaderStats?.()
|
|
921
|
+
const presentation = stats?.liveFramePresentation
|
|
922
|
+
liveFrameChannels = Number(presentation?.activeChannels) || 0
|
|
923
|
+
liveFramePublishes = Number(presentation?.publishes) || 0
|
|
924
|
+
const previous = window.__sootsimWaitReadyLiveFramePublishes
|
|
925
|
+
liveFrameActive =
|
|
926
|
+
liveFrameChannels > 0 &&
|
|
927
|
+
typeof previous === 'number' &&
|
|
928
|
+
liveFramePublishes > previous
|
|
929
|
+
window.__sootsimWaitReadyLiveFramePublishes = liveFramePublishes
|
|
930
|
+
} catch {}
|
|
931
|
+
let externalReady = null
|
|
932
|
+
let externalStatus = ''
|
|
933
|
+
let externalError = ''
|
|
934
|
+
let suppressedEntryError = ''
|
|
935
|
+
try {
|
|
936
|
+
const getExternalAppState = t?.getExternalAppState
|
|
937
|
+
const external = typeof getExternalAppState === 'function'
|
|
938
|
+
? await Promise.race([
|
|
939
|
+
getExternalAppState(),
|
|
940
|
+
new Promise((resolve) => setTimeout(
|
|
941
|
+
() => resolve({
|
|
942
|
+
state: {
|
|
943
|
+
ready: false,
|
|
944
|
+
loading: true,
|
|
945
|
+
status: 'waiting for tenant worker...',
|
|
946
|
+
},
|
|
947
|
+
}),
|
|
948
|
+
1000,
|
|
949
|
+
)),
|
|
950
|
+
])
|
|
951
|
+
: null
|
|
952
|
+
const state = external?.state
|
|
953
|
+
if (state && typeof state === 'object') {
|
|
954
|
+
externalReady = state.ready === true
|
|
955
|
+
if (typeof state.status === 'string') externalStatus = state.status
|
|
956
|
+
if (typeof state.error === 'string') externalError = state.error
|
|
957
|
+
}
|
|
958
|
+
if (!externalError && Array.isArray(external?.entryErrors)) {
|
|
959
|
+
// suppressed-and-continued entry errors (bundle-loader's patched __r
|
|
960
|
+
// swallows entry throws and moves on) must NOT gate readiness \u2014 the
|
|
961
|
+
// app frequently runs fine after one (e.g. metro's "Unknown named
|
|
962
|
+
// module" probing noise). they surface separately as a diagnostic
|
|
963
|
+
// for the timeout path.
|
|
964
|
+
const isReal = (item) => item && typeof item.message === 'string' && item.message.trim()
|
|
965
|
+
const fatal = external.entryErrors.find((item) => isReal(item) && item.suppressed !== true)
|
|
966
|
+
if (fatal) externalError = fatal.message
|
|
967
|
+
const suppressed = external.entryErrors.find((item) => isReal(item) && item.suppressed === true)
|
|
968
|
+
if (suppressed) suppressedEntryError = suppressed.message
|
|
969
|
+
}
|
|
970
|
+
// once the app has errored its last status ("injecting sootsim
|
|
971
|
+
// modules...") is stale \u2014 reporting it makes a dead app read as one that
|
|
972
|
+
// is still booting.
|
|
973
|
+
if (externalError) loadingText = ''
|
|
974
|
+
else if (externalReady === false && externalStatus) loadingText = externalStatus
|
|
975
|
+
} catch {}
|
|
976
|
+
let errors = 0
|
|
977
|
+
try { errors = window.__sootsimConsole?.count?.()?.errors ?? 0 } catch {}
|
|
978
|
+
return {
|
|
979
|
+
flag: (window).__sootsimExternalAppReady,
|
|
980
|
+
at: (window).__sootsimExternalAppReadyAt || 0,
|
|
981
|
+
nodes,
|
|
982
|
+
targets,
|
|
983
|
+
liveFrameActive,
|
|
984
|
+
liveFrameChannels,
|
|
985
|
+
liveFramePublishes,
|
|
986
|
+
errors,
|
|
987
|
+
loadingText,
|
|
988
|
+
externalReady,
|
|
989
|
+
externalStatus,
|
|
990
|
+
externalError,
|
|
991
|
+
suppressedEntryError,
|
|
992
|
+
}
|
|
993
|
+
})()`;
|
|
994
|
+
var READY_CONTENT_NODE_FLOOR = 100;
|
|
995
|
+
var READY_NODE_STABLE_MS = 750;
|
|
996
|
+
var WAIT_READY_PROGRESS_INTERVAL_MS = 2e3;
|
|
997
|
+
var READY_PROBE_POLL_MS = 150;
|
|
998
|
+
function readyProbeHasContent(probe) {
|
|
999
|
+
return probe.liveFrameActive || probe.targets > 0 || probe.nodes >= READY_CONTENT_NODE_FLOOR;
|
|
1000
|
+
}
|
|
1001
|
+
function readyProbeHasTargetContent(probe) {
|
|
1002
|
+
return probe.liveFrameActive || probe.targets > 0;
|
|
1003
|
+
}
|
|
1004
|
+
function waitReadyReason(status) {
|
|
1005
|
+
if (status.bridgeError) {
|
|
1006
|
+
return `sim unreachable: ${status.bridgeError} \u2014 the target tab is closed or no sim is connected (check \`rnxsim list\`, reopen with \`rnxsim open\`)`;
|
|
1007
|
+
}
|
|
1008
|
+
const base = status.externalError ? `guest app errored: ${status.externalError}` : status.loadingText ? `still showing "${status.loadingText}"` : status.externalReady === false ? "guest app is still loading" : status.flag !== true && status.targets > 0 ? "native content is rendered but the ready signal has not settled" : status.flag !== true ? "guest app has not emitted sootsim:externalAppReady" : status.targets <= 0 ? "ready flag emitted but no visible app content is inspectable yet" : "node tree is still changing";
|
|
1009
|
+
return !status.externalError && status.suppressedEntryError ? `${base} (suppressed entry error: ${status.suppressedEntryError})` : base;
|
|
1010
|
+
}
|
|
1011
|
+
async function inspectWaitReady(bridge, timeoutMs = 2e4, options = {}) {
|
|
1012
|
+
const start = Date.now();
|
|
1013
|
+
const deadline = start + timeoutMs;
|
|
1014
|
+
const progressIntervalMs = options.progressIntervalMs ?? WAIT_READY_PROGRESS_INTERVAL_MS;
|
|
1015
|
+
let nextProgressAt = start + progressIntervalMs;
|
|
1016
|
+
let lastNodes = -1;
|
|
1017
|
+
let nodeStableSince = start;
|
|
1018
|
+
let bridgeError = "";
|
|
1019
|
+
let last = {
|
|
1020
|
+
flag: void 0,
|
|
1021
|
+
at: 0,
|
|
1022
|
+
nodes: 0,
|
|
1023
|
+
targets: 0,
|
|
1024
|
+
liveFrameActive: false,
|
|
1025
|
+
liveFrameChannels: 0,
|
|
1026
|
+
liveFramePublishes: 0,
|
|
1027
|
+
errors: 0,
|
|
1028
|
+
loadingText: "",
|
|
1029
|
+
externalReady: null,
|
|
1030
|
+
externalStatus: "",
|
|
1031
|
+
externalError: "",
|
|
1032
|
+
suppressedEntryError: ""
|
|
1033
|
+
};
|
|
1034
|
+
while (Date.now() < deadline) {
|
|
1035
|
+
try {
|
|
1036
|
+
last = await bridge.send({ type: "evaluate", code: WAIT_READY_PROBE }) ?? last;
|
|
1037
|
+
bridgeError = "";
|
|
1038
|
+
} catch (error) {
|
|
1039
|
+
bridgeError = error instanceof Error ? error.message : String(error);
|
|
1040
|
+
if (bridgeError.startsWith("multiple sims are connected:") || bridgeError.startsWith("saved sim ")) {
|
|
1041
|
+
throw error;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
const now = Date.now();
|
|
1045
|
+
const status2 = {
|
|
1046
|
+
ready: false,
|
|
1047
|
+
elapsedMs: now - start,
|
|
1048
|
+
nodes: last.nodes,
|
|
1049
|
+
targets: last.targets,
|
|
1050
|
+
liveFrameActive: last.liveFrameActive,
|
|
1051
|
+
liveFrameChannels: last.liveFrameChannels,
|
|
1052
|
+
liveFramePublishes: last.liveFramePublishes,
|
|
1053
|
+
flag: last.flag,
|
|
1054
|
+
loadingText: last.loadingText,
|
|
1055
|
+
externalReady: last.externalReady,
|
|
1056
|
+
externalStatus: last.externalStatus,
|
|
1057
|
+
externalError: last.externalError,
|
|
1058
|
+
suppressedEntryError: last.suppressedEntryError,
|
|
1059
|
+
errors: last.errors,
|
|
1060
|
+
bridgeError
|
|
1061
|
+
};
|
|
1062
|
+
if (last.nodes !== lastNodes) {
|
|
1063
|
+
lastNodes = last.nodes;
|
|
1064
|
+
nodeStableSince = now;
|
|
1065
|
+
}
|
|
1066
|
+
const hasReadySignal = last.flag === true && readyProbeHasContent(last);
|
|
1067
|
+
const hasRenderedContentWithoutReadySignal = last.flag !== true && readyProbeHasTargetContent(last);
|
|
1068
|
+
if ((hasReadySignal || hasRenderedContentWithoutReadySignal) && last.externalReady !== false && !last.externalError && !last.loadingText) {
|
|
1069
|
+
if (now - nodeStableSince >= READY_NODE_STABLE_MS) {
|
|
1070
|
+
return {
|
|
1071
|
+
...status2,
|
|
1072
|
+
ready: true
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
if (last.externalError) return status2;
|
|
1077
|
+
if (options.onProgress && progressIntervalMs > 0 && now >= nextProgressAt) {
|
|
1078
|
+
options.onProgress(status2);
|
|
1079
|
+
do {
|
|
1080
|
+
nextProgressAt += progressIntervalMs;
|
|
1081
|
+
} while (now >= nextProgressAt);
|
|
1082
|
+
}
|
|
1083
|
+
await new Promise((r) => setTimeout(r, READY_PROBE_POLL_MS));
|
|
1084
|
+
}
|
|
1085
|
+
const status = {
|
|
1086
|
+
ready: false,
|
|
1087
|
+
elapsedMs: Date.now() - start,
|
|
1088
|
+
nodes: last.nodes,
|
|
1089
|
+
targets: last.targets,
|
|
1090
|
+
liveFrameActive: last.liveFrameActive,
|
|
1091
|
+
liveFrameChannels: last.liveFrameChannels,
|
|
1092
|
+
liveFramePublishes: last.liveFramePublishes,
|
|
1093
|
+
flag: last.flag,
|
|
1094
|
+
loadingText: last.loadingText,
|
|
1095
|
+
externalReady: last.externalReady,
|
|
1096
|
+
externalStatus: last.externalStatus,
|
|
1097
|
+
externalError: last.externalError,
|
|
1098
|
+
suppressedEntryError: last.suppressedEntryError,
|
|
1099
|
+
errors: last.errors,
|
|
1100
|
+
bridgeError
|
|
1101
|
+
};
|
|
1102
|
+
if (options.onProgress && progressIntervalMs > 0 && Date.now() >= nextProgressAt) {
|
|
1103
|
+
options.onProgress(status);
|
|
1104
|
+
}
|
|
1105
|
+
return status;
|
|
1106
|
+
}
|
|
1107
|
+
async function inspectWaitSelector(bridge, testId, timeoutMs = 5e3, opts = {}) {
|
|
1108
|
+
const gone = opts.gone === true;
|
|
1109
|
+
const result = await bridge.send(
|
|
1110
|
+
{
|
|
1111
|
+
type: "evaluate",
|
|
1112
|
+
code: `(async () => {
|
|
1113
|
+
const start = Date.now()
|
|
1114
|
+
const deadline = start + ${timeoutMs}
|
|
1115
|
+
const gone = ${gone}
|
|
1116
|
+
const ID = ${JSON.stringify(testId)}
|
|
1117
|
+
const present = (node) => !!(node && node.layout && node.layout.width > 0 && node.layout.height > 0)
|
|
1118
|
+
const find = async () => {
|
|
1119
|
+
const t = window.__sootsimTest
|
|
1120
|
+
if (!t) return undefined // bridge not ready \u2014 indeterminate, not "gone"
|
|
1121
|
+
try {
|
|
1122
|
+
// gone-mode confirms a gate/screen LEFT \u2014 it only needs structural
|
|
1123
|
+
// existence + layout, NOT the full-tree occlusion pass (pruneHidden).
|
|
1124
|
+
// that pass (computeOccludedInspectNodeIds) walks the whole tree and
|
|
1125
|
+
// does O(n\xB2)-ish rect-occlusion testing EVERY poll; on a large
|
|
1126
|
+
// post-login app tree it costs seconds per poll, so --gone can never
|
|
1127
|
+
// get two clean "absent" polls inside budget and falsely reports the
|
|
1128
|
+
// gate as still blocked \u2014 the root cause of the 3pc PR-preview outage.
|
|
1129
|
+
// presence-mode keeps pruneHidden so "appeared" still means
|
|
1130
|
+
// visibly-reachable. a departed gate is unmounted or zero-sized, so the
|
|
1131
|
+
// cheap structural+layout check is correct here and ~O(n) cheap.
|
|
1132
|
+
const matches = await t.queryAll?.(gone ? { hasId: ID } : { hasId: ID, pruneHidden: true })
|
|
1133
|
+
if (!Array.isArray(matches)) return undefined
|
|
1134
|
+
return matches.find(present) || null
|
|
1135
|
+
} catch {
|
|
1136
|
+
return undefined
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
let goneStreak = 0
|
|
1140
|
+
while (Date.now() < deadline) {
|
|
1141
|
+
const node = await find()
|
|
1142
|
+
if (gone) {
|
|
1143
|
+
if (node === null) {
|
|
1144
|
+
goneStreak += 1
|
|
1145
|
+
if (goneStreak >= 2) return { found: true, elapsed: Date.now() - start }
|
|
1146
|
+
} else {
|
|
1147
|
+
goneStreak = 0
|
|
1148
|
+
}
|
|
1149
|
+
} else if (present(node)) {
|
|
1150
|
+
return { found: true, node, elapsed: Date.now() - start }
|
|
1151
|
+
}
|
|
1152
|
+
await new Promise((r) => setTimeout(r, 80))
|
|
1153
|
+
}
|
|
1154
|
+
return { found: false, elapsed: Date.now() - start }
|
|
1155
|
+
})()`
|
|
1156
|
+
},
|
|
1157
|
+
{
|
|
1158
|
+
timeoutMs: timeoutMs + 1e3
|
|
1159
|
+
}
|
|
1160
|
+
);
|
|
1161
|
+
return result ?? { found: false, elapsed: timeoutMs };
|
|
1162
|
+
}
|
|
1163
|
+
function consoleEntriesEval(level, limit) {
|
|
1164
|
+
const getter = level === "error" ? "getErrors" : "getWarnings";
|
|
1165
|
+
return `(() => {
|
|
1166
|
+
const out = []
|
|
1167
|
+
const seen = new Set()
|
|
1168
|
+
const norm = (s) => (typeof s === 'string' ? s : (() => { try { return JSON.stringify(s) } catch { return String(s) } })())
|
|
1169
|
+
const key = (ts, args) => Math.round((ts || 0) / 250) + '|' + (Array.isArray(args) ? args.map(norm).join(' ') : norm(args))
|
|
1170
|
+
const push = (e) => {
|
|
1171
|
+
if (!e) return
|
|
1172
|
+
const ts = typeof e.timestamp === 'number' ? e.timestamp : (typeof e.ts === 'number' ? e.ts : 0)
|
|
1173
|
+
const k = key(ts, e.args)
|
|
1174
|
+
if (seen.has(k)) return
|
|
1175
|
+
seen.add(k)
|
|
1176
|
+
out.push({ timestamp: ts, args: Array.isArray(e.args) ? e.args : [e.args], stack: e.stack || undefined, source: e.source || undefined })
|
|
1177
|
+
}
|
|
1178
|
+
// page-realm ws-bridge buffer first (richest stacks for page-origin errors)
|
|
1179
|
+
try { for (const e of (window.__sootsimConsole?.${getter}(${limit}) || [])) push(e) } catch {}
|
|
1180
|
+
// engine observability store \u2014 the always-on render-worker / forwarded path
|
|
1181
|
+
try {
|
|
1182
|
+
const obs = window.__sootsimObservability
|
|
1183
|
+
const snap = obs && obs.logs && typeof obs.logs.getSnapshot === 'function' ? obs.logs.getSnapshot() : []
|
|
1184
|
+
for (const e of snap) if (e && e.level === ${JSON.stringify(level)}) push(e)
|
|
1185
|
+
} catch {}
|
|
1186
|
+
return out.sort((a, b) => (a.timestamp || 0) - (b.timestamp || 0)).slice(-${limit})
|
|
1187
|
+
})()`;
|
|
1188
|
+
}
|
|
1189
|
+
async function inspectErrors(bridge, limit = 20) {
|
|
1190
|
+
const result = await bridge.send({
|
|
1191
|
+
type: "evaluate",
|
|
1192
|
+
code: consoleEntriesEval("error", limit)
|
|
1193
|
+
});
|
|
1194
|
+
return Array.isArray(result) ? result : [];
|
|
1195
|
+
}
|
|
1196
|
+
async function inspectWarnings(bridge, limit = 20) {
|
|
1197
|
+
const result = await bridge.send({
|
|
1198
|
+
type: "evaluate",
|
|
1199
|
+
code: consoleEntriesEval("warn", limit)
|
|
1200
|
+
});
|
|
1201
|
+
return Array.isArray(result) ? result : [];
|
|
1202
|
+
}
|
|
1203
|
+
var MERGED_CONSOLE_COUNT_EVAL = `(() => {
|
|
1204
|
+
const norm = (s) => (typeof s === 'string' ? s : (() => { try { return JSON.stringify(s) } catch { return String(s) } })())
|
|
1205
|
+
const key = (lvl, ts, args) => lvl + '|' + Math.round((ts || 0) / 250) + '|' + (Array.isArray(args) ? args.map(norm).join(' ') : norm(args))
|
|
1206
|
+
const seen = new Set()
|
|
1207
|
+
let errors = 0
|
|
1208
|
+
let warnings = 0
|
|
1209
|
+
const add = (lvl, ts, args) => {
|
|
1210
|
+
if (lvl !== 'error' && lvl !== 'warn') return
|
|
1211
|
+
const k = key(lvl, ts, args)
|
|
1212
|
+
if (seen.has(k)) return
|
|
1213
|
+
seen.add(k)
|
|
1214
|
+
if (lvl === 'error') errors++
|
|
1215
|
+
else warnings++
|
|
1216
|
+
}
|
|
1217
|
+
try {
|
|
1218
|
+
const c = window.__sootsimConsole
|
|
1219
|
+
for (const e of (c?.getErrors?.(200) || [])) add('error', e?.timestamp ?? e?.ts, e?.args)
|
|
1220
|
+
for (const e of (c?.getWarnings?.(200) || [])) add('warn', e?.timestamp ?? e?.ts, e?.args)
|
|
1221
|
+
} catch {}
|
|
1222
|
+
try {
|
|
1223
|
+
const obs = window.__sootsimObservability
|
|
1224
|
+
const snap = obs && obs.logs && typeof obs.logs.getSnapshot === 'function' ? obs.logs.getSnapshot() : []
|
|
1225
|
+
for (const e of snap) if (e) add(e.level, e.ts, e.args)
|
|
1226
|
+
} catch {}
|
|
1227
|
+
return { errors, warnings, total: errors + warnings }
|
|
1228
|
+
})()`;
|
|
1229
|
+
async function clearConsole(bridge) {
|
|
1230
|
+
await bridge.send({
|
|
1231
|
+
type: "evaluate",
|
|
1232
|
+
code: 'window.__sootsimConsole?.clear(); window.__sootsimObservability?.logs?.clear?.(); "cleared"'
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
async function inspectRequests(bridge, opts = {}) {
|
|
1236
|
+
const limit = opts.limit ?? 20;
|
|
1237
|
+
const method = opts.failed === false ? "getRequests" : "getFailedRequests";
|
|
1238
|
+
const result = await bridge.send({
|
|
1239
|
+
type: "call",
|
|
1240
|
+
path: `__sootsimTest.${method}`,
|
|
1241
|
+
args: [limit]
|
|
1242
|
+
});
|
|
1243
|
+
return Array.isArray(result) ? result : [];
|
|
1244
|
+
}
|
|
1245
|
+
async function clearRequests(bridge) {
|
|
1246
|
+
await bridge.send({ type: "call", path: "__sootsimTest.clearRequests", args: [] });
|
|
1247
|
+
}
|
|
1248
|
+
async function inspectScrollStateAt(bridge, x, y) {
|
|
1249
|
+
const result = await bridge.send({
|
|
1250
|
+
type: "call",
|
|
1251
|
+
path: "__sootsimTest.getScrollStateAt",
|
|
1252
|
+
args: [x, y]
|
|
1253
|
+
});
|
|
1254
|
+
if (!result || typeof result !== "object") return null;
|
|
1255
|
+
const state = result;
|
|
1256
|
+
return {
|
|
1257
|
+
...state,
|
|
1258
|
+
scrollOffsetX: typeof state.scrollOffsetX === "number" ? state.scrollOffsetX : state.offsetX,
|
|
1259
|
+
scrollOffsetY: typeof state.scrollOffsetY === "number" ? state.scrollOffsetY : state.offsetY
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1262
|
+
async function inspectLogs(bridge) {
|
|
1263
|
+
const res = await bridge.send({
|
|
1264
|
+
type: "evaluate",
|
|
1265
|
+
code: `(() => {
|
|
1266
|
+
const obs = window.__sootsimObservability;
|
|
1267
|
+
if (!obs) return { ok: false };
|
|
1268
|
+
return { ok: true, entries: obs.logs.getSnapshot() };
|
|
1269
|
+
})()`
|
|
1270
|
+
});
|
|
1271
|
+
if (!res || !res.ok) return [];
|
|
1272
|
+
return res.entries ?? [];
|
|
1273
|
+
}
|
|
1274
|
+
async function clearLogs(bridge) {
|
|
1275
|
+
await bridge.send({
|
|
1276
|
+
type: "evaluate",
|
|
1277
|
+
code: 'window.__sootsimObservability?.logs.clear(); "cleared"'
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
function isForwardedWorkerLogTwin(a, b) {
|
|
1281
|
+
if (a.source === b.source) return false;
|
|
1282
|
+
if (a.level !== b.level) return false;
|
|
1283
|
+
if (Math.abs(a.ts - b.ts) > 1e3) return false;
|
|
1284
|
+
if (a.args.length !== b.args.length) return false;
|
|
1285
|
+
const sources = /* @__PURE__ */ new Set([a.source, b.source]);
|
|
1286
|
+
if (!sources.has("sootsim-worker")) return false;
|
|
1287
|
+
if (!sources.has("render-worker") && !sources.has("forwarded-render-worker")) {
|
|
1288
|
+
return false;
|
|
1289
|
+
}
|
|
1290
|
+
return a.args.every((arg, index) => arg === b.args[index]);
|
|
1291
|
+
}
|
|
1292
|
+
function filterLogEntries(entries, opts = {}) {
|
|
1293
|
+
let out = [];
|
|
1294
|
+
for (const entry of entries) {
|
|
1295
|
+
if (out.some((candidate) => isForwardedWorkerLogTwin(candidate, entry))) {
|
|
1296
|
+
continue;
|
|
1297
|
+
}
|
|
1298
|
+
out.push(entry);
|
|
1299
|
+
}
|
|
1300
|
+
if (!opts.showInternal) {
|
|
1301
|
+
out = out.filter((e) => {
|
|
1302
|
+
const first = e.args[0];
|
|
1303
|
+
return !(typeof first === "string" && first.startsWith("[rnx]"));
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
if (opts.level) out = out.filter((e) => opts.level.has(e.level));
|
|
1307
|
+
if (opts.filter) {
|
|
1308
|
+
const lf = opts.filter.toLowerCase();
|
|
1309
|
+
out = out.filter((e) => e.args.join(" ").toLowerCase().includes(lf));
|
|
1310
|
+
}
|
|
1311
|
+
return out;
|
|
1312
|
+
}
|
|
1313
|
+
async function inspectTimelineSummary(bridge, query) {
|
|
1314
|
+
return await bridge.send({
|
|
1315
|
+
type: "call",
|
|
1316
|
+
path: "SootSim.bridges.timeline.summary",
|
|
1317
|
+
args: [query]
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
async function inspectTimelineRecent(bridge, query) {
|
|
1321
|
+
return await bridge.send({
|
|
1322
|
+
type: "call",
|
|
1323
|
+
path: "SootSim.bridges.timeline.recent",
|
|
1324
|
+
args: [query]
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
async function detectOpenNativeUI(bridge) {
|
|
1328
|
+
let events;
|
|
1329
|
+
try {
|
|
1330
|
+
const res = await inspectTimelineRecent(bridge, {
|
|
1331
|
+
kinds: ["alert", "actionsheet"],
|
|
1332
|
+
limit: 80
|
|
1333
|
+
});
|
|
1334
|
+
events = res.events;
|
|
1335
|
+
} catch {
|
|
1336
|
+
return [];
|
|
1337
|
+
}
|
|
1338
|
+
const latest = /* @__PURE__ */ new Map();
|
|
1339
|
+
for (const ev of events) latest.set(ev.kind, ev);
|
|
1340
|
+
const out = [];
|
|
1341
|
+
const check = (kind, label) => {
|
|
1342
|
+
const ev = latest.get(kind);
|
|
1343
|
+
if (!ev || !ev.data || typeof ev.data !== "object") return;
|
|
1344
|
+
const d = ev.data;
|
|
1345
|
+
if (d.phase !== "show") return;
|
|
1346
|
+
out.push({ label, title: typeof d.title === "string" ? d.title : null });
|
|
1347
|
+
};
|
|
1348
|
+
check("alert", "Alert");
|
|
1349
|
+
check("actionsheet", "ActionSheet");
|
|
1350
|
+
return out;
|
|
1351
|
+
}
|
|
1352
|
+
async function inspectTimelineAdvanceCursor(bridge, cursorKey, watermark) {
|
|
1353
|
+
await bridge.send({
|
|
1354
|
+
type: "call",
|
|
1355
|
+
path: "SootSim.bridges.timeline.cursorAdvance",
|
|
1356
|
+
args: [cursorKey, watermark]
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
async function inspectKeyboard(bridge) {
|
|
1360
|
+
const result = await bridge.send({
|
|
1361
|
+
type: "evaluate",
|
|
1362
|
+
code: `(() => {
|
|
1363
|
+
const kb = window.__sootsimKeyboard
|
|
1364
|
+
if (!kb || typeof kb.getLayout !== 'function') {
|
|
1365
|
+
return { error: 'keyboard bridge getLayout() not available' }
|
|
1366
|
+
}
|
|
1367
|
+
return kb.getLayout()
|
|
1368
|
+
})()`
|
|
1369
|
+
});
|
|
1370
|
+
return result ?? { error: "keyboard bridge returned no result" };
|
|
1371
|
+
}
|
|
1372
|
+
function isShellCommandUnavailable(error) {
|
|
1373
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1374
|
+
return message.includes("call target not found: SootSim.bridges.mainShell") || message.includes("test bridge unavailable before app-in-worker boot");
|
|
1375
|
+
}
|
|
1376
|
+
async function getShellState(bridge, readyTimeoutMs = 0) {
|
|
1377
|
+
const deadline = Date.now() + Math.max(0, readyTimeoutMs);
|
|
1378
|
+
while (true) {
|
|
1379
|
+
try {
|
|
1380
|
+
return await bridge.send({
|
|
1381
|
+
type: "call",
|
|
1382
|
+
path: "SootSim.bridges.mainShell.getState",
|
|
1383
|
+
args: []
|
|
1384
|
+
});
|
|
1385
|
+
} catch (error) {
|
|
1386
|
+
if (!isShellCommandUnavailable(error) || Date.now() >= deadline) throw error;
|
|
1387
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
async function inspectScreens(bridge) {
|
|
1392
|
+
const payload = await bridge.send({
|
|
1393
|
+
type: "evaluate",
|
|
1394
|
+
code: `(async () => {
|
|
1395
|
+
const test = window.__sootsimTest
|
|
1396
|
+
const kb = window.__sootsimKeyboard
|
|
1397
|
+
const navSnap =
|
|
1398
|
+
test && typeof test.getNavigationSnapshot === 'function'
|
|
1399
|
+
? await test.getNavigationSnapshot()
|
|
1400
|
+
: null
|
|
1401
|
+
const route =
|
|
1402
|
+
test && typeof test.getRouteInfo === 'function'
|
|
1403
|
+
? await test.getRouteInfo()
|
|
1404
|
+
: null
|
|
1405
|
+
const keyboard =
|
|
1406
|
+
kb && typeof kb.getLayout === 'function'
|
|
1407
|
+
? (() => {
|
|
1408
|
+
const layout = kb.getLayout()
|
|
1409
|
+
return layout ? {
|
|
1410
|
+
visible: layout.visible,
|
|
1411
|
+
mode: layout.mode,
|
|
1412
|
+
spec: layout.spec
|
|
1413
|
+
? {
|
|
1414
|
+
keyboardType: layout.spec.keyboardType,
|
|
1415
|
+
returnKeyType: layout.spec.returnKeyType,
|
|
1416
|
+
}
|
|
1417
|
+
: null,
|
|
1418
|
+
} : null
|
|
1419
|
+
})()
|
|
1420
|
+
: null
|
|
1421
|
+
return { nav: navSnap, route, keyboard }
|
|
1422
|
+
})()`
|
|
1423
|
+
});
|
|
1424
|
+
const shell = await getShellState(bridge, 500).catch(() => null);
|
|
1425
|
+
return {
|
|
1426
|
+
shell,
|
|
1427
|
+
nav: payload?.nav ?? null,
|
|
1428
|
+
route: payload?.route ?? null,
|
|
1429
|
+
keyboard: payload?.keyboard ?? null
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
var DEBUG_CHANNELS = [
|
|
1433
|
+
"portals",
|
|
1434
|
+
"sheets",
|
|
1435
|
+
"layout",
|
|
1436
|
+
"onlayout",
|
|
1437
|
+
"animated",
|
|
1438
|
+
"render",
|
|
1439
|
+
"touch",
|
|
1440
|
+
"yoga"
|
|
1441
|
+
];
|
|
1442
|
+
async function inspectDebugStatus(bridge) {
|
|
1443
|
+
return bridge.send({ type: "evaluate", code: "window.__sootsimDebug.status()" });
|
|
1444
|
+
}
|
|
1445
|
+
async function inspectDebugFlags(bridge) {
|
|
1446
|
+
return bridge.send({ type: "evaluate", code: "window.__sootsimDebug.flags()" });
|
|
1447
|
+
}
|
|
1448
|
+
async function inspectDebugFind(bridge, target) {
|
|
1449
|
+
return bridge.send({
|
|
1450
|
+
type: "evaluate",
|
|
1451
|
+
code: `window.__sootsimTest.debugFind(${JSON.stringify(target)})`
|
|
1452
|
+
});
|
|
1453
|
+
}
|
|
1454
|
+
async function inspectDebugRecent(bridge, channel, limit = 50) {
|
|
1455
|
+
const code = channel && channel !== "all" ? `window.__sootsimDebug.recent(${JSON.stringify(channel)}, ${limit})` : `window.__sootsimDebug.recent(undefined, ${limit})`;
|
|
1456
|
+
return bridge.send({ type: "evaluate", code });
|
|
1457
|
+
}
|
|
1458
|
+
async function setDebugChannels(bridge, action, channels) {
|
|
1459
|
+
const args = channels.length > 0 ? channels.map((c) => JSON.stringify(c)).join(", ") : action === "disable" ? "'all'" : "";
|
|
1460
|
+
return bridge.send({
|
|
1461
|
+
type: "evaluate",
|
|
1462
|
+
code: `window.__sootsimDebug.${action}(${args})`
|
|
1463
|
+
});
|
|
1464
|
+
}
|
|
1465
|
+
async function inspectMemory(bridge) {
|
|
1466
|
+
const result = await bridge.send({
|
|
1467
|
+
type: "evaluate",
|
|
1468
|
+
code: `(async () => {
|
|
1469
|
+
const host = window.__sootsimRenderHost
|
|
1470
|
+
const stats = host?.queryStats ? await host.queryStats() : null
|
|
1471
|
+
const shellRaw = window.__sootsimShellMemory
|
|
1472
|
+
? await window.__sootsimShellMemory()
|
|
1473
|
+
: null
|
|
1474
|
+
const shell = shellRaw && !shellRaw.error ? shellRaw : null
|
|
1475
|
+
// the compositor paints home + app:one + app:two, so every app-surface
|
|
1476
|
+
// picture and raster image is counted here and nowhere else.
|
|
1477
|
+
let compositor = null
|
|
1478
|
+
try {
|
|
1479
|
+
const cs = await window.__sootsimCompositor?.getStats?.(false, true)
|
|
1480
|
+
compositor = cs?.memory ?? null
|
|
1481
|
+
} catch {}
|
|
1482
|
+
const normalize = (m) =>
|
|
1483
|
+
m
|
|
1484
|
+
? {
|
|
1485
|
+
nodesRegistered: m.nodesRegistered ?? null,
|
|
1486
|
+
nodesDetached: m.nodesDetached ?? null,
|
|
1487
|
+
detachedTypes: m.detachedTypes ?? null,
|
|
1488
|
+
objects: m.objects ?? null,
|
|
1489
|
+
activeNativeAnimations: m.activeNativeAnimations ?? null,
|
|
1490
|
+
imageLoader: m.imageLoader ?? null,
|
|
1491
|
+
workerHeap: m.workerHeap ?? null,
|
|
1492
|
+
wasmHeapBytes: m.wasmHeapBytes ?? null,
|
|
1493
|
+
}
|
|
1494
|
+
: null
|
|
1495
|
+
const hostMem = performance.memory
|
|
1496
|
+
? {
|
|
1497
|
+
usedJSHeapSize: performance.memory.usedJSHeapSize,
|
|
1498
|
+
totalJSHeapSize: performance.memory.totalJSHeapSize,
|
|
1499
|
+
jsHeapSizeLimit: performance.memory.jsHeapSizeLimit,
|
|
1500
|
+
}
|
|
1501
|
+
: null
|
|
1502
|
+
return {
|
|
1503
|
+
tenant: normalize(stats?.memory),
|
|
1504
|
+
shell: normalize(shell),
|
|
1505
|
+
compositor: normalize(compositor),
|
|
1506
|
+
hostHeap: hostMem,
|
|
1507
|
+
}
|
|
1508
|
+
})()`
|
|
1509
|
+
});
|
|
1510
|
+
return result ?? { tenant: null, shell: null, compositor: null, hostHeap: null };
|
|
1511
|
+
}
|
|
1512
|
+
function formatTimelineSummary(summary) {
|
|
1513
|
+
if (summary.total === 0) return "nothing recorded";
|
|
1514
|
+
const parts = [];
|
|
1515
|
+
const ORDER = [
|
|
1516
|
+
"error",
|
|
1517
|
+
"warning",
|
|
1518
|
+
"console",
|
|
1519
|
+
"fetch",
|
|
1520
|
+
"toast",
|
|
1521
|
+
"alert",
|
|
1522
|
+
"actionsheet",
|
|
1523
|
+
"picker",
|
|
1524
|
+
"notification",
|
|
1525
|
+
"screen",
|
|
1526
|
+
"route",
|
|
1527
|
+
"keyboard",
|
|
1528
|
+
"app-launch",
|
|
1529
|
+
"shell",
|
|
1530
|
+
"scroll",
|
|
1531
|
+
"gesture",
|
|
1532
|
+
"text-input",
|
|
1533
|
+
"react-commit",
|
|
1534
|
+
"animation",
|
|
1535
|
+
"reanimated"
|
|
1536
|
+
];
|
|
1537
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1538
|
+
for (const k of ORDER) {
|
|
1539
|
+
const n = summary.byKind[k];
|
|
1540
|
+
if (n) {
|
|
1541
|
+
parts.push(`${n} ${k}${n === 1 ? "" : "s"}`);
|
|
1542
|
+
seen.add(k);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
for (const [k, n] of Object.entries(summary.byKind)) {
|
|
1546
|
+
if (!seen.has(k) && n) parts.push(`${n} ${k}${n === 1 ? "" : "s"}`);
|
|
1547
|
+
}
|
|
1548
|
+
return parts.join(" \xB7 ");
|
|
1549
|
+
}
|
|
1550
|
+
var NOISY_TIMELINE_KINDS = /* @__PURE__ */ new Set([
|
|
1551
|
+
"react-commit",
|
|
1552
|
+
"layout",
|
|
1553
|
+
"scroll"
|
|
1554
|
+
]);
|
|
1555
|
+
function formatTimelineRelativeTime(t, anchor) {
|
|
1556
|
+
if (anchor === null) return new Date(t).toLocaleTimeString();
|
|
1557
|
+
const dt = (t - anchor) / 1e3;
|
|
1558
|
+
const sign = dt >= 0 ? "+" : "";
|
|
1559
|
+
return `${sign}${dt.toFixed(2)}s`;
|
|
1560
|
+
}
|
|
1561
|
+
function formatTimelinePayload(kind, d) {
|
|
1562
|
+
switch (kind) {
|
|
1563
|
+
case "app-launch":
|
|
1564
|
+
return d.phase === "launch" ? `launch ${d.appName ?? d.toAppId ?? ""}` : `dismiss ${d.appName ?? d.fromAppId ?? ""} \u2192 ${d.toAppId ?? ""}`;
|
|
1565
|
+
case "toast":
|
|
1566
|
+
return `"${d.text ?? ""}"${d.durationMs ? ` (${d.durationMs}ms)` : ""}`;
|
|
1567
|
+
case "keyboard":
|
|
1568
|
+
return `${d.phase ?? "?"}${d.heightPx ? ` h=${d.heightPx}` : ""}${d.mode ? ` ${d.mode}` : ""}`;
|
|
1569
|
+
case "screen":
|
|
1570
|
+
return `${d.phase ?? "?"} ${d.name ?? d.activeName ?? ""}`;
|
|
1571
|
+
case "flow-step":
|
|
1572
|
+
return `${d.status ?? "?"} ${d.stepName ?? "step"}${d.durationMs ? ` ${d.durationMs}ms` : ""}`;
|
|
1573
|
+
case "route":
|
|
1574
|
+
return `${d.phase ?? "?"} ${d.path ?? d.pathname ?? ""}`;
|
|
1575
|
+
case "alert":
|
|
1576
|
+
case "actionsheet":
|
|
1577
|
+
case "picker":
|
|
1578
|
+
return `${d.phase ?? "?"} ${d.title ?? d.message ?? ""}`;
|
|
1579
|
+
case "notification":
|
|
1580
|
+
return `${d.title ?? ""}${d.body ? ` \u2014 ${d.body}` : ""}`;
|
|
1581
|
+
case "fetch":
|
|
1582
|
+
return `${d.method ?? "GET"} ${d.url ?? ""}${d.status ? ` -> ${d.status}` : ""}`;
|
|
1583
|
+
case "console":
|
|
1584
|
+
case "console-log":
|
|
1585
|
+
return `${d.level ?? "log"}: ${(d.message ?? "").toString().slice(0, 120)}`;
|
|
1586
|
+
case "shell":
|
|
1587
|
+
return `${d.event ?? d.type ?? d.phase ?? ""}`;
|
|
1588
|
+
case "scroll":
|
|
1589
|
+
return `${d.phase ?? "?"} ${d.target ?? ""}`;
|
|
1590
|
+
case "gesture":
|
|
1591
|
+
return `${d.phase ?? "?"} ${d.type ?? ""}`;
|
|
1592
|
+
case "text-input":
|
|
1593
|
+
return `${d.phase ?? "?"}${d.value !== void 0 ? ` "${String(d.value).slice(0, 40)}"` : ""}`;
|
|
1594
|
+
case "layout":
|
|
1595
|
+
return `${d.kind ?? "?"} ${d.testID ?? d.type ?? ""}${d.skipped ? ` skipped:${d.reason ?? "unknown"}` : ""}`;
|
|
1596
|
+
case "react-commit": {
|
|
1597
|
+
const slowest = d.slowest;
|
|
1598
|
+
return `${d.fiberCount ?? "?"} fibers ${d.durationMs ?? "?"}ms${slowest?.displayName ? ` \xB7 ${slowest.displayName} ${slowest.durationMs ?? "?"}ms` : ""}`;
|
|
1599
|
+
}
|
|
1600
|
+
case "frame":
|
|
1601
|
+
return `${d.totalMs ?? "?"}ms${d.renderMs ? ` \xB7 render ${d.renderMs}ms` : ""}${d.layoutMs ? ` \xB7 layout ${d.layoutMs}ms` : ""}${d.copyMs ? ` \xB7 copy ${d.copyMs}ms` : ""}`;
|
|
1602
|
+
case "reanimated":
|
|
1603
|
+
case "animation":
|
|
1604
|
+
return `${d.kind ?? ""} ${d.target ?? ""}${d.durationMs ? ` ${d.durationMs}ms` : ""}`;
|
|
1605
|
+
}
|
|
1606
|
+
return "";
|
|
1607
|
+
}
|
|
1608
|
+
function formatTimelineEvent(event, anchor) {
|
|
1609
|
+
const ts = formatTimelineRelativeTime(event.t, anchor).padStart(8);
|
|
1610
|
+
const ctx = event.context.padEnd(6);
|
|
1611
|
+
const kind = `[${event.kind}]`.padEnd(15);
|
|
1612
|
+
const d = event.data;
|
|
1613
|
+
const payload = d && typeof d === "object" ? formatTimelinePayload(event.kind, d) : "";
|
|
1614
|
+
return ` ${ts} ${ctx} ${kind} ${payload}`;
|
|
1615
|
+
}
|
|
1616
|
+
function formatTimelineEvents(events) {
|
|
1617
|
+
if (!events.length) return "";
|
|
1618
|
+
const anchor = events[0]?.t ?? null;
|
|
1619
|
+
return events.map((e) => formatTimelineEvent(e, anchor)).join("\n");
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
// cli/commands/inspect/settling.ts
|
|
1623
|
+
async function waitForSootsimIdle({
|
|
1624
|
+
bridge,
|
|
1625
|
+
simId,
|
|
1626
|
+
maxMs,
|
|
1627
|
+
pollMs = 50,
|
|
1628
|
+
stablePolls = 3,
|
|
1629
|
+
strict = false
|
|
1630
|
+
}) {
|
|
1631
|
+
const result = await bridge.send(
|
|
1632
|
+
{
|
|
1633
|
+
type: "evaluate",
|
|
1634
|
+
simId,
|
|
1635
|
+
code: `(async () => {
|
|
1636
|
+
const start = Date.now()
|
|
1637
|
+
const deadline = start + ${Math.max(0, Math.round(maxMs))}
|
|
1638
|
+
const pollMs = ${Math.max(1, Math.round(pollMs))}
|
|
1639
|
+
const requiredStablePolls = ${Math.max(1, Math.round(stablePolls))}
|
|
1640
|
+
const strict = ${strict ? "true" : "false"}
|
|
1641
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
1642
|
+
|
|
1643
|
+
// route-aware settle: a tap that pushes/pops a screen is async \u2014 the
|
|
1644
|
+
// old screen still renders for a moment, then the new one mounts and
|
|
1645
|
+
// its content loads. a pure layout-hash check reports "idle" on the
|
|
1646
|
+
// outgoing screen or on the incoming skeleton, so a driver re-taps
|
|
1647
|
+
// and stacks duplicate navigations. drain any in-flight screen
|
|
1648
|
+
// transition FIRST, bounded by the overall budget. when no
|
|
1649
|
+
// transition is happening this returns in ~80ms (startWindowMs), so
|
|
1650
|
+
// a plain button tap barely pays for it.
|
|
1651
|
+
try {
|
|
1652
|
+
const wfst = window.__sootsimTest?.waitForScreenTransitions
|
|
1653
|
+
if (typeof wfst === 'function') {
|
|
1654
|
+
const remaining = deadline - Date.now()
|
|
1655
|
+
if (remaining > 120) {
|
|
1656
|
+
await wfst({
|
|
1657
|
+
timeoutMs: Math.min(remaining - 80, 4000),
|
|
1658
|
+
settleMs: 64,
|
|
1659
|
+
startWindowMs: 80,
|
|
1660
|
+
})
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
} catch {}
|
|
1664
|
+
|
|
1665
|
+
const readSnapshot = async () => {
|
|
1666
|
+
let animating = false
|
|
1667
|
+
let pendingFetches = 0
|
|
1668
|
+
let requestTotal = 0
|
|
1669
|
+
let requestInFlight = 0
|
|
1670
|
+
try {
|
|
1671
|
+
const stats = await window.__sootsimRenderHost?.queryStats?.()
|
|
1672
|
+
if (stats) {
|
|
1673
|
+
animating =
|
|
1674
|
+
stats.hasActiveAnims === true ||
|
|
1675
|
+
stats.hasActiveNativeAnimations === true ||
|
|
1676
|
+
stats.hasPendingAnimationFrames === true
|
|
1677
|
+
// a freshly-pushed screen showing a skeleton is layout-stable
|
|
1678
|
+
// but not actually settled \u2014 its data/images are still in
|
|
1679
|
+
// flight. treat bounded image-loader fetches as not-idle so
|
|
1680
|
+
// settle waits for real content, capped by the budget.
|
|
1681
|
+
const pf = stats.memory && stats.memory.imageLoader
|
|
1682
|
+
? stats.memory.imageLoader.pendingFetches
|
|
1683
|
+
: 0
|
|
1684
|
+
pendingFetches = typeof pf === 'number' ? pf : 0
|
|
1685
|
+
}
|
|
1686
|
+
} catch {}
|
|
1687
|
+
try {
|
|
1688
|
+
const counts = await window.__sootsimTest?.getRequestCounts?.()
|
|
1689
|
+
requestTotal = typeof counts?.total === 'number' ? counts.total : 0
|
|
1690
|
+
requestInFlight = typeof counts?.inFlight === 'number' ? counts.inFlight : 0
|
|
1691
|
+
} catch {}
|
|
1692
|
+
const root = window.__sootsimRoot
|
|
1693
|
+
const nodes = []
|
|
1694
|
+
if (root) {
|
|
1695
|
+
const walk = (n) => {
|
|
1696
|
+
if (n.layout && n.layout.width > 0) {
|
|
1697
|
+
nodes.push(Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width))
|
|
1698
|
+
}
|
|
1699
|
+
for (const c of n.children || []) walk(c)
|
|
1700
|
+
}
|
|
1701
|
+
walk(root)
|
|
1702
|
+
}
|
|
1703
|
+
return { layout: nodes.join(';'), animating, pendingFetches, requestTotal, requestInFlight }
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
// how long generic background network is allowed to keep us waiting AFTER
|
|
1707
|
+
// the screen is otherwise visually settled. apps with continuous traffic
|
|
1708
|
+
// (polling, realtime sockets, a tap that fires 20-50 fetches) never reach
|
|
1709
|
+
// requestInFlight===0 / a stable requestTotal, so requiring full network
|
|
1710
|
+
// quiet burns the ENTIRE budget on every command \u2014 the leading idle that
|
|
1711
|
+
// failed PR-preview recordings for network-heavy apps (3pc fight-pulse).
|
|
1712
|
+
// layout-stability + the image-loader already prove visible content
|
|
1713
|
+
// loaded (a data load changes layout; an image load shows in the loader),
|
|
1714
|
+
// so the generic request counters are a courtesy, not a gate: honor them
|
|
1715
|
+
// only within this grace once the screen is visually still.
|
|
1716
|
+
const networkQuietGraceMs = 1200
|
|
1717
|
+
let lastLayout = ''
|
|
1718
|
+
let lastRequestTotal = -1
|
|
1719
|
+
let stable = 0
|
|
1720
|
+
let visuallyStillSince = 0
|
|
1721
|
+
while (Date.now() < deadline) {
|
|
1722
|
+
const snapshot = await readSnapshot()
|
|
1723
|
+
const strictOk = !strict || !snapshot.animating
|
|
1724
|
+
// visually settled: no animations, no image content loading, layout
|
|
1725
|
+
// unchanged since the last poll.
|
|
1726
|
+
const visuallyStill =
|
|
1727
|
+
strictOk && snapshot.pendingFetches === 0 && snapshot.layout === lastLayout
|
|
1728
|
+
// generic network quiet: nothing in flight and no new requests issued.
|
|
1729
|
+
const networkQuiet =
|
|
1730
|
+
snapshot.requestInFlight === 0 && snapshot.requestTotal === lastRequestTotal
|
|
1731
|
+
if (visuallyStill) {
|
|
1732
|
+
stable++
|
|
1733
|
+
if (visuallyStillSince === 0) visuallyStillSince = Date.now()
|
|
1734
|
+
// settle once the screen has held still long enough AND either the
|
|
1735
|
+
// network is genuinely quiet OR it has refused to quiet within the
|
|
1736
|
+
// grace (continuous background traffic must not block forever).
|
|
1737
|
+
if (
|
|
1738
|
+
stable >= requiredStablePolls &&
|
|
1739
|
+
(networkQuiet || Date.now() - visuallyStillSince >= networkQuietGraceMs)
|
|
1740
|
+
) {
|
|
1741
|
+
return { settled: true, elapsed: Date.now() - start }
|
|
1742
|
+
}
|
|
1743
|
+
} else {
|
|
1744
|
+
stable = 0
|
|
1745
|
+
visuallyStillSince = 0
|
|
1746
|
+
}
|
|
1747
|
+
lastLayout = snapshot.layout
|
|
1748
|
+
lastRequestTotal = snapshot.requestTotal
|
|
1749
|
+
await sleep(pollMs)
|
|
1750
|
+
}
|
|
1751
|
+
return { settled: false, elapsed: Date.now() - start }
|
|
1752
|
+
})()`
|
|
1753
|
+
},
|
|
1754
|
+
{
|
|
1755
|
+
timeoutMs: maxMs + 1e3
|
|
1756
|
+
}
|
|
1757
|
+
);
|
|
1758
|
+
const { elapsed, settled } = result ?? {};
|
|
1759
|
+
return {
|
|
1760
|
+
elapsed: typeof elapsed === "number" ? elapsed : maxMs,
|
|
1761
|
+
settled: settled === true
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
// cli/commands/inspect/actions.ts
|
|
1766
|
+
var SCREEN_EVAL = `(() => {
|
|
1767
|
+
const spec = window.SootSim?.state?.engineSnapshot?.windowState?.deviceSpec
|
|
1768
|
+
return spec && spec.width > 0 && spec.height > 0
|
|
1769
|
+
? { width: spec.width, height: spec.height }
|
|
1770
|
+
: null
|
|
1771
|
+
})()`;
|
|
1772
|
+
var DEFAULT_AGENT_TIMING = {
|
|
1773
|
+
initialWaitMs: 3e3,
|
|
1774
|
+
deadlineMs: 5e3,
|
|
1775
|
+
retryWaitMs: 700
|
|
1776
|
+
};
|
|
1777
|
+
var DEFAULT_INTERACTIVE_TIMING = {
|
|
1778
|
+
initialWaitMs: 1200,
|
|
1779
|
+
deadlineMs: 2500,
|
|
1780
|
+
retryWaitMs: 700
|
|
1781
|
+
};
|
|
1782
|
+
function tapTiming(agent, opts = {}) {
|
|
1783
|
+
return {
|
|
1784
|
+
...agent ? DEFAULT_AGENT_TIMING : DEFAULT_INTERACTIVE_TIMING,
|
|
1785
|
+
...opts
|
|
1786
|
+
};
|
|
1787
|
+
}
|
|
1788
|
+
function isTapSuccess(result) {
|
|
1789
|
+
if (!result || result.hit === false || result.ok === false) return false;
|
|
1790
|
+
if (result.requestedTargetMatched === false) return false;
|
|
1791
|
+
if (result.pointerTapHandled === false && !result.keyboardOpened && !result.isTextInput) {
|
|
1792
|
+
return false;
|
|
1793
|
+
}
|
|
1794
|
+
return true;
|
|
1795
|
+
}
|
|
1796
|
+
function tapTargetFromPayload(payload, textFallback) {
|
|
1797
|
+
return {
|
|
1798
|
+
nodeId: payload.target?.nodeId ?? payload.match?.nodeId ?? payload.node?.nodeId ?? null,
|
|
1799
|
+
id: payload.target?.id ?? payload.match?.id ?? payload.node?.id ?? null,
|
|
1800
|
+
testID: payload.target?.testID ?? payload.match?.testID ?? payload.node?.testID ?? null,
|
|
1801
|
+
text: payload.target?.text ?? payload.target?.accessibilityLabel ?? payload.match?.text ?? payload.match?.accessibilityLabel ?? payload.node?.text ?? textFallback ?? null,
|
|
1802
|
+
type: payload.target?.type ?? payload.match?.type ?? payload.node?.type ?? null
|
|
1803
|
+
};
|
|
1804
|
+
}
|
|
1805
|
+
async function tapResolvedTarget(bridge, args) {
|
|
1806
|
+
const timing = tapTiming(!!args.agent, args.timing);
|
|
1807
|
+
let attempts = 0;
|
|
1808
|
+
let lastPayload = null;
|
|
1809
|
+
let lastResult = null;
|
|
1810
|
+
try {
|
|
1811
|
+
await waitForSootsimIdle({
|
|
1812
|
+
bridge,
|
|
1813
|
+
maxMs: timing.initialWaitMs,
|
|
1814
|
+
pollMs: 32,
|
|
1815
|
+
stablePolls: 2
|
|
1816
|
+
});
|
|
1817
|
+
} catch {
|
|
1818
|
+
}
|
|
1819
|
+
const deadline = Date.now() + timing.deadlineMs;
|
|
1820
|
+
let lastOffscreenAt = null;
|
|
1821
|
+
while (Date.now() <= deadline || attempts === 0) {
|
|
1822
|
+
attempts++;
|
|
1823
|
+
const payload = await args.resolve();
|
|
1824
|
+
lastPayload = payload;
|
|
1825
|
+
if (payload?.error === "bridge-not-ready" || payload?.ambiguous || payload?.nthOutOfRange) {
|
|
1826
|
+
return { payload, result: null, attempts, failure: "special" };
|
|
1827
|
+
}
|
|
1828
|
+
if (payload && typeof payload.cx === "number" && typeof payload.cy === "number") {
|
|
1829
|
+
if (payload.offscreen) {
|
|
1830
|
+
lastResult = {
|
|
1831
|
+
hit: false,
|
|
1832
|
+
reason: "offscreen",
|
|
1833
|
+
x: payload.cx,
|
|
1834
|
+
y: payload.cy,
|
|
1835
|
+
screen: payload.screen
|
|
1836
|
+
};
|
|
1837
|
+
const at = `${Math.round(payload.cx)},${Math.round(payload.cy)}`;
|
|
1838
|
+
if (lastOffscreenAt === at) {
|
|
1839
|
+
return { payload, result: lastResult, attempts, failure: "missed" };
|
|
1840
|
+
}
|
|
1841
|
+
lastOffscreenAt = at;
|
|
1842
|
+
} else {
|
|
1843
|
+
lastOffscreenAt = null;
|
|
1844
|
+
const requestedTarget = tapTargetFromPayload(payload, args.textFallback);
|
|
1845
|
+
const verification = await bridge.send({
|
|
1846
|
+
type: "evaluate",
|
|
1847
|
+
code: `(async () => {
|
|
1848
|
+
const t = window.__sootsimTest
|
|
1849
|
+
if (
|
|
1850
|
+
!t ||
|
|
1851
|
+
typeof t.inspectAt !== 'function' ||
|
|
1852
|
+
typeof t.resolveTapTarget !== 'function'
|
|
1853
|
+
) {
|
|
1854
|
+
return { error: 'tap-target-inspection-unavailable' }
|
|
1855
|
+
}
|
|
1856
|
+
const requestedTarget = ${JSON.stringify(requestedTarget)}
|
|
1857
|
+
const inspected = await t.inspectAt(${payload.cx}, ${payload.cy})
|
|
1858
|
+
const resolved =
|
|
1859
|
+
inspected && typeof inspected.nodeId === 'number'
|
|
1860
|
+
? await t.resolveTapTarget(inspected.nodeId)
|
|
1861
|
+
: null
|
|
1862
|
+
const node = (resolved && resolved.target) || inspected
|
|
1863
|
+
const coordinateTarget = node
|
|
1864
|
+
? {
|
|
1865
|
+
nodeId: node.nodeId ?? null,
|
|
1866
|
+
id: node.id ?? null,
|
|
1867
|
+
testID: node.testID ?? null,
|
|
1868
|
+
text: node.text ?? node.accessibilityLabel ?? null,
|
|
1869
|
+
type: node.type ?? null,
|
|
1870
|
+
}
|
|
1871
|
+
: null
|
|
1872
|
+
const coordinateAncestors = Array.isArray(inspected?.ancestors)
|
|
1873
|
+
? inspected.ancestors
|
|
1874
|
+
: []
|
|
1875
|
+
const ancestorMatchesRequested = coordinateAncestors.some(
|
|
1876
|
+
(ancestor) =>
|
|
1877
|
+
(typeof requestedTarget.nodeId === 'number' &&
|
|
1878
|
+
ancestor?.nodeId === requestedTarget.nodeId) ||
|
|
1879
|
+
(requestedTarget.testID &&
|
|
1880
|
+
ancestor?.testID === requestedTarget.testID) ||
|
|
1881
|
+
(requestedTarget.id && ancestor?.id === requestedTarget.id),
|
|
1882
|
+
)
|
|
1883
|
+
const requestedTargetMatched =
|
|
1884
|
+
coordinateTarget === null
|
|
1885
|
+
? false
|
|
1886
|
+
: typeof requestedTarget.nodeId === 'number' &&
|
|
1887
|
+
typeof coordinateTarget.nodeId === 'number'
|
|
1888
|
+
? requestedTarget.nodeId === coordinateTarget.nodeId ||
|
|
1889
|
+
ancestorMatchesRequested
|
|
1890
|
+
: requestedTarget.testID && coordinateTarget.testID
|
|
1891
|
+
? requestedTarget.testID === coordinateTarget.testID
|
|
1892
|
+
|| ancestorMatchesRequested
|
|
1893
|
+
: requestedTarget.id && coordinateTarget.id
|
|
1894
|
+
? requestedTarget.id === coordinateTarget.id
|
|
1895
|
+
|| ancestorMatchesRequested
|
|
1896
|
+
: ancestorMatchesRequested
|
|
1897
|
+
if (!requestedTargetMatched) {
|
|
1898
|
+
return {
|
|
1899
|
+
requestedTargetMatched,
|
|
1900
|
+
requestedTarget,
|
|
1901
|
+
coordinateTarget,
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
if (typeof t.activatePressAt !== 'function') {
|
|
1905
|
+
return { error: 'tap-target-activation-unavailable' }
|
|
1906
|
+
}
|
|
1907
|
+
const activation = await t.activatePressAt(
|
|
1908
|
+
${payload.cx},
|
|
1909
|
+
${payload.cy},
|
|
1910
|
+
requestedTarget.nodeId,
|
|
1911
|
+
)
|
|
1912
|
+
if (activation?.ok) {
|
|
1913
|
+
window.dispatchEvent(
|
|
1914
|
+
new CustomEvent('sootsim:agentAction', {
|
|
1915
|
+
detail: {
|
|
1916
|
+
type: 'tap',
|
|
1917
|
+
x: ${payload.cx},
|
|
1918
|
+
y: ${payload.cy},
|
|
1919
|
+
target: requestedTarget,
|
|
1920
|
+
},
|
|
1921
|
+
}),
|
|
1922
|
+
)
|
|
1923
|
+
}
|
|
1924
|
+
return {
|
|
1925
|
+
activation,
|
|
1926
|
+
requestedTargetMatched,
|
|
1927
|
+
requestedTarget,
|
|
1928
|
+
coordinateTarget,
|
|
1929
|
+
}
|
|
1930
|
+
})()`
|
|
1931
|
+
});
|
|
1932
|
+
if (verification?.error) {
|
|
1933
|
+
return {
|
|
1934
|
+
payload,
|
|
1935
|
+
result: {
|
|
1936
|
+
hit: false,
|
|
1937
|
+
reason: verification.error,
|
|
1938
|
+
requestedTarget
|
|
1939
|
+
},
|
|
1940
|
+
attempts,
|
|
1941
|
+
failure: "special"
|
|
1942
|
+
};
|
|
1943
|
+
}
|
|
1944
|
+
if (verification?.requestedTargetMatched === false) {
|
|
1945
|
+
return {
|
|
1946
|
+
payload,
|
|
1947
|
+
result: {
|
|
1948
|
+
hit: false,
|
|
1949
|
+
reason: "target-covered",
|
|
1950
|
+
...verification
|
|
1951
|
+
},
|
|
1952
|
+
attempts,
|
|
1953
|
+
failure: "missed"
|
|
1954
|
+
};
|
|
1955
|
+
}
|
|
1956
|
+
const dispatched = verification?.activation?.tap ?? verification?.activation;
|
|
1957
|
+
const result = dispatched && typeof dispatched === "object" ? { ...dispatched, ...verification?.activation, ...verification } : { hit: !!dispatched, ...verification };
|
|
1958
|
+
lastResult = result;
|
|
1959
|
+
if (isTapSuccess(result)) return { payload, result, attempts };
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
const remaining = deadline - Date.now();
|
|
1963
|
+
if (remaining <= 0) break;
|
|
1964
|
+
try {
|
|
1965
|
+
await waitForSootsimIdle({
|
|
1966
|
+
bridge,
|
|
1967
|
+
maxMs: Math.min(remaining, timing.retryWaitMs),
|
|
1968
|
+
pollMs: 32,
|
|
1969
|
+
stablePolls: 2
|
|
1970
|
+
});
|
|
1971
|
+
} catch {
|
|
1972
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(120, remaining)));
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
return {
|
|
1976
|
+
payload: lastPayload,
|
|
1977
|
+
result: lastResult,
|
|
1978
|
+
attempts,
|
|
1979
|
+
failure: lastPayload && typeof lastPayload.cx === "number" ? "missed" : "not-found"
|
|
1980
|
+
};
|
|
1981
|
+
}
|
|
1982
|
+
async function tapCoordinates(bridge, x, y, target) {
|
|
1983
|
+
return bridge.send({
|
|
1984
|
+
type: "tap",
|
|
1985
|
+
x,
|
|
1986
|
+
y,
|
|
1987
|
+
...target ? { target } : {}
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
async function tapById(bridge, query, opts = {}) {
|
|
1991
|
+
const arg = JSON.stringify(query);
|
|
1992
|
+
return tapResolvedTarget(bridge, {
|
|
1993
|
+
agent: opts.agent,
|
|
1994
|
+
timing: opts.timing,
|
|
1995
|
+
resolve: () => bridge.send({
|
|
1996
|
+
type: "evaluate",
|
|
1997
|
+
code: `(async () => {
|
|
1998
|
+
const t = window.__sootsimTest
|
|
1999
|
+
if (!t) return null
|
|
2000
|
+
const n = (await t.findByTestId(${arg})) || (await t.findById(${arg}))
|
|
2001
|
+
if (!n || !n.absolutePosition || !n.layout) return { cx: null }
|
|
2002
|
+
const resolved =
|
|
2003
|
+
typeof n.nodeId === 'number' && typeof t.resolveTapTarget === 'function'
|
|
2004
|
+
? await t.resolveTapTarget(n.nodeId)
|
|
2005
|
+
: null
|
|
2006
|
+
const target = (resolved && resolved.target) || n
|
|
2007
|
+
const cx =
|
|
2008
|
+
resolved && typeof resolved.cx === 'number'
|
|
2009
|
+
? resolved.cx
|
|
2010
|
+
: n.absolutePosition.x + (n.layout.width || 0) / 2
|
|
2011
|
+
const cy =
|
|
2012
|
+
resolved && typeof resolved.cy === 'number'
|
|
2013
|
+
? resolved.cy
|
|
2014
|
+
: n.absolutePosition.y + (n.layout.height || 0) / 2
|
|
2015
|
+
const scr = ${SCREEN_EVAL}
|
|
2016
|
+
const offscreen =
|
|
2017
|
+
!!scr && (cx < 0 || cy < 0 || cx > scr.width || cy > scr.height)
|
|
2018
|
+
return {
|
|
2019
|
+
cx,
|
|
2020
|
+
cy,
|
|
2021
|
+
...(offscreen ? { offscreen: true, screen: scr } : {}),
|
|
2022
|
+
match: {
|
|
2023
|
+
nodeId: n.nodeId ?? null,
|
|
2024
|
+
id: n.id,
|
|
2025
|
+
testID: n.testID,
|
|
2026
|
+
text: n.text ?? n.accessibilityLabel ?? null,
|
|
2027
|
+
type: n.type,
|
|
2028
|
+
},
|
|
2029
|
+
target: {
|
|
2030
|
+
nodeId: target.nodeId ?? null,
|
|
2031
|
+
id: target.id,
|
|
2032
|
+
testID: target.testID,
|
|
2033
|
+
text:
|
|
2034
|
+
target.text ??
|
|
2035
|
+
target.accessibilityLabel ??
|
|
2036
|
+
n.text ??
|
|
2037
|
+
n.accessibilityLabel ??
|
|
2038
|
+
null,
|
|
2039
|
+
type: target.type,
|
|
2040
|
+
},
|
|
2041
|
+
strategy: (resolved && resolved.strategy) || 'matched-node',
|
|
2042
|
+
}
|
|
2043
|
+
})()`
|
|
2044
|
+
})
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
async function tapByText(bridge, query, options = {}, opts = {}) {
|
|
2048
|
+
const filterArg = JSON.stringify({
|
|
2049
|
+
query,
|
|
2050
|
+
exact: !!options.exact,
|
|
2051
|
+
role: options.role ?? null,
|
|
2052
|
+
within: options.within ?? null,
|
|
2053
|
+
minX: options.minX ?? null,
|
|
2054
|
+
maxX: options.maxX ?? null,
|
|
2055
|
+
minY: options.minY ?? null,
|
|
2056
|
+
maxY: options.maxY ?? null,
|
|
2057
|
+
near: options.near ?? null,
|
|
2058
|
+
nth: options.nth ?? null,
|
|
2059
|
+
first: !!options.first
|
|
2060
|
+
});
|
|
2061
|
+
return tapResolvedTarget(bridge, {
|
|
2062
|
+
agent: opts.agent,
|
|
2063
|
+
timing: opts.timing,
|
|
2064
|
+
textFallback: query,
|
|
2065
|
+
resolve: () => bridge.send({
|
|
2066
|
+
type: "evaluate",
|
|
2067
|
+
code: `(async () => {
|
|
2068
|
+
const t = window.__sootsimTest
|
|
2069
|
+
if (!t) return { error: 'bridge-not-ready' }
|
|
2070
|
+
const F = ${filterArg}
|
|
2071
|
+
|
|
2072
|
+
const res = await t.queryTextCandidates({
|
|
2073
|
+
query: F.query,
|
|
2074
|
+
exact: !!F.exact,
|
|
2075
|
+
...(F.role ? { role: F.role } : {}),
|
|
2076
|
+
})
|
|
2077
|
+
|
|
2078
|
+
let candidates = res.candidates || []
|
|
2079
|
+
|
|
2080
|
+
candidates = candidates.filter((c) => {
|
|
2081
|
+
const ax = c.info.absolutePosition && c.info.absolutePosition.x
|
|
2082
|
+
const ay = c.info.absolutePosition && c.info.absolutePosition.y
|
|
2083
|
+
if (F.minX !== null && !(ax >= F.minX)) return false
|
|
2084
|
+
if (F.maxX !== null && !(ax <= F.maxX)) return false
|
|
2085
|
+
if (F.minY !== null && !(ay >= F.minY)) return false
|
|
2086
|
+
if (F.maxY !== null && !(ay <= F.maxY)) return false
|
|
2087
|
+
if (F.within && !c.ancestorTestIDs.includes(F.within)) return false
|
|
2088
|
+
return true
|
|
2089
|
+
})
|
|
2090
|
+
|
|
2091
|
+
if (F.near) {
|
|
2092
|
+
candidates.sort((a, b) => {
|
|
2093
|
+
const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
|
|
2094
|
+
const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
|
|
2095
|
+
const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
|
|
2096
|
+
const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
|
|
2097
|
+
return (
|
|
2098
|
+
Math.hypot(ax - F.near.x, ay - F.near.y) -
|
|
2099
|
+
Math.hypot(bx - F.near.x, by - F.near.y)
|
|
2100
|
+
)
|
|
2101
|
+
})
|
|
2102
|
+
} else {
|
|
2103
|
+
candidates.sort((a, b) => {
|
|
2104
|
+
const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
|
|
2105
|
+
const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
|
|
2106
|
+
if (Math.abs(ay - by) > 2) return ay - by
|
|
2107
|
+
const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
|
|
2108
|
+
const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
|
|
2109
|
+
return ax - bx
|
|
2110
|
+
})
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
const total = candidates.length
|
|
2114
|
+
if (total === 0) return { matched: 0, total: 0 }
|
|
2115
|
+
|
|
2116
|
+
let idx = 0
|
|
2117
|
+
if (F.nth !== null) {
|
|
2118
|
+
idx = F.nth < 0 ? total + F.nth : F.nth
|
|
2119
|
+
if (idx < 0 || idx >= total) {
|
|
2120
|
+
return { matched: 0, total, nthOutOfRange: true, nth: F.nth }
|
|
2121
|
+
}
|
|
2122
|
+
} else if (total > 1 && !F.first && !F.near) {
|
|
2123
|
+
return {
|
|
2124
|
+
ambiguous: true,
|
|
2125
|
+
total,
|
|
2126
|
+
candidates: candidates.slice(0, 10).map((c, i) => ({
|
|
2127
|
+
idx: i,
|
|
2128
|
+
nodeId: c.info.nodeId,
|
|
2129
|
+
type: c.info.type,
|
|
2130
|
+
testID: c.info.testID,
|
|
2131
|
+
text: (c.info.text || '').slice(0, 60),
|
|
2132
|
+
abs: c.info.absolutePosition,
|
|
2133
|
+
layout: c.info.layout
|
|
2134
|
+
? {
|
|
2135
|
+
width: Math.round(c.info.layout.width || 0),
|
|
2136
|
+
height: Math.round(c.info.layout.height || 0),
|
|
2137
|
+
}
|
|
2138
|
+
: null,
|
|
2139
|
+
ancestorTestIDs: (c.ancestorTestIDs || []).slice(0, 5),
|
|
2140
|
+
})),
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
const picked = candidates[idx]
|
|
2145
|
+
const n = picked.info
|
|
2146
|
+
if (!n.absolutePosition || !n.layout) return { matched: 0, total }
|
|
2147
|
+
|
|
2148
|
+
const resolved =
|
|
2149
|
+
typeof n.nodeId === 'number' &&
|
|
2150
|
+
typeof t.resolveTapTarget === 'function'
|
|
2151
|
+
? await t.resolveTapTarget(n.nodeId)
|
|
2152
|
+
: null
|
|
2153
|
+
const target = (resolved && resolved.target) || n
|
|
2154
|
+
const cx =
|
|
2155
|
+
resolved && typeof resolved.cx === 'number'
|
|
2156
|
+
? resolved.cx
|
|
2157
|
+
: n.absolutePosition.x + (n.layout.width || 0) / 2
|
|
2158
|
+
const cy =
|
|
2159
|
+
resolved && typeof resolved.cy === 'number'
|
|
2160
|
+
? resolved.cy
|
|
2161
|
+
: n.absolutePosition.y + (n.layout.height || 0) / 2
|
|
2162
|
+
const scr = ${SCREEN_EVAL}
|
|
2163
|
+
const offscreen =
|
|
2164
|
+
!!scr && (cx < 0 || cy < 0 || cx > scr.width || cy > scr.height)
|
|
2165
|
+
return {
|
|
2166
|
+
cx,
|
|
2167
|
+
cy,
|
|
2168
|
+
...(offscreen ? { offscreen: true, screen: scr } : {}),
|
|
2169
|
+
match: {
|
|
2170
|
+
nodeId: n.nodeId ?? null,
|
|
2171
|
+
id: n.id,
|
|
2172
|
+
testID: n.testID,
|
|
2173
|
+
type: n.type,
|
|
2174
|
+
},
|
|
2175
|
+
target: {
|
|
2176
|
+
nodeId: target.nodeId ?? null,
|
|
2177
|
+
id: target.id,
|
|
2178
|
+
testID: target.testID,
|
|
2179
|
+
text:
|
|
2180
|
+
target.text ??
|
|
2181
|
+
target.accessibilityLabel ??
|
|
2182
|
+
n.text ??
|
|
2183
|
+
n.accessibilityLabel ??
|
|
2184
|
+
null,
|
|
2185
|
+
type: target.type,
|
|
2186
|
+
},
|
|
2187
|
+
strategy: (resolved && resolved.strategy) || 'matched-node',
|
|
2188
|
+
total,
|
|
2189
|
+
idx,
|
|
2190
|
+
}
|
|
2191
|
+
})()`
|
|
2192
|
+
})
|
|
2193
|
+
});
|
|
2194
|
+
}
|
|
2195
|
+
async function tapBest(bridge, query, opts = {}) {
|
|
2196
|
+
const arg = JSON.stringify(query);
|
|
2197
|
+
return tapResolvedTarget(bridge, {
|
|
2198
|
+
agent: opts.agent,
|
|
2199
|
+
timing: opts.timing,
|
|
2200
|
+
textFallback: query,
|
|
2201
|
+
resolve: async () => {
|
|
2202
|
+
const payload = await bridge.send({
|
|
2203
|
+
type: "evaluate",
|
|
2204
|
+
code: `(async () => {
|
|
2205
|
+
const t = window.__sootsimTest
|
|
2206
|
+
if (!t) return { error: 'bridge-not-ready' }
|
|
2207
|
+
const byTestId =
|
|
2208
|
+
(await t.findByTestId(${arg})) || (await t.findById(${arg}))
|
|
2209
|
+
if (byTestId && byTestId.absolutePosition && byTestId.layout) {
|
|
2210
|
+
return {
|
|
2211
|
+
strategy: 'testid',
|
|
2212
|
+
node: {
|
|
2213
|
+
nodeId: byTestId.nodeId ?? null,
|
|
2214
|
+
id: byTestId.id,
|
|
2215
|
+
testID: byTestId.testID,
|
|
2216
|
+
type: byTestId.type,
|
|
2217
|
+
text: byTestId.text,
|
|
2218
|
+
absolutePosition: byTestId.absolutePosition,
|
|
2219
|
+
layout: byTestId.layout,
|
|
2220
|
+
},
|
|
2221
|
+
screen: ${SCREEN_EVAL},
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
const byText = await t.findByText(${arg})
|
|
2225
|
+
if (byText && byText.absolutePosition && byText.layout) {
|
|
2226
|
+
return {
|
|
2227
|
+
strategy: 'text',
|
|
2228
|
+
node: {
|
|
2229
|
+
nodeId: byText.nodeId ?? null,
|
|
2230
|
+
id: byText.id,
|
|
2231
|
+
testID: byText.testID,
|
|
2232
|
+
type: byText.type,
|
|
2233
|
+
text: byText.text,
|
|
2234
|
+
absolutePosition: byText.absolutePosition,
|
|
2235
|
+
layout: byText.layout,
|
|
2236
|
+
},
|
|
2237
|
+
screen: ${SCREEN_EVAL},
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
return { strategy: 'none' }
|
|
2241
|
+
})()`
|
|
2242
|
+
});
|
|
2243
|
+
if (!payload || !("node" in payload)) return payload;
|
|
2244
|
+
const node = payload.node;
|
|
2245
|
+
const cx = node.absolutePosition.x + node.layout.width / 2;
|
|
2246
|
+
const cy = node.absolutePosition.y + node.layout.height / 2;
|
|
2247
|
+
const screen = payload.screen ?? null;
|
|
2248
|
+
const offscreen = !!screen && (cx < 0 || cy < 0 || cx > screen.width || cy > screen.height);
|
|
2249
|
+
return {
|
|
2250
|
+
...payload,
|
|
2251
|
+
cx,
|
|
2252
|
+
cy,
|
|
2253
|
+
...offscreen ? { offscreen: true, screen } : {},
|
|
2254
|
+
target: {
|
|
2255
|
+
id: node.id,
|
|
2256
|
+
testID: node.testID,
|
|
2257
|
+
text: payload.strategy === "text" ? query : node.text,
|
|
2258
|
+
type: node.type
|
|
2259
|
+
}
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2265
|
+
0 && (module.exports = {
|
|
2266
|
+
DEBUG_CHANNELS,
|
|
2267
|
+
LAYOUT_GET_NATIVE_EVAL,
|
|
2268
|
+
MERGED_CONSOLE_COUNT_EVAL,
|
|
2269
|
+
NOISY_TIMELINE_KINDS,
|
|
2270
|
+
READY_CONTENT_NODE_FLOOR,
|
|
2271
|
+
READY_NODE_STABLE_MS,
|
|
2272
|
+
READY_PROBE_POLL_MS,
|
|
2273
|
+
WAIT_READY_PROBE,
|
|
2274
|
+
WAIT_READY_PROGRESS_INTERVAL_MS,
|
|
2275
|
+
clearConsole,
|
|
2276
|
+
clearLogs,
|
|
2277
|
+
clearRequests,
|
|
2278
|
+
detectOpenNativeUI,
|
|
2279
|
+
filterLogEntries,
|
|
2280
|
+
formatLayoutElements,
|
|
2281
|
+
formatTimelineEvent,
|
|
2282
|
+
formatTimelineEvents,
|
|
2283
|
+
formatTimelinePayload,
|
|
2284
|
+
formatTimelineSummary,
|
|
2285
|
+
getShellState,
|
|
2286
|
+
inspectAccessibilityTree,
|
|
2287
|
+
inspectDebugFind,
|
|
2288
|
+
inspectDebugFlags,
|
|
2289
|
+
inspectDebugRecent,
|
|
2290
|
+
inspectDebugStatus,
|
|
2291
|
+
inspectDescribe,
|
|
2292
|
+
inspectErrors,
|
|
2293
|
+
inspectFind,
|
|
2294
|
+
inspectGetLayout,
|
|
2295
|
+
inspectKeyboard,
|
|
2296
|
+
inspectLogs,
|
|
2297
|
+
inspectMemory,
|
|
2298
|
+
inspectNodeCount,
|
|
2299
|
+
inspectRequests,
|
|
2300
|
+
inspectScreens,
|
|
2301
|
+
inspectScrollStateAt,
|
|
2302
|
+
inspectTimelineAdvanceCursor,
|
|
2303
|
+
inspectTimelineRecent,
|
|
2304
|
+
inspectTimelineSummary,
|
|
2305
|
+
inspectTree,
|
|
2306
|
+
inspectUrl,
|
|
2307
|
+
inspectWaitReady,
|
|
2308
|
+
inspectWaitSelector,
|
|
2309
|
+
inspectWarnings,
|
|
2310
|
+
isInspectModeActive,
|
|
2311
|
+
isInspectPickCommand,
|
|
2312
|
+
isShellCommandUnavailable,
|
|
2313
|
+
isTapSuccess,
|
|
2314
|
+
layoutGetNativeEval,
|
|
2315
|
+
rankInteractive,
|
|
2316
|
+
readyProbeHasContent,
|
|
2317
|
+
readyProbeHasTargetContent,
|
|
2318
|
+
resolveFindMode,
|
|
2319
|
+
resolveMaxMsFlag,
|
|
2320
|
+
scoreInteractive,
|
|
2321
|
+
scoreLayoutTextContrast,
|
|
2322
|
+
setDebugChannels,
|
|
2323
|
+
shouldSkipAutoSettleForInspectPick,
|
|
2324
|
+
tapBest,
|
|
2325
|
+
tapById,
|
|
2326
|
+
tapByText,
|
|
2327
|
+
tapCommandForNode,
|
|
2328
|
+
tapCoordinates,
|
|
2329
|
+
tapResolvedTarget,
|
|
2330
|
+
tapTargetFromPayload,
|
|
2331
|
+
waitForSootsimIdle,
|
|
2332
|
+
waitReadyReason
|
|
2333
|
+
});
|