rnxsim 0.1.417 → 0.1.418
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/cli/cloud-client.ts +104 -32
- package/cli/cloud-dispatch.ts +38 -4
- package/cli/commands/inspect/actions.ts +313 -385
- package/cli/commands/inspect/core.ts +6 -0
- package/cli/commands/inspect/resolve-target.ts +2 -3
- package/cli/commands/inspect/settle.ts +10 -0
- package/cli/commands/inspect.ts +31 -48
- package/cli/commands/platform.ts +41 -10
- package/cli/outbound-endpoints.ts +1 -1
- package/cli/shell-init.ts +1 -1
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.cjs +1 -1
- package/dist-lib/agent-sessions.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/detox/index.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +1 -1
- package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +626 -749
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1206 -1342
- package/dist-lib/sdk.mjs +1206 -1342
- package/dist-lib/skills.cjs +57 -1
- package/dist-lib/vite.cjs +1 -1
- package/package.json +1 -1
package/dist-lib/sdk.mjs
CHANGED
|
@@ -1,658 +1,8 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.418 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
|
|
6
|
-
// cli/commands/inspect/settling.ts
|
|
7
|
-
async function waitForSootsimIdle({
|
|
8
|
-
bridge,
|
|
9
|
-
simId,
|
|
10
|
-
maxMs,
|
|
11
|
-
pollMs = 50,
|
|
12
|
-
stablePolls = 3,
|
|
13
|
-
strict = false
|
|
14
|
-
}) {
|
|
15
|
-
const result = await bridge.send(
|
|
16
|
-
{
|
|
17
|
-
type: "evaluate",
|
|
18
|
-
simId,
|
|
19
|
-
code: `(async () => {
|
|
20
|
-
const start = Date.now()
|
|
21
|
-
const deadline = start + ${Math.max(0, Math.round(maxMs))}
|
|
22
|
-
const pollMs = ${Math.max(1, Math.round(pollMs))}
|
|
23
|
-
const requiredStablePolls = ${Math.max(1, Math.round(stablePolls))}
|
|
24
|
-
const strict = ${strict ? "true" : "false"}
|
|
25
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
26
|
-
|
|
27
|
-
// route-aware settle: a tap that pushes/pops a screen is async \u2014 the
|
|
28
|
-
// old screen still renders for a moment, then the new one mounts and
|
|
29
|
-
// its content loads. a pure layout-hash check reports "idle" on the
|
|
30
|
-
// outgoing screen or on the incoming skeleton, so a driver re-taps
|
|
31
|
-
// and stacks duplicate navigations. drain any in-flight screen
|
|
32
|
-
// transition FIRST, bounded by the overall budget. when no
|
|
33
|
-
// transition is happening this returns in ~80ms (startWindowMs), so
|
|
34
|
-
// a plain button tap barely pays for it.
|
|
35
|
-
try {
|
|
36
|
-
const wfst = window.__sootsimTest?.waitForScreenTransitions
|
|
37
|
-
if (typeof wfst === 'function') {
|
|
38
|
-
const remaining = deadline - Date.now()
|
|
39
|
-
if (remaining > 120) {
|
|
40
|
-
await wfst({
|
|
41
|
-
timeoutMs: Math.min(remaining - 80, 4000),
|
|
42
|
-
settleMs: 64,
|
|
43
|
-
startWindowMs: 80,
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
} catch {}
|
|
48
|
-
|
|
49
|
-
const readSnapshot = async () => {
|
|
50
|
-
let animating = false
|
|
51
|
-
let layoutDirty = false
|
|
52
|
-
let pendingFetches = 0
|
|
53
|
-
let requestTotal = 0
|
|
54
|
-
let requestInFlight = 0
|
|
55
|
-
let renderStatsAvailable = false
|
|
56
|
-
try {
|
|
57
|
-
const stats = await window.__sootsimRenderHost?.queryStats?.()
|
|
58
|
-
if (stats) {
|
|
59
|
-
renderStatsAvailable = true
|
|
60
|
-
animating =
|
|
61
|
-
stats.hasActiveAnims === true ||
|
|
62
|
-
stats.hasActiveNativeAnimations === true ||
|
|
63
|
-
stats.hasPendingAnimationFrames === true
|
|
64
|
-
layoutDirty =
|
|
65
|
-
stats.layoutDirty === true && stats.renderRequested === true
|
|
66
|
-
// a freshly-pushed screen showing a skeleton is layout-stable
|
|
67
|
-
// but not actually settled \u2014 its data/images are still in
|
|
68
|
-
// flight. treat bounded image-loader fetches as not-idle so
|
|
69
|
-
// settle waits for real content, capped by the budget.
|
|
70
|
-
const pf = stats.memory && stats.memory.imageLoader
|
|
71
|
-
? stats.memory.imageLoader.pendingFetches
|
|
72
|
-
: 0
|
|
73
|
-
pendingFetches = typeof pf === 'number' ? pf : 0
|
|
74
|
-
}
|
|
75
|
-
} catch {}
|
|
76
|
-
try {
|
|
77
|
-
const counts = await window.__sootsimTest?.getRequestCounts?.()
|
|
78
|
-
requestTotal = typeof counts?.total === 'number' ? counts.total : 0
|
|
79
|
-
requestInFlight = typeof counts?.inFlight === 'number' ? counts.inFlight : 0
|
|
80
|
-
} catch {}
|
|
81
|
-
const root = window.__sootsimRoot
|
|
82
|
-
const nodes = []
|
|
83
|
-
if (root) {
|
|
84
|
-
const walk = (n) => {
|
|
85
|
-
if (n.layout && n.layout.width > 0) {
|
|
86
|
-
nodes.push(Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width))
|
|
87
|
-
}
|
|
88
|
-
for (const c of n.children || []) walk(c)
|
|
89
|
-
}
|
|
90
|
-
walk(root)
|
|
91
|
-
}
|
|
92
|
-
return { layout: nodes.join(';'), animating, layoutDirty, pendingFetches, renderStatsAvailable, requestTotal, requestInFlight }
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// how long generic background network is allowed to keep us waiting AFTER
|
|
96
|
-
// the screen is otherwise visually settled. apps with continuous traffic
|
|
97
|
-
// (polling, realtime sockets, a tap that fires 20-50 fetches) never reach
|
|
98
|
-
// requestInFlight===0 / a stable requestTotal, so requiring full network
|
|
99
|
-
// quiet burns the ENTIRE budget on every command \u2014 the leading idle that
|
|
100
|
-
// failed PR-preview recordings for network-heavy apps (3pc fight-pulse).
|
|
101
|
-
// layout-stability + the image-loader already prove visible content
|
|
102
|
-
// loaded (a data load changes layout; an image load shows in the loader),
|
|
103
|
-
// so the generic request counters are a courtesy, not a gate: honor them
|
|
104
|
-
// only within this grace once the screen is visually still.
|
|
105
|
-
const networkQuietGraceMs = 1200
|
|
106
|
-
let lastLayout = ''
|
|
107
|
-
let lastRequestTotal = -1
|
|
108
|
-
let stable = 0
|
|
109
|
-
let visuallyStillSince = 0
|
|
110
|
-
while (Date.now() < deadline) {
|
|
111
|
-
const snapshot = await readSnapshot()
|
|
112
|
-
const strictOk =
|
|
113
|
-
!strict ||
|
|
114
|
-
(snapshot.renderStatsAvailable && !snapshot.animating && !snapshot.layoutDirty)
|
|
115
|
-
// visually settled: no animations, no image content loading, layout
|
|
116
|
-
// unchanged since the last poll.
|
|
117
|
-
const visuallyStill =
|
|
118
|
-
strictOk && snapshot.pendingFetches === 0 && snapshot.layout === lastLayout
|
|
119
|
-
// generic network quiet: nothing in flight and no new requests issued.
|
|
120
|
-
const networkQuiet =
|
|
121
|
-
snapshot.requestInFlight === 0 && snapshot.requestTotal === lastRequestTotal
|
|
122
|
-
if (visuallyStill) {
|
|
123
|
-
stable++
|
|
124
|
-
if (visuallyStillSince === 0) visuallyStillSince = Date.now()
|
|
125
|
-
// settle once the screen has held still long enough AND either the
|
|
126
|
-
// network is genuinely quiet OR it has refused to quiet within the
|
|
127
|
-
// grace (continuous background traffic must not block forever).
|
|
128
|
-
if (
|
|
129
|
-
stable >= requiredStablePolls &&
|
|
130
|
-
(networkQuiet || Date.now() - visuallyStillSince >= networkQuietGraceMs)
|
|
131
|
-
) {
|
|
132
|
-
return { settled: true, elapsed: Date.now() - start }
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
stable = 0
|
|
136
|
-
visuallyStillSince = 0
|
|
137
|
-
}
|
|
138
|
-
lastLayout = snapshot.layout
|
|
139
|
-
lastRequestTotal = snapshot.requestTotal
|
|
140
|
-
await sleep(pollMs)
|
|
141
|
-
}
|
|
142
|
-
return { settled: false, elapsed: Date.now() - start }
|
|
143
|
-
})()`
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
timeoutMs: maxMs + 1e3
|
|
147
|
-
}
|
|
148
|
-
);
|
|
149
|
-
const { elapsed, settled } = result ?? {};
|
|
150
|
-
return {
|
|
151
|
-
elapsed: typeof elapsed === "number" ? elapsed : maxMs,
|
|
152
|
-
settled: settled === true
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// cli/commands/inspect/actions.ts
|
|
157
|
-
var SCREEN_EVAL = `(() => {
|
|
158
|
-
const spec = window.SootSim?.state?.engineSnapshot?.windowState?.deviceSpec
|
|
159
|
-
return spec && spec.width > 0 && spec.height > 0
|
|
160
|
-
? { width: spec.width, height: spec.height }
|
|
161
|
-
: null
|
|
162
|
-
})()`;
|
|
163
|
-
var DEFAULT_AGENT_TIMING = {
|
|
164
|
-
initialWaitMs: 3e3,
|
|
165
|
-
deadlineMs: 5e3,
|
|
166
|
-
retryWaitMs: 700
|
|
167
|
-
};
|
|
168
|
-
var DEFAULT_INTERACTIVE_TIMING = {
|
|
169
|
-
initialWaitMs: 1200,
|
|
170
|
-
deadlineMs: 2500,
|
|
171
|
-
retryWaitMs: 700
|
|
172
|
-
};
|
|
173
|
-
function tapTiming(agent, opts = {}) {
|
|
174
|
-
return {
|
|
175
|
-
...agent ? DEFAULT_AGENT_TIMING : DEFAULT_INTERACTIVE_TIMING,
|
|
176
|
-
...opts
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
function isTapSuccess(result) {
|
|
180
|
-
if (!result || result.hit === false || result.ok === false) return false;
|
|
181
|
-
if (result.requestedTargetMatched === false) return false;
|
|
182
|
-
if (result.pointerTapHandled === false && !result.keyboardOpened && !result.isTextInput) {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
return true;
|
|
186
|
-
}
|
|
187
|
-
function tapTargetFromPayload(payload, textFallback) {
|
|
188
|
-
return {
|
|
189
|
-
nodeId: payload.target?.nodeId ?? payload.match?.nodeId ?? payload.node?.nodeId ?? null,
|
|
190
|
-
id: payload.target?.id ?? payload.match?.id ?? payload.node?.id ?? null,
|
|
191
|
-
testID: payload.target?.testID ?? payload.match?.testID ?? payload.node?.testID ?? null,
|
|
192
|
-
text: payload.target?.text ?? payload.target?.accessibilityLabel ?? payload.match?.text ?? payload.match?.accessibilityLabel ?? payload.node?.text ?? textFallback ?? null,
|
|
193
|
-
type: payload.target?.type ?? payload.match?.type ?? payload.node?.type ?? null
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
async function tapResolvedTarget(bridge, args) {
|
|
197
|
-
const timing = tapTiming(!!args.agent, args.timing);
|
|
198
|
-
let attempts = 0;
|
|
199
|
-
let lastPayload = null;
|
|
200
|
-
let lastResult = null;
|
|
201
|
-
try {
|
|
202
|
-
await waitForSootsimIdle({
|
|
203
|
-
bridge,
|
|
204
|
-
maxMs: timing.initialWaitMs,
|
|
205
|
-
pollMs: 32,
|
|
206
|
-
stablePolls: 2
|
|
207
|
-
});
|
|
208
|
-
} catch {
|
|
209
|
-
}
|
|
210
|
-
const deadline = Date.now() + timing.deadlineMs;
|
|
211
|
-
let lastOffscreenAt = null;
|
|
212
|
-
while (Date.now() <= deadline || attempts === 0) {
|
|
213
|
-
attempts++;
|
|
214
|
-
const payload = await args.resolve();
|
|
215
|
-
lastPayload = payload;
|
|
216
|
-
if (payload?.error === "bridge-not-ready" || payload?.ambiguous || payload?.nthOutOfRange) {
|
|
217
|
-
return { payload, result: null, attempts, failure: "special" };
|
|
218
|
-
}
|
|
219
|
-
if (payload && typeof payload.cx === "number" && typeof payload.cy === "number") {
|
|
220
|
-
if (payload.offscreen) {
|
|
221
|
-
lastResult = {
|
|
222
|
-
hit: false,
|
|
223
|
-
reason: "offscreen",
|
|
224
|
-
x: payload.cx,
|
|
225
|
-
y: payload.cy,
|
|
226
|
-
screen: payload.screen
|
|
227
|
-
};
|
|
228
|
-
const at = `${Math.round(payload.cx)},${Math.round(payload.cy)}`;
|
|
229
|
-
if (lastOffscreenAt === at) {
|
|
230
|
-
return { payload, result: lastResult, attempts, failure: "missed" };
|
|
231
|
-
}
|
|
232
|
-
lastOffscreenAt = at;
|
|
233
|
-
} else {
|
|
234
|
-
lastOffscreenAt = null;
|
|
235
|
-
const requestedTarget = tapTargetFromPayload(payload, args.textFallback);
|
|
236
|
-
const verification = await bridge.send({
|
|
237
|
-
type: "evaluate",
|
|
238
|
-
code: `(async () => {
|
|
239
|
-
const t = window.__sootsimTest
|
|
240
|
-
if (
|
|
241
|
-
!t ||
|
|
242
|
-
typeof t.inspectAt !== 'function' ||
|
|
243
|
-
typeof t.resolveTapTarget !== 'function'
|
|
244
|
-
) {
|
|
245
|
-
return { error: 'tap-target-inspection-unavailable' }
|
|
246
|
-
}
|
|
247
|
-
const requestedTarget = ${JSON.stringify(requestedTarget)}
|
|
248
|
-
const inspected = await t.inspectAt(${payload.cx}, ${payload.cy})
|
|
249
|
-
const resolved =
|
|
250
|
-
inspected && typeof inspected.nodeId === 'number'
|
|
251
|
-
? await t.resolveTapTarget(inspected.nodeId)
|
|
252
|
-
: null
|
|
253
|
-
const node = (resolved && resolved.target) || inspected
|
|
254
|
-
const coordinateTarget = node
|
|
255
|
-
? {
|
|
256
|
-
nodeId: node.nodeId ?? null,
|
|
257
|
-
id: node.id ?? null,
|
|
258
|
-
testID: node.testID ?? null,
|
|
259
|
-
text: node.text ?? node.accessibilityLabel ?? null,
|
|
260
|
-
type: node.type ?? null,
|
|
261
|
-
}
|
|
262
|
-
: null
|
|
263
|
-
const coordinateAncestors = Array.isArray(inspected?.ancestors)
|
|
264
|
-
? inspected.ancestors
|
|
265
|
-
: []
|
|
266
|
-
const ancestorMatchesRequested = coordinateAncestors.some(
|
|
267
|
-
(ancestor) =>
|
|
268
|
-
(typeof requestedTarget.nodeId === 'number' &&
|
|
269
|
-
ancestor?.nodeId === requestedTarget.nodeId) ||
|
|
270
|
-
(requestedTarget.testID &&
|
|
271
|
-
ancestor?.testID === requestedTarget.testID) ||
|
|
272
|
-
(requestedTarget.id && ancestor?.id === requestedTarget.id),
|
|
273
|
-
)
|
|
274
|
-
const requestedTargetMatched =
|
|
275
|
-
coordinateTarget === null
|
|
276
|
-
? false
|
|
277
|
-
: typeof requestedTarget.nodeId === 'number' &&
|
|
278
|
-
typeof coordinateTarget.nodeId === 'number'
|
|
279
|
-
? requestedTarget.nodeId === coordinateTarget.nodeId ||
|
|
280
|
-
ancestorMatchesRequested
|
|
281
|
-
: requestedTarget.testID && coordinateTarget.testID
|
|
282
|
-
? requestedTarget.testID === coordinateTarget.testID
|
|
283
|
-
|| ancestorMatchesRequested
|
|
284
|
-
: requestedTarget.id && coordinateTarget.id
|
|
285
|
-
? requestedTarget.id === coordinateTarget.id
|
|
286
|
-
|| ancestorMatchesRequested
|
|
287
|
-
: ancestorMatchesRequested
|
|
288
|
-
if (!requestedTargetMatched) {
|
|
289
|
-
return {
|
|
290
|
-
requestedTargetMatched,
|
|
291
|
-
requestedTarget,
|
|
292
|
-
coordinateTarget,
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if (typeof t.activatePressAt !== 'function') {
|
|
296
|
-
return { error: 'tap-target-activation-unavailable' }
|
|
297
|
-
}
|
|
298
|
-
const activation = await t.activatePressAt(
|
|
299
|
-
${payload.cx},
|
|
300
|
-
${payload.cy},
|
|
301
|
-
requestedTarget.nodeId,
|
|
302
|
-
)
|
|
303
|
-
if (activation?.ok) {
|
|
304
|
-
window.dispatchEvent(
|
|
305
|
-
new CustomEvent('sootsim:agentAction', {
|
|
306
|
-
detail: {
|
|
307
|
-
type: 'tap',
|
|
308
|
-
x: ${payload.cx},
|
|
309
|
-
y: ${payload.cy},
|
|
310
|
-
target: requestedTarget,
|
|
311
|
-
},
|
|
312
|
-
}),
|
|
313
|
-
)
|
|
314
|
-
}
|
|
315
|
-
return {
|
|
316
|
-
activation,
|
|
317
|
-
requestedTargetMatched,
|
|
318
|
-
requestedTarget,
|
|
319
|
-
coordinateTarget,
|
|
320
|
-
}
|
|
321
|
-
})()`
|
|
322
|
-
});
|
|
323
|
-
if (verification?.error) {
|
|
324
|
-
return {
|
|
325
|
-
payload,
|
|
326
|
-
result: {
|
|
327
|
-
hit: false,
|
|
328
|
-
reason: verification.error,
|
|
329
|
-
requestedTarget
|
|
330
|
-
},
|
|
331
|
-
attempts,
|
|
332
|
-
failure: "special"
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
if (verification?.requestedTargetMatched === false) {
|
|
336
|
-
return {
|
|
337
|
-
payload,
|
|
338
|
-
result: {
|
|
339
|
-
hit: false,
|
|
340
|
-
reason: "target-covered",
|
|
341
|
-
...verification
|
|
342
|
-
},
|
|
343
|
-
attempts,
|
|
344
|
-
failure: "missed"
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
const dispatched = verification?.activation?.tap ?? verification?.activation;
|
|
348
|
-
const result = dispatched && typeof dispatched === "object" ? { ...dispatched, ...verification?.activation, ...verification } : { hit: !!dispatched, ...verification };
|
|
349
|
-
lastResult = result;
|
|
350
|
-
if (isTapSuccess(result)) return { payload, result, attempts };
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
const remaining = deadline - Date.now();
|
|
354
|
-
if (remaining <= 0) break;
|
|
355
|
-
try {
|
|
356
|
-
await waitForSootsimIdle({
|
|
357
|
-
bridge,
|
|
358
|
-
maxMs: Math.min(remaining, timing.retryWaitMs),
|
|
359
|
-
pollMs: 32,
|
|
360
|
-
stablePolls: 2
|
|
361
|
-
});
|
|
362
|
-
} catch {
|
|
363
|
-
await new Promise((resolve) => setTimeout(resolve, Math.min(120, remaining)));
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
return {
|
|
367
|
-
payload: lastPayload,
|
|
368
|
-
result: lastResult,
|
|
369
|
-
attempts,
|
|
370
|
-
failure: lastPayload && typeof lastPayload.cx === "number" ? "missed" : "not-found"
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
async function tapCoordinates(bridge, x, y, target) {
|
|
374
|
-
return bridge.send({
|
|
375
|
-
type: "tap",
|
|
376
|
-
x,
|
|
377
|
-
y,
|
|
378
|
-
...target ? { target } : {}
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
async function tapById(bridge, query, opts = {}) {
|
|
382
|
-
const arg = JSON.stringify(query);
|
|
383
|
-
return tapResolvedTarget(bridge, {
|
|
384
|
-
agent: opts.agent,
|
|
385
|
-
timing: opts.timing,
|
|
386
|
-
resolve: () => bridge.send({
|
|
387
|
-
type: "evaluate",
|
|
388
|
-
code: `(async () => {
|
|
389
|
-
const t = window.__sootsimTest
|
|
390
|
-
if (!t) return null
|
|
391
|
-
const n = (await t.findByTestId(${arg})) || (await t.findById(${arg}))
|
|
392
|
-
if (!n || !n.absolutePosition || !n.layout) return { cx: null }
|
|
393
|
-
const resolved =
|
|
394
|
-
typeof n.nodeId === 'number' && typeof t.resolveTapTarget === 'function'
|
|
395
|
-
? await t.resolveTapTarget(n.nodeId)
|
|
396
|
-
: null
|
|
397
|
-
const target = (resolved && resolved.target) || n
|
|
398
|
-
const cx =
|
|
399
|
-
resolved && typeof resolved.cx === 'number'
|
|
400
|
-
? resolved.cx
|
|
401
|
-
: n.absolutePosition.x + (n.layout.width || 0) / 2
|
|
402
|
-
const cy =
|
|
403
|
-
resolved && typeof resolved.cy === 'number'
|
|
404
|
-
? resolved.cy
|
|
405
|
-
: n.absolutePosition.y + (n.layout.height || 0) / 2
|
|
406
|
-
const scr = ${SCREEN_EVAL}
|
|
407
|
-
const offscreen =
|
|
408
|
-
!!scr && (cx < 0 || cy < 0 || cx > scr.width || cy > scr.height)
|
|
409
|
-
return {
|
|
410
|
-
cx,
|
|
411
|
-
cy,
|
|
412
|
-
...(offscreen ? { offscreen: true, screen: scr } : {}),
|
|
413
|
-
match: {
|
|
414
|
-
nodeId: n.nodeId ?? null,
|
|
415
|
-
id: n.id,
|
|
416
|
-
testID: n.testID,
|
|
417
|
-
text: n.text ?? n.accessibilityLabel ?? null,
|
|
418
|
-
type: n.type,
|
|
419
|
-
},
|
|
420
|
-
target: {
|
|
421
|
-
nodeId: target.nodeId ?? null,
|
|
422
|
-
id: target.id,
|
|
423
|
-
testID: target.testID,
|
|
424
|
-
text:
|
|
425
|
-
target.text ??
|
|
426
|
-
target.accessibilityLabel ??
|
|
427
|
-
n.text ??
|
|
428
|
-
n.accessibilityLabel ??
|
|
429
|
-
null,
|
|
430
|
-
type: target.type,
|
|
431
|
-
},
|
|
432
|
-
strategy: (resolved && resolved.strategy) || 'matched-node',
|
|
433
|
-
}
|
|
434
|
-
})()`
|
|
435
|
-
})
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
async function tapByText(bridge, query, options = {}, opts = {}) {
|
|
439
|
-
const filterArg = JSON.stringify({
|
|
440
|
-
query,
|
|
441
|
-
exact: !!options.exact,
|
|
442
|
-
role: options.role ?? null,
|
|
443
|
-
within: options.within ?? null,
|
|
444
|
-
minX: options.minX ?? null,
|
|
445
|
-
maxX: options.maxX ?? null,
|
|
446
|
-
minY: options.minY ?? null,
|
|
447
|
-
maxY: options.maxY ?? null,
|
|
448
|
-
near: options.near ?? null,
|
|
449
|
-
nth: options.nth ?? null,
|
|
450
|
-
first: !!options.first
|
|
451
|
-
});
|
|
452
|
-
return tapResolvedTarget(bridge, {
|
|
453
|
-
agent: opts.agent,
|
|
454
|
-
timing: opts.timing,
|
|
455
|
-
textFallback: query,
|
|
456
|
-
resolve: () => bridge.send({
|
|
457
|
-
type: "evaluate",
|
|
458
|
-
code: `(async () => {
|
|
459
|
-
const t = window.__sootsimTest
|
|
460
|
-
if (!t) return { error: 'bridge-not-ready' }
|
|
461
|
-
const F = ${filterArg}
|
|
462
|
-
|
|
463
|
-
const res = await t.queryTextCandidates({
|
|
464
|
-
query: F.query,
|
|
465
|
-
exact: !!F.exact,
|
|
466
|
-
...(F.role ? { role: F.role } : {}),
|
|
467
|
-
})
|
|
468
|
-
|
|
469
|
-
let candidates = res.candidates || []
|
|
470
|
-
|
|
471
|
-
candidates = candidates.filter((c) => {
|
|
472
|
-
const ax = c.info.absolutePosition && c.info.absolutePosition.x
|
|
473
|
-
const ay = c.info.absolutePosition && c.info.absolutePosition.y
|
|
474
|
-
if (F.minX !== null && !(ax >= F.minX)) return false
|
|
475
|
-
if (F.maxX !== null && !(ax <= F.maxX)) return false
|
|
476
|
-
if (F.minY !== null && !(ay >= F.minY)) return false
|
|
477
|
-
if (F.maxY !== null && !(ay <= F.maxY)) return false
|
|
478
|
-
if (F.within && !c.ancestorTestIDs.includes(F.within)) return false
|
|
479
|
-
return true
|
|
480
|
-
})
|
|
481
|
-
|
|
482
|
-
if (F.near) {
|
|
483
|
-
candidates.sort((a, b) => {
|
|
484
|
-
const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
|
|
485
|
-
const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
|
|
486
|
-
const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
|
|
487
|
-
const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
|
|
488
|
-
return (
|
|
489
|
-
Math.hypot(ax - F.near.x, ay - F.near.y) -
|
|
490
|
-
Math.hypot(bx - F.near.x, by - F.near.y)
|
|
491
|
-
)
|
|
492
|
-
})
|
|
493
|
-
} else {
|
|
494
|
-
candidates.sort((a, b) => {
|
|
495
|
-
const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
|
|
496
|
-
const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
|
|
497
|
-
if (Math.abs(ay - by) > 2) return ay - by
|
|
498
|
-
const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
|
|
499
|
-
const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
|
|
500
|
-
return ax - bx
|
|
501
|
-
})
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
const total = candidates.length
|
|
505
|
-
if (total === 0) return { matched: 0, total: 0 }
|
|
506
|
-
|
|
507
|
-
let idx = 0
|
|
508
|
-
if (F.nth !== null) {
|
|
509
|
-
idx = F.nth < 0 ? total + F.nth : F.nth
|
|
510
|
-
if (idx < 0 || idx >= total) {
|
|
511
|
-
return { matched: 0, total, nthOutOfRange: true, nth: F.nth }
|
|
512
|
-
}
|
|
513
|
-
} else if (total > 1 && !F.first && !F.near) {
|
|
514
|
-
return {
|
|
515
|
-
ambiguous: true,
|
|
516
|
-
total,
|
|
517
|
-
candidates: candidates.slice(0, 10).map((c, i) => ({
|
|
518
|
-
idx: i,
|
|
519
|
-
nodeId: c.info.nodeId,
|
|
520
|
-
type: c.info.type,
|
|
521
|
-
testID: c.info.testID,
|
|
522
|
-
text: (c.info.text || '').slice(0, 60),
|
|
523
|
-
abs: c.info.absolutePosition,
|
|
524
|
-
layout: c.info.layout
|
|
525
|
-
? {
|
|
526
|
-
width: Math.round(c.info.layout.width || 0),
|
|
527
|
-
height: Math.round(c.info.layout.height || 0),
|
|
528
|
-
}
|
|
529
|
-
: null,
|
|
530
|
-
ancestorTestIDs: (c.ancestorTestIDs || []).slice(0, 5),
|
|
531
|
-
})),
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
const picked = candidates[idx]
|
|
536
|
-
const n = picked.info
|
|
537
|
-
if (!n.absolutePosition || !n.layout) return { matched: 0, total }
|
|
538
|
-
|
|
539
|
-
const resolved =
|
|
540
|
-
typeof n.nodeId === 'number' &&
|
|
541
|
-
typeof t.resolveTapTarget === 'function'
|
|
542
|
-
? await t.resolveTapTarget(n.nodeId)
|
|
543
|
-
: null
|
|
544
|
-
const target = (resolved && resolved.target) || n
|
|
545
|
-
const cx =
|
|
546
|
-
resolved && typeof resolved.cx === 'number'
|
|
547
|
-
? resolved.cx
|
|
548
|
-
: n.absolutePosition.x + (n.layout.width || 0) / 2
|
|
549
|
-
const cy =
|
|
550
|
-
resolved && typeof resolved.cy === 'number'
|
|
551
|
-
? resolved.cy
|
|
552
|
-
: n.absolutePosition.y + (n.layout.height || 0) / 2
|
|
553
|
-
const scr = ${SCREEN_EVAL}
|
|
554
|
-
const offscreen =
|
|
555
|
-
!!scr && (cx < 0 || cy < 0 || cx > scr.width || cy > scr.height)
|
|
556
|
-
return {
|
|
557
|
-
cx,
|
|
558
|
-
cy,
|
|
559
|
-
...(offscreen ? { offscreen: true, screen: scr } : {}),
|
|
560
|
-
match: {
|
|
561
|
-
nodeId: n.nodeId ?? null,
|
|
562
|
-
id: n.id,
|
|
563
|
-
testID: n.testID,
|
|
564
|
-
type: n.type,
|
|
565
|
-
},
|
|
566
|
-
target: {
|
|
567
|
-
nodeId: target.nodeId ?? null,
|
|
568
|
-
id: target.id,
|
|
569
|
-
testID: target.testID,
|
|
570
|
-
text:
|
|
571
|
-
target.text ??
|
|
572
|
-
target.accessibilityLabel ??
|
|
573
|
-
n.text ??
|
|
574
|
-
n.accessibilityLabel ??
|
|
575
|
-
null,
|
|
576
|
-
type: target.type,
|
|
577
|
-
},
|
|
578
|
-
strategy: (resolved && resolved.strategy) || 'matched-node',
|
|
579
|
-
total,
|
|
580
|
-
idx,
|
|
581
|
-
}
|
|
582
|
-
})()`
|
|
583
|
-
})
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
async function tapBest(bridge, query, opts = {}) {
|
|
587
|
-
const arg = JSON.stringify(query);
|
|
588
|
-
return tapResolvedTarget(bridge, {
|
|
589
|
-
agent: opts.agent,
|
|
590
|
-
timing: opts.timing,
|
|
591
|
-
textFallback: query,
|
|
592
|
-
resolve: async () => {
|
|
593
|
-
const payload = await bridge.send({
|
|
594
|
-
type: "evaluate",
|
|
595
|
-
code: `(async () => {
|
|
596
|
-
const t = window.__sootsimTest
|
|
597
|
-
if (!t) return { error: 'bridge-not-ready' }
|
|
598
|
-
const byTestId =
|
|
599
|
-
(await t.findByTestId(${arg})) || (await t.findById(${arg}))
|
|
600
|
-
if (byTestId && byTestId.absolutePosition && byTestId.layout) {
|
|
601
|
-
return {
|
|
602
|
-
strategy: 'testid',
|
|
603
|
-
node: {
|
|
604
|
-
nodeId: byTestId.nodeId ?? null,
|
|
605
|
-
id: byTestId.id,
|
|
606
|
-
testID: byTestId.testID,
|
|
607
|
-
type: byTestId.type,
|
|
608
|
-
text: byTestId.text,
|
|
609
|
-
absolutePosition: byTestId.absolutePosition,
|
|
610
|
-
layout: byTestId.layout,
|
|
611
|
-
},
|
|
612
|
-
screen: ${SCREEN_EVAL},
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
const byText = await t.findByText(${arg})
|
|
616
|
-
if (byText && byText.absolutePosition && byText.layout) {
|
|
617
|
-
return {
|
|
618
|
-
strategy: 'text',
|
|
619
|
-
node: {
|
|
620
|
-
nodeId: byText.nodeId ?? null,
|
|
621
|
-
id: byText.id,
|
|
622
|
-
testID: byText.testID,
|
|
623
|
-
type: byText.type,
|
|
624
|
-
text: byText.text,
|
|
625
|
-
absolutePosition: byText.absolutePosition,
|
|
626
|
-
layout: byText.layout,
|
|
627
|
-
},
|
|
628
|
-
screen: ${SCREEN_EVAL},
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
return { strategy: 'none' }
|
|
632
|
-
})()`
|
|
633
|
-
});
|
|
634
|
-
if (!payload || !("node" in payload)) return payload;
|
|
635
|
-
const node = payload.node;
|
|
636
|
-
const cx = node.absolutePosition.x + node.layout.width / 2;
|
|
637
|
-
const cy = node.absolutePosition.y + node.layout.height / 2;
|
|
638
|
-
const screen = payload.screen ?? null;
|
|
639
|
-
const offscreen = !!screen && (cx < 0 || cy < 0 || cx > screen.width || cy > screen.height);
|
|
640
|
-
return {
|
|
641
|
-
...payload,
|
|
642
|
-
cx,
|
|
643
|
-
cy,
|
|
644
|
-
...offscreen ? { offscreen: true, screen } : {},
|
|
645
|
-
target: {
|
|
646
|
-
id: node.id,
|
|
647
|
-
testID: node.testID,
|
|
648
|
-
text: payload.strategy === "text" ? query : node.text,
|
|
649
|
-
type: node.type
|
|
650
|
-
}
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
|
|
656
6
|
// src/bridge-contract.ts
|
|
657
7
|
var SEMANTIC_READY_CONTENT_NODE_FLOOR = 100;
|
|
658
8
|
function readyProbeHasContent(probe) {
|
|
@@ -1119,778 +469,1292 @@ async function inspectGetLayout(bridge, opts = {}) {
|
|
|
1119
469
|
w: Math.round(node.geometry.width),
|
|
1120
470
|
h: Math.round(node.geometry.height)
|
|
1121
471
|
}
|
|
1122
|
-
}));
|
|
472
|
+
}));
|
|
473
|
+
}
|
|
474
|
+
const raw = await bridge.send({
|
|
475
|
+
type: "evaluate",
|
|
476
|
+
code: layoutGetNativeEval(opts)
|
|
477
|
+
});
|
|
478
|
+
return Array.isArray(raw) ? raw : [];
|
|
479
|
+
}
|
|
480
|
+
function formatLayoutElements(elements, opts) {
|
|
481
|
+
if (elements.length === 0) return " no visible elements found";
|
|
482
|
+
const lines = elements.map((el) => {
|
|
483
|
+
const ident = el.testID ? `#${el.testID}` : el.selector ? el.selector : el.role ? `[${el.role}]` : `<${el.type}>`;
|
|
484
|
+
const parts = [ident, `@(${el.box.x},${el.box.y})`, `${el.box.w}x${el.box.h}`];
|
|
485
|
+
if (el.borderRadius !== void 0 && el.borderRadius > 0) {
|
|
486
|
+
parts.push(`radius:${el.borderRadius}`);
|
|
487
|
+
}
|
|
488
|
+
const p = el.padding;
|
|
489
|
+
if (p && (p.t || p.r || p.b || p.l)) {
|
|
490
|
+
const uniform = p.t === p.r && p.r === p.b && p.b === p.l;
|
|
491
|
+
parts.push(uniform ? `pad:${p.t}` : `pad:${p.t},${p.r},${p.b},${p.l}`);
|
|
492
|
+
}
|
|
493
|
+
if (el.fontSize !== void 0 && el.fontSize > 0) {
|
|
494
|
+
parts.push(`font:${el.fontSize}`);
|
|
495
|
+
}
|
|
496
|
+
if (opts?.styling) {
|
|
497
|
+
if (el.fontWeight) parts.push(`weight:${el.fontWeight}`);
|
|
498
|
+
if (el.color) parts.push(`color:${el.color}`);
|
|
499
|
+
if (el.bg) parts.push(`bg:${el.bg}`);
|
|
500
|
+
if (el.contrast) {
|
|
501
|
+
const score = el.contrast.ratio == null ? `?/${el.contrast.required}` : `${el.contrast.ratio}/${el.contrast.required}${el.contrast.ratio < el.contrast.required ? " FAIL" : ""}`;
|
|
502
|
+
parts.push(`contrast:${score}`);
|
|
503
|
+
if (el.contrast.background) parts.push(`on:${el.contrast.background}`);
|
|
504
|
+
}
|
|
505
|
+
if (el.opacity != null) parts.push(`opacity:${el.opacity}`);
|
|
506
|
+
if (el.textDecoration) parts.push(`deco:${el.textDecoration}`);
|
|
507
|
+
if (el.overflow) parts.push(`overflow:${el.overflow}`);
|
|
508
|
+
if (el.borderWidth) {
|
|
509
|
+
parts.push(
|
|
510
|
+
el.borderColor ? `border:${el.borderWidth}/${el.borderColor}` : `border:${el.borderWidth}`
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
if (el.text) {
|
|
515
|
+
const text = el.text.length > 40 ? `${el.text.slice(0, 39)}\u2026` : el.text;
|
|
516
|
+
parts.push(`"${text}"`);
|
|
517
|
+
}
|
|
518
|
+
return ` ${parts.join(" ")}`;
|
|
519
|
+
});
|
|
520
|
+
return lines.join("\n");
|
|
521
|
+
}
|
|
522
|
+
async function inspectAccessibilityTree(bridge) {
|
|
523
|
+
const result = await bridge.send({
|
|
524
|
+
type: "query",
|
|
525
|
+
query: { kind: "find", selector: { visible: true } }
|
|
526
|
+
});
|
|
527
|
+
if (!isSemanticQueryResult(result)) return [];
|
|
528
|
+
return result.nodes.flatMap((node) => {
|
|
529
|
+
if (!node.role && !node.label && !node.text && !node.pressable) return [];
|
|
530
|
+
return [
|
|
531
|
+
{
|
|
532
|
+
role: node.role ?? (node.pressable ? "button" : node.type === "text" ? "statictext" : "none"),
|
|
533
|
+
label: node.label ?? node.text ?? null,
|
|
534
|
+
hint: null,
|
|
535
|
+
state: null,
|
|
536
|
+
testID: node.testID ?? null,
|
|
537
|
+
position: {
|
|
538
|
+
x: Math.round(node.geometry.x),
|
|
539
|
+
y: Math.round(node.geometry.y)
|
|
540
|
+
},
|
|
541
|
+
size: {
|
|
542
|
+
w: Math.round(node.geometry.width),
|
|
543
|
+
h: Math.round(node.geometry.height)
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
];
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
function resolveFindMode(q) {
|
|
550
|
+
if (q.testId) {
|
|
551
|
+
return { mode: "testid", selector: { testID: q.testId } };
|
|
552
|
+
}
|
|
553
|
+
if (q.role) {
|
|
554
|
+
return { mode: "role", selector: { role: q.role } };
|
|
555
|
+
}
|
|
556
|
+
if (q.type) {
|
|
557
|
+
return { mode: "type", selector: { type: q.type } };
|
|
558
|
+
}
|
|
559
|
+
if (q.pressable) {
|
|
560
|
+
return { mode: "pressable", selector: { pressable: true } };
|
|
561
|
+
}
|
|
562
|
+
if (q.interactive) {
|
|
563
|
+
return { mode: "interactive-targets", selector: { pressable: true } };
|
|
564
|
+
}
|
|
565
|
+
if (q.visible) {
|
|
566
|
+
return { mode: "visible", selector: { visible: true } };
|
|
567
|
+
}
|
|
568
|
+
if (q.text) {
|
|
569
|
+
return { mode: "text", selector: { text: q.text } };
|
|
570
|
+
}
|
|
571
|
+
return null;
|
|
572
|
+
}
|
|
573
|
+
async function inspectFind(bridge, q) {
|
|
574
|
+
const resolved = resolveFindMode(q);
|
|
575
|
+
if (!resolved) return null;
|
|
576
|
+
const result = await bridge.send({
|
|
577
|
+
type: "query",
|
|
578
|
+
query: { kind: "find", selector: resolved.selector }
|
|
579
|
+
});
|
|
580
|
+
if (!isSemanticQueryResult(result)) return { mode: resolved.mode, result: [] };
|
|
581
|
+
const nodes = result.nodes.map(
|
|
582
|
+
(node) => ({
|
|
583
|
+
type: node.type,
|
|
584
|
+
nodeId: node.nodeId,
|
|
585
|
+
...node.testID ? { testID: node.testID } : {},
|
|
586
|
+
...node.text ? { text: node.text } : {},
|
|
587
|
+
...node.pressable ? { pressable: true } : {},
|
|
588
|
+
...node.role ? { accessibilityRole: node.role } : {},
|
|
589
|
+
...node.label ? { accessibilityLabel: node.label } : {},
|
|
590
|
+
absolutePosition: { x: node.geometry.x, y: node.geometry.y },
|
|
591
|
+
layout: { width: node.geometry.width, height: node.geometry.height }
|
|
592
|
+
})
|
|
593
|
+
);
|
|
594
|
+
const resultValue = resolved.mode === "testid" || resolved.mode === "text" ? nodes[0] ?? null : nodes;
|
|
595
|
+
return { mode: resolved.mode, result: resultValue };
|
|
596
|
+
}
|
|
597
|
+
function rankInteractive(nodes) {
|
|
598
|
+
return [...nodes].sort((a, b) => scoreInteractive(b) - scoreInteractive(a));
|
|
599
|
+
}
|
|
600
|
+
function scoreInteractive(n) {
|
|
601
|
+
let score = 0;
|
|
602
|
+
if (n.testID) score += 100;
|
|
603
|
+
if (typeof n.text === "string" && n.text.trim().length > 0) score += 60;
|
|
604
|
+
if (typeof n.accessibilityLabel === "string" && n.accessibilityLabel.trim().length > 0) {
|
|
605
|
+
score += 30;
|
|
606
|
+
}
|
|
607
|
+
if (n.accessibilityRole) score += 15;
|
|
608
|
+
const w = n.layout?.width ?? 0;
|
|
609
|
+
const h = n.layout?.height ?? 0;
|
|
610
|
+
const area = w * h;
|
|
611
|
+
if (area >= 400 && area <= 6e4) score += 25;
|
|
612
|
+
else if (area > 6e4) score -= 20;
|
|
613
|
+
const y = n.absolutePosition?.y ?? 0;
|
|
614
|
+
if (y < 0) score -= 30;
|
|
615
|
+
return score;
|
|
616
|
+
}
|
|
617
|
+
function tapCommandForNode(n) {
|
|
618
|
+
if (n.testID) return `rnx do tap-id ${shellEscape(n.testID)}`;
|
|
619
|
+
const text = typeof n.text === "string" ? n.text.trim() : "";
|
|
620
|
+
if (text.length > 0 && text.length <= 80) return `rnx do tap-text ${shellEscape(text)}`;
|
|
621
|
+
const x = Math.round(((n.absolutePosition?.x ?? 0) + (n.layout?.width ?? 0) / 2) * 10) / 10;
|
|
622
|
+
const y = Math.round(((n.absolutePosition?.y ?? 0) + (n.layout?.height ?? 0) / 2) * 10) / 10;
|
|
623
|
+
return `rnx do tap ${x} ${y}`;
|
|
624
|
+
}
|
|
625
|
+
function shellEscape(value) {
|
|
626
|
+
if (/^[A-Za-z0-9_./@:-]+$/.test(value)) return value;
|
|
627
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
628
|
+
}
|
|
629
|
+
function waitReadyReason(status) {
|
|
630
|
+
if (status.bridgeError) {
|
|
631
|
+
if (status.bridgeError.includes("headless tenant fetch hung") || status.bridgeError.includes("public RNX Cloud simulators have no network")) {
|
|
632
|
+
return status.bridgeError;
|
|
633
|
+
}
|
|
634
|
+
return `sim unreachable: ${status.bridgeError} \u2014 the target tab is closed or no sim is connected (check \`rnx list\`, reopen with \`rnx open\`)`;
|
|
635
|
+
}
|
|
636
|
+
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";
|
|
637
|
+
return !status.externalError && status.suppressedEntryError ? `${base} (suppressed entry error: ${status.suppressedEntryError})` : base;
|
|
638
|
+
}
|
|
639
|
+
async function inspectWaitReady(bridge, timeoutMs = 2e4, options = {}) {
|
|
640
|
+
const start = Date.now();
|
|
641
|
+
let result;
|
|
642
|
+
try {
|
|
643
|
+
result = await bridge.send(
|
|
644
|
+
{
|
|
645
|
+
type: "waitFor",
|
|
646
|
+
waitForOptions: { condition: { type: "ready" }, timeoutMs }
|
|
647
|
+
},
|
|
648
|
+
{ timeoutMs: timeoutMs + 1e3 }
|
|
649
|
+
);
|
|
650
|
+
} catch (error) {
|
|
651
|
+
const bridgeError = error instanceof Error ? error.message : String(error);
|
|
652
|
+
if (bridgeError.startsWith("multiple sims are connected:") || bridgeError.startsWith("saved sim ")) {
|
|
653
|
+
throw error;
|
|
654
|
+
}
|
|
655
|
+
result = {
|
|
656
|
+
matched: false,
|
|
657
|
+
elapsedMs: Date.now() - start,
|
|
658
|
+
polls: 0,
|
|
659
|
+
error: bridgeError
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
const probe = result.probe;
|
|
663
|
+
const externalError = probe?.externalError ?? "";
|
|
664
|
+
const status = {
|
|
665
|
+
ready: result.matched && !externalError,
|
|
666
|
+
elapsedMs: result.elapsedMs,
|
|
667
|
+
nodes: probe?.nodes ?? 0,
|
|
668
|
+
targets: probe?.targets ?? 0,
|
|
669
|
+
liveFrameActive: probe?.liveFrameActive ?? false,
|
|
670
|
+
liveFrameChannels: probe?.liveFrameChannels ?? 0,
|
|
671
|
+
liveFramePublishes: probe?.liveFramePublishes ?? 0,
|
|
672
|
+
flag: probe?.flag,
|
|
673
|
+
loadingText: probe?.loadingText ?? "",
|
|
674
|
+
externalReady: probe?.externalReady ?? null,
|
|
675
|
+
externalStatus: probe?.externalStatus ?? "",
|
|
676
|
+
externalError,
|
|
677
|
+
suppressedEntryError: probe?.suppressedEntryError ?? "",
|
|
678
|
+
errors: probe?.errors ?? 0,
|
|
679
|
+
bridgeError: result.error ?? ""
|
|
680
|
+
};
|
|
681
|
+
if (!status.ready && options.onProgress) options.onProgress(status);
|
|
682
|
+
return status;
|
|
683
|
+
}
|
|
684
|
+
async function inspectWaitSelector(bridge, testId, timeoutMs = 5e3, opts = {}) {
|
|
685
|
+
const gone = opts.gone === true;
|
|
686
|
+
const result = await bridge.send(
|
|
687
|
+
{
|
|
688
|
+
type: "waitFor",
|
|
689
|
+
waitForOptions: {
|
|
690
|
+
condition: {
|
|
691
|
+
type: gone ? "absent" : "present",
|
|
692
|
+
selector: { testID: testId }
|
|
693
|
+
},
|
|
694
|
+
timeoutMs
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
{ timeoutMs: timeoutMs + 1e3 }
|
|
698
|
+
);
|
|
699
|
+
if (result?.error) throw new Error(result.error);
|
|
700
|
+
if (result?.node && !isSimSemanticTree([result.node])) {
|
|
701
|
+
throw new Error("waitFor returned an invalid semantic node");
|
|
1123
702
|
}
|
|
1124
|
-
|
|
703
|
+
return {
|
|
704
|
+
found: result?.matched === true,
|
|
705
|
+
...result?.node ? { node: result.node } : {},
|
|
706
|
+
elapsed: result?.elapsedMs ?? timeoutMs
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
function consoleEntriesEval(level, limit) {
|
|
710
|
+
const getter = level === "error" ? "getErrors" : "getWarnings";
|
|
711
|
+
return `(() => {
|
|
712
|
+
const out = []
|
|
713
|
+
const seen = new Set()
|
|
714
|
+
const norm = (s) => (typeof s === 'string' ? s : (() => { try { return JSON.stringify(s) } catch { return String(s) } })())
|
|
715
|
+
const key = (ts, args) => Math.round((ts || 0) / 250) + '|' + (Array.isArray(args) ? args.map(norm).join(' ') : norm(args))
|
|
716
|
+
const push = (e) => {
|
|
717
|
+
if (!e) return
|
|
718
|
+
const ts = typeof e.timestamp === 'number' ? e.timestamp : (typeof e.ts === 'number' ? e.ts : 0)
|
|
719
|
+
const k = key(ts, e.args)
|
|
720
|
+
if (seen.has(k)) return
|
|
721
|
+
seen.add(k)
|
|
722
|
+
out.push({ timestamp: ts, args: Array.isArray(e.args) ? e.args : [e.args], stack: e.stack || undefined, source: e.source || undefined })
|
|
723
|
+
}
|
|
724
|
+
// page-realm ws-bridge buffer first (richest stacks for page-origin errors)
|
|
725
|
+
try { for (const e of (window.__sootsimConsole?.${getter}(${limit}) || [])) push(e) } catch {}
|
|
726
|
+
// engine observability store \u2014 the always-on render-worker / forwarded path
|
|
727
|
+
try {
|
|
728
|
+
const obs = window.__sootsimObservability
|
|
729
|
+
const snap = obs && obs.logs && typeof obs.logs.getSnapshot === 'function' ? obs.logs.getSnapshot() : []
|
|
730
|
+
for (const e of snap) if (e && e.level === ${JSON.stringify(level)}) push(e)
|
|
731
|
+
} catch {}
|
|
732
|
+
return out.sort((a, b) => (a.timestamp || 0) - (b.timestamp || 0)).slice(-${limit})
|
|
733
|
+
})()`;
|
|
734
|
+
}
|
|
735
|
+
async function inspectErrors(bridge, limit = 20) {
|
|
736
|
+
const result = await bridge.send({
|
|
1125
737
|
type: "evaluate",
|
|
1126
|
-
code:
|
|
738
|
+
code: consoleEntriesEval("error", limit)
|
|
1127
739
|
});
|
|
1128
|
-
return Array.isArray(
|
|
740
|
+
return Array.isArray(result) ? result : [];
|
|
1129
741
|
}
|
|
1130
|
-
function
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
const
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
if (
|
|
1149
|
-
|
|
1150
|
-
if (el.contrast) {
|
|
1151
|
-
const score = el.contrast.ratio == null ? `?/${el.contrast.required}` : `${el.contrast.ratio}/${el.contrast.required}${el.contrast.ratio < el.contrast.required ? " FAIL" : ""}`;
|
|
1152
|
-
parts.push(`contrast:${score}`);
|
|
1153
|
-
if (el.contrast.background) parts.push(`on:${el.contrast.background}`);
|
|
1154
|
-
}
|
|
1155
|
-
if (el.opacity != null) parts.push(`opacity:${el.opacity}`);
|
|
1156
|
-
if (el.textDecoration) parts.push(`deco:${el.textDecoration}`);
|
|
1157
|
-
if (el.overflow) parts.push(`overflow:${el.overflow}`);
|
|
1158
|
-
if (el.borderWidth) {
|
|
1159
|
-
parts.push(
|
|
1160
|
-
el.borderColor ? `border:${el.borderWidth}/${el.borderColor}` : `border:${el.borderWidth}`
|
|
1161
|
-
);
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
if (el.text) {
|
|
1165
|
-
const text = el.text.length > 40 ? `${el.text.slice(0, 39)}\u2026` : el.text;
|
|
1166
|
-
parts.push(`"${text}"`);
|
|
742
|
+
async function inspectWarnings(bridge, limit = 20) {
|
|
743
|
+
const result = await bridge.send({
|
|
744
|
+
type: "evaluate",
|
|
745
|
+
code: consoleEntriesEval("warn", limit)
|
|
746
|
+
});
|
|
747
|
+
return Array.isArray(result) ? result : [];
|
|
748
|
+
}
|
|
749
|
+
var MERGED_CONSOLE_COUNT_EVAL = `(() => {
|
|
750
|
+
const norm = (s) => (typeof s === 'string' ? s : (() => { try { return JSON.stringify(s) } catch { return String(s) } })())
|
|
751
|
+
const key = (lvl, ts, args) => lvl + '|' + Math.round((ts || 0) / 250) + '|' + (Array.isArray(args) ? args.map(norm).join(' ') : norm(args))
|
|
752
|
+
const seen = new Set()
|
|
753
|
+
let errors = 0
|
|
754
|
+
let warnings = 0
|
|
755
|
+
const add = (lvl, ts, args) => {
|
|
756
|
+
if (lvl !== 'error' && lvl !== 'warn') return
|
|
757
|
+
const k = key(lvl, ts, args)
|
|
758
|
+
if (seen.has(k)) return
|
|
759
|
+
seen.add(k)
|
|
760
|
+
if (lvl === 'error') errors++
|
|
761
|
+
else warnings++
|
|
1167
762
|
}
|
|
1168
|
-
|
|
763
|
+
try {
|
|
764
|
+
const c = window.__sootsimConsole
|
|
765
|
+
for (const e of (c?.getErrors?.(200) || [])) add('error', e?.timestamp ?? e?.ts, e?.args)
|
|
766
|
+
for (const e of (c?.getWarnings?.(200) || [])) add('warn', e?.timestamp ?? e?.ts, e?.args)
|
|
767
|
+
} catch {}
|
|
768
|
+
try {
|
|
769
|
+
const obs = window.__sootsimObservability
|
|
770
|
+
const snap = obs && obs.logs && typeof obs.logs.getSnapshot === 'function' ? obs.logs.getSnapshot() : []
|
|
771
|
+
for (const e of snap) if (e) add(e.level, e.ts, e.args)
|
|
772
|
+
} catch {}
|
|
773
|
+
return { errors, warnings, total: errors + warnings }
|
|
774
|
+
})()`;
|
|
775
|
+
async function clearConsole(bridge) {
|
|
776
|
+
await bridge.send({
|
|
777
|
+
type: "evaluate",
|
|
778
|
+
code: 'window.__sootsimConsole?.clear(); window.__sootsimObservability?.logs?.clear?.(); "cleared"'
|
|
1169
779
|
});
|
|
1170
|
-
return lines.join("\n");
|
|
1171
780
|
}
|
|
1172
|
-
async function
|
|
781
|
+
async function inspectRequests(bridge, opts = {}) {
|
|
782
|
+
const limit = opts.limit ?? 20;
|
|
783
|
+
const method = opts.failed === false ? "getRequests" : "getFailedRequests";
|
|
1173
784
|
const result = await bridge.send({
|
|
1174
|
-
type: "
|
|
1175
|
-
|
|
785
|
+
type: "call",
|
|
786
|
+
path: `__sootsimTest.${method}`,
|
|
787
|
+
args: [limit]
|
|
1176
788
|
});
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
position: {
|
|
1188
|
-
x: Math.round(node.geometry.x),
|
|
1189
|
-
y: Math.round(node.geometry.y)
|
|
1190
|
-
},
|
|
1191
|
-
size: {
|
|
1192
|
-
w: Math.round(node.geometry.width),
|
|
1193
|
-
h: Math.round(node.geometry.height)
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
];
|
|
789
|
+
return Array.isArray(result) ? result : [];
|
|
790
|
+
}
|
|
791
|
+
async function clearRequests(bridge) {
|
|
792
|
+
await bridge.send({ type: "call", path: "__sootsimTest.clearRequests", args: [] });
|
|
793
|
+
}
|
|
794
|
+
async function inspectScrollStateAt(bridge, x, y) {
|
|
795
|
+
const result = await bridge.send({
|
|
796
|
+
type: "call",
|
|
797
|
+
path: "__sootsimTest.getScrollStateAt",
|
|
798
|
+
args: [x, y]
|
|
1197
799
|
});
|
|
800
|
+
if (!result || typeof result !== "object") return null;
|
|
801
|
+
const state = result;
|
|
802
|
+
return {
|
|
803
|
+
...state,
|
|
804
|
+
scrollOffsetX: typeof state.scrollOffsetX === "number" ? state.scrollOffsetX : state.offsetX,
|
|
805
|
+
scrollOffsetY: typeof state.scrollOffsetY === "number" ? state.scrollOffsetY : state.offsetY
|
|
806
|
+
};
|
|
1198
807
|
}
|
|
1199
|
-
function
|
|
1200
|
-
if (
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
808
|
+
async function inspectLogs(bridge) {
|
|
809
|
+
if (bridge.plane === "cloud") {
|
|
810
|
+
const state = await bridge.send({
|
|
811
|
+
type: "state",
|
|
812
|
+
stateOptions: {
|
|
813
|
+
screenshot: false,
|
|
814
|
+
tree: false,
|
|
815
|
+
route: false,
|
|
816
|
+
errors: false,
|
|
817
|
+
logs: true,
|
|
818
|
+
logLimit: 100
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
const recentLogs = state && typeof state === "object" && Array.isArray(Reflect.get(state, "recentLogs")) ? Reflect.get(state, "recentLogs") : [];
|
|
822
|
+
return recentLogs.flatMap((entry, index) => {
|
|
823
|
+
if (!entry || typeof entry !== "object") return [];
|
|
824
|
+
const text = Reflect.get(entry, "text");
|
|
825
|
+
const rawLevel = Reflect.get(entry, "level");
|
|
826
|
+
if (typeof text !== "string") return [];
|
|
827
|
+
const level = rawLevel === "log" || rawLevel === "info" || rawLevel === "warn" || rawLevel === "error" || rawLevel === "debug" ? rawLevel : "error";
|
|
828
|
+
const at = Reflect.get(entry, "at");
|
|
829
|
+
const ts = typeof at === "number" && Number.isFinite(at) ? at : 0;
|
|
830
|
+
return [
|
|
831
|
+
{
|
|
832
|
+
id: `cloud-${ts}-${index}`,
|
|
833
|
+
source: "rnx-cloud",
|
|
834
|
+
level,
|
|
835
|
+
ts,
|
|
836
|
+
args: [text],
|
|
837
|
+
stack: null
|
|
838
|
+
}
|
|
839
|
+
];
|
|
840
|
+
});
|
|
1208
841
|
}
|
|
1209
|
-
|
|
1210
|
-
|
|
842
|
+
const res = await bridge.send({
|
|
843
|
+
type: "evaluate",
|
|
844
|
+
code: `(() => {
|
|
845
|
+
const obs = window.__sootsimObservability;
|
|
846
|
+
if (!obs) return { ok: false };
|
|
847
|
+
return { ok: true, entries: obs.logs.getSnapshot() };
|
|
848
|
+
})()`
|
|
849
|
+
});
|
|
850
|
+
if (!res || !res.ok) return [];
|
|
851
|
+
return res.entries ?? [];
|
|
852
|
+
}
|
|
853
|
+
async function clearLogs(bridge) {
|
|
854
|
+
await bridge.send({
|
|
855
|
+
type: "evaluate",
|
|
856
|
+
code: 'window.__sootsimObservability?.logs.clear(); "cleared"'
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
function isForwardedWorkerLogTwin(a, b) {
|
|
860
|
+
if (a.source === b.source) return false;
|
|
861
|
+
if (a.level !== b.level) return false;
|
|
862
|
+
if (Math.abs(a.ts - b.ts) > 1e3) return false;
|
|
863
|
+
if (a.args.length !== b.args.length) return false;
|
|
864
|
+
const sources = /* @__PURE__ */ new Set([a.source, b.source]);
|
|
865
|
+
if (!sources.has("sootsim-worker")) return false;
|
|
866
|
+
if (!sources.has("render-worker") && !sources.has("forwarded-render-worker")) {
|
|
867
|
+
return false;
|
|
1211
868
|
}
|
|
1212
|
-
|
|
1213
|
-
|
|
869
|
+
return a.args.every((arg, index) => arg === b.args[index]);
|
|
870
|
+
}
|
|
871
|
+
function filterLogEntries(entries, opts = {}) {
|
|
872
|
+
let out = [];
|
|
873
|
+
for (const entry of entries) {
|
|
874
|
+
if (out.some((candidate) => isForwardedWorkerLogTwin(candidate, entry))) {
|
|
875
|
+
continue;
|
|
876
|
+
}
|
|
877
|
+
out.push(entry);
|
|
1214
878
|
}
|
|
1215
|
-
if (
|
|
1216
|
-
|
|
879
|
+
if (!opts.showInternal) {
|
|
880
|
+
out = out.filter((e) => {
|
|
881
|
+
const first = e.args[0];
|
|
882
|
+
return !(typeof first === "string" && /^\[(?:rnx|sootsim)(?:\s[^\]]*)?\]/.test(first));
|
|
883
|
+
});
|
|
1217
884
|
}
|
|
1218
|
-
if (
|
|
1219
|
-
|
|
885
|
+
if (opts.level) out = out.filter((e) => opts.level.has(e.level));
|
|
886
|
+
if (opts.filter) {
|
|
887
|
+
const lf = opts.filter.toLowerCase();
|
|
888
|
+
out = out.filter((e) => e.args.join(" ").toLowerCase().includes(lf));
|
|
1220
889
|
}
|
|
1221
|
-
return
|
|
890
|
+
return out;
|
|
1222
891
|
}
|
|
1223
|
-
async function
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
query: { kind: "find", selector: resolved.selector }
|
|
892
|
+
async function inspectTimelineSummary(bridge, query) {
|
|
893
|
+
return await bridge.send({
|
|
894
|
+
type: "call",
|
|
895
|
+
path: "SootSim.bridges.timeline.summary",
|
|
896
|
+
args: [query]
|
|
1229
897
|
});
|
|
1230
|
-
if (!isSemanticQueryResult(result)) return { mode: resolved.mode, result: [] };
|
|
1231
|
-
const nodes = result.nodes.map(
|
|
1232
|
-
(node) => ({
|
|
1233
|
-
type: node.type,
|
|
1234
|
-
nodeId: node.nodeId,
|
|
1235
|
-
...node.testID ? { testID: node.testID } : {},
|
|
1236
|
-
...node.text ? { text: node.text } : {},
|
|
1237
|
-
...node.pressable ? { pressable: true } : {},
|
|
1238
|
-
...node.role ? { accessibilityRole: node.role } : {},
|
|
1239
|
-
...node.label ? { accessibilityLabel: node.label } : {},
|
|
1240
|
-
absolutePosition: { x: node.geometry.x, y: node.geometry.y },
|
|
1241
|
-
layout: { width: node.geometry.width, height: node.geometry.height }
|
|
1242
|
-
})
|
|
1243
|
-
);
|
|
1244
|
-
const resultValue = resolved.mode === "testid" || resolved.mode === "text" ? nodes[0] ?? null : nodes;
|
|
1245
|
-
return { mode: resolved.mode, result: resultValue };
|
|
1246
898
|
}
|
|
1247
|
-
function
|
|
1248
|
-
return
|
|
899
|
+
async function inspectTimelineRecent(bridge, query) {
|
|
900
|
+
return await bridge.send({
|
|
901
|
+
type: "call",
|
|
902
|
+
path: "SootSim.bridges.timeline.recent",
|
|
903
|
+
args: [query]
|
|
904
|
+
});
|
|
1249
905
|
}
|
|
1250
|
-
function
|
|
1251
|
-
let
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
906
|
+
async function detectOpenNativeUI(bridge) {
|
|
907
|
+
let events;
|
|
908
|
+
try {
|
|
909
|
+
const res = await inspectTimelineRecent(bridge, {
|
|
910
|
+
kinds: ["alert", "actionsheet"],
|
|
911
|
+
limit: 80
|
|
912
|
+
});
|
|
913
|
+
events = res.events;
|
|
914
|
+
} catch {
|
|
915
|
+
return [];
|
|
1256
916
|
}
|
|
1257
|
-
|
|
1258
|
-
const
|
|
1259
|
-
const
|
|
1260
|
-
const
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
917
|
+
const latest = /* @__PURE__ */ new Map();
|
|
918
|
+
for (const ev of events) latest.set(ev.kind, ev);
|
|
919
|
+
const out = [];
|
|
920
|
+
const check = (kind, label) => {
|
|
921
|
+
const ev = latest.get(kind);
|
|
922
|
+
if (!ev || !ev.data || typeof ev.data !== "object") return;
|
|
923
|
+
const d = ev.data;
|
|
924
|
+
if (d.phase !== "show") return;
|
|
925
|
+
out.push({ label, title: typeof d.title === "string" ? d.title : null });
|
|
926
|
+
};
|
|
927
|
+
check("alert", "Alert");
|
|
928
|
+
check("actionsheet", "ActionSheet");
|
|
929
|
+
return out;
|
|
1266
930
|
}
|
|
1267
|
-
function
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
return `rnx do tap ${x} ${y}`;
|
|
931
|
+
async function inspectTimelineAdvanceCursor(bridge, cursorKey, watermark) {
|
|
932
|
+
await bridge.send({
|
|
933
|
+
type: "call",
|
|
934
|
+
path: "SootSim.bridges.timeline.cursorAdvance",
|
|
935
|
+
args: [cursorKey, watermark]
|
|
936
|
+
});
|
|
1274
937
|
}
|
|
1275
|
-
function
|
|
1276
|
-
|
|
1277
|
-
|
|
938
|
+
async function inspectKeyboard(bridge) {
|
|
939
|
+
const result = await bridge.send({
|
|
940
|
+
type: "evaluate",
|
|
941
|
+
code: `(() => {
|
|
942
|
+
const kb = window.__sootsimKeyboard
|
|
943
|
+
if (!kb || typeof kb.getLayout !== 'function') {
|
|
944
|
+
return { error: 'keyboard bridge getLayout() not available' }
|
|
945
|
+
}
|
|
946
|
+
return kb.getLayout()
|
|
947
|
+
})()`
|
|
948
|
+
});
|
|
949
|
+
return result ?? { error: "keyboard bridge returned no result" };
|
|
1278
950
|
}
|
|
1279
|
-
function
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
}
|
|
1283
|
-
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";
|
|
1284
|
-
return !status.externalError && status.suppressedEntryError ? `${base} (suppressed entry error: ${status.suppressedEntryError})` : base;
|
|
951
|
+
function isShellCommandUnavailable(error) {
|
|
952
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
953
|
+
return message.includes("call target not found: SootSim.bridges.mainShell") || message.includes("test bridge unavailable before app-in-worker boot");
|
|
1285
954
|
}
|
|
1286
|
-
async function
|
|
1287
|
-
const
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
const bridgeError = error instanceof Error ? error.message : String(error);
|
|
1299
|
-
if (bridgeError.startsWith("multiple sims are connected:") || bridgeError.startsWith("saved sim ")) {
|
|
1300
|
-
throw error;
|
|
955
|
+
async function getShellState(bridge, readyTimeoutMs = 0) {
|
|
956
|
+
const deadline = Date.now() + Math.max(0, readyTimeoutMs);
|
|
957
|
+
while (true) {
|
|
958
|
+
try {
|
|
959
|
+
return await bridge.send({
|
|
960
|
+
type: "call",
|
|
961
|
+
path: "SootSim.bridges.mainShell.getState",
|
|
962
|
+
args: []
|
|
963
|
+
});
|
|
964
|
+
} catch (error) {
|
|
965
|
+
if (!isShellCommandUnavailable(error) || Date.now() >= deadline) throw error;
|
|
966
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
1301
967
|
}
|
|
1302
|
-
result = {
|
|
1303
|
-
matched: false,
|
|
1304
|
-
elapsedMs: Date.now() - start,
|
|
1305
|
-
polls: 0,
|
|
1306
|
-
error: bridgeError
|
|
1307
|
-
};
|
|
1308
968
|
}
|
|
1309
|
-
const probe = result.probe;
|
|
1310
|
-
const externalError = probe?.externalError ?? "";
|
|
1311
|
-
const status = {
|
|
1312
|
-
ready: result.matched && !externalError,
|
|
1313
|
-
elapsedMs: result.elapsedMs,
|
|
1314
|
-
nodes: probe?.nodes ?? 0,
|
|
1315
|
-
targets: probe?.targets ?? 0,
|
|
1316
|
-
liveFrameActive: probe?.liveFrameActive ?? false,
|
|
1317
|
-
liveFrameChannels: probe?.liveFrameChannels ?? 0,
|
|
1318
|
-
liveFramePublishes: probe?.liveFramePublishes ?? 0,
|
|
1319
|
-
flag: probe?.flag,
|
|
1320
|
-
loadingText: probe?.loadingText ?? "",
|
|
1321
|
-
externalReady: probe?.externalReady ?? null,
|
|
1322
|
-
externalStatus: probe?.externalStatus ?? "",
|
|
1323
|
-
externalError,
|
|
1324
|
-
suppressedEntryError: probe?.suppressedEntryError ?? "",
|
|
1325
|
-
errors: probe?.errors ?? 0,
|
|
1326
|
-
bridgeError: result.error ?? ""
|
|
1327
|
-
};
|
|
1328
|
-
if (!status.ready && options.onProgress) options.onProgress(status);
|
|
1329
|
-
return status;
|
|
1330
969
|
}
|
|
1331
|
-
async function
|
|
1332
|
-
const
|
|
1333
|
-
|
|
1334
|
-
{
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
970
|
+
async function inspectScreens(bridge) {
|
|
971
|
+
const payload = await bridge.send({
|
|
972
|
+
type: "evaluate",
|
|
973
|
+
code: `(async () => {
|
|
974
|
+
const test = window.__sootsimTest
|
|
975
|
+
const kb = window.__sootsimKeyboard
|
|
976
|
+
const navSnap =
|
|
977
|
+
test && typeof test.getNavigationSnapshot === 'function'
|
|
978
|
+
? await test.getNavigationSnapshot()
|
|
979
|
+
: null
|
|
980
|
+
const route =
|
|
981
|
+
test && typeof test.getRouteInfo === 'function'
|
|
982
|
+
? await test.getRouteInfo()
|
|
983
|
+
: null
|
|
984
|
+
const keyboard =
|
|
985
|
+
kb && typeof kb.getLayout === 'function'
|
|
986
|
+
? (() => {
|
|
987
|
+
const layout = kb.getLayout()
|
|
988
|
+
return layout ? {
|
|
989
|
+
visible: layout.visible,
|
|
990
|
+
mode: layout.mode,
|
|
991
|
+
spec: layout.spec
|
|
992
|
+
? {
|
|
993
|
+
keyboardType: layout.spec.keyboardType,
|
|
994
|
+
returnKeyType: layout.spec.returnKeyType,
|
|
995
|
+
}
|
|
996
|
+
: null,
|
|
997
|
+
} : null
|
|
998
|
+
})()
|
|
999
|
+
: null
|
|
1000
|
+
return { nav: navSnap, route, keyboard }
|
|
1001
|
+
})()`
|
|
1002
|
+
});
|
|
1003
|
+
const shell = await getShellState(bridge, 500).catch(() => null);
|
|
1350
1004
|
return {
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1005
|
+
shell,
|
|
1006
|
+
nav: payload?.nav ?? null,
|
|
1007
|
+
route: payload?.route ?? null,
|
|
1008
|
+
keyboard: payload?.keyboard ?? null
|
|
1354
1009
|
};
|
|
1355
1010
|
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
seen.add(k)
|
|
1369
|
-
out.push({ timestamp: ts, args: Array.isArray(e.args) ? e.args : [e.args], stack: e.stack || undefined, source: e.source || undefined })
|
|
1370
|
-
}
|
|
1371
|
-
// page-realm ws-bridge buffer first (richest stacks for page-origin errors)
|
|
1372
|
-
try { for (const e of (window.__sootsimConsole?.${getter}(${limit}) || [])) push(e) } catch {}
|
|
1373
|
-
// engine observability store \u2014 the always-on render-worker / forwarded path
|
|
1374
|
-
try {
|
|
1375
|
-
const obs = window.__sootsimObservability
|
|
1376
|
-
const snap = obs && obs.logs && typeof obs.logs.getSnapshot === 'function' ? obs.logs.getSnapshot() : []
|
|
1377
|
-
for (const e of snap) if (e && e.level === ${JSON.stringify(level)}) push(e)
|
|
1378
|
-
} catch {}
|
|
1379
|
-
return out.sort((a, b) => (a.timestamp || 0) - (b.timestamp || 0)).slice(-${limit})
|
|
1380
|
-
})()`;
|
|
1011
|
+
var DEBUG_CHANNELS = [
|
|
1012
|
+
"portals",
|
|
1013
|
+
"sheets",
|
|
1014
|
+
"layout",
|
|
1015
|
+
"onlayout",
|
|
1016
|
+
"animated",
|
|
1017
|
+
"render",
|
|
1018
|
+
"touch",
|
|
1019
|
+
"yoga"
|
|
1020
|
+
];
|
|
1021
|
+
async function inspectDebugStatus(bridge) {
|
|
1022
|
+
return bridge.send({ type: "evaluate", code: "window.__sootsimDebug.status()" });
|
|
1381
1023
|
}
|
|
1382
|
-
async function
|
|
1383
|
-
|
|
1024
|
+
async function inspectDebugFlags(bridge) {
|
|
1025
|
+
return bridge.send({ type: "evaluate", code: "window.__sootsimDebug.flags()" });
|
|
1026
|
+
}
|
|
1027
|
+
async function inspectDebugFind(bridge, target) {
|
|
1028
|
+
return bridge.send({
|
|
1384
1029
|
type: "evaluate",
|
|
1385
|
-
code:
|
|
1030
|
+
code: `window.__sootsimTest.debugFind(${JSON.stringify(target)})`
|
|
1386
1031
|
});
|
|
1387
|
-
return Array.isArray(result) ? result : [];
|
|
1388
1032
|
}
|
|
1389
|
-
async function
|
|
1390
|
-
const
|
|
1033
|
+
async function inspectDebugRecent(bridge, channel, limit = 50) {
|
|
1034
|
+
const code = channel && channel !== "all" ? `window.__sootsimDebug.recent(${JSON.stringify(channel)}, ${limit})` : `window.__sootsimDebug.recent(undefined, ${limit})`;
|
|
1035
|
+
return bridge.send({ type: "evaluate", code });
|
|
1036
|
+
}
|
|
1037
|
+
async function setDebugChannels(bridge, action, channels) {
|
|
1038
|
+
const args = channels.length > 0 ? channels.map((c) => JSON.stringify(c)).join(", ") : action === "disable" ? "'all'" : "";
|
|
1039
|
+
return bridge.send({
|
|
1391
1040
|
type: "evaluate",
|
|
1392
|
-
code:
|
|
1041
|
+
code: `window.__sootsimDebug.${action}(${args})`
|
|
1393
1042
|
});
|
|
1394
|
-
return Array.isArray(result) ? result : [];
|
|
1395
1043
|
}
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
const
|
|
1399
|
-
const
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
for (const e of snap) if (e) add(e.level, e.ts, e.args)
|
|
1419
|
-
} catch {}
|
|
1420
|
-
return { errors, warnings, total: errors + warnings }
|
|
1421
|
-
})()`;
|
|
1422
|
-
async function clearConsole(bridge) {
|
|
1423
|
-
await bridge.send({
|
|
1044
|
+
async function inspectMemory(bridge) {
|
|
1045
|
+
if (bridge.plane === "cloud") {
|
|
1046
|
+
const value = await bridge.send({ type: "memory" });
|
|
1047
|
+
const rawWasmHeapBytes = typeof value === "object" && value !== null ? Reflect.get(value, "wasmHeapBytes") : null;
|
|
1048
|
+
const wasmHeapBytes = typeof rawWasmHeapBytes === "number" ? rawWasmHeapBytes : null;
|
|
1049
|
+
return {
|
|
1050
|
+
tenant: {
|
|
1051
|
+
nodesRegistered: null,
|
|
1052
|
+
nodesDetached: null,
|
|
1053
|
+
detachedTypes: null,
|
|
1054
|
+
objects: null,
|
|
1055
|
+
activeNativeAnimations: null,
|
|
1056
|
+
imageLoader: null,
|
|
1057
|
+
workerHeap: null,
|
|
1058
|
+
wasmHeapBytes
|
|
1059
|
+
},
|
|
1060
|
+
shell: null,
|
|
1061
|
+
compositor: null,
|
|
1062
|
+
hostHeap: null
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
const result = await bridge.send({
|
|
1424
1066
|
type: "evaluate",
|
|
1425
|
-
code:
|
|
1067
|
+
code: `(async () => {
|
|
1068
|
+
const host = window.__sootsimRenderHost
|
|
1069
|
+
const stats = host?.queryStats ? await host.queryStats() : null
|
|
1070
|
+
const shellRaw = window.__sootsimShellMemory
|
|
1071
|
+
? await window.__sootsimShellMemory()
|
|
1072
|
+
: null
|
|
1073
|
+
const shell = shellRaw && !shellRaw.error ? shellRaw : null
|
|
1074
|
+
// the compositor paints home + app:one + app:two, so every app-surface
|
|
1075
|
+
// picture and raster image is counted here and nowhere else.
|
|
1076
|
+
let compositor = null
|
|
1077
|
+
try {
|
|
1078
|
+
const cs = await window.__sootsimCompositor?.getStats?.(false, true)
|
|
1079
|
+
compositor = cs?.memory ?? null
|
|
1080
|
+
} catch {}
|
|
1081
|
+
const normalize = (m) =>
|
|
1082
|
+
m
|
|
1083
|
+
? {
|
|
1084
|
+
nodesRegistered: m.nodesRegistered ?? null,
|
|
1085
|
+
nodesDetached: m.nodesDetached ?? null,
|
|
1086
|
+
detachedTypes: m.detachedTypes ?? null,
|
|
1087
|
+
objects: m.objects ?? null,
|
|
1088
|
+
activeNativeAnimations: m.activeNativeAnimations ?? null,
|
|
1089
|
+
imageLoader: m.imageLoader ?? null,
|
|
1090
|
+
workerHeap: m.workerHeap ?? null,
|
|
1091
|
+
wasmHeapBytes: m.wasmHeapBytes ?? null,
|
|
1092
|
+
}
|
|
1093
|
+
: null
|
|
1094
|
+
const hostMem = performance.memory
|
|
1095
|
+
? {
|
|
1096
|
+
usedJSHeapSize: performance.memory.usedJSHeapSize,
|
|
1097
|
+
totalJSHeapSize: performance.memory.totalJSHeapSize,
|
|
1098
|
+
jsHeapSizeLimit: performance.memory.jsHeapSizeLimit,
|
|
1099
|
+
}
|
|
1100
|
+
: null
|
|
1101
|
+
return {
|
|
1102
|
+
tenant: normalize(stats?.memory),
|
|
1103
|
+
shell: normalize(shell),
|
|
1104
|
+
compositor: normalize(compositor),
|
|
1105
|
+
hostHeap: hostMem,
|
|
1106
|
+
}
|
|
1107
|
+
})()`
|
|
1426
1108
|
});
|
|
1109
|
+
return result ?? { tenant: null, shell: null, compositor: null, hostHeap: null };
|
|
1110
|
+
}
|
|
1111
|
+
function formatTimelineSummary(summary) {
|
|
1112
|
+
if (summary.total === 0) return "nothing recorded";
|
|
1113
|
+
const parts = [];
|
|
1114
|
+
const ORDER = [
|
|
1115
|
+
"error",
|
|
1116
|
+
"warning",
|
|
1117
|
+
"console",
|
|
1118
|
+
"fetch",
|
|
1119
|
+
"toast",
|
|
1120
|
+
"alert",
|
|
1121
|
+
"actionsheet",
|
|
1122
|
+
"picker",
|
|
1123
|
+
"notification",
|
|
1124
|
+
"screen",
|
|
1125
|
+
"route",
|
|
1126
|
+
"keyboard",
|
|
1127
|
+
"app-launch",
|
|
1128
|
+
"shell",
|
|
1129
|
+
"scroll",
|
|
1130
|
+
"gesture",
|
|
1131
|
+
"text-input",
|
|
1132
|
+
"react-commit",
|
|
1133
|
+
"animation",
|
|
1134
|
+
"reanimated"
|
|
1135
|
+
];
|
|
1136
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1137
|
+
for (const k of ORDER) {
|
|
1138
|
+
const n = summary.byKind[k];
|
|
1139
|
+
if (n) {
|
|
1140
|
+
parts.push(`${n} ${k}${n === 1 ? "" : "s"}`);
|
|
1141
|
+
seen.add(k);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
for (const [k, n] of Object.entries(summary.byKind)) {
|
|
1145
|
+
if (!seen.has(k) && n) parts.push(`${n} ${k}${n === 1 ? "" : "s"}`);
|
|
1146
|
+
}
|
|
1147
|
+
return parts.join(" \xB7 ");
|
|
1148
|
+
}
|
|
1149
|
+
var NOISY_TIMELINE_KINDS = /* @__PURE__ */ new Set([
|
|
1150
|
+
"react-commit",
|
|
1151
|
+
"layout",
|
|
1152
|
+
"scroll"
|
|
1153
|
+
]);
|
|
1154
|
+
function formatTimelineRelativeTime(t, anchor) {
|
|
1155
|
+
if (anchor === null) return new Date(t).toLocaleTimeString();
|
|
1156
|
+
const dt = (t - anchor) / 1e3;
|
|
1157
|
+
const sign = dt >= 0 ? "+" : "";
|
|
1158
|
+
return `${sign}${dt.toFixed(2)}s`;
|
|
1159
|
+
}
|
|
1160
|
+
function formatTimelinePayload(kind, d) {
|
|
1161
|
+
switch (kind) {
|
|
1162
|
+
case "app-launch":
|
|
1163
|
+
return d.phase === "launch" ? `launch ${d.appName ?? d.toAppId ?? ""}` : `dismiss ${d.appName ?? d.fromAppId ?? ""} \u2192 ${d.toAppId ?? ""}`;
|
|
1164
|
+
case "toast":
|
|
1165
|
+
return `"${d.text ?? ""}"${d.durationMs ? ` (${d.durationMs}ms)` : ""}`;
|
|
1166
|
+
case "keyboard":
|
|
1167
|
+
return `${d.phase ?? "?"}${d.heightPx ? ` h=${d.heightPx}` : ""}${d.mode ? ` ${d.mode}` : ""}`;
|
|
1168
|
+
case "screen":
|
|
1169
|
+
return `${d.phase ?? "?"} ${d.name ?? d.activeName ?? ""}`;
|
|
1170
|
+
case "flow-step":
|
|
1171
|
+
return `${d.status ?? "?"} ${d.stepName ?? "step"}${d.durationMs ? ` ${d.durationMs}ms` : ""}`;
|
|
1172
|
+
case "route":
|
|
1173
|
+
return `${d.phase ?? "?"} ${d.path ?? d.pathname ?? ""}`;
|
|
1174
|
+
case "alert":
|
|
1175
|
+
case "actionsheet":
|
|
1176
|
+
case "picker":
|
|
1177
|
+
return `${d.phase ?? "?"} ${d.title ?? d.message ?? ""}`;
|
|
1178
|
+
case "notification":
|
|
1179
|
+
return `${d.title ?? ""}${d.body ? ` \u2014 ${d.body}` : ""}`;
|
|
1180
|
+
case "fetch":
|
|
1181
|
+
return `${d.method ?? "GET"} ${d.url ?? ""}${d.status ? ` -> ${d.status}` : ""}`;
|
|
1182
|
+
case "console":
|
|
1183
|
+
case "console-log":
|
|
1184
|
+
return `${d.level ?? "log"}: ${(d.message ?? "").toString().slice(0, 120)}`;
|
|
1185
|
+
case "shell":
|
|
1186
|
+
return `${d.event ?? d.type ?? d.phase ?? ""}`;
|
|
1187
|
+
case "scroll":
|
|
1188
|
+
return `${d.phase ?? "?"} ${d.target ?? ""}`;
|
|
1189
|
+
case "gesture":
|
|
1190
|
+
return `${d.phase ?? "?"} ${d.type ?? ""}`;
|
|
1191
|
+
case "text-input":
|
|
1192
|
+
return `${d.phase ?? "?"}${d.value !== void 0 ? ` "${String(d.value).slice(0, 40)}"` : ""}`;
|
|
1193
|
+
case "layout":
|
|
1194
|
+
return `${d.kind ?? "?"} ${d.testID ?? d.type ?? ""}${d.skipped ? ` skipped:${d.reason ?? "unknown"}` : ""}`;
|
|
1195
|
+
case "react-commit": {
|
|
1196
|
+
const slowest = d.slowest;
|
|
1197
|
+
return `${d.fiberCount ?? "?"} fibers ${d.durationMs ?? "?"}ms${slowest?.displayName ? ` \xB7 ${slowest.displayName} ${slowest.durationMs ?? "?"}ms` : ""}`;
|
|
1198
|
+
}
|
|
1199
|
+
case "frame":
|
|
1200
|
+
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` : ""}`;
|
|
1201
|
+
case "reanimated":
|
|
1202
|
+
case "animation":
|
|
1203
|
+
return `${d.kind ?? ""} ${d.target ?? ""}${d.durationMs ? ` ${d.durationMs}ms` : ""}`;
|
|
1204
|
+
}
|
|
1205
|
+
return "";
|
|
1427
1206
|
}
|
|
1428
|
-
|
|
1429
|
-
const
|
|
1430
|
-
const
|
|
1431
|
-
const
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
});
|
|
1436
|
-
return Array.isArray(result) ? result : [];
|
|
1207
|
+
function formatTimelineEvent(event, anchor) {
|
|
1208
|
+
const ts = formatTimelineRelativeTime(event.t, anchor).padStart(8);
|
|
1209
|
+
const ctx = event.context.padEnd(6);
|
|
1210
|
+
const kind = `[${event.kind}]`.padEnd(15);
|
|
1211
|
+
const d = event.data;
|
|
1212
|
+
const payload = d && typeof d === "object" ? formatTimelinePayload(event.kind, d) : "";
|
|
1213
|
+
return ` ${ts} ${ctx} ${kind} ${payload}`;
|
|
1437
1214
|
}
|
|
1438
|
-
|
|
1439
|
-
|
|
1215
|
+
function formatTimelineEvents(events) {
|
|
1216
|
+
if (!events.length) return "";
|
|
1217
|
+
const anchor = events[0]?.t ?? null;
|
|
1218
|
+
return events.map((e) => formatTimelineEvent(e, anchor)).join("\n");
|
|
1440
1219
|
}
|
|
1441
|
-
|
|
1220
|
+
|
|
1221
|
+
// cli/commands/inspect/resolve-target.ts
|
|
1222
|
+
async function resolveTargetCoords(bridge, target) {
|
|
1442
1223
|
const result = await bridge.send({
|
|
1443
|
-
type: "
|
|
1444
|
-
|
|
1445
|
-
args: [x, y]
|
|
1224
|
+
type: "resolve",
|
|
1225
|
+
selector: target.mode === "testid" ? { testID: target.value } : { text: target.value }
|
|
1446
1226
|
});
|
|
1447
|
-
if (
|
|
1448
|
-
|
|
1227
|
+
if (result === null) return null;
|
|
1228
|
+
if (typeof result !== "object") throw new Error("resolve returned an invalid result");
|
|
1229
|
+
const match = Reflect.get(result, "match");
|
|
1230
|
+
const resolvedTarget = Reflect.get(result, "target");
|
|
1231
|
+
const semanticNodes = [match, resolvedTarget];
|
|
1232
|
+
const point = Reflect.get(result, "point");
|
|
1233
|
+
const x = point !== null && typeof point === "object" ? Reflect.get(point, "x") : void 0;
|
|
1234
|
+
const y = point !== null && typeof point === "object" ? Reflect.get(point, "y") : void 0;
|
|
1235
|
+
if (!isSimSemanticTree(semanticNodes) || typeof x !== "number" || !Number.isFinite(x) || typeof y !== "number" || !Number.isFinite(y)) {
|
|
1236
|
+
throw new Error("resolve returned an invalid result");
|
|
1237
|
+
}
|
|
1238
|
+
const semanticMatch = semanticNodes[0];
|
|
1239
|
+
if (!semanticMatch) throw new Error("resolve returned an invalid result");
|
|
1449
1240
|
return {
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1241
|
+
x,
|
|
1242
|
+
y,
|
|
1243
|
+
testID: semanticMatch.testID ?? null,
|
|
1244
|
+
text: semanticMatch.text ?? (target.mode === "text" ? target.value : semanticMatch.label),
|
|
1245
|
+
type: semanticMatch.type
|
|
1453
1246
|
};
|
|
1454
1247
|
}
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1248
|
+
|
|
1249
|
+
// cli/commands/inspect/settling.ts
|
|
1250
|
+
async function waitForSootsimIdle({
|
|
1251
|
+
bridge,
|
|
1252
|
+
simId,
|
|
1253
|
+
maxMs,
|
|
1254
|
+
pollMs = 50,
|
|
1255
|
+
stablePolls = 3,
|
|
1256
|
+
strict = false
|
|
1257
|
+
}) {
|
|
1258
|
+
const result = await bridge.send(
|
|
1259
|
+
{
|
|
1260
|
+
type: "evaluate",
|
|
1261
|
+
simId,
|
|
1262
|
+
code: `(async () => {
|
|
1263
|
+
const start = Date.now()
|
|
1264
|
+
const deadline = start + ${Math.max(0, Math.round(maxMs))}
|
|
1265
|
+
const pollMs = ${Math.max(1, Math.round(pollMs))}
|
|
1266
|
+
const requiredStablePolls = ${Math.max(1, Math.round(stablePolls))}
|
|
1267
|
+
const strict = ${strict ? "true" : "false"}
|
|
1268
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
1269
|
+
|
|
1270
|
+
// route-aware settle: a tap that pushes/pops a screen is async \u2014 the
|
|
1271
|
+
// old screen still renders for a moment, then the new one mounts and
|
|
1272
|
+
// its content loads. a pure layout-hash check reports "idle" on the
|
|
1273
|
+
// outgoing screen or on the incoming skeleton, so a driver re-taps
|
|
1274
|
+
// and stacks duplicate navigations. drain any in-flight screen
|
|
1275
|
+
// transition FIRST, bounded by the overall budget. when no
|
|
1276
|
+
// transition is happening this returns in ~80ms (startWindowMs), so
|
|
1277
|
+
// a plain button tap barely pays for it.
|
|
1278
|
+
try {
|
|
1279
|
+
const wfst = window.__sootsimTest?.waitForScreenTransitions
|
|
1280
|
+
if (typeof wfst === 'function') {
|
|
1281
|
+
const remaining = deadline - Date.now()
|
|
1282
|
+
if (remaining > 120) {
|
|
1283
|
+
await wfst({
|
|
1284
|
+
timeoutMs: Math.min(remaining - 80, 4000),
|
|
1285
|
+
settleMs: 64,
|
|
1286
|
+
startWindowMs: 80,
|
|
1287
|
+
})
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
} catch {}
|
|
1291
|
+
|
|
1292
|
+
const readSnapshot = async () => {
|
|
1293
|
+
let animating = false
|
|
1294
|
+
let layoutDirty = false
|
|
1295
|
+
let pendingFetches = 0
|
|
1296
|
+
let requestTotal = 0
|
|
1297
|
+
let requestInFlight = 0
|
|
1298
|
+
let renderStatsAvailable = false
|
|
1299
|
+
try {
|
|
1300
|
+
const stats = await window.__sootsimRenderHost?.queryStats?.()
|
|
1301
|
+
if (stats) {
|
|
1302
|
+
renderStatsAvailable = true
|
|
1303
|
+
animating =
|
|
1304
|
+
stats.hasActiveAnims === true ||
|
|
1305
|
+
stats.hasActiveNativeAnimations === true ||
|
|
1306
|
+
stats.hasPendingAnimationFrames === true
|
|
1307
|
+
layoutDirty =
|
|
1308
|
+
stats.layoutDirty === true && stats.renderRequested === true
|
|
1309
|
+
// a freshly-pushed screen showing a skeleton is layout-stable
|
|
1310
|
+
// but not actually settled \u2014 its data/images are still in
|
|
1311
|
+
// flight. treat bounded image-loader fetches as not-idle so
|
|
1312
|
+
// settle waits for real content, capped by the budget.
|
|
1313
|
+
const pf = stats.memory && stats.memory.imageLoader
|
|
1314
|
+
? stats.memory.imageLoader.pendingFetches
|
|
1315
|
+
: 0
|
|
1316
|
+
pendingFetches = typeof pf === 'number' ? pf : 0
|
|
1317
|
+
}
|
|
1318
|
+
} catch {}
|
|
1319
|
+
try {
|
|
1320
|
+
const counts = await window.__sootsimTest?.getRequestCounts?.()
|
|
1321
|
+
requestTotal = typeof counts?.total === 'number' ? counts.total : 0
|
|
1322
|
+
requestInFlight = typeof counts?.inFlight === 'number' ? counts.inFlight : 0
|
|
1323
|
+
} catch {}
|
|
1324
|
+
const root = window.__sootsimRoot
|
|
1325
|
+
const nodes = []
|
|
1326
|
+
if (root) {
|
|
1327
|
+
const walk = (n) => {
|
|
1328
|
+
if (n.layout && n.layout.width > 0) {
|
|
1329
|
+
nodes.push(Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width))
|
|
1330
|
+
}
|
|
1331
|
+
for (const c of n.children || []) walk(c)
|
|
1332
|
+
}
|
|
1333
|
+
walk(root)
|
|
1334
|
+
}
|
|
1335
|
+
return { layout: nodes.join(';'), animating, layoutDirty, pendingFetches, renderStatsAvailable, requestTotal, requestInFlight }
|
|
1466
1336
|
}
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1337
|
+
|
|
1338
|
+
// how long generic background network is allowed to keep us waiting AFTER
|
|
1339
|
+
// the screen is otherwise visually settled. apps with continuous traffic
|
|
1340
|
+
// (polling, realtime sockets, a tap that fires 20-50 fetches) never reach
|
|
1341
|
+
// requestInFlight===0 / a stable requestTotal, so requiring full network
|
|
1342
|
+
// quiet burns the ENTIRE budget on every command \u2014 the leading idle that
|
|
1343
|
+
// failed PR-preview recordings for network-heavy apps (3pc fight-pulse).
|
|
1344
|
+
// layout-stability + the image-loader already prove visible content
|
|
1345
|
+
// loaded (a data load changes layout; an image load shows in the loader),
|
|
1346
|
+
// so the generic request counters are a courtesy, not a gate: honor them
|
|
1347
|
+
// only within this grace once the screen is visually still.
|
|
1348
|
+
const networkQuietGraceMs = 1200
|
|
1349
|
+
let lastLayout = ''
|
|
1350
|
+
let lastRequestTotal = -1
|
|
1351
|
+
let stable = 0
|
|
1352
|
+
let visuallyStillSince = 0
|
|
1353
|
+
while (Date.now() < deadline) {
|
|
1354
|
+
const snapshot = await readSnapshot()
|
|
1355
|
+
const strictOk =
|
|
1356
|
+
!strict ||
|
|
1357
|
+
(snapshot.renderStatsAvailable && !snapshot.animating && !snapshot.layoutDirty)
|
|
1358
|
+
// visually settled: no animations, no image content loading, layout
|
|
1359
|
+
// unchanged since the last poll.
|
|
1360
|
+
const visuallyStill =
|
|
1361
|
+
strictOk && snapshot.pendingFetches === 0 && snapshot.layout === lastLayout
|
|
1362
|
+
// generic network quiet: nothing in flight and no new requests issued.
|
|
1363
|
+
const networkQuiet =
|
|
1364
|
+
snapshot.requestInFlight === 0 && snapshot.requestTotal === lastRequestTotal
|
|
1365
|
+
if (visuallyStill) {
|
|
1366
|
+
stable++
|
|
1367
|
+
if (visuallyStillSince === 0) visuallyStillSince = Date.now()
|
|
1368
|
+
// settle once the screen has held still long enough AND either the
|
|
1369
|
+
// network is genuinely quiet OR it has refused to quiet within the
|
|
1370
|
+
// grace (continuous background traffic must not block forever).
|
|
1371
|
+
if (
|
|
1372
|
+
stable >= requiredStablePolls &&
|
|
1373
|
+
(networkQuiet || Date.now() - visuallyStillSince >= networkQuietGraceMs)
|
|
1374
|
+
) {
|
|
1375
|
+
return { settled: true, elapsed: Date.now() - start }
|
|
1376
|
+
}
|
|
1377
|
+
} else {
|
|
1378
|
+
stable = 0
|
|
1379
|
+
visuallyStillSince = 0
|
|
1485
1380
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
})()`
|
|
1496
|
-
});
|
|
1497
|
-
if (!res || !res.ok) return [];
|
|
1498
|
-
return res.entries ?? [];
|
|
1499
|
-
}
|
|
1500
|
-
async function clearLogs(bridge) {
|
|
1501
|
-
await bridge.send({
|
|
1502
|
-
type: "evaluate",
|
|
1503
|
-
code: 'window.__sootsimObservability?.logs.clear(); "cleared"'
|
|
1504
|
-
});
|
|
1505
|
-
}
|
|
1506
|
-
function isForwardedWorkerLogTwin(a, b) {
|
|
1507
|
-
if (a.source === b.source) return false;
|
|
1508
|
-
if (a.level !== b.level) return false;
|
|
1509
|
-
if (Math.abs(a.ts - b.ts) > 1e3) return false;
|
|
1510
|
-
if (a.args.length !== b.args.length) return false;
|
|
1511
|
-
const sources = /* @__PURE__ */ new Set([a.source, b.source]);
|
|
1512
|
-
if (!sources.has("sootsim-worker")) return false;
|
|
1513
|
-
if (!sources.has("render-worker") && !sources.has("forwarded-render-worker")) {
|
|
1514
|
-
return false;
|
|
1515
|
-
}
|
|
1516
|
-
return a.args.every((arg, index) => arg === b.args[index]);
|
|
1517
|
-
}
|
|
1518
|
-
function filterLogEntries(entries, opts = {}) {
|
|
1519
|
-
let out = [];
|
|
1520
|
-
for (const entry of entries) {
|
|
1521
|
-
if (out.some((candidate) => isForwardedWorkerLogTwin(candidate, entry))) {
|
|
1522
|
-
continue;
|
|
1381
|
+
lastLayout = snapshot.layout
|
|
1382
|
+
lastRequestTotal = snapshot.requestTotal
|
|
1383
|
+
await sleep(pollMs)
|
|
1384
|
+
}
|
|
1385
|
+
return { settled: false, elapsed: Date.now() - start }
|
|
1386
|
+
})()`
|
|
1387
|
+
},
|
|
1388
|
+
{
|
|
1389
|
+
timeoutMs: maxMs + 1e3
|
|
1523
1390
|
}
|
|
1524
|
-
|
|
1525
|
-
}
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1391
|
+
);
|
|
1392
|
+
const { elapsed, settled } = result ?? {};
|
|
1393
|
+
return {
|
|
1394
|
+
elapsed: typeof elapsed === "number" ? elapsed : maxMs,
|
|
1395
|
+
settled: settled === true
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
// cli/commands/inspect/actions.ts
|
|
1400
|
+
function isScreenSize(value) {
|
|
1401
|
+
if (value === null || typeof value !== "object") return false;
|
|
1402
|
+
const width = Reflect.get(value, "width");
|
|
1403
|
+
const height = Reflect.get(value, "height");
|
|
1404
|
+
return typeof width === "number" && Number.isFinite(width) && width > 0 && typeof height === "number" && Number.isFinite(height) && height > 0;
|
|
1405
|
+
}
|
|
1406
|
+
function viewportFromCapture(value) {
|
|
1407
|
+
if (value === null || typeof value !== "object") return void 0;
|
|
1408
|
+
const tree = Reflect.get(value, "tree");
|
|
1409
|
+
return tree !== null && typeof tree === "object" ? Reflect.get(tree, "viewport") : void 0;
|
|
1410
|
+
}
|
|
1411
|
+
async function readScreen(bridge) {
|
|
1412
|
+
try {
|
|
1413
|
+
const viewport = viewportFromCapture(
|
|
1414
|
+
await bridge.send({ type: "capture", includeVisual: false })
|
|
1415
|
+
);
|
|
1416
|
+
return isScreenSize(viewport) ? { width: viewport.width, height: viewport.height } : null;
|
|
1417
|
+
} catch {
|
|
1418
|
+
return null;
|
|
1531
1419
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1420
|
+
}
|
|
1421
|
+
function offscreenPayload(cx, cy, screen) {
|
|
1422
|
+
if (!screen || cx >= 0 && cy >= 0 && cx <= screen.width && cy <= screen.height) {
|
|
1423
|
+
return {};
|
|
1536
1424
|
}
|
|
1537
|
-
return
|
|
1425
|
+
return { offscreen: true, screen };
|
|
1538
1426
|
}
|
|
1539
|
-
|
|
1540
|
-
return
|
|
1541
|
-
type: "call",
|
|
1542
|
-
path: "SootSim.bridges.timeline.summary",
|
|
1543
|
-
args: [query]
|
|
1544
|
-
});
|
|
1427
|
+
function geometryContains(geometry, x, y) {
|
|
1428
|
+
return x >= geometry.x && y >= geometry.y && x <= geometry.x + geometry.width && y <= geometry.y + geometry.height;
|
|
1545
1429
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1430
|
+
function hitTestSemanticTree(nodes, x, y, ancestors = []) {
|
|
1431
|
+
for (let index = nodes.length - 1; index >= 0; index--) {
|
|
1432
|
+
const node = nodes[index];
|
|
1433
|
+
if (!node || !geometryContains(node.geometry, x, y)) continue;
|
|
1434
|
+
const childHit = node.children?.length ? hitTestSemanticTree(node.children, x, y, [...ancestors, node]) : null;
|
|
1435
|
+
return childHit ?? { node, ancestors };
|
|
1436
|
+
}
|
|
1437
|
+
return null;
|
|
1552
1438
|
}
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
const res = await inspectTimelineRecent(bridge, {
|
|
1557
|
-
kinds: ["alert", "actionsheet"],
|
|
1558
|
-
limit: 80
|
|
1559
|
-
});
|
|
1560
|
-
events = res.events;
|
|
1561
|
-
} catch {
|
|
1562
|
-
return [];
|
|
1439
|
+
function nodeMatchesRequested(node, requested) {
|
|
1440
|
+
if (typeof requested.nodeId === "number" && node.nodeId === requested.nodeId) {
|
|
1441
|
+
return true;
|
|
1563
1442
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1443
|
+
if (requested.testID && node.testID === requested.testID) return true;
|
|
1444
|
+
if (requested.id && node.testID === requested.id) return true;
|
|
1445
|
+
return false;
|
|
1446
|
+
}
|
|
1447
|
+
function coveringNodeSummary(node) {
|
|
1448
|
+
return {
|
|
1449
|
+
nodeId: node.nodeId,
|
|
1450
|
+
testID: node.testID ?? null,
|
|
1451
|
+
text: node.text ?? node.label ?? null,
|
|
1452
|
+
type: node.type
|
|
1573
1453
|
};
|
|
1574
|
-
check("alert", "Alert");
|
|
1575
|
-
check("actionsheet", "ActionSheet");
|
|
1576
|
-
return out;
|
|
1577
1454
|
}
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1455
|
+
var DEFAULT_AGENT_TIMING = {
|
|
1456
|
+
initialWaitMs: 3e3,
|
|
1457
|
+
deadlineMs: 5e3,
|
|
1458
|
+
retryWaitMs: 700
|
|
1459
|
+
};
|
|
1460
|
+
var DEFAULT_INTERACTIVE_TIMING = {
|
|
1461
|
+
initialWaitMs: 1200,
|
|
1462
|
+
deadlineMs: 2500,
|
|
1463
|
+
retryWaitMs: 700
|
|
1464
|
+
};
|
|
1465
|
+
function tapTiming(agent, opts = {}) {
|
|
1466
|
+
return {
|
|
1467
|
+
...agent ? DEFAULT_AGENT_TIMING : DEFAULT_INTERACTIVE_TIMING,
|
|
1468
|
+
...opts
|
|
1469
|
+
};
|
|
1584
1470
|
}
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
return kb.getLayout()
|
|
1594
|
-
})()`
|
|
1595
|
-
});
|
|
1596
|
-
return result ?? { error: "keyboard bridge returned no result" };
|
|
1471
|
+
function isTapSuccess(result) {
|
|
1472
|
+
if (!result || result.hit === false || result.ok === false) return false;
|
|
1473
|
+
if (result.handled === false) return false;
|
|
1474
|
+
if (result.requestedTargetMatched === false) return false;
|
|
1475
|
+
if (result.pointerTapHandled === false && !result.keyboardOpened && !result.isTextInput) {
|
|
1476
|
+
return false;
|
|
1477
|
+
}
|
|
1478
|
+
return true;
|
|
1597
1479
|
}
|
|
1598
|
-
function
|
|
1599
|
-
|
|
1600
|
-
|
|
1480
|
+
function tapTargetFromPayload(payload, textFallback) {
|
|
1481
|
+
return {
|
|
1482
|
+
nodeId: payload.target?.nodeId ?? payload.match?.nodeId ?? payload.node?.nodeId ?? null,
|
|
1483
|
+
id: payload.target?.id ?? payload.match?.id ?? payload.node?.id ?? null,
|
|
1484
|
+
testID: payload.target?.testID ?? payload.match?.testID ?? payload.node?.testID ?? null,
|
|
1485
|
+
text: payload.target?.text ?? payload.target?.accessibilityLabel ?? payload.match?.text ?? payload.match?.accessibilityLabel ?? payload.node?.text ?? textFallback ?? null,
|
|
1486
|
+
type: payload.target?.type ?? payload.match?.type ?? payload.node?.type ?? null
|
|
1487
|
+
};
|
|
1601
1488
|
}
|
|
1602
|
-
async function
|
|
1603
|
-
const
|
|
1604
|
-
|
|
1489
|
+
async function tapResolvedTarget(bridge, args) {
|
|
1490
|
+
const timing = tapTiming(!!args.agent, args.timing);
|
|
1491
|
+
let attempts = 0;
|
|
1492
|
+
let lastPayload = null;
|
|
1493
|
+
let lastResult = null;
|
|
1494
|
+
const canWaitForIdle = bridge.plane !== "cloud" && timing.initialWaitMs > 0;
|
|
1495
|
+
if (canWaitForIdle) {
|
|
1605
1496
|
try {
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1497
|
+
await waitForSootsimIdle({
|
|
1498
|
+
bridge,
|
|
1499
|
+
maxMs: timing.initialWaitMs,
|
|
1500
|
+
pollMs: 32,
|
|
1501
|
+
stablePolls: 2
|
|
1610
1502
|
});
|
|
1611
|
-
} catch
|
|
1612
|
-
|
|
1613
|
-
|
|
1503
|
+
} catch {
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
const deadline = Date.now() + timing.deadlineMs;
|
|
1507
|
+
let lastOffscreenAt = null;
|
|
1508
|
+
const screen = await readScreen(bridge);
|
|
1509
|
+
while (Date.now() <= deadline || attempts === 0) {
|
|
1510
|
+
attempts++;
|
|
1511
|
+
const resolved = await args.resolve();
|
|
1512
|
+
const payload = resolved && typeof resolved.cx === "number" && typeof resolved.cy === "number" ? { ...resolved, ...offscreenPayload(resolved.cx, resolved.cy, screen) } : resolved;
|
|
1513
|
+
lastPayload = payload;
|
|
1514
|
+
if (payload?.error === "bridge-not-ready" || payload?.ambiguous || payload?.nthOutOfRange) {
|
|
1515
|
+
return { payload, result: null, attempts, failure: "special" };
|
|
1516
|
+
}
|
|
1517
|
+
if (payload && typeof payload.cx === "number" && typeof payload.cy === "number") {
|
|
1518
|
+
if (payload.offscreen) {
|
|
1519
|
+
lastResult = {
|
|
1520
|
+
hit: false,
|
|
1521
|
+
reason: "offscreen",
|
|
1522
|
+
x: payload.cx,
|
|
1523
|
+
y: payload.cy,
|
|
1524
|
+
screen: payload.screen
|
|
1525
|
+
};
|
|
1526
|
+
const at = `${Math.round(payload.cx)},${Math.round(payload.cy)}`;
|
|
1527
|
+
if (lastOffscreenAt === at) {
|
|
1528
|
+
return { payload, result: lastResult, attempts, failure: "missed" };
|
|
1529
|
+
}
|
|
1530
|
+
lastOffscreenAt = at;
|
|
1531
|
+
} else {
|
|
1532
|
+
lastOffscreenAt = null;
|
|
1533
|
+
const requestedTarget = tapTargetFromPayload(payload, args.textFallback);
|
|
1534
|
+
const { tree } = await inspectTree(bridge, 50);
|
|
1535
|
+
if (Array.isArray(tree) && tree.length > 0) {
|
|
1536
|
+
const hit = hitTestSemanticTree(tree, payload.cx, payload.cy);
|
|
1537
|
+
const matched = hit !== null && (nodeMatchesRequested(hit.node, requestedTarget) || hit.ancestors.some(
|
|
1538
|
+
(ancestor) => nodeMatchesRequested(ancestor, requestedTarget)
|
|
1539
|
+
));
|
|
1540
|
+
if (hit && !matched) {
|
|
1541
|
+
lastResult = {
|
|
1542
|
+
hit: false,
|
|
1543
|
+
reason: "target-covered",
|
|
1544
|
+
requestedTarget,
|
|
1545
|
+
coordinateTarget: coveringNodeSummary(hit.node)
|
|
1546
|
+
};
|
|
1547
|
+
return { payload, result: lastResult, attempts, failure: "missed" };
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
const result = await tapCoordinates(
|
|
1551
|
+
bridge,
|
|
1552
|
+
payload.cx,
|
|
1553
|
+
payload.cy,
|
|
1554
|
+
requestedTarget
|
|
1555
|
+
);
|
|
1556
|
+
lastResult = result;
|
|
1557
|
+
if (isTapSuccess(result)) return { payload, result, attempts };
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
const remaining = deadline - Date.now();
|
|
1561
|
+
if (remaining <= 0) break;
|
|
1562
|
+
if (bridge.plane === "cloud" || timing.retryWaitMs <= 0) break;
|
|
1563
|
+
try {
|
|
1564
|
+
await waitForSootsimIdle({
|
|
1565
|
+
bridge,
|
|
1566
|
+
maxMs: Math.min(remaining, timing.retryWaitMs),
|
|
1567
|
+
pollMs: 32,
|
|
1568
|
+
stablePolls: 2
|
|
1569
|
+
});
|
|
1570
|
+
} catch {
|
|
1571
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(120, remaining)));
|
|
1614
1572
|
}
|
|
1615
1573
|
}
|
|
1616
|
-
}
|
|
1617
|
-
async function inspectScreens(bridge) {
|
|
1618
|
-
const payload = await bridge.send({
|
|
1619
|
-
type: "evaluate",
|
|
1620
|
-
code: `(async () => {
|
|
1621
|
-
const test = window.__sootsimTest
|
|
1622
|
-
const kb = window.__sootsimKeyboard
|
|
1623
|
-
const navSnap =
|
|
1624
|
-
test && typeof test.getNavigationSnapshot === 'function'
|
|
1625
|
-
? await test.getNavigationSnapshot()
|
|
1626
|
-
: null
|
|
1627
|
-
const route =
|
|
1628
|
-
test && typeof test.getRouteInfo === 'function'
|
|
1629
|
-
? await test.getRouteInfo()
|
|
1630
|
-
: null
|
|
1631
|
-
const keyboard =
|
|
1632
|
-
kb && typeof kb.getLayout === 'function'
|
|
1633
|
-
? (() => {
|
|
1634
|
-
const layout = kb.getLayout()
|
|
1635
|
-
return layout ? {
|
|
1636
|
-
visible: layout.visible,
|
|
1637
|
-
mode: layout.mode,
|
|
1638
|
-
spec: layout.spec
|
|
1639
|
-
? {
|
|
1640
|
-
keyboardType: layout.spec.keyboardType,
|
|
1641
|
-
returnKeyType: layout.spec.returnKeyType,
|
|
1642
|
-
}
|
|
1643
|
-
: null,
|
|
1644
|
-
} : null
|
|
1645
|
-
})()
|
|
1646
|
-
: null
|
|
1647
|
-
return { nav: navSnap, route, keyboard }
|
|
1648
|
-
})()`
|
|
1649
|
-
});
|
|
1650
|
-
const shell = await getShellState(bridge, 500).catch(() => null);
|
|
1651
1574
|
return {
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1575
|
+
payload: lastPayload,
|
|
1576
|
+
result: lastResult,
|
|
1577
|
+
attempts,
|
|
1578
|
+
failure: lastPayload && typeof lastPayload.cx === "number" ? "missed" : "not-found"
|
|
1656
1579
|
};
|
|
1657
1580
|
}
|
|
1658
|
-
|
|
1659
|
-
"portals",
|
|
1660
|
-
"sheets",
|
|
1661
|
-
"layout",
|
|
1662
|
-
"onlayout",
|
|
1663
|
-
"animated",
|
|
1664
|
-
"render",
|
|
1665
|
-
"touch",
|
|
1666
|
-
"yoga"
|
|
1667
|
-
];
|
|
1668
|
-
async function inspectDebugStatus(bridge) {
|
|
1669
|
-
return bridge.send({ type: "evaluate", code: "window.__sootsimDebug.status()" });
|
|
1670
|
-
}
|
|
1671
|
-
async function inspectDebugFlags(bridge) {
|
|
1672
|
-
return bridge.send({ type: "evaluate", code: "window.__sootsimDebug.flags()" });
|
|
1673
|
-
}
|
|
1674
|
-
async function inspectDebugFind(bridge, target) {
|
|
1675
|
-
return bridge.send({
|
|
1676
|
-
type: "evaluate",
|
|
1677
|
-
code: `window.__sootsimTest.debugFind(${JSON.stringify(target)})`
|
|
1678
|
-
});
|
|
1679
|
-
}
|
|
1680
|
-
async function inspectDebugRecent(bridge, channel, limit = 50) {
|
|
1681
|
-
const code = channel && channel !== "all" ? `window.__sootsimDebug.recent(${JSON.stringify(channel)}, ${limit})` : `window.__sootsimDebug.recent(undefined, ${limit})`;
|
|
1682
|
-
return bridge.send({ type: "evaluate", code });
|
|
1683
|
-
}
|
|
1684
|
-
async function setDebugChannels(bridge, action, channels) {
|
|
1685
|
-
const args = channels.length > 0 ? channels.map((c) => JSON.stringify(c)).join(", ") : action === "disable" ? "'all'" : "";
|
|
1581
|
+
async function tapCoordinates(bridge, x, y, target) {
|
|
1686
1582
|
return bridge.send({
|
|
1687
|
-
type: "
|
|
1688
|
-
|
|
1583
|
+
type: "tap",
|
|
1584
|
+
x,
|
|
1585
|
+
y,
|
|
1586
|
+
...target ? { target } : {}
|
|
1689
1587
|
});
|
|
1690
1588
|
}
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
}
|
|
1712
|
-
const result = await bridge.send({
|
|
1713
|
-
type: "evaluate",
|
|
1714
|
-
code: `(async () => {
|
|
1715
|
-
const host = window.__sootsimRenderHost
|
|
1716
|
-
const stats = host?.queryStats ? await host.queryStats() : null
|
|
1717
|
-
const shellRaw = window.__sootsimShellMemory
|
|
1718
|
-
? await window.__sootsimShellMemory()
|
|
1719
|
-
: null
|
|
1720
|
-
const shell = shellRaw && !shellRaw.error ? shellRaw : null
|
|
1721
|
-
// the compositor paints home + app:one + app:two, so every app-surface
|
|
1722
|
-
// picture and raster image is counted here and nowhere else.
|
|
1723
|
-
let compositor = null
|
|
1724
|
-
try {
|
|
1725
|
-
const cs = await window.__sootsimCompositor?.getStats?.(false, true)
|
|
1726
|
-
compositor = cs?.memory ?? null
|
|
1727
|
-
} catch {}
|
|
1728
|
-
const normalize = (m) =>
|
|
1729
|
-
m
|
|
1730
|
-
? {
|
|
1731
|
-
nodesRegistered: m.nodesRegistered ?? null,
|
|
1732
|
-
nodesDetached: m.nodesDetached ?? null,
|
|
1733
|
-
detachedTypes: m.detachedTypes ?? null,
|
|
1734
|
-
objects: m.objects ?? null,
|
|
1735
|
-
activeNativeAnimations: m.activeNativeAnimations ?? null,
|
|
1736
|
-
imageLoader: m.imageLoader ?? null,
|
|
1737
|
-
workerHeap: m.workerHeap ?? null,
|
|
1738
|
-
wasmHeapBytes: m.wasmHeapBytes ?? null,
|
|
1739
|
-
}
|
|
1740
|
-
: null
|
|
1741
|
-
const hostMem = performance.memory
|
|
1742
|
-
? {
|
|
1743
|
-
usedJSHeapSize: performance.memory.usedJSHeapSize,
|
|
1744
|
-
totalJSHeapSize: performance.memory.totalJSHeapSize,
|
|
1745
|
-
jsHeapSizeLimit: performance.memory.jsHeapSizeLimit,
|
|
1746
|
-
}
|
|
1747
|
-
: null
|
|
1748
|
-
return {
|
|
1749
|
-
tenant: normalize(stats?.memory),
|
|
1750
|
-
shell: normalize(shell),
|
|
1751
|
-
compositor: normalize(compositor),
|
|
1752
|
-
hostHeap: hostMem,
|
|
1753
|
-
}
|
|
1754
|
-
})()`
|
|
1755
|
-
});
|
|
1756
|
-
return result ?? { tenant: null, shell: null, compositor: null, hostHeap: null };
|
|
1589
|
+
function payloadFromResolved(resolved, match, extra = {}) {
|
|
1590
|
+
return {
|
|
1591
|
+
cx: resolved.x,
|
|
1592
|
+
cy: resolved.y,
|
|
1593
|
+
match: {
|
|
1594
|
+
nodeId: match.nodeId ?? null,
|
|
1595
|
+
id: match.testID ?? null,
|
|
1596
|
+
testID: match.testID ?? null,
|
|
1597
|
+
text: match.text ?? null,
|
|
1598
|
+
type: match.type ?? null
|
|
1599
|
+
},
|
|
1600
|
+
target: {
|
|
1601
|
+
nodeId: match.nodeId ?? null,
|
|
1602
|
+
id: resolved.testID ?? match.testID ?? null,
|
|
1603
|
+
testID: resolved.testID ?? match.testID ?? null,
|
|
1604
|
+
text: resolved.text ?? match.text ?? null,
|
|
1605
|
+
type: resolved.type ?? match.type ?? null
|
|
1606
|
+
},
|
|
1607
|
+
strategy: "matched-node",
|
|
1608
|
+
...extra
|
|
1609
|
+
};
|
|
1757
1610
|
}
|
|
1758
|
-
function
|
|
1759
|
-
|
|
1760
|
-
const
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
"fetch",
|
|
1766
|
-
"toast",
|
|
1767
|
-
"alert",
|
|
1768
|
-
"actionsheet",
|
|
1769
|
-
"picker",
|
|
1770
|
-
"notification",
|
|
1771
|
-
"screen",
|
|
1772
|
-
"route",
|
|
1773
|
-
"keyboard",
|
|
1774
|
-
"app-launch",
|
|
1775
|
-
"shell",
|
|
1776
|
-
"scroll",
|
|
1777
|
-
"gesture",
|
|
1778
|
-
"text-input",
|
|
1779
|
-
"react-commit",
|
|
1780
|
-
"animation",
|
|
1781
|
-
"reanimated"
|
|
1782
|
-
];
|
|
1783
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1784
|
-
for (const k of ORDER) {
|
|
1785
|
-
const n = summary.byKind[k];
|
|
1786
|
-
if (n) {
|
|
1787
|
-
parts.push(`${n} ${k}${n === 1 ? "" : "s"}`);
|
|
1788
|
-
seen.add(k);
|
|
1611
|
+
function collectTextCandidates(nodes, ancestors = []) {
|
|
1612
|
+
const out = [];
|
|
1613
|
+
for (const node of nodes) {
|
|
1614
|
+
out.push({ node, ancestorTestIDs: ancestors });
|
|
1615
|
+
if (node.children?.length) {
|
|
1616
|
+
const next = node.testID ? [...ancestors, node.testID] : ancestors;
|
|
1617
|
+
out.push(...collectTextCandidates(node.children, next));
|
|
1789
1618
|
}
|
|
1790
1619
|
}
|
|
1791
|
-
|
|
1792
|
-
if (!seen.has(k) && n) parts.push(`${n} ${k}${n === 1 ? "" : "s"}`);
|
|
1793
|
-
}
|
|
1794
|
-
return parts.join(" \xB7 ");
|
|
1620
|
+
return out;
|
|
1795
1621
|
}
|
|
1796
|
-
|
|
1797
|
-
"
|
|
1798
|
-
"layout",
|
|
1799
|
-
"scroll"
|
|
1800
|
-
]);
|
|
1801
|
-
function formatTimelineRelativeTime(t, anchor) {
|
|
1802
|
-
if (anchor === null) return new Date(t).toLocaleTimeString();
|
|
1803
|
-
const dt = (t - anchor) / 1e3;
|
|
1804
|
-
const sign = dt >= 0 ? "+" : "";
|
|
1805
|
-
return `${sign}${dt.toFixed(2)}s`;
|
|
1622
|
+
function nodeText(node) {
|
|
1623
|
+
return node.text ?? node.label ?? "";
|
|
1806
1624
|
}
|
|
1807
|
-
function
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
return
|
|
1815
|
-
case "screen":
|
|
1816
|
-
return `${d.phase ?? "?"} ${d.name ?? d.activeName ?? ""}`;
|
|
1817
|
-
case "flow-step":
|
|
1818
|
-
return `${d.status ?? "?"} ${d.stepName ?? "step"}${d.durationMs ? ` ${d.durationMs}ms` : ""}`;
|
|
1819
|
-
case "route":
|
|
1820
|
-
return `${d.phase ?? "?"} ${d.path ?? d.pathname ?? ""}`;
|
|
1821
|
-
case "alert":
|
|
1822
|
-
case "actionsheet":
|
|
1823
|
-
case "picker":
|
|
1824
|
-
return `${d.phase ?? "?"} ${d.title ?? d.message ?? ""}`;
|
|
1825
|
-
case "notification":
|
|
1826
|
-
return `${d.title ?? ""}${d.body ? ` \u2014 ${d.body}` : ""}`;
|
|
1827
|
-
case "fetch":
|
|
1828
|
-
return `${d.method ?? "GET"} ${d.url ?? ""}${d.status ? ` -> ${d.status}` : ""}`;
|
|
1829
|
-
case "console":
|
|
1830
|
-
case "console-log":
|
|
1831
|
-
return `${d.level ?? "log"}: ${(d.message ?? "").toString().slice(0, 120)}`;
|
|
1832
|
-
case "shell":
|
|
1833
|
-
return `${d.event ?? d.type ?? d.phase ?? ""}`;
|
|
1834
|
-
case "scroll":
|
|
1835
|
-
return `${d.phase ?? "?"} ${d.target ?? ""}`;
|
|
1836
|
-
case "gesture":
|
|
1837
|
-
return `${d.phase ?? "?"} ${d.type ?? ""}`;
|
|
1838
|
-
case "text-input":
|
|
1839
|
-
return `${d.phase ?? "?"}${d.value !== void 0 ? ` "${String(d.value).slice(0, 40)}"` : ""}`;
|
|
1840
|
-
case "layout":
|
|
1841
|
-
return `${d.kind ?? "?"} ${d.testID ?? d.type ?? ""}${d.skipped ? ` skipped:${d.reason ?? "unknown"}` : ""}`;
|
|
1842
|
-
case "react-commit": {
|
|
1843
|
-
const slowest = d.slowest;
|
|
1844
|
-
return `${d.fiberCount ?? "?"} fibers ${d.durationMs ?? "?"}ms${slowest?.displayName ? ` \xB7 ${slowest.displayName} ${slowest.durationMs ?? "?"}ms` : ""}`;
|
|
1625
|
+
async function tapById(bridge, query, opts = {}) {
|
|
1626
|
+
return tapResolvedTarget(bridge, {
|
|
1627
|
+
agent: opts.agent,
|
|
1628
|
+
timing: opts.timing,
|
|
1629
|
+
resolve: async () => {
|
|
1630
|
+
const resolved = await resolveTargetCoords(bridge, { mode: "testid", value: query });
|
|
1631
|
+
if (!resolved) return { cx: null };
|
|
1632
|
+
return payloadFromResolved(resolved, resolved);
|
|
1845
1633
|
}
|
|
1846
|
-
|
|
1847
|
-
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` : ""}`;
|
|
1848
|
-
case "reanimated":
|
|
1849
|
-
case "animation":
|
|
1850
|
-
return `${d.kind ?? ""} ${d.target ?? ""}${d.durationMs ? ` ${d.durationMs}ms` : ""}`;
|
|
1851
|
-
}
|
|
1852
|
-
return "";
|
|
1853
|
-
}
|
|
1854
|
-
function formatTimelineEvent(event, anchor) {
|
|
1855
|
-
const ts = formatTimelineRelativeTime(event.t, anchor).padStart(8);
|
|
1856
|
-
const ctx = event.context.padEnd(6);
|
|
1857
|
-
const kind = `[${event.kind}]`.padEnd(15);
|
|
1858
|
-
const d = event.data;
|
|
1859
|
-
const payload = d && typeof d === "object" ? formatTimelinePayload(event.kind, d) : "";
|
|
1860
|
-
return ` ${ts} ${ctx} ${kind} ${payload}`;
|
|
1634
|
+
});
|
|
1861
1635
|
}
|
|
1862
|
-
function
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1636
|
+
async function tapByText(bridge, query, options = {}, opts = {}) {
|
|
1637
|
+
return tapResolvedTarget(bridge, {
|
|
1638
|
+
agent: opts.agent,
|
|
1639
|
+
timing: opts.timing,
|
|
1640
|
+
textFallback: query,
|
|
1641
|
+
resolve: async () => {
|
|
1642
|
+
const { tree } = await inspectTree(bridge, 50);
|
|
1643
|
+
if (!Array.isArray(tree)) return { matched: 0, total: 0 };
|
|
1644
|
+
const needle = options.exact ? query : query.toLowerCase();
|
|
1645
|
+
let candidates = collectTextCandidates(tree).filter(({ node: node2, ancestorTestIDs }) => {
|
|
1646
|
+
const text = nodeText(node2);
|
|
1647
|
+
if (!text) return false;
|
|
1648
|
+
if (options.exact ? text !== needle : !text.toLowerCase().includes(needle)) {
|
|
1649
|
+
return false;
|
|
1650
|
+
}
|
|
1651
|
+
if (options.role && node2.role !== options.role) return false;
|
|
1652
|
+
if (options.within && !ancestorTestIDs.includes(options.within)) return false;
|
|
1653
|
+
const ax = node2.geometry.x;
|
|
1654
|
+
const ay = node2.geometry.y;
|
|
1655
|
+
if (options.minX != null && !(ax >= options.minX)) return false;
|
|
1656
|
+
if (options.maxX != null && !(ax <= options.maxX)) return false;
|
|
1657
|
+
if (options.minY != null && !(ay >= options.minY)) return false;
|
|
1658
|
+
if (options.maxY != null && !(ay <= options.maxY)) return false;
|
|
1659
|
+
return true;
|
|
1660
|
+
});
|
|
1661
|
+
if (options.near) {
|
|
1662
|
+
const { x, y } = options.near;
|
|
1663
|
+
candidates.sort(
|
|
1664
|
+
(a, b) => Math.hypot(a.node.geometry.x - x, a.node.geometry.y - y) - Math.hypot(b.node.geometry.x - x, b.node.geometry.y - y)
|
|
1665
|
+
);
|
|
1666
|
+
} else {
|
|
1667
|
+
candidates.sort((a, b) => {
|
|
1668
|
+
if (Math.abs(a.node.geometry.y - b.node.geometry.y) > 2) {
|
|
1669
|
+
return a.node.geometry.y - b.node.geometry.y;
|
|
1670
|
+
}
|
|
1671
|
+
return a.node.geometry.x - b.node.geometry.x;
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1674
|
+
const total = candidates.length;
|
|
1675
|
+
if (total === 0) return { matched: 0, total: 0 };
|
|
1676
|
+
let idx = 0;
|
|
1677
|
+
if (options.nth != null) {
|
|
1678
|
+
idx = options.nth < 0 ? total + options.nth : options.nth;
|
|
1679
|
+
if (idx < 0 || idx >= total) {
|
|
1680
|
+
return { matched: 0, total, nthOutOfRange: true, nth: options.nth };
|
|
1681
|
+
}
|
|
1682
|
+
} else if (total > 1 && !options.first && !options.near) {
|
|
1683
|
+
return {
|
|
1684
|
+
ambiguous: true,
|
|
1685
|
+
total,
|
|
1686
|
+
candidates: candidates.slice(0, 10).map((candidate, index) => ({
|
|
1687
|
+
idx: index,
|
|
1688
|
+
nodeId: candidate.node.nodeId,
|
|
1689
|
+
type: candidate.node.type,
|
|
1690
|
+
testID: candidate.node.testID ?? null,
|
|
1691
|
+
text: nodeText(candidate.node).slice(0, 60),
|
|
1692
|
+
abs: { x: candidate.node.geometry.x, y: candidate.node.geometry.y },
|
|
1693
|
+
layout: {
|
|
1694
|
+
width: Math.round(candidate.node.geometry.width),
|
|
1695
|
+
height: Math.round(candidate.node.geometry.height)
|
|
1696
|
+
},
|
|
1697
|
+
ancestorTestIDs: candidate.ancestorTestIDs.slice(0, 5)
|
|
1698
|
+
}))
|
|
1699
|
+
};
|
|
1700
|
+
}
|
|
1701
|
+
const picked = candidates[idx];
|
|
1702
|
+
if (!picked) return { matched: 0, total };
|
|
1703
|
+
const node = picked.node;
|
|
1704
|
+
let resolved = node.testID ? await resolveTargetCoords(bridge, { mode: "testid", value: node.testID }) : await resolveTargetCoords(bridge, {
|
|
1705
|
+
mode: "text",
|
|
1706
|
+
value: nodeText(node) || query
|
|
1707
|
+
});
|
|
1708
|
+
if (!resolved) {
|
|
1709
|
+
resolved = {
|
|
1710
|
+
x: node.geometry.x + node.geometry.width / 2,
|
|
1711
|
+
y: node.geometry.y + node.geometry.height / 2,
|
|
1712
|
+
testID: node.testID ?? null,
|
|
1713
|
+
text: nodeText(node) || query,
|
|
1714
|
+
type: node.type
|
|
1715
|
+
};
|
|
1716
|
+
}
|
|
1717
|
+
return payloadFromResolved(resolved, node, { total, idx });
|
|
1718
|
+
}
|
|
1719
|
+
});
|
|
1866
1720
|
}
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1721
|
+
async function tapBest(bridge, query, opts = {}) {
|
|
1722
|
+
return tapResolvedTarget(bridge, {
|
|
1723
|
+
agent: opts.agent,
|
|
1724
|
+
timing: opts.timing,
|
|
1725
|
+
textFallback: query,
|
|
1726
|
+
resolve: async () => {
|
|
1727
|
+
const byId = await resolveTargetCoords(bridge, { mode: "testid", value: query });
|
|
1728
|
+
if (byId) {
|
|
1729
|
+
return {
|
|
1730
|
+
...payloadFromResolved(byId, byId),
|
|
1731
|
+
strategy: "testid",
|
|
1732
|
+
node: {
|
|
1733
|
+
nodeId: null,
|
|
1734
|
+
id: byId.testID ?? query,
|
|
1735
|
+
testID: byId.testID ?? query,
|
|
1736
|
+
type: byId.type ?? null,
|
|
1737
|
+
text: byId.text ?? null
|
|
1738
|
+
}
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
const byText = await resolveTargetCoords(bridge, { mode: "text", value: query });
|
|
1742
|
+
if (byText) {
|
|
1743
|
+
return {
|
|
1744
|
+
...payloadFromResolved(byText, byText),
|
|
1745
|
+
strategy: "text",
|
|
1746
|
+
node: {
|
|
1747
|
+
nodeId: null,
|
|
1748
|
+
id: byText.testID ?? null,
|
|
1749
|
+
testID: byText.testID ?? null,
|
|
1750
|
+
type: byText.type ?? null,
|
|
1751
|
+
text: byText.text ?? query
|
|
1752
|
+
}
|
|
1753
|
+
};
|
|
1754
|
+
}
|
|
1755
|
+
return { strategy: "none" };
|
|
1756
|
+
}
|
|
1873
1757
|
});
|
|
1874
|
-
if (result === null) return null;
|
|
1875
|
-
if (typeof result !== "object") throw new Error("resolve returned an invalid result");
|
|
1876
|
-
const match = Reflect.get(result, "match");
|
|
1877
|
-
const resolvedTarget = Reflect.get(result, "target");
|
|
1878
|
-
const semanticNodes = [match, resolvedTarget];
|
|
1879
|
-
const point = Reflect.get(result, "point");
|
|
1880
|
-
const x = point !== null && typeof point === "object" ? Reflect.get(point, "x") : void 0;
|
|
1881
|
-
const y = point !== null && typeof point === "object" ? Reflect.get(point, "y") : void 0;
|
|
1882
|
-
if (!isSimSemanticTree(semanticNodes) || typeof x !== "number" || !Number.isFinite(x) || typeof y !== "number" || !Number.isFinite(y)) {
|
|
1883
|
-
throw new Error("resolve returned an invalid result");
|
|
1884
|
-
}
|
|
1885
|
-
const semanticMatch = semanticNodes[0];
|
|
1886
|
-
if (!semanticMatch) throw new Error("resolve returned an invalid result");
|
|
1887
|
-
return {
|
|
1888
|
-
x,
|
|
1889
|
-
y,
|
|
1890
|
-
testID: semanticMatch.testID ?? null,
|
|
1891
|
-
text: semanticMatch.text ?? (target.mode === "text" ? target.value : semanticMatch.label),
|
|
1892
|
-
type: semanticMatch.type
|
|
1893
|
-
};
|
|
1894
1758
|
}
|
|
1895
1759
|
|
|
1896
1760
|
// src/app-url.ts
|