agent-device 0.21.14 → 0.21.15
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/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.14.apk → agent-device-android-ime-helper-0.21.15.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.15.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.14.manifest.json → agent-device-android-ime-helper-0.21.15.manifest.json} +4 -4
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.15.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.15.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.14.manifest.json → agent-device-android-snapshot-helper-0.21.15.manifest.json} +6 -6
- package/apple/snapshot-bridge/SnapshotBridgeRuntime.m +11 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +87 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.m +4 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerMainOwnedState.swift +27 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedTextEntry.h +8 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedTextEntry.m +26 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +40 -5
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandDispatch.swift +179 -91
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +5 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +1 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+GestureExecution.swift +1 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +36 -49
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+MainThreadWork.swift +11 -15
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +136 -29
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +4 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXPresentation.swift +3 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift +6 -5
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollDragExecution.swift +4 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +2 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +8 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotAcquisition.swift +56 -14
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +18 -8
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCaptureTarget.swift +9 -7
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotExecution.swift +5 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTiming.swift +2 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +4 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift +5 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedTextEntry.swift +78 -3
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +32 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift +7 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextTyping.swift +23 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift +17 -10
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +8 -9
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TypeExecution.swift +2 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +12 -11
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotGeometry.swift +7 -4
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotModels.swift +15 -8
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationProjection.swift +1 -0
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFold.swift +26 -9
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFoldProjection.swift +1 -0
- package/dist/src/adapter.js +1 -1
- package/dist/src/adb-executor.js +1 -1
- package/dist/src/adb-failure.js +1 -1
- package/dist/src/adb-transport.js +1 -1
- package/dist/src/agent-browser-provider.js +1 -1
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/agent-device-client.js +2 -2
- package/dist/src/ai-sdk.js +1 -1
- package/dist/src/alert-runtime.js +1 -1
- package/dist/src/android-adb.d.ts +1 -8
- package/dist/src/android-input-ownership.js +1 -1
- package/dist/src/android-snapshot-quality.js +1 -0
- package/dist/src/android-system-chrome.js +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/app-catalog.js +1 -1
- package/dist/src/app-deployment-resolution.js +1 -1
- package/dist/src/app-inventory.js +1 -1
- package/dist/src/app-launch.js +1 -1
- package/dist/src/app-lifecycle.js +1 -1
- package/dist/src/app-lifecycle2.js +1 -1
- package/dist/src/app-log-files.js +1 -1
- package/dist/src/app-log-runtime2.js +1 -1
- package/dist/src/app-resolution.js +2 -2
- package/dist/src/apple-runner-platform.js +1 -1
- package/dist/src/application-lifecycle-interaction.js +1 -1
- package/dist/src/archive.js +1 -1
- package/dist/src/artifact-download.js +1 -1
- package/dist/src/auth-session.js +1 -1
- package/dist/src/auth.js +1 -1
- package/dist/src/backend-snapshot-options.js +1 -1
- package/dist/src/boot-diagnostics.js +1 -1
- package/dist/src/capture-disclosure.js +1 -1
- package/dist/src/capture.js +1 -1
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli.js +1 -1
- package/dist/src/click-button.js +1 -1
- package/dist/src/client-metro.js +1 -1
- package/dist/src/client-types.d.ts +102 -95
- package/dist/src/clipboard-shell-response.js +1 -1
- package/dist/src/command-schema.js +1 -1
- package/dist/src/command-tools.js +3 -3
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/connection.js +1 -1
- package/dist/src/contracts.d.ts +1 -1
- package/dist/src/contracts.js +1 -1
- package/dist/src/daemon-client-lifecycle.js +1 -1
- package/dist/src/daemon.js +1 -1
- package/dist/src/debug-symbols-facade.js +1 -1
- package/dist/src/device-claim-rule.js +2 -2
- package/dist/src/device-input-state.d.ts +15 -2
- package/dist/src/device-inventory-context.js +1 -1
- package/dist/src/device-rotation.js +1 -1
- package/dist/src/device-selection-resolver.js +1 -1
- package/dist/src/device-session.js +1 -1
- package/dist/src/device-shell.js +1 -1
- package/dist/src/device2.js +1 -1
- package/dist/src/devicectl.js +1 -1
- package/dist/src/diagnostics.js +1 -1
- package/dist/src/dispatch-resolve.js +1 -1
- package/dist/src/doctor2.js +1 -1
- package/dist/src/engine-eval-script.js +1 -1
- package/dist/src/error.js +1 -1
- package/dist/src/exec.js +1 -1
- package/dist/src/file.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/format.js +1 -1
- package/dist/src/gesture-plan-types.d.ts +1 -1
- package/dist/src/gesture-plan.js +1 -1
- package/dist/src/gesture-runtime.js +1 -1
- package/dist/src/harmonyos.js +1 -1
- package/dist/src/helper.js +2 -2
- package/dist/src/human-control-contract.js +1 -1
- package/dist/src/human-control.js +1 -1
- package/dist/src/index.d.ts +7 -3
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions.js +1 -1
- package/dist/src/input-actions2.js +1 -1
- package/dist/src/install-artifact-facade.js +1 -1
- package/dist/src/install-source-network-transport.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-positionals.js +1 -1
- package/dist/src/interaction-ref-policy.js +1 -1
- package/dist/src/interaction2.js +1 -1
- package/dist/src/interactor-operation-binding.js +1 -1
- package/dist/src/interactor.js +4 -4
- package/dist/src/interactor2.js +1 -1
- package/dist/src/interactors.js +1 -1
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +2 -2
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/internal/run-script-http-child.js +1 -1
- package/dist/src/inventory.js +1 -1
- package/dist/src/inventory2.js +1 -1
- package/dist/src/inventory3.js +1 -1
- package/dist/src/inventory5.js +1 -1
- package/dist/src/ios-snapshot-acquisition.js +1 -1
- package/dist/src/ios-snapshot-engine.js +1 -0
- package/dist/src/ios-snapshot-runtime.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/limrun-download-file.js +1 -1
- package/dist/src/limrun-runtime-dependencies.js +1 -1
- package/dist/src/limrun.d.ts +16 -3
- package/dist/src/linux.js +1 -1
- package/dist/src/location-coordinates.js +1 -1
- package/dist/src/managed-device-scope.js +1 -1
- package/dist/src/mechanics.js +17 -17
- package/dist/src/mobile-snapshot-semantics.js +1 -1
- package/dist/src/multitouch-support.js +1 -1
- package/dist/src/native-build-cache.js +1 -1
- package/dist/src/observation.js +1 -1
- package/dist/src/overlay.js +3 -0
- package/dist/src/parameterized-recorded-fill.js +1 -1
- package/dist/src/perf-facade.js +1 -1
- package/dist/src/perf-runtime-operation-builder.js +1 -1
- package/dist/src/perf-runtime-plan.js +1 -1
- package/dist/src/perf-target.js +1 -1
- package/dist/src/perf.js +1 -1
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-runtime-managed-owner.js +1 -1
- package/dist/src/platform-runtime-open-target.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +4 -4
- package/dist/src/platform-runtime-runtime-hints.js +1 -1
- package/dist/src/platform-runtime-screen-recording-apple-simulator-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-process-host.js +1 -1
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -1
- package/dist/src/png-crop-bytes.js +1 -1
- package/dist/src/png-size.js +1 -1
- package/dist/src/png-worker-client.js +1 -1
- package/dist/src/png.js +1 -1
- package/dist/src/prepare-kind.js +1 -1
- package/dist/src/provider-session-ownership.js +1 -1
- package/dist/src/provider-webdriver.js +1 -1
- package/dist/src/proxy.js +1 -1
- package/dist/src/quality-warnings.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-runtime.js +1 -1
- package/dist/src/recording.js +1 -1
- package/dist/src/rect-center.js +1 -1
- package/dist/src/register-builtins.js +1 -1
- package/dist/src/registry.js +36 -36
- package/dist/src/remote-config2.js +1 -1
- package/dist/src/replay-divergence.js +1 -1
- package/dist/src/replay.js +1 -1
- package/dist/src/reporting.js +1 -1
- package/dist/src/request-admission.js +1 -1
- package/dist/src/request-cancel.js +1 -1
- package/dist/src/request-runtime-binding.js +1 -1
- package/dist/src/retry.js +1 -1
- package/dist/src/runner-cache-metadata.js +1 -1
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-dev-tools-security.js +1 -1
- package/dist/src/runner-device-readiness.js +1 -1
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-error-classification.js +2 -2
- package/dist/src/runner.js +1 -1
- package/dist/src/runtime-transport-hints.js +1 -1
- package/dist/src/runtime.js +1 -3
- package/dist/src/runtime10.js +2 -2
- package/dist/src/runtime2.js +4 -4
- package/dist/src/runtime3.js +1 -1
- package/dist/src/runtime4.js +5 -5
- package/dist/src/runtime5.js +1 -1
- package/dist/src/runtime6.js +1 -1
- package/dist/src/runtime7.js +1 -1
- package/dist/src/runtime8.js +1 -1
- package/dist/src/runtime9.js +1 -1
- package/dist/src/screen-recording-admission-ledger.js +1 -1
- package/dist/src/screen-recording-completion.js +1 -1
- package/dist/src/screen-recording-options.js +1 -1
- package/dist/src/screen-recording-resource-recovery.js +1 -1
- package/dist/src/screenshot-density.js +1 -1
- package/dist/src/screenshot-image.js +1 -1
- package/dist/src/screenshot-overlay-draw.js +1 -1
- package/dist/src/screenshot-runtime.js +1 -1
- package/dist/src/screenshot.js +1 -1
- package/dist/src/screenshot3.js +1 -1
- package/dist/src/script.js +1 -1
- package/dist/src/scroll-command.d.ts +13 -6
- package/dist/src/scroll-command.js +1 -1
- package/dist/src/scroll-gesture.js +1 -1
- package/dist/src/sdk-batch-runner.js +1 -1
- package/dist/src/sdk-batch.js +2 -2
- package/dist/src/sdk-contracts.d.ts +38 -10
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-device.js +1 -1
- package/dist/src/sdk-finders.d.ts +1 -1
- package/dist/src/sdk-io.js +1 -1
- package/dist/src/sdk-remote-config.js +1 -1
- package/dist/src/sdk-selectors.d.ts +1 -1
- package/dist/src/selection.js +0 -0
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/server.js +1 -1
- package/dist/src/session-allocation.js +1 -1
- package/dist/src/session-routing.js +1 -1
- package/dist/src/session-runtime-admission.js +1 -1
- package/dist/src/session-snapshot.js +1 -1
- package/dist/src/session-store.js +2 -2
- package/dist/src/session.js +1 -1
- package/dist/src/session2.js +4 -4
- package/dist/src/settings.js +1 -1
- package/dist/src/settings2.js +1 -0
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-capture-annotations.js +1 -1
- package/dist/src/snapshot-desktop-projection.js +1 -1
- package/dist/src/snapshot-runtime.js +1 -1
- package/dist/src/snapshot-state.js +1 -1
- package/dist/src/snapshot2.js +1 -1
- package/dist/src/snapshot3.js +1 -1
- package/dist/src/snapshot4.js +1 -1
- package/dist/src/src.js +1 -1
- package/dist/src/src4.js +1 -1
- package/dist/src/src7.js +1 -1
- package/dist/src/src8.js +2 -2
- package/dist/src/string-enum.js +1 -1
- package/dist/src/surface-snapshot.js +1 -1
- package/dist/src/takeover.js +1 -1
- package/dist/src/text-entry-focus.js +1 -1
- package/dist/src/tool-provider.js +1 -1
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/touch-runtime.js +1 -1
- package/dist/src/transport.js +1 -1
- package/dist/src/tree.js +1 -1
- package/dist/src/tv-remote.js +1 -1
- package/dist/src/type-text-runtime.js +1 -1
- package/dist/src/verified-file.js +1 -1
- package/dist/src/video.js +1 -1
- package/dist/src/viewport.js +1 -1
- package/dist/src/web.js +1 -1
- package/dist/src/web2.js +1 -1
- package/dist/src/webdriver-source.js +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.14.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.14.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.14.apk.sha256 +0 -1
- package/dist/src/absence-observation-errors.js +0 -1
- package/dist/src/runner-presentation.js +0 -1
- package/dist/src/semantic-index.js +0 -1
- package/dist/src/snapshot-scope.js +0 -1
package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextTyping.swift
CHANGED
|
@@ -3,6 +3,7 @@ import XCTest
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
extension RunnerTests {
|
|
6
|
+
@MainActor
|
|
6
7
|
func typeTextReliably(
|
|
7
8
|
app: XCUIApplication,
|
|
8
9
|
target: TextEntryTarget,
|
|
@@ -162,6 +163,28 @@ extension RunnerTests {
|
|
|
162
163
|
return (currentTarget, nil)
|
|
163
164
|
} else if activeTarget.prefersFocusedElement && isKeyboardVisible(app: app) {
|
|
164
165
|
#if os(iOS)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
if SynthesizedDeliveryBudget.exceeds(
|
|
175
|
+
textLength: text.count,
|
|
176
|
+
delaySeconds: delaySeconds,
|
|
177
|
+
typeWarmup: repairMode != .none
|
|
178
|
+
) {
|
|
179
|
+
textEntryRoute = "xctest-application-fallback"
|
|
180
|
+
NSLog(
|
|
181
|
+
"AGENT_DEVICE_RUNNER_TEXT_ENTRY_ROUTE route=xctest-application-fallback "
|
|
182
|
+
+ "reason=delivery-budget chars=%d",
|
|
183
|
+
value.count
|
|
184
|
+
)
|
|
185
|
+
app.typeText(value)
|
|
186
|
+
return (resolveTextEntryElement(app: app, target: activeTarget), nil)
|
|
187
|
+
}
|
|
165
188
|
textEntryRoute = "synthesized-first-responder"
|
|
166
189
|
NSLog("AGENT_DEVICE_RUNNER_TEXT_ENTRY_ROUTE route=synthesized-first-responder")
|
|
167
190
|
let action = synthesizer.enterText(
|
package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift
CHANGED
|
@@ -33,11 +33,7 @@ extension RunnerTests {
|
|
|
33
33
|
let combined = buffer + data
|
|
34
34
|
if let body = self.parseRequest(data: combined) {
|
|
35
35
|
self.handleRequestBody(body) { [weak self] result in
|
|
36
|
-
self?.
|
|
37
|
-
if result.shouldFinish {
|
|
38
|
-
self?.finish()
|
|
39
|
-
}
|
|
40
|
-
}
|
|
36
|
+
self?.sendResult(result, over: connection)
|
|
41
37
|
}
|
|
42
38
|
} else {
|
|
43
39
|
self.receiveRequest(connection: connection, buffer: combined)
|
|
@@ -45,10 +41,21 @@ extension RunnerTests {
|
|
|
45
41
|
}
|
|
46
42
|
}
|
|
47
43
|
|
|
44
|
+
private func sendResult(
|
|
45
|
+
_ result: (data: Data, shouldFinish: Bool),
|
|
46
|
+
over connection: NWConnection
|
|
47
|
+
) {
|
|
48
|
+
sendResponse(result.data, over: connection) { [weak self] in
|
|
49
|
+
if result.shouldFinish {
|
|
50
|
+
self?.finish()
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
48
55
|
private func sendResponse(
|
|
49
56
|
_ response: Data,
|
|
50
57
|
over connection: NWConnection,
|
|
51
|
-
afterSend: @escaping () -> Void = {}
|
|
58
|
+
afterSend: @escaping @Sendable () -> Void = {}
|
|
52
59
|
) {
|
|
53
60
|
connection.send(content: response, isComplete: true, completion: .contentProcessed { error in
|
|
54
61
|
if let error {
|
|
@@ -89,7 +96,7 @@ extension RunnerTests {
|
|
|
89
96
|
|
|
90
97
|
private func handleRequestBody(
|
|
91
98
|
_ body: Data,
|
|
92
|
-
completion: @escaping ((data: Data, shouldFinish: Bool)) -> Void
|
|
99
|
+
completion: @escaping @Sendable ((data: Data, shouldFinish: Bool)) -> Void
|
|
93
100
|
) {
|
|
94
101
|
guard String(data: body, encoding: .utf8) != nil else {
|
|
95
102
|
completion((
|
|
@@ -187,7 +194,7 @@ extension RunnerTests {
|
|
|
187
194
|
|
|
188
195
|
func enqueueAccepted(
|
|
189
196
|
command: Command,
|
|
190
|
-
completion: @escaping (Result<Response, Error>) -> Void
|
|
197
|
+
completion: @escaping @Sendable (Result<Response, Error>) -> Void
|
|
191
198
|
) {
|
|
192
199
|
commandJournal.accept(command: command)
|
|
193
200
|
commandExecutionQueue.async {
|
|
@@ -202,7 +209,7 @@ extension RunnerTests {
|
|
|
202
209
|
|
|
203
210
|
func attachToInFlightCommandIfNeeded(
|
|
204
211
|
command: Command,
|
|
205
|
-
completion: @escaping ((data: Data, shouldFinish: Bool)) -> Void
|
|
212
|
+
completion: @escaping @Sendable ((data: Data, shouldFinish: Bool)) -> Void
|
|
206
213
|
) -> Bool {
|
|
207
214
|
guard let commandId = command.commandId?.trimmedNonEmpty else { return false }
|
|
208
215
|
inFlightCommandLock.lock()
|
|
@@ -226,7 +233,7 @@ extension RunnerTests {
|
|
|
226
233
|
result: (data: Data, shouldFinish: Bool),
|
|
227
234
|
completion: ((data: Data, shouldFinish: Bool)) -> Void
|
|
228
235
|
) {
|
|
229
|
-
var waiters: [((data: Data, shouldFinish: Bool)) -> Void] = []
|
|
236
|
+
var waiters: [@Sendable ((data: Data, shouldFinish: Bool)) -> Void] = []
|
|
230
237
|
if let commandId = command.commandId?.trimmedNonEmpty {
|
|
231
238
|
inFlightCommandLock.lock()
|
|
232
239
|
inFlightCommandIds.remove(commandId)
|
package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift
CHANGED
|
@@ -52,23 +52,22 @@ extension RunnerTests {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
func elementHasFocus(_ element: XCUIElement) -> Bool {
|
|
55
|
-
|
|
56
|
-
_ = RunnerObjCExceptionCatcher.catchException({
|
|
57
|
-
if let value = (element as NSObject).value(forKey: "hasFocus") as? Bool {
|
|
58
|
-
focused = value
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
return focused
|
|
55
|
+
return focusBool(element as NSObject)
|
|
62
56
|
}
|
|
63
57
|
|
|
64
|
-
func activateElement(
|
|
58
|
+
func activateElement(
|
|
59
|
+
app: XCUIApplication,
|
|
60
|
+
element: XCUIElement,
|
|
61
|
+
action: String,
|
|
62
|
+
resolvedFrame: CGRect? = nil
|
|
63
|
+
) -> RunnerInteractionOutcome {
|
|
65
64
|
if let outcome = selectFocusedTvElement(app: app, element: element, action: action) {
|
|
66
65
|
return outcome
|
|
67
66
|
}
|
|
68
67
|
#if os(tvOS)
|
|
69
68
|
return performElementTap(element)
|
|
70
69
|
#else
|
|
71
|
-
let frame = element.frame
|
|
70
|
+
let frame = resolvedFrame ?? element.frame
|
|
72
71
|
if !frame.isEmpty {
|
|
73
72
|
|
|
74
73
|
|
package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TypeExecution.swift
CHANGED
|
@@ -2,6 +2,7 @@ import XCTest
|
|
|
2
2
|
import AgentDeviceSnapshotPresentation
|
|
3
3
|
|
|
4
4
|
extension RunnerTests {
|
|
5
|
+
@MainActor
|
|
5
6
|
func executeTypeCommand(activeApp: XCUIApplication, command: Command) -> Response {
|
|
6
7
|
guard let text = command.text else {
|
|
7
8
|
return Response(ok: false, error: ErrorPayload(message: "type requires text"))
|
|
@@ -18,7 +19,7 @@ extension RunnerTests {
|
|
|
18
19
|
: nil
|
|
19
20
|
let focusStartedAt = Date()
|
|
20
21
|
#if os(iOS)
|
|
21
|
-
let xCTestChannelPenalized = isSnapshotXCTestChannelPenalized(bundleId:
|
|
22
|
+
let xCTestChannelPenalized = isSnapshotXCTestChannelPenalized(bundleId: mainOwned.bundleId)
|
|
22
23
|
var resolvedCoordinateTarget: TextEntryTarget?
|
|
23
24
|
if Self.shouldUseResolvedCoordinateTextEntryRoute(
|
|
24
25
|
repairMode: textEntryMode,
|
|
@@ -54,11 +54,7 @@ final class RunnerTests: XCTestCase {
|
|
|
54
54
|
let commandExecutionQueue = DispatchQueue(label: "agent-device.runner.commands")
|
|
55
55
|
let app = XCUIApplication()
|
|
56
56
|
lazy var springboard = XCUIApplication(bundleIdentifier: Self.springboardBundleId)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var currentApp: XCUIApplication?
|
|
60
|
-
var currentBundleId: String?
|
|
61
|
-
var currentAppProcessIdentifier: Int?
|
|
57
|
+
let mainOwned = RunnerMainOwnedState()
|
|
62
58
|
|
|
63
59
|
|
|
64
60
|
var pendingTargetActivation: TargetActivationFactPayload?
|
|
@@ -68,7 +64,7 @@ final class RunnerTests: XCTestCase {
|
|
|
68
64
|
|
|
69
65
|
var textEntryTapWitness: TextEntryTapWitness?
|
|
70
66
|
let maxRequestBytes = 2 * 1024 * 1024
|
|
71
|
-
let mainThreadExecutionTimeout: TimeInterval = 30
|
|
67
|
+
static let mainThreadExecutionTimeout: TimeInterval = 30
|
|
72
68
|
let appExistenceTimeout: TimeInterval = 30
|
|
73
69
|
let retryCooldown: TimeInterval = 0.2
|
|
74
70
|
let postSnapshotInteractionDelay: TimeInterval = 0.2
|
|
@@ -83,27 +79,25 @@ final class RunnerTests: XCTestCase {
|
|
|
83
79
|
|
|
84
80
|
|
|
85
81
|
let recordingFrameCaptureTimeout: TimeInterval = 1
|
|
86
|
-
var needsPostSnapshotInteractionDelay = false
|
|
87
82
|
|
|
88
83
|
|
|
89
84
|
|
|
90
85
|
|
|
91
86
|
var lastLoggedFastAppGuardLine: String?
|
|
92
87
|
var lastLoggedGesturePolicyLines: [SynthesizedGesturePolicyKind: String] = [:]
|
|
93
|
-
var runnerMarkerWriter: (String) -> Void = { NSLog("%@", $0) }
|
|
88
|
+
var runnerMarkerWriter: @MainActor (String) -> Void = { NSLog("%@", $0) }
|
|
94
89
|
|
|
95
90
|
|
|
96
91
|
|
|
97
92
|
|
|
98
93
|
var firstInteractionReadyUptime: TimeInterval?
|
|
99
|
-
var runnerAccessibilityHealth: RunnerAccessibilityHealth = .unknown
|
|
100
94
|
var activeRecording: ScreenRecorder?
|
|
101
95
|
let commandJournal = RunnerCommandJournal()
|
|
102
96
|
|
|
103
97
|
|
|
104
98
|
let inFlightCommandLock = NSLock()
|
|
105
99
|
var inFlightCommandIds: Set<String> = []
|
|
106
|
-
var inFlightCommandWaiters: [String: [((data: Data, shouldFinish: Bool)) -> Void]] = [:]
|
|
100
|
+
var inFlightCommandWaiters: [String: [@Sendable ((data: Data, shouldFinish: Bool)) -> Void]] = [:]
|
|
107
101
|
|
|
108
102
|
|
|
109
103
|
|
|
@@ -206,6 +200,13 @@ final class RunnerTests: XCTestCase {
|
|
|
206
200
|
|
|
207
201
|
|
|
208
202
|
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
209
210
|
|
|
210
211
|
|
|
211
212
|
|
|
@@ -316,7 +317,7 @@ final class RunnerTests: XCTestCase {
|
|
|
316
317
|
deadline: .now() + xctestIdleKeepaliveInterval,
|
|
317
318
|
repeating: xctestIdleKeepaliveInterval
|
|
318
319
|
)
|
|
319
|
-
idleKeepaliveTimer.setEventHandler {
|
|
320
|
+
idleKeepaliveTimer.setEventHandler { @Sendable in
|
|
320
321
|
NSLog("AGENT_DEVICE_RUNNER_IDLE_KEEPALIVE")
|
|
321
322
|
}
|
|
322
323
|
idleKeepaliveTimer.resume()
|
|
@@ -2,12 +2,15 @@ import Foundation
|
|
|
2
2
|
import CoreGraphics
|
|
3
3
|
|
|
4
4
|
public enum SnapshotGeometry {
|
|
5
|
-
/// Twin of `isPositiveFiniteRect` in `packages/kernel/src/rect.ts
|
|
6
|
-
///
|
|
5
|
+
/// Twin of `isPositiveFiniteRect` in `packages/kernel/src/rect.ts`, and the one place the
|
|
6
|
+
/// `hittable` rule asks whether a box may be plotted or measured (#2891). Three refusals, each
|
|
7
|
+
/// reachable by a different input: a non-finite component, a finite box wide enough to overflow
|
|
8
|
+
/// its own right or bottom edge, and `CGRect.infinite`, which is built of finite components and
|
|
9
|
+
/// finite extents and so is refused by identity alone.
|
|
7
10
|
public static func isPositiveFinite(_ rect: CGRect) -> Bool {
|
|
8
11
|
!rect.isInfinite
|
|
9
|
-
&& rect.
|
|
10
|
-
&& rect.
|
|
12
|
+
&& rect.minX.isFinite && rect.minY.isFinite
|
|
13
|
+
&& rect.maxX.isFinite && rect.maxY.isFinite
|
|
11
14
|
&& rect.size.width > 0 && rect.size.height > 0
|
|
12
15
|
}
|
|
13
16
|
|
|
@@ -34,6 +34,8 @@ public struct RawAXNode: Equatable {
|
|
|
34
34
|
public let label: String?
|
|
35
35
|
public let identifier: String?
|
|
36
36
|
public let value: String?
|
|
37
|
+
/// The text a text field shows while empty (`placeholderValue`); `nil` for every other node.
|
|
38
|
+
public let placeholder: String?
|
|
37
39
|
public var rect: SnapshotRect
|
|
38
40
|
public let enabled: Bool
|
|
39
41
|
public let focused: Bool?
|
|
@@ -52,6 +54,7 @@ public struct RawAXNode: Equatable {
|
|
|
52
54
|
label: String?,
|
|
53
55
|
identifier: String?,
|
|
54
56
|
value: String?,
|
|
57
|
+
placeholder: String? = nil,
|
|
55
58
|
rect: SnapshotRect,
|
|
56
59
|
enabled: Bool,
|
|
57
60
|
focused: Bool?,
|
|
@@ -68,6 +71,7 @@ public struct RawAXNode: Equatable {
|
|
|
68
71
|
self.label = label
|
|
69
72
|
self.identifier = identifier
|
|
70
73
|
self.value = value
|
|
74
|
+
self.placeholder = placeholder
|
|
71
75
|
self.rect = rect
|
|
72
76
|
self.enabled = enabled
|
|
73
77
|
self.focused = focused
|
|
@@ -157,11 +161,14 @@ public struct PresentationOptions: Equatable {
|
|
|
157
161
|
/// What a capture knows about the viewport hosting its tree: the three cases of the host's
|
|
158
162
|
/// `IosViewportEvidence` (#2891). No rectangle stands for "unknown".
|
|
159
163
|
public enum SnapshotViewport: Equatable {
|
|
160
|
-
/// A box
|
|
164
|
+
/// A box that was checked on the way in. The initializer is the only gate: no caller, inside this
|
|
165
|
+
/// package or outside it, holds a `Box` whose rectangle `SnapshotGeometry.isPositiveFinite`
|
|
166
|
+
/// refuses, so a `.reported` case never needs re-checking what it was handed.
|
|
161
167
|
public struct Box: Equatable {
|
|
162
168
|
public let rect: CGRect
|
|
163
169
|
|
|
164
|
-
init(
|
|
170
|
+
init?(checked rect: CGRect) {
|
|
171
|
+
guard SnapshotGeometry.isPositiveFinite(rect) else { return nil }
|
|
165
172
|
self.rect = rect
|
|
166
173
|
}
|
|
167
174
|
}
|
|
@@ -194,15 +201,13 @@ public enum SnapshotViewport: Equatable {
|
|
|
194
201
|
box: CGRect,
|
|
195
202
|
interfaceOrientation: Int = RunnerInterfaceOrientation.unknown
|
|
196
203
|
) -> SnapshotViewport {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
: .missing(reason: .invalid)
|
|
204
|
+
guard let checked = Box(checked: box) else { return .missing(reason: .invalid) }
|
|
205
|
+
return .reported(checked, interfaceOrientation: interfaceOrientation)
|
|
200
206
|
}
|
|
201
207
|
|
|
202
208
|
public static func derived(box: CGRect) -> SnapshotViewport {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
: .missing(reason: .invalid)
|
|
209
|
+
guard let checked = Box(checked: box) else { return .missing(reason: .invalid) }
|
|
210
|
+
return .derived(checked)
|
|
206
211
|
}
|
|
207
212
|
}
|
|
208
213
|
|
|
@@ -271,6 +276,7 @@ public struct PresentedNode: Codable, Equatable {
|
|
|
271
276
|
public let label: String?
|
|
272
277
|
public let identifier: String?
|
|
273
278
|
public let value: String?
|
|
279
|
+
public let placeholder: String?
|
|
274
280
|
public let rect: SnapshotRect
|
|
275
281
|
public let enabled: Bool
|
|
276
282
|
public let focused: Bool?
|
|
@@ -294,6 +300,7 @@ public struct PresentedNode: Codable, Equatable {
|
|
|
294
300
|
self.label = raw.label
|
|
295
301
|
self.identifier = raw.identifier
|
|
296
302
|
self.value = raw.value
|
|
303
|
+
self.placeholder = raw.placeholder
|
|
297
304
|
self.rect = rect ?? raw.rect
|
|
298
305
|
self.enabled = raw.enabled
|
|
299
306
|
self.focused = raw.focused
|
|
@@ -199,21 +199,19 @@ public enum SnapshotVisibilityFold {
|
|
|
199
199
|
label: node.label,
|
|
200
200
|
identifier: node.identifier,
|
|
201
201
|
value: node.value,
|
|
202
|
+
placeholder: node.placeholder,
|
|
202
203
|
rect: node.rect,
|
|
203
204
|
enabled: node.enabled,
|
|
204
205
|
focused: node.focused,
|
|
205
206
|
selected: node.selected,
|
|
206
207
|
hittable: node.parentIndex == nil
|
|
207
208
|
? false
|
|
208
|
-
:
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
)
|
|
215
|
-
: false
|
|
216
|
-
},
|
|
209
|
+
: clippedHittability(
|
|
210
|
+
source: node.hittable,
|
|
211
|
+
enabled: node.enabled,
|
|
212
|
+
clippedFrame: decision.effectiveFrame,
|
|
213
|
+
viewport: viewport
|
|
214
|
+
),
|
|
217
215
|
depth: outDepth,
|
|
218
216
|
parentIndex: keptIndex,
|
|
219
217
|
hiddenContentAbove: node.hiddenContentAbove,
|
|
@@ -244,4 +242,23 @@ public enum SnapshotVisibilityFold {
|
|
|
244
242
|
return applyHiddenContentHints(hints, to: kept)
|
|
245
243
|
}
|
|
246
244
|
|
|
245
|
+
/// The fold's share of the `hittable` policy (#2891). A declared `false` is kept; anything the
|
|
246
|
+
/// source left undecided is re-decided on the clipped frame: a disabled or degenerate frame —
|
|
247
|
+
/// including a `visibilityExempt` carrier a scroll anchor clipped to nothing — answers `false`,
|
|
248
|
+
/// and `nil` stays reserved for the one question the clipped frame cannot answer, containment
|
|
249
|
+
/// while the capture has no viewport box.
|
|
250
|
+
private static func clippedHittability(
|
|
251
|
+
source: Bool?,
|
|
252
|
+
enabled: Bool,
|
|
253
|
+
clippedFrame: CGRect,
|
|
254
|
+
viewport: SnapshotViewport
|
|
255
|
+
) -> Bool? {
|
|
256
|
+
if source == false { return false }
|
|
257
|
+
return SnapshotGeometry.isGeometricallyActionable(
|
|
258
|
+
enabled: enabled,
|
|
259
|
+
frame: clippedFrame,
|
|
260
|
+
viewport: viewport
|
|
261
|
+
)
|
|
262
|
+
}
|
|
263
|
+
|
|
247
264
|
}
|
package/dist/src/adapter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{O as e}from"./sdk-contracts.js";import{Gr as t,Ur as n,Wr as r}from"./sdk-batch.js";import{t as i}from"./apple-runner-platform.js";import{_ as a,a as o,d as s,f as c,h as l,i as u,l as d,m as f,n as p,o as m,p as h,r as g,s as _,t as ee,u as v}from"./native-build-cache.js";import y from"node:path";import{randomUUID as b}from"node:crypto";import{Buffer as x}from"node:buffer";var te=class{entries=new Map;probeBackAfterUses;constructor(e=8){this.probeBackAfterUses=e}consume(e,t,n){if(n)return{nativeLevels:void 0,reason:`explicit-depth`};let r=this.currentEntry(e);return r===`unidentified`?{nativeLevels:void 0,reason:`unidentified-target`}:!r||r.nativeLevels>=t?{nativeLevels:void 0,reason:`no-hint`}:r.remainingUses<=0?{nativeLevels:void 0,reason:`probe-back`}:(--r.remainingUses,{nativeLevels:r.nativeLevels,reason:`hinted`})}learn(e,t,n,r){return n||!e.targetId?`ignored`:r.rejected>0&&r.acceptedLevels<t?(this.remember(e.targetId,{generation:e.generation,nativeLevels:r.acceptedLevels,remainingUses:this.probeBackAfterUses}),`learned`):r.rejected===0&&r.acceptedLevels>=t?this.entries.delete(e.targetId)?`forgotten`:`ignored`:this.currentEntry(e)?`kept`:`ignored`}currentEntry(e){if(!e.targetId)return`unidentified`;let t=this.entries.get(e.targetId);if(t){if(t.generation!==e.generation){this.entries.delete(e.targetId);return}return t}}remember(e,t){if(this.entries.delete(e),this.entries.size>=32){let e=this.entries.keys().next().value;e!==void 0&&this.entries.delete(e)}this.entries.set(e,t)}};const S=new WeakSet;async function C(e,t){let n;try{n=(await t.wait).exitCode}catch{n=void 0}return S.has(t)||(S.add(t),e.emitDiagnostic({level:`error`,phase:`ios.snapshot-source.bridge-process-exit`,data:{pid:t.pid,...n===void 0?{}:{exitCode:n},stderr:ne(t.readLog())}})),l(`process-crash`,`bridge-exited`,{pid:t.pid,...n===void 0?{}:{exitCode:n}})}function ne(e){let t=x.from(e);return t.length<=65536?e:t.subarray(-65536).toString(`utf8`)}const w=`agent-device-simulator-ax-v1.7.0`;Object.freeze([`verb`,`requestId`,`pid`,`generation`,`snapshotTree`,`automationMode`,`maxDepth`,`maxNodes`,`maxDurationMs`,`maxResponseBytes`,`nativeLevelsHint`]),Object.freeze([`protocolVersion`,`sourceVersion`,`requestId`,`generation`,`ok`,`pid`,`tree`,`truncated`,`automationEnabled`,`recovery`,`error_kind`,`error_code`,`error`]),Object.freeze([`XC_kAXXCAttributeElementType`,`XC_kAXXCAttributeElementBaseType`,`XC_kAXXCAttributeLabel`,`XC_kAXXCAttributeValue`,`XC_kAXXCAttributeIdentifier`,`XC_kAXXCAttributeFrame`,`XC_kAXXCAttributeAutomationType`,`XC_kAXXCAttributeTraits`,`XC_kAXXCAttributeIsUserInteractionEnabled`,`XC_kAXXCAttributeChildren`]);const T=[`requests`,`rejected`,`continuations`,`acceptedLevels`];function re(e){let t=e.recovery;if(!j(t))throw l(`malformed-tree`,`recovery-invalid`);let n=T.map(e=>[e,t[e]]);if(n.some(([,e])=>!Number.isSafeInteger(e)||e<0))throw l(`malformed-tree`,`recovery-invalid`);return Object.freeze(Object.fromEntries(n))}function ie(e,t){let n;try{n=x.from(JSON.stringify(e),`utf8`)}catch(e){throw l(`malformed-tree`,`request-not-json`,{},e)}let r=n.length+4;if(r>t.maxRequestBytes)throw l(`transport-failure`,`request-limit-exceeded`,{frameBytes:r,maxRequestBytes:t.maxRequestBytes});let i=x.alloc(4);return i.writeUInt32BE(n.length,0),x.concat([i,n])}var E=class{header=x.alloc(4);headerBytes=0;chunks=[];payloadBytes=0;expectedBodyBytes;frame;maxFrameBytes;constructor(e){if(!Number.isSafeInteger(e)||e<=0)throw l(`malformed-tree`,`frame-limit-invalid`,{maxFrameBytes:e});this.maxFrameBytes=e}push(e){if(this.frame)return this.acceptTrailingChunk(e);let t=this.readHeader(e);if(t&&(this.appendPayload(e,t.offset,t.bodyBytes),this.payloadBytes===t.bodyBytes))return this.frame=x.concat(this.chunks,t.bodyBytes),this.frame}acceptTrailingChunk(e){if(e.length>0)throw l(`malformed-tree`,`multiple-frames`,{trailingBytes:e.length});return this.frame}readHeader(e){if(this.headerBytes===4)return{offset:0,bodyBytes:this.expectedBodyBytes};let t=Math.min(4-this.headerBytes,e.length);if(e.copy(this.header,this.headerBytes,0,t),this.headerBytes+=t,this.headerBytes<4)return;let n=this.header.readUInt32BE(0);if(n===0||n>this.maxFrameBytes)throw l(`malformed-tree`,`frame-limit-exceeded`,{bodyBytes:n,maxFrameBytes:this.maxFrameBytes});return this.expectedBodyBytes=n,{offset:t,bodyBytes:n}}appendPayload(e,t,n){let r=n-this.payloadBytes,i=e.length-t;if(i>r)throw l(`malformed-tree`,`multiple-frames`,{trailingBytes:i-r});i!==0&&(this.chunks.push(e.subarray(t)),this.payloadBytes+=i)}finish(){if(this.frame)return this.frame;throw l(`transport-failure`,`bridge-frame-incomplete`,{headerBytes:this.headerBytes,payloadBytes:this.payloadBytes,expectedBodyBytes:this.expectedBodyBytes})}};function ae(e){let t;try{t=JSON.parse(e.toString(`utf8`))}catch(e){throw l(`malformed-tree`,`response-not-json`,{},e)}if(!j(t))throw l(`malformed-tree`,`response-not-object`);return t}function D(e){return Object.freeze({verb:`describe`,requestId:e.requestId,pid:e.pid,generation:e.generation,snapshotTree:!0,automationMode:!0,maxDepth:e.maxDepth,maxNodes:e.maxNodes,maxDurationMs:e.maxDurationMs,maxResponseBytes:e.maxResponseBytes,...e.nativeLevelsHint===void 0?{}:{nativeLevelsHint:e.nativeLevelsHint}})}function O(e,t){if(e.protocolVersion!==1)throw l(`transport-failure`,`protocol-version-mismatch`,{expected:1,observed:e.protocolVersion});if(e.sourceVersion!==`agent-device-simulator-ax-v1.7.0`)throw l(`transport-failure`,`source-version-mismatch`,{expected:w,observed:e.sourceVersion});if(e.requestId!==t)throw l(`transport-failure`,`request-id-mismatch`,{expected:t,observed:e.requestId})}function k(e,t){if(typeof e.pid!=`number`||e.pid!==t.pid)throw l(`stale-target`,`bridge-pid-mismatch`,{expectedPid:t.pid,observedPid:e.pid});if(e.generation!==t.generation)throw l(`stale-target`,`bridge-generation-mismatch`,{expectedGeneration:t.generation,observedGeneration:e.generation})}function A(e){let t=e.error_kind,n=typeof e.error_code==`string`?e.error_code:`guest-error`,r=typeof e.error==`string`?e.error:void 0,i=r?{guestMessage:r.slice(0,1024)}:{};throw l(t===`unsupported`?`unsupported`:t===`malformed_tree`?`malformed-tree`:t===`application_not_responding`?`timeout`:t===`application_unavailable`?`transport-failure`:t===`bad_request`?`malformed-tree`:`transport-failure`,n,i)}function j(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function oe(e){let t=new E(e.limits.maxResponseBytes-4),n=s(e.deadline,`bridge-request-deadline`);return await new Promise((r,i)=>{let a=!1,o=!1,s=setTimeout(()=>{h(l(`timeout`,`bridge-request-deadline`,{dispatched:o})),e.socket.destroy()},n),c=()=>{h(l(`cancelled`,`abort-signal`,{dispatched:o})),e.socket.destroy()},u=n=>{try{if(!Buffer.isBuffer(n))throw l(`transport-failure`,`bridge-data-invalid`);let r=t.push(n);if(r){let t=ae(r);if(O(t,e.requestId),k(t,{pid:e.expectedPid,generation:e.expectedGeneration}),t.ok!==!0&&A(t),typeof t.truncated!=`boolean`)throw l(`malformed-tree`,`truncated-invalid`);m(t);return}}catch(t){h(t),e.socket.destroy()}},d=e=>h(f(e)),p=()=>{a||(e.process.isAlive()?h(l(`transport-failure`,`bridge-connection-closed`)):C(e.host,e.process).then(h))};e.process.wait.then(()=>{a||C(e.host,e.process).then(h)},e=>{a||h(f(e))});let m=e=>g(()=>r(e)),h=e=>g(()=>i(e)),g=t=>{a||(a=!0,clearTimeout(s),e.deadline.signal?.removeEventListener(`abort`,c),e.socket.off(`data`,u),e.socket.off(`error`,d),e.socket.off(`close`,p),t())};e.socket.on(`data`,u),e.socket.on(`error`,d),e.socket.on(`close`,p),e.deadline.signal?.addEventListener(`abort`,c,{once:!0});try{if(e.deadline.signal?.aborted)throw l(`cancelled`,`abort-signal`);o=!0,e.socket.write(e.frame)}catch(t){h(f(t)),e.socket.destroy()}})}var se=class{sessions=new Map;requestQueues=new Map;ownerId=b();closed=!1;host;constructor(e){this.host=e}async request(e){if(this.closed)throw l(`unsupported`,`source-closed`);return await this.withSimulatorLock(e.target.simulator.udid,e.deadline,()=>this.requestInSimulator(e))}async requestInSimulator(e){if(this.closed)throw l(`unsupported`,`source-closed`);let t=e.deadline;s(t,`bridge-request-deadline`);let n=this.sessions.get(e.target.simulator.udid),r=await this.ensureSession(e,t);try{let n=await this.readTargetStartTime(e.target,t),i=await this.exchange(r,e,t);return await this.assertTargetStillCurrent(e.target,n,t),i}catch(e){throw await this.handleRequestFailure(e,r,n)}}async handleRequestFailure(e,t,n){let r=f(e);return le(r,t,n)?await this.removeSession(t,!0):r.failureKind===`process-crash`?await this.removeSession(t,!1):r.failureKind===`transport-failure`&&(t.socket?.destroy(),t.socket=void 0),r}async withSimulatorLock(e,t,n){let r=this.requestQueues.get(e)??Promise.resolve(),i,a=new Promise(e=>{i=e}),o=r.then(()=>a);this.requestQueues.set(e,o);try{return await ce(r,t),await n()}finally{i(),this.requestQueues.get(e)===o&&this.requestQueues.delete(e)}}async close(){if(this.closed)return;this.closed=!0;let e=[...this.sessions.values()];this.sessions.clear(),await Promise.all(e.map(async e=>await this.dispose(e,!0)))}async ensureSession(e,t){let n=e.target.simulator.udid,r=this.sessions.get(n);if(r&&r.bridgePath===e.bridge.path&&r.process.isAlive())return(!r.socket||r.socket.destroyed)&&(r.socket=await this.connectUntilReady(r,t)),r;r&&await this.removeSession(r,!0);let i=o(this.host,e.target.simulator.udid,this.ownerId);await this.host.ensureDirectory(y.dirname(i)),await this.host.remove(i);let a=this.host.start(e.target.simulator,e.bridge.path,i,{signal:t.signal}),s={udid:e.target.simulator.udid,bridgePath:e.bridge.path,socketPath:i,process:a};this.sessions.set(n,s);try{return s.socket=await this.connectUntilReady(s,t),s}catch(e){throw await this.removeSession(s,!0),f(e)}}async connectUntilReady(e,t){let n;for(;;){let r=s(t,`bridge-connect-deadline`);if(!e.process.isAlive())throw await C(this.host,e.process);try{return await this.host.connect(e.socketPath,{signal:t.signal,timeoutMs:Math.min(250,r)})}catch(e){if(n=e,e instanceof h&&e.failureKind===`cancelled`)throw e;let r=Math.min(20,s(t,`bridge-connect-deadline`));try{await c(t,r,`bridge-connect-deadline`)}catch(e){throw f(e)}}if(n instanceof h&&n.failureKind===`timeout`)throw n}}async exchange(e,t,n){(!e.socket||e.socket.destroyed)&&(e.socket=await this.connectUntilReady(e,n));let r=b(),i=ie(D({requestId:r,pid:t.target.pid,generation:t.target.generation,maxDepth:Math.min(t.limits.maxTraversalDepth,t.maxDepth),maxNodes:t.limits.maxNodes,maxDurationMs:s(n,`bridge-request-deadline`),maxResponseBytes:t.limits.maxResponseBytes,...t.nativeLevelsHint===void 0?{}:{nativeLevelsHint:t.nativeLevelsHint}}),t.limits);return await oe({process:e.process,socket:e.socket,frame:i,requestId:r,deadline:n,limits:t.limits,expectedPid:t.target.pid,expectedGeneration:t.target.generation,host:this.host})}async readTargetStartTime(e,t){let n=await this.host.readTargetProcessStartTime(e.pid,{signal:t.signal,timeoutMs:s(t,`target-identity-deadline`)});if(!n)throw l(`stale-target`,`target-process-unavailable`,{pid:e.pid,generation:e.generation});if(e.processStartTime!==void 0&&e.processStartTime!==n)throw l(`stale-target`,`target-process-changed`,{pid:e.pid,generation:e.generation,expectedStartTime:e.processStartTime,observedStartTime:n});return n}async assertTargetStillCurrent(e,t,n){let r=await this.host.readTargetProcessStartTime(e.pid,{signal:n.signal,timeoutMs:s(n,`target-identity-deadline`)});if(r!==t)throw l(`stale-target`,`target-process-changed`,{pid:e.pid,generation:e.generation,expectedStartTime:t,observedStartTime:r})}async removeSession(e,t){this.sessions.get(e.udid)===e&&this.sessions.delete(e.udid),await this.dispose(e,t)}async dispose(e,t){e.socket?.destroy(),e.socket=void 0,t&&e.process.isAlive()&&(e.process.signal(`SIGTERM`),await M(e.process,500),e.process.isAlive()&&(e.process.signal(`SIGKILL`),await M(e.process,500))),await this.host.remove(e.socketPath)}};async function ce(e,t){let n=s(t,`bridge-request-deadline`);await Promise.race([e,c(t,n,`bridge-request-deadline`).then(()=>{throw l(`timeout`,`bridge-request-deadline`)})])}function le(e,t,n){return(e.failureKind===`cancelled`||e.failureKind===`timeout`)&&(e.details?.dispatched===!0||n!==t)}async function M(e,t){await Promise.race([e.wait.catch(()=>void 0),new Promise(e=>setTimeout(e,t))])}const N=16777216,P=12e4,F=1e4,I=Object.freeze({maxRequestBytes:65536,maxResponseBytes:4194304,maxNodes:5e3,maxTraversalDepth:64,maxDurationMs:5e3});function L(t){let n={...I,...t??{}};for(let[t,r]of Object.entries(n))if(!Number.isSafeInteger(r)||r<=0)throw new e(`INVALID_ARGS`,`Snapshot source limit ${t} must be a positive integer`,{name:t,value:r});if(n.maxRequestBytes>n.maxResponseBytes)throw new e(`INVALID_ARGS`,`Snapshot source request bytes cannot exceed response bytes`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes});if(n.maxRequestBytes>N||n.maxResponseBytes>N)throw new e(`INVALID_ARGS`,`Snapshot source frame limits exceed the bridge bound`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes,maximumFrameBytes:N});if(n.maxNodes>F||n.maxTraversalDepth>128)throw new e(`INVALID_ARGS`,`Snapshot source tree limits exceed the bridge bound`,{maxNodes:n.maxNodes,maxTraversalDepth:n.maxTraversalDepth,maximumNodes:F,maximumDepth:128});if(n.maxDurationMs>P)throw new e(`INVALID_ARGS`,`Snapshot source duration exceeds the bridge bound`,{maxDurationMs:n.maxDurationMs,maximumDurationMs:P});if(n.maxRequestBytes<=4||n.maxResponseBytes<=4)throw new e(`INVALID_ARGS`,`Snapshot source frame limits must leave room for a body`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes});return Object.freeze(n)}const R=12e4;async function z(e){let t=e.deadline,n=e.sourceRoot??V(e.host),r=await g(e.host,n,_,t),i=await d(e.host,e.runtime,t),a=e.cacheRoot??y.join(e.host.homeDirectory(),`.agent-device`,`snapshot-source`),o=await ee({host:e.host,deadline:t,cacheRoot:a,binaryFilename:`snapshot-bridge`,lockDescription:`iOS Simulator snapshot bridge cache`,keyInputs:{schemaVersion:1,protocolVersion:1,sourceVersion:w,sourceHash:r,toolchain:i,compileArgv:B({architecture:i.architecture,sourceRoot:``,outputPath:``})},build:async r=>{let a=await p({host:e.host,deadline:t,argv:B({architecture:i.architecture,sourceRoot:n,outputPath:r}),budgetMs:R,label:`bridge`});if(a.exitCode!==0||!e.host.exists(r))throw l(`unsupported`,`native-build-failed`,{exitCode:a.exitCode,stderr:a.stderr.slice(0,4096)})}});return{path:o.path,sourceHash:r,cacheKey:o.cacheKey,protocolVersion:1,sourceVersion:w}}function B(e){return[`--sdk`,`iphonesimulator`,`clang`,`-arch`,e.architecture,`-mios-simulator-version-min=15.0`,`-fobjc-arc`,`-Wall`,`-Wextra`,`-framework`,`Foundation`,`-framework`,`CoreGraphics`,...m.map(t=>y.join(e.sourceRoot,t)),`-o`,e.outputPath]}function V(e){let t=e.projectRoot(),n=y.join(t,`apple`,`snapshot-bridge`);if(_.every(t=>e.exists(y.join(n,t))))return n;let r=y.join(t,`dist`,`apple`,`snapshot-bridge`);if(_.every(t=>e.exists(y.join(r,t))))return r;throw l(`unsupported`,`native-source-missing`,{projectRoot:t})}const H=i+R;function U(e){let t=e.now??Date.now,n=new Map,r=a({waitMs:2e3,waitGrant:`first-caller`,retryAfterMs:6e4,now:t}),i=async(r,i)=>{let a=v(H,i,t);try{let t=await e.host.withDiagnosticTimer(`ios.snapshot-source.prepare`,async()=>await z({host:e.host,runtime:r,limits:e.limits,deadline:a,sourceRoot:e.sourceRoot,cacheRoot:e.cacheRoot}),{producer:e.producer});return n.set(r,t),t}catch(e){throw f(e)}};return{readyBinary:async(e,t,a)=>n.get(e)||await r.value(e,{start:t=>i(e,t),wait:(e,n)=>c(t,e,a,n),pending:()=>l(`preparing`,`bridge-preparation-pending`)}),close:()=>{n.clear(),r.close()}}}function W(e,t){return!r(e)||!r(t)||Math.abs(t.width-t.height)<=1?!1:Math.abs(e.width-t.height)<=1&&Math.abs(e.height-t.width)<=1}const G=Object.freeze({elementType:`XC_kAXXCAttributeElementType`,elementBaseType:`XC_kAXXCAttributeElementBaseType`,label:`XC_kAXXCAttributeLabel`,value:`XC_kAXXCAttributeValue`,identifier:`XC_kAXXCAttributeIdentifier`,frame:`XC_kAXXCAttributeFrame`,automationType:`XC_kAXXCAttributeAutomationType`,traits:`XC_kAXXCAttributeTraits`,userInteractionEnabled:`XC_kAXXCAttributeIsUserInteractionEnabled`,children:`XC_kAXXCAttributeChildren`}),K=`Other.Other.Application.Group.Window.Sheet.Drawer.Alert.Dialog.Button.RadioButton.RadioGroup.CheckBox.DisclosureTriangle.PopUpButton.ComboBox.MenuButton.ToolbarButton.Popover.Keyboard.Key.NavigationBar.TabBar.TabGroup.Toolbar.StatusBar.Table.TableRow.TableColumn.Outline.OutlineRow.Browser.CollectionView.Slider.PageIndicator.ProgressIndicator.ActivityIndicator.SegmentedControl.Picker.PickerWheel.Switch.Toggle.Link.Image.Icon.SearchField.ScrollView.ScrollBar.StaticText.TextField.SecureTextField.DatePicker.TextView.Menu.MenuItem.MenuBar.MenuBarItem.Map.WebView.IncrementArrow.DecrementArrow.Timeline.RatingIndicator.ValueIndicator.SplitGroup.Splitter.RelevanceIndicator.ColorWell.HelpTag.Matte.DockItem.Ruler.RulerMarker.Grid.LevelIndicator.Cell.LayoutArea.LayoutItem.Handle.Stepper.Tab.TouchBar.StatusItem`.split(`.`),q={UIApplication:`Application`,UIWindow:`Window`},ue=new Set(Object.values(G)),de=1n<<8n,fe=1n<<3n,pe={x:0,y:0,width:0,height:0};function me(e,t,n){let r=Array.isArray(e)?e:[e];if(r.length===0||r.some(e=>!j(e)))throw l(`malformed-tree`,`guest-tree-root-invalid`);let i=[],a=[],o=0;for(let e of r)c(e,void 0,0,!1);if(i.length>n.maxNodes)throw l(`malformed-tree`,`node-limit-exceeded`,{nodeCount:i.length,maxNodes:n.maxNodes});if(o>n.maxTraversalDepth)throw l(`malformed-tree`,`traversal-depth-exceeded`,{maxTraversalDepth:o,maxAllowedDepth:n.maxTraversalDepth});if(typeof t.truncated!=`boolean`)throw l(`malformed-tree`,`truncated-invalid`);let s=ye(i.filter(Y)[0]);return s.kind===`reported`&&be(i,s.rect),{nodes:i,maxTraversalDepth:o,viewport:s,opaqueRemoteElements:a.filter(e=>_e(e,s)).length,unresolvedCoordinateSpaceWindows:xe(i,s)};function c(e,t,r,s){if(i.length>=n.maxNodes)throw l(`malformed-tree`,`node-limit-exceeded`,{maxNodes:n.maxNodes});for(let t of Object.keys(e))if(!ue.has(t))throw l(`malformed-tree`,`node-contains-unknown-field`,{key:t});let u=e[G.children];if(!Array.isArray(u))throw l(`malformed-tree`,`children-invalid`);let d=i.length,f=he(e,d,t,r);i.push(f),o=Math.max(o,r),ge(f,u.length,s)&&a.push(f.rect);let p=s||f.type===`WebView`;for(let e of u){if(!j(e))throw l(`malformed-tree`,`child-invalid`);c(e,d,r+1,p)}}}function he(e,t,n,r){let i=X(e[G.elementType]),a=X(e[G.elementBaseType]),o=Te(e[G.automationType]),s=ve(e[G.frame]),c=Ce(e[G.traits]),l=c===void 0?void 0:(c&de)===0n,u=c===void 0||(c&fe)===0n?void 0:!0,d=we(e[G.userInteractionEnabled]);return{index:t,...n===void 0?{}:{parentIndex:n},...J(i,o)?{type:J(i,o)}:{},...i?{role:i}:{},...a&&a!==i?{subrole:a}:{},...X(e[G.label])?{label:X(e[G.label])}:{},...Z(e[G.value])?{value:Z(e[G.value])}:{},...X(e[G.identifier])?{identifier:X(e[G.identifier])}:{},...s?{rect:s}:{},...l===void 0?{}:{enabled:l},...u===void 0?{}:{selected:u},...d===void 0?{}:{userInteractionEnabled:d},depth:r}}function J(e,t){if(e!==void 0&&q[e])return q[e];if(e!==void 0&&K.includes(e))return e;if(t!==void 0)return K[t]??`Other`}function ge(e,t,n){return n&&e.role===`AXRemoteElement`&&t===0}function _e(e,n){return e===void 0?!0:r(e)?n.kind!==`reported`||t(e,n.rect):!1}function ve(e){if(e===void 0)return;if(!j(e))throw l(`malformed-tree`,`frame-invalid`);let t=[`X`,`Y`,`Width`,`Height`].map(t=>e[t]);if(!t.every(e=>typeof e==`number`&&Number.isFinite(e)))throw l(`malformed-tree`,`frame-invalid`);let[n,r,i,a]=t;if(i<0||a<0)throw l(`malformed-tree`,`frame-invalid`);return{x:n,y:r,width:i,height:a}}function ye(e){return!e||!Y(e)?{kind:`missing`,reason:`not-provided`}:r(e.rect)?{kind:`reported`,rect:e.rect}:{kind:`missing`,reason:e.rect?`invalid`:`not-provided`}}function Y(e){return e.type===`Application`||e.type===`Window`}function be(e,t){for(let r of e)r.hittable=r.parentIndex!==void 0&&n(r.enabled!==!1,r.rect,t)}function xe(e,t){return t.kind===`reported`?e.filter(n=>Se(n,e)&&W(n.rect??pe,t.rect)).length:0}function Se(e,t){return Y(e)?!0:e.parentIndex!==void 0&&Y(t[e.parentIndex]??e)}function X(e){return typeof e==`string`&&e.length>0?e:void 0}function Z(e){if(typeof e==`string`)return e.length>0?e:void 0;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(e!=null)throw l(`malformed-tree`,`scalar-invalid`)}function Ce(e){if(e!=null){if(typeof e!=`string`||!/^\d{1,20}$/.test(e))throw l(`malformed-tree`,`traits-invalid`);return BigInt(e)}}function we(e){if(e!=null){if(typeof e!=`boolean`)throw l(`malformed-tree`,`user-interaction-invalid`);return e}}function Te(e){if(e!=null){if(!Number.isSafeInteger(e))throw l(`malformed-tree`,`automation-type-invalid`);return e}}const Q=`simulator-ax-bridge`;function Ee(e={}){let t=e.host??u(),n=new se(t),r=new te,i=U({host:t,limits:L(e.limits),producer:Q,sourceRoot:e.sourceRoot,cacheRoot:e.cacheRoot}),a=!1;return{acquire:async o=>{try{if(a)throw l(`unsupported`,`source-closed`);De(o);let c=L({...e.limits,...o.limits}),u=v(c.maxDurationMs,o.signal),d=ke(o.hint,c.maxTraversalDepth),f=d+1,p=o.hint.rawTraversalDepth!==null;return await t.withDiagnosticTimer(`ios.snapshot-source.acquire`,async()=>{let e=await i.readyBinary(o.target.runtime,u,`bridge-preparation-deadline`),a=r.consume(o.target,f,p),l=await n.request({target:o.target,bridge:e,limits:c,maxDepth:d,nativeLevelsHint:a.nativeLevels,deadline:u});s(u,`snapshot-decode-deadline`);let m=Ae(o.hint,o.target,l,c);return Oe(t,r,o.target,f,p,a,l),{stage:`acquired`,acquisition:m}},{producer:Q})}catch(e){let t=f(e);return{stage:`failed`,failure:{kind:t.failureKind,code:t.failureCode,...t.details?{details:t.details}:{}}}}},close:async()=>{a||(a=!0,i.close(),await n.close())}}}function De(t){if(!t.target.simulator.udid.trim()||!t.target.runtime.trim()||!t.target.generation.trim()||!Number.isSafeInteger(t.target.pid)||t.target.pid<=0)throw new e(`INVALID_ARGS`,`Simulator snapshot source target identity is incomplete`);let n=t.hint;if(n.projection!==`raw`&&n.projection!==`regular`||![`full`,`surface-observation`].includes(n.acquisitionIntent)||typeof n.interactiveOnly!=`boolean`||typeof n.customActions!=`boolean`||!$(n.rawTraversalDepth)||!$(n.regularPresentedDepth))throw new e(`INVALID_ARGS`,`Simulator snapshot source capture hint is invalid`)}function Oe(e,t,n,r,i,a,o){let s=re(o),c=o.truncated===!0,l=t.learn(n,r,i,s);e.emitDiagnostic({level:`debug`,phase:`ios_snapshot_source_recovery`,data:{producer:Q,...n.targetId?{targetId:n.targetId}:{},generation:n.generation,requestedLevels:r,hint:a.reason,...a.nativeLevels===void 0?{}:{hintedLevels:a.nativeLevels},...s,truncated:c,learning:l}})}function ke(t,n){let r=t.rawTraversalDepth??n;if(r>n)throw new e(`INVALID_ARGS`,`Simulator snapshot source depth exceeds its bound`,{requested:r,maximum:n});return r}function $(e){return e===null||Number.isSafeInteger(e)&&e>=0}function Ae(e,t,n,r){if(n.automationEnabled!==!0)throw l(`unsupported`,`automation-mode-unavailable`);let i=n.tree,a=n.truncated;if(typeof a!=`boolean`)throw l(`malformed-tree`,`truncated-invalid`);let o=me(i,{truncated:a},r),s=n.generation;if(typeof s!=`string`||!s)throw l(`malformed-tree`,`generation-invalid`);if(o.opaqueRemoteElements>0)throw l(`unsupported`,`remote-content-boundary`,{remoteElements:o.opaqueRemoteElements});if(o.unresolvedCoordinateSpaceWindows>0)throw l(`unsupported`,`window-coordinate-space-unresolved`,{windows:o.unresolvedCoordinateSpaceWindows});let c=Object.freeze(o.nodes.map(e=>Object.freeze({...e,pid:t.pid}))),u=je(e,a,o.viewport),d=Object.freeze({...t.targetId?{targetId:t.targetId}:{},generation:s}),f={producer:Q,nodes:c,truncated:a,viewport:o.viewport,lineage:d,residue:u};return e.acquisitionIntent===`full`?{...f,intent:`full`,hint:{...e,acquisitionIntent:`full`}}:{...f,intent:`surface-observation`,hint:{...e,acquisitionIntent:`surface-observation`}}}function je(e,t,n){let r=n.kind===`reported`?[]:[{kind:`unavailable-fact`,fact:`hittability`}];return Object.freeze([...r,...e.interactiveOnly?[{kind:`unavailable-fact`,fact:`interactive-query`}]:[],...t?[{kind:`truncated`}]:[],...n.kind===`missing`?[{kind:`missing-viewport`,reason:n.reason}]:[]])}export{Ee as createSimulatorSnapshotSource};
|
|
1
|
+
import{A as e}from"./sdk-contracts.js";import{Jr as t,Yr as n,qr as r}from"./sdk-batch.js";import{t as i}from"./apple-runner-platform.js";import{_ as a,a as o,d as s,f as c,h as l,i as u,l as d,m as f,n as p,o as m,p as h,r as g,s as _,t as ee,u as v}from"./native-build-cache.js";import y from"node:path";import{randomUUID as b}from"node:crypto";import{Buffer as x}from"node:buffer";var te=class{entries=new Map;probeBackAfterUses;constructor(e=8){this.probeBackAfterUses=e}consume(e,t,n){if(n)return{nativeLevels:void 0,reason:`explicit-depth`};let r=this.currentEntry(e);return r===`unidentified`?{nativeLevels:void 0,reason:`unidentified-target`}:!r||r.nativeLevels>=t?{nativeLevels:void 0,reason:`no-hint`}:r.remainingUses<=0?{nativeLevels:void 0,reason:`probe-back`}:(--r.remainingUses,{nativeLevels:r.nativeLevels,reason:`hinted`})}learn(e,t,n,r){return n||!e.targetId?`ignored`:r.rejected>0&&r.acceptedLevels<t?(this.remember(e.targetId,{generation:e.generation,nativeLevels:r.acceptedLevels,remainingUses:this.probeBackAfterUses}),`learned`):r.rejected===0&&r.acceptedLevels>=t?this.entries.delete(e.targetId)?`forgotten`:`ignored`:this.currentEntry(e)?`kept`:`ignored`}currentEntry(e){if(!e.targetId)return`unidentified`;let t=this.entries.get(e.targetId);if(t){if(t.generation!==e.generation){this.entries.delete(e.targetId);return}return t}}remember(e,t){if(this.entries.delete(e),this.entries.size>=32){let e=this.entries.keys().next().value;e!==void 0&&this.entries.delete(e)}this.entries.set(e,t)}};const S=new WeakSet;async function C(e,t){let n;try{n=(await t.wait).exitCode}catch{n=void 0}return S.has(t)||(S.add(t),e.emitDiagnostic({level:`error`,phase:`ios.snapshot-source.bridge-process-exit`,data:{pid:t.pid,...n===void 0?{}:{exitCode:n},stderr:ne(t.readLog())}})),l(`process-crash`,`bridge-exited`,{pid:t.pid,...n===void 0?{}:{exitCode:n}})}function ne(e){let t=x.from(e);return t.length<=65536?e:t.subarray(-65536).toString(`utf8`)}const w=`agent-device-simulator-ax-v1.8.0`;Object.freeze([`verb`,`requestId`,`pid`,`generation`,`snapshotTree`,`automationMode`,`maxDepth`,`maxNodes`,`maxDurationMs`,`maxResponseBytes`,`nativeLevelsHint`]),Object.freeze([`protocolVersion`,`sourceVersion`,`requestId`,`generation`,`ok`,`pid`,`tree`,`truncated`,`automationEnabled`,`recovery`,`error_kind`,`error_code`,`error`]),Object.freeze([`XC_kAXXCAttributeElementType`,`XC_kAXXCAttributeElementBaseType`,`XC_kAXXCAttributeLabel`,`XC_kAXXCAttributeValue`,`XC_kAXXCAttributePlaceholderValue`,`XC_kAXXCAttributeIdentifier`,`XC_kAXXCAttributeFrame`,`XC_kAXXCAttributeAutomationType`,`XC_kAXXCAttributeTraits`,`XC_kAXXCAttributeIsUserInteractionEnabled`,`XC_kAXXCAttributeChildren`]);const T=[`requests`,`rejected`,`continuations`,`acceptedLevels`];function re(e){let t=e.recovery;if(!j(t))throw l(`malformed-tree`,`recovery-invalid`);let n=T.map(e=>[e,t[e]]);if(n.some(([,e])=>!Number.isSafeInteger(e)||e<0))throw l(`malformed-tree`,`recovery-invalid`);return Object.freeze(Object.fromEntries(n))}function ie(e,t){let n;try{n=x.from(JSON.stringify(e),`utf8`)}catch(e){throw l(`malformed-tree`,`request-not-json`,{},e)}let r=n.length+4;if(r>t.maxRequestBytes)throw l(`transport-failure`,`request-limit-exceeded`,{frameBytes:r,maxRequestBytes:t.maxRequestBytes});let i=x.alloc(4);return i.writeUInt32BE(n.length,0),x.concat([i,n])}var E=class{header=x.alloc(4);headerBytes=0;chunks=[];payloadBytes=0;expectedBodyBytes;frame;maxFrameBytes;constructor(e){if(!Number.isSafeInteger(e)||e<=0)throw l(`malformed-tree`,`frame-limit-invalid`,{maxFrameBytes:e});this.maxFrameBytes=e}push(e){if(this.frame)return this.acceptTrailingChunk(e);let t=this.readHeader(e);if(t&&(this.appendPayload(e,t.offset,t.bodyBytes),this.payloadBytes===t.bodyBytes))return this.frame=x.concat(this.chunks,t.bodyBytes),this.frame}acceptTrailingChunk(e){if(e.length>0)throw l(`malformed-tree`,`multiple-frames`,{trailingBytes:e.length});return this.frame}readHeader(e){if(this.headerBytes===4)return{offset:0,bodyBytes:this.expectedBodyBytes};let t=Math.min(4-this.headerBytes,e.length);if(e.copy(this.header,this.headerBytes,0,t),this.headerBytes+=t,this.headerBytes<4)return;let n=this.header.readUInt32BE(0);if(n===0||n>this.maxFrameBytes)throw l(`malformed-tree`,`frame-limit-exceeded`,{bodyBytes:n,maxFrameBytes:this.maxFrameBytes});return this.expectedBodyBytes=n,{offset:t,bodyBytes:n}}appendPayload(e,t,n){let r=n-this.payloadBytes,i=e.length-t;if(i>r)throw l(`malformed-tree`,`multiple-frames`,{trailingBytes:i-r});i!==0&&(this.chunks.push(e.subarray(t)),this.payloadBytes+=i)}finish(){if(this.frame)return this.frame;throw l(`transport-failure`,`bridge-frame-incomplete`,{headerBytes:this.headerBytes,payloadBytes:this.payloadBytes,expectedBodyBytes:this.expectedBodyBytes})}};function ae(e){let t;try{t=JSON.parse(e.toString(`utf8`))}catch(e){throw l(`malformed-tree`,`response-not-json`,{},e)}if(!j(t))throw l(`malformed-tree`,`response-not-object`);return t}function D(e){return Object.freeze({verb:`describe`,requestId:e.requestId,pid:e.pid,generation:e.generation,snapshotTree:!0,automationMode:!0,maxDepth:e.maxDepth,maxNodes:e.maxNodes,maxDurationMs:e.maxDurationMs,maxResponseBytes:e.maxResponseBytes,...e.nativeLevelsHint===void 0?{}:{nativeLevelsHint:e.nativeLevelsHint}})}function O(e,t){if(e.protocolVersion!==1)throw l(`transport-failure`,`protocol-version-mismatch`,{expected:1,observed:e.protocolVersion});if(e.sourceVersion!==`agent-device-simulator-ax-v1.8.0`)throw l(`transport-failure`,`source-version-mismatch`,{expected:w,observed:e.sourceVersion});if(e.requestId!==t)throw l(`transport-failure`,`request-id-mismatch`,{expected:t,observed:e.requestId})}function k(e,t){if(typeof e.pid!=`number`||e.pid!==t.pid)throw l(`stale-target`,`bridge-pid-mismatch`,{expectedPid:t.pid,observedPid:e.pid});if(e.generation!==t.generation)throw l(`stale-target`,`bridge-generation-mismatch`,{expectedGeneration:t.generation,observedGeneration:e.generation})}function A(e){let t=e.error_kind,n=typeof e.error_code==`string`?e.error_code:`guest-error`,r=typeof e.error==`string`?e.error:void 0,i=r?{guestMessage:r.slice(0,1024)}:{};throw l(t===`unsupported`?`unsupported`:t===`malformed_tree`?`malformed-tree`:t===`application_not_responding`?`timeout`:t===`application_unavailable`?`transport-failure`:t===`bad_request`?`malformed-tree`:`transport-failure`,n,i)}function j(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function oe(e){let t=new E(e.limits.maxResponseBytes-4),n=s(e.deadline,`bridge-request-deadline`);return await new Promise((r,i)=>{let a=!1,o=!1,s=setTimeout(()=>{h(l(`timeout`,`bridge-request-deadline`,{dispatched:o})),e.socket.destroy()},n),c=()=>{h(l(`cancelled`,`abort-signal`,{dispatched:o})),e.socket.destroy()},u=n=>{try{if(!Buffer.isBuffer(n))throw l(`transport-failure`,`bridge-data-invalid`);let r=t.push(n);if(r){let t=ae(r);if(O(t,e.requestId),k(t,{pid:e.expectedPid,generation:e.expectedGeneration}),t.ok!==!0&&A(t),typeof t.truncated!=`boolean`)throw l(`malformed-tree`,`truncated-invalid`);m(t);return}}catch(t){h(t),e.socket.destroy()}},d=e=>h(f(e)),p=()=>{a||(e.process.isAlive()?h(l(`transport-failure`,`bridge-connection-closed`)):C(e.host,e.process).then(h))};e.process.wait.then(()=>{a||C(e.host,e.process).then(h)},e=>{a||h(f(e))});let m=e=>g(()=>r(e)),h=e=>g(()=>i(e)),g=t=>{a||(a=!0,clearTimeout(s),e.deadline.signal?.removeEventListener(`abort`,c),e.socket.off(`data`,u),e.socket.off(`error`,d),e.socket.off(`close`,p),t())};e.socket.on(`data`,u),e.socket.on(`error`,d),e.socket.on(`close`,p),e.deadline.signal?.addEventListener(`abort`,c,{once:!0});try{if(e.deadline.signal?.aborted)throw l(`cancelled`,`abort-signal`);o=!0,e.socket.write(e.frame)}catch(t){h(f(t)),e.socket.destroy()}})}var se=class{sessions=new Map;requestQueues=new Map;ownerId=b();closed=!1;host;constructor(e){this.host=e}async request(e){if(this.closed)throw l(`unsupported`,`source-closed`);return await this.withSimulatorLock(e.target.simulator.udid,e.deadline,()=>this.requestInSimulator(e))}async requestInSimulator(e){if(this.closed)throw l(`unsupported`,`source-closed`);let t=e.deadline;s(t,`bridge-request-deadline`);let n=this.sessions.get(e.target.simulator.udid),r=await this.ensureSession(e,t);try{let n=await this.readTargetStartTime(e.target,t),i=await this.exchange(r,e,t);return await this.assertTargetStillCurrent(e.target,n,t),i}catch(e){throw await this.handleRequestFailure(e,r,n)}}async handleRequestFailure(e,t,n){let r=f(e);return le(r,t,n)?await this.removeSession(t,!0):r.failureKind===`process-crash`?await this.removeSession(t,!1):r.failureKind===`transport-failure`&&(t.socket?.destroy(),t.socket=void 0),r}async withSimulatorLock(e,t,n){let r=this.requestQueues.get(e)??Promise.resolve(),i,a=new Promise(e=>{i=e}),o=r.then(()=>a);this.requestQueues.set(e,o);try{return await ce(r,t),await n()}finally{i(),this.requestQueues.get(e)===o&&this.requestQueues.delete(e)}}async close(){if(this.closed)return;this.closed=!0;let e=[...this.sessions.values()];this.sessions.clear(),await Promise.all(e.map(async e=>await this.dispose(e,!0)))}async ensureSession(e,t){let n=e.target.simulator.udid,r=this.sessions.get(n);if(r&&r.bridgePath===e.bridge.path&&r.process.isAlive())return(!r.socket||r.socket.destroyed)&&(r.socket=await this.connectUntilReady(r,t)),r;r&&await this.removeSession(r,!0);let i=o(this.host,e.target.simulator.udid,this.ownerId);await this.host.ensureDirectory(y.dirname(i)),await this.host.remove(i);let a=this.host.start(e.target.simulator,e.bridge.path,i,{signal:t.signal}),s={udid:e.target.simulator.udid,bridgePath:e.bridge.path,socketPath:i,process:a};this.sessions.set(n,s);try{return s.socket=await this.connectUntilReady(s,t),s}catch(e){throw await this.removeSession(s,!0),f(e)}}async connectUntilReady(e,t){let n;for(;;){let r=s(t,`bridge-connect-deadline`);if(!e.process.isAlive())throw await C(this.host,e.process);try{return await this.host.connect(e.socketPath,{signal:t.signal,timeoutMs:Math.min(250,r)})}catch(e){if(n=e,e instanceof h&&e.failureKind===`cancelled`)throw e;let r=Math.min(20,s(t,`bridge-connect-deadline`));try{await c(t,r,`bridge-connect-deadline`)}catch(e){throw f(e)}}if(n instanceof h&&n.failureKind===`timeout`)throw n}}async exchange(e,t,n){(!e.socket||e.socket.destroyed)&&(e.socket=await this.connectUntilReady(e,n));let r=b(),i=ie(D({requestId:r,pid:t.target.pid,generation:t.target.generation,maxDepth:Math.min(t.limits.maxTraversalDepth,t.maxDepth),maxNodes:t.limits.maxNodes,maxDurationMs:s(n,`bridge-request-deadline`),maxResponseBytes:t.limits.maxResponseBytes,...t.nativeLevelsHint===void 0?{}:{nativeLevelsHint:t.nativeLevelsHint}}),t.limits);return await oe({process:e.process,socket:e.socket,frame:i,requestId:r,deadline:n,limits:t.limits,expectedPid:t.target.pid,expectedGeneration:t.target.generation,host:this.host})}async readTargetStartTime(e,t){let n=await this.host.readTargetProcessStartTime(e.pid,{signal:t.signal,timeoutMs:s(t,`target-identity-deadline`)});if(!n)throw l(`stale-target`,`target-process-unavailable`,{pid:e.pid,generation:e.generation});if(e.processStartTime!==void 0&&e.processStartTime!==n)throw l(`stale-target`,`target-process-changed`,{pid:e.pid,generation:e.generation,expectedStartTime:e.processStartTime,observedStartTime:n});return n}async assertTargetStillCurrent(e,t,n){let r=await this.host.readTargetProcessStartTime(e.pid,{signal:n.signal,timeoutMs:s(n,`target-identity-deadline`)});if(r!==t)throw l(`stale-target`,`target-process-changed`,{pid:e.pid,generation:e.generation,expectedStartTime:t,observedStartTime:r})}async removeSession(e,t){this.sessions.get(e.udid)===e&&this.sessions.delete(e.udid),await this.dispose(e,t)}async dispose(e,t){e.socket?.destroy(),e.socket=void 0,t&&e.process.isAlive()&&(e.process.signal(`SIGTERM`),await M(e.process,500),e.process.isAlive()&&(e.process.signal(`SIGKILL`),await M(e.process,500))),await this.host.remove(e.socketPath)}};async function ce(e,t){let n=s(t,`bridge-request-deadline`);await Promise.race([e,c(t,n,`bridge-request-deadline`).then(()=>{throw l(`timeout`,`bridge-request-deadline`)})])}function le(e,t,n){return(e.failureKind===`cancelled`||e.failureKind===`timeout`)&&(e.details?.dispatched===!0||n!==t)}async function M(e,t){await Promise.race([e.wait.catch(()=>void 0),new Promise(e=>setTimeout(e,t))])}const N=16777216,P=12e4,F=1e4,I=Object.freeze({maxRequestBytes:65536,maxResponseBytes:4194304,maxNodes:5e3,maxTraversalDepth:64,maxDurationMs:5e3});function L(t){let n={...I,...t??{}};for(let[t,r]of Object.entries(n))if(!Number.isSafeInteger(r)||r<=0)throw new e(`INVALID_ARGS`,`Snapshot source limit ${t} must be a positive integer`,{name:t,value:r});if(n.maxRequestBytes>n.maxResponseBytes)throw new e(`INVALID_ARGS`,`Snapshot source request bytes cannot exceed response bytes`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes});if(n.maxRequestBytes>N||n.maxResponseBytes>N)throw new e(`INVALID_ARGS`,`Snapshot source frame limits exceed the bridge bound`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes,maximumFrameBytes:N});if(n.maxNodes>F||n.maxTraversalDepth>128)throw new e(`INVALID_ARGS`,`Snapshot source tree limits exceed the bridge bound`,{maxNodes:n.maxNodes,maxTraversalDepth:n.maxTraversalDepth,maximumNodes:F,maximumDepth:128});if(n.maxDurationMs>P)throw new e(`INVALID_ARGS`,`Snapshot source duration exceeds the bridge bound`,{maxDurationMs:n.maxDurationMs,maximumDurationMs:P});if(n.maxRequestBytes<=4||n.maxResponseBytes<=4)throw new e(`INVALID_ARGS`,`Snapshot source frame limits must leave room for a body`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes});return Object.freeze(n)}const R=12e4;async function z(e){let t=e.deadline,n=e.sourceRoot??V(e.host),r=await g(e.host,n,_,t),i=await d(e.host,e.runtime,t),a=e.cacheRoot??y.join(e.host.homeDirectory(),`.agent-device`,`snapshot-source`),o=await ee({host:e.host,deadline:t,cacheRoot:a,binaryFilename:`snapshot-bridge`,lockDescription:`iOS Simulator snapshot bridge cache`,keyInputs:{schemaVersion:1,protocolVersion:1,sourceVersion:w,sourceHash:r,toolchain:i,compileArgv:B({architecture:i.architecture,sourceRoot:``,outputPath:``})},build:async r=>{let a=await p({host:e.host,deadline:t,argv:B({architecture:i.architecture,sourceRoot:n,outputPath:r}),budgetMs:R,label:`bridge`});if(a.exitCode!==0||!e.host.exists(r))throw l(`unsupported`,`native-build-failed`,{exitCode:a.exitCode,stderr:a.stderr.slice(0,4096)})}});return{path:o.path,sourceHash:r,cacheKey:o.cacheKey,protocolVersion:1,sourceVersion:w}}function B(e){return[`--sdk`,`iphonesimulator`,`clang`,`-arch`,e.architecture,`-mios-simulator-version-min=15.0`,`-fobjc-arc`,`-Wall`,`-Wextra`,`-framework`,`Foundation`,`-framework`,`CoreGraphics`,...m.map(t=>y.join(e.sourceRoot,t)),`-o`,e.outputPath]}function V(e){let t=e.projectRoot(),n=y.join(t,`apple`,`snapshot-bridge`);if(_.every(t=>e.exists(y.join(n,t))))return n;let r=y.join(t,`dist`,`apple`,`snapshot-bridge`);if(_.every(t=>e.exists(y.join(r,t))))return r;throw l(`unsupported`,`native-source-missing`,{projectRoot:t})}const H=i+R;function U(e){let t=e.now??Date.now,n=new Map,r=a({waitMs:2e3,waitGrant:`first-caller`,retryAfterMs:6e4,now:t}),i=async(r,i)=>{let a=v(H,i,t);try{let t=await e.host.withDiagnosticTimer(`ios.snapshot-source.prepare`,async()=>await z({host:e.host,runtime:r,limits:e.limits,deadline:a,sourceRoot:e.sourceRoot,cacheRoot:e.cacheRoot}),{producer:e.producer});return n.set(r,t),t}catch(e){throw f(e)}};return{readyBinary:async(e,t,a)=>n.get(e)||await r.value(e,{start:t=>i(e,t),wait:(e,n)=>c(t,e,a,n),pending:()=>l(`preparing`,`bridge-preparation-pending`)}),close:()=>{n.clear(),r.close()}}}function W(e,n){return!t(e)||!t(n)||Math.abs(n.width-n.height)<=1?!1:Math.abs(e.width-n.height)<=1&&Math.abs(e.height-n.width)<=1}const G=Object.freeze({elementType:`XC_kAXXCAttributeElementType`,elementBaseType:`XC_kAXXCAttributeElementBaseType`,label:`XC_kAXXCAttributeLabel`,value:`XC_kAXXCAttributeValue`,placeholder:`XC_kAXXCAttributePlaceholderValue`,identifier:`XC_kAXXCAttributeIdentifier`,frame:`XC_kAXXCAttributeFrame`,automationType:`XC_kAXXCAttributeAutomationType`,traits:`XC_kAXXCAttributeTraits`,userInteractionEnabled:`XC_kAXXCAttributeIsUserInteractionEnabled`,children:`XC_kAXXCAttributeChildren`}),K=`Other.Other.Application.Group.Window.Sheet.Drawer.Alert.Dialog.Button.RadioButton.RadioGroup.CheckBox.DisclosureTriangle.PopUpButton.ComboBox.MenuButton.ToolbarButton.Popover.Keyboard.Key.NavigationBar.TabBar.TabGroup.Toolbar.StatusBar.Table.TableRow.TableColumn.Outline.OutlineRow.Browser.CollectionView.Slider.PageIndicator.ProgressIndicator.ActivityIndicator.SegmentedControl.Picker.PickerWheel.Switch.Toggle.Link.Image.Icon.SearchField.ScrollView.ScrollBar.StaticText.TextField.SecureTextField.DatePicker.TextView.Menu.MenuItem.MenuBar.MenuBarItem.Map.WebView.IncrementArrow.DecrementArrow.Timeline.RatingIndicator.ValueIndicator.SplitGroup.Splitter.RelevanceIndicator.ColorWell.HelpTag.Matte.DockItem.Ruler.RulerMarker.Grid.LevelIndicator.Cell.LayoutArea.LayoutItem.Handle.Stepper.Tab.TouchBar.StatusItem`.split(`.`),q={UIApplication:`Application`,UIWindow:`Window`},ue=new Set(Object.values(G)),de=1n<<8n,fe=1n<<3n,pe={x:0,y:0,width:0,height:0};function me(e,t,n){let r=Array.isArray(e)?e:[e];if(r.length===0||r.some(e=>!j(e)))throw l(`malformed-tree`,`guest-tree-root-invalid`);let i=[],a=[],o=0;for(let e of r)c(e,void 0,0,!1);if(i.length>n.maxNodes)throw l(`malformed-tree`,`node-limit-exceeded`,{nodeCount:i.length,maxNodes:n.maxNodes});if(o>n.maxTraversalDepth)throw l(`malformed-tree`,`traversal-depth-exceeded`,{maxTraversalDepth:o,maxAllowedDepth:n.maxTraversalDepth});if(typeof t.truncated!=`boolean`)throw l(`malformed-tree`,`truncated-invalid`);let s=ye(i.filter(Y)[0]);return s.kind===`reported`&&be(i,s.rect),{nodes:i,maxTraversalDepth:o,viewport:s,opaqueRemoteElements:a.filter(e=>_e(e,s)).length,unresolvedCoordinateSpaceWindows:xe(i,s)};function c(e,t,r,s){if(i.length>=n.maxNodes)throw l(`malformed-tree`,`node-limit-exceeded`,{maxNodes:n.maxNodes});for(let t of Object.keys(e))if(!ue.has(t))throw l(`malformed-tree`,`node-contains-unknown-field`,{key:t});let u=e[G.children];if(!Array.isArray(u))throw l(`malformed-tree`,`children-invalid`);let d=i.length,f=he(e,d,t,r);i.push(f),o=Math.max(o,r),ge(f,u.length,s)&&a.push(f.rect);let p=s||f.type===`WebView`;for(let e of u){if(!j(e))throw l(`malformed-tree`,`child-invalid`);c(e,d,r+1,p)}}}function he(e,t,n,r){let i=X(e[G.elementType]),a=X(e[G.elementBaseType]),o=Te(e[G.automationType]),s=ve(e[G.frame]),c=Ce(e[G.traits]),l=c===void 0?void 0:(c&de)===0n,u=c===void 0||(c&fe)===0n?void 0:!0,d=we(e[G.userInteractionEnabled]),f=X(e[G.placeholder])?.trim();return{index:t,...n===void 0?{}:{parentIndex:n},...J(i,o)?{type:J(i,o)}:{},...i?{role:i}:{},...a&&a!==i?{subrole:a}:{},...X(e[G.label])?{label:X(e[G.label])}:{},...Z(e[G.value])?{value:Z(e[G.value])}:{},...f?{placeholder:f}:{},...X(e[G.identifier])?{identifier:X(e[G.identifier])}:{},...s?{rect:s}:{},...l===void 0?{}:{enabled:l},...u===void 0?{}:{selected:u},...d===void 0?{}:{userInteractionEnabled:d},depth:r}}function J(e,t){if(e!==void 0&&q[e])return q[e];if(e!==void 0&&K.includes(e))return e;if(t!==void 0)return K[t]??`Other`}function ge(e,t,n){return n&&e.role===`AXRemoteElement`&&t===0}function _e(e,r){return e===void 0?!0:t(e)?r.kind!==`reported`||n(e,r.rect):!1}function ve(e){if(e===void 0)return;if(!j(e))throw l(`malformed-tree`,`frame-invalid`);let t=[`X`,`Y`,`Width`,`Height`].map(t=>e[t]);if(!t.every(e=>typeof e==`number`&&Number.isFinite(e)))throw l(`malformed-tree`,`frame-invalid`);let[n,r,i,a]=t;if(i<0||a<0)throw l(`malformed-tree`,`frame-invalid`);return{x:n,y:r,width:i,height:a}}function ye(e){return!e||!Y(e)?{kind:`missing`,reason:`not-provided`}:t(e.rect)?{kind:`reported`,rect:e.rect}:{kind:`missing`,reason:e.rect?`invalid`:`not-provided`}}function Y(e){return e.type===`Application`||e.type===`Window`}function be(e,t){for(let n of e)n.hittable=n.parentIndex!==void 0&&r(n.enabled!==!1,n.rect,t)}function xe(e,t){return t.kind===`reported`?e.filter(n=>Se(n,e)&&W(n.rect??pe,t.rect)).length:0}function Se(e,t){return Y(e)?!0:e.parentIndex!==void 0&&Y(t[e.parentIndex]??e)}function X(e){return typeof e==`string`&&e.length>0?e:void 0}function Z(e){if(typeof e==`string`)return e.length>0?e:void 0;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(e!=null)throw l(`malformed-tree`,`scalar-invalid`)}function Ce(e){if(e!=null){if(typeof e!=`string`||!/^\d{1,20}$/.test(e))throw l(`malformed-tree`,`traits-invalid`);return BigInt(e)}}function we(e){if(e!=null){if(typeof e!=`boolean`)throw l(`malformed-tree`,`user-interaction-invalid`);return e}}function Te(e){if(e!=null){if(!Number.isSafeInteger(e))throw l(`malformed-tree`,`automation-type-invalid`);return e}}const Q=`simulator-ax-bridge`;function Ee(e={}){let t=e.host??u(),n=new se(t),r=new te,i=U({host:t,limits:L(e.limits),producer:Q,sourceRoot:e.sourceRoot,cacheRoot:e.cacheRoot}),a=!1;return{acquire:async o=>{try{if(a)throw l(`unsupported`,`source-closed`);De(o);let c=L({...e.limits,...o.limits}),u=v(c.maxDurationMs,o.signal),d=ke(o.hint,c.maxTraversalDepth),f=d+1,p=o.hint.rawTraversalDepth!==null;return await t.withDiagnosticTimer(`ios.snapshot-source.acquire`,async()=>{let e=await i.readyBinary(o.target.runtime,u,`bridge-preparation-deadline`),a=r.consume(o.target,f,p),l=await n.request({target:o.target,bridge:e,limits:c,maxDepth:d,nativeLevelsHint:a.nativeLevels,deadline:u});s(u,`snapshot-decode-deadline`);let m=Ae(o.hint,o.target,l,c);return Oe(t,r,o.target,f,p,a,l),{stage:`acquired`,acquisition:m}},{producer:Q})}catch(e){let t=f(e);return{stage:`failed`,failure:{kind:t.failureKind,code:t.failureCode,...t.details?{details:t.details}:{}}}}},close:async()=>{a||(a=!0,i.close(),await n.close())}}}function De(t){if(!t.target.simulator.udid.trim()||!t.target.runtime.trim()||!t.target.generation.trim()||!Number.isSafeInteger(t.target.pid)||t.target.pid<=0)throw new e(`INVALID_ARGS`,`Simulator snapshot source target identity is incomplete`);let n=t.hint;if(n.projection!==`raw`&&n.projection!==`regular`||![`full`,`surface-observation`].includes(n.acquisitionIntent)||typeof n.interactiveOnly!=`boolean`||typeof n.customActions!=`boolean`||!$(n.rawTraversalDepth)||!$(n.regularPresentedDepth))throw new e(`INVALID_ARGS`,`Simulator snapshot source capture hint is invalid`)}function Oe(e,t,n,r,i,a,o){let s=re(o),c=o.truncated===!0,l=t.learn(n,r,i,s);e.emitDiagnostic({level:`debug`,phase:`ios_snapshot_source_recovery`,data:{producer:Q,...n.targetId?{targetId:n.targetId}:{},generation:n.generation,requestedLevels:r,hint:a.reason,...a.nativeLevels===void 0?{}:{hintedLevels:a.nativeLevels},...s,truncated:c,learning:l}})}function ke(t,n){let r=t.rawTraversalDepth??n;if(r>n)throw new e(`INVALID_ARGS`,`Simulator snapshot source depth exceeds its bound`,{requested:r,maximum:n});return r}function $(e){return e===null||Number.isSafeInteger(e)&&e>=0}function Ae(e,t,n,r){if(n.automationEnabled!==!0)throw l(`unsupported`,`automation-mode-unavailable`);let i=n.tree,a=n.truncated;if(typeof a!=`boolean`)throw l(`malformed-tree`,`truncated-invalid`);let o=me(i,{truncated:a},r),s=n.generation;if(typeof s!=`string`||!s)throw l(`malformed-tree`,`generation-invalid`);if(o.opaqueRemoteElements>0)throw l(`unsupported`,`remote-content-boundary`,{remoteElements:o.opaqueRemoteElements});if(o.unresolvedCoordinateSpaceWindows>0)throw l(`unsupported`,`window-coordinate-space-unresolved`,{windows:o.unresolvedCoordinateSpaceWindows});let c=Object.freeze(o.nodes.map(e=>Object.freeze({...e,pid:t.pid}))),u=je(e,a,o.viewport),d=Object.freeze({...t.targetId?{targetId:t.targetId}:{},generation:s}),f={producer:Q,nodes:c,truncated:a,viewport:o.viewport,lineage:d,residue:u};return e.acquisitionIntent===`full`?{...f,intent:`full`,hint:{...e,acquisitionIntent:`full`}}:{...f,intent:`surface-observation`,hint:{...e,acquisitionIntent:`surface-observation`}}}function je(e,t,n){let r=n.kind===`reported`?[]:[{kind:`unavailable-fact`,fact:`hittability`}];return Object.freeze([...r,...e.interactiveOnly?[{kind:`unavailable-fact`,fact:`interactive-query`}]:[],...t?[{kind:`truncated`}]:[],...n.kind===`missing`?[{kind:`missing-viewport`,reason:n.reason}]:[]])}export{Ee as createSimulatorSnapshotSource};
|
package/dist/src/adb-executor.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{A as e}from"./sdk-contracts.js";import{n as t,r as n,t as r}from"./device-shell.js";import{a as i,d as a,f as o,i as s,l as c,m as l,n as u,p as d,s as f,u as p}from"./adb-transport.js";import{c as m,n as h}from"./adb-failure.js";import{AsyncLocalStorage as g}from"node:async_hooks";let _;const v=new g;function y(e){_=e}function b(){if(!_)throw Error(`Android adb host port is not bound; import the platform composition wiring (src/platform-runtime-android-adb-host.ts) before using the adb/IME cluster.`);return _}async function x(e,t){let n=b(),r=v.getStore(),i=n.coerceAdbResult(r?await r(e,t):await n.execAdb(e,{...t,allowFailure:!0}));if(!t?.allowFailure&&i.exitCode!==0){let{androidAdbResultError:t}=await import(`./adb-failure.js`).then(e=>e.t),{serializeAndroidAdbInvocation:n}=await import(`./adb-transport.js`).then(e=>e.t);throw t(`adb ${n(e).join(` `)} exited with code ${i.exitCode}`,i)}return i}async function S(e,t){return await v.run(e,t)}function ee(e){b().emitDiagnostic(e)}const C=new WeakSet;function w(e){return T(typeof e==`function`?{exec:e}:e)}function T(e){if(C.has(e))return e;let t={...e,exec:m(E(e.exec)),...e.pull?{pull:m(E(e.pull))}:{},...e.install?{install:m(E(e.install))}:{},...e.installBundle?{installBundle:m(e.installBundle)}:{}};return C.add(t),t}function E(e){return async(...t)=>b().coerceAdbResult(await e(...t))}const D=new WeakSet;function te(t){let n=w(t);if(n.reverse&&D.has(n.reverse))return n.reverse;let r=n.reverse??O(n.exec),i=new Map,a={async ensure(t,n){let a=i.get(t.local);if(a&&a.ownerId!==t.ownerId)throw new e(`COMMAND_FAILED`,`Android port reverse ${t.local} is already owned by ${a.ownerId??`another session`}`,{current:a,requested:t});a?.remote!==t.remote&&(await r.ensure(t,n),i.set(t.local,{...t}))},async remove(e,t){if(!i.has(e)){await r.remove(e,t);return}await r.remove(e,t),i.delete(e)},async removeAllOwned(e,t){let n=[...i.values()].filter(t=>t.ownerId===e).map(e=>e.local);if(n.length===0){await r.removeAllOwned(e,t);return}for(let e of n)await r.remove(e,t),i.delete(e)},async list(e){return r.list?await r.list(e):[...i.values()]}};return D.add(a),a}function O(e){let t=new Map;return{async ensure(n,r){if(await e([`reverse`,n.local,n.remote],{allowFailure:!1,signal:r?.signal,timeoutMs:r?.timeoutMs}),n.ownerId){let e=t.get(n.ownerId)??new Set;e.add(n.local),t.set(n.ownerId,e)}},async remove(n,r){let i=await e([`reverse`,`--remove`,n],{allowFailure:!0,signal:r?.signal,timeoutMs:r?.timeoutMs});if(i.exitCode!==0&&!A(i.stdout,i.stderr))throw h(`Failed to remove Android port reverse ${n}`,i,{local:n});for(let e of t.values())e.delete(n)},async removeAllOwned(e,n){let r=[...t.get(e)??[]];for(let e of r)await this.remove(e,n);t.delete(e)},async list(n){let r=await e([`reverse`,`--list`],{allowFailure:!0,signal:n?.signal,timeoutMs:n?.timeoutMs});return r.exitCode===0?k(r.stdout,t):[]}}}function k(e,t){let n=new Map;for(let[e,r]of t)for(let t of r)n.set(t,e);return e.split(`
|
|
2
2
|
`).map(e=>e.trim().split(/\s+/)).filter(e=>e.length>=3).map(([,e,t])=>{let r=e;return{local:r,remote:t,ownerId:n.get(r)}})}function A(e,t){let n=`${e}\n${t}`.toLowerCase();return n.includes(`listener`)&&n.includes(`not found`)}const j=new g;function M(e,t={}){return Q(N(e.id,t.serverPort))}function N(e,t){return m(async(n,r)=>{let i=F(e,t,n,r);return await b().withoutAdbCommandExecutorOverride(async()=>await b().execAdb(i.invocation,i.options))})}function P(e,t){return $((n,r)=>{let i=F(e,t,n,r);return b().spawnAdb(i.invocation,i.options)})}function F(e,t,n,r){let{serverPort:i,...a}=r??{};return{invocation:I(e,n,L(e,t,i)),options:a}}function I(e,t,n){let r=p(t),i=u(r.target,e);if(n===void 0)return s(i,r.command,[`-s`,e,...t]);let a=f(r,{port:n});return s(o(a.target,e),a.command)}function L(e,t,n){let r=j.getStore();return r&&X(r,{kind:`serial`,serial:e}),r?.serverPort===void 0?t??n:(d(t,r.serverPort),d(n,r.serverPort))}function R(e,t={}){let n=M(e,t);return{exec:n,spawn:P(e.id,t.serverPort),reverse:O(n),pull:async(e,t,r)=>await n([`pull`,e,t],r),install:async(e,t)=>{let{installArgs:r,execOptions:i}=c(t);return await n([`install`,...r,e],i)}}}function z(e,t){let n=Y(e);return t?Q(t):n?.serial===e.id?Q(n.provider.exec):M(e)}function B(e,t){let n=Y(e);return ie(t?w(t):n?.serial===e.id?w(n.provider):R(e))}function V(e){let t=Y(e);return t?.serial===e.id?{mode:`transport-composed`,...t.provider.spawn?{spawn:$(t.provider.spawn)}:{}}:{mode:`local`}}function H(e){let t=Y(e);return t?.serial===e.id?t.provider.text:void 0}function U(e){let t=Y(e);return t?.serial===e.id&&t.provider.touch?t.provider:void 0}function W(e,t){if(t)return w(t);if(e)return B(e);let n=j.getStore();if(n)return w(n.provider)}async function G(e,t,n){if(!e)return await n();let r={provider:w(e),serial:t.serial,...t.serverPort===void 0?{}:{serverPort:t.serverPort}},i=K(r),a=async()=>await j.run(r,async()=>await b().withAdbCommandExecutorOverride(i,n));return t.serverPort===void 0?await a():await S(q(r,t.serverPort),a)}function K(e){return(t,n,r)=>{if(!Z(t)||e.serverPort===void 0&&t!==`adb`)return;let o=p(n);if(X(e,o.target.selector),o.target.selector.kind===`serial`){if(o.target.selector.serial!==e.serial)return;e.serverPort!==void 0&&a(o.target,e.serverPort);let t=i(n,e.serial);return t===void 0?void 0:b().withoutAdbCommandExecutorOverride(async()=>await e.provider.exec(t,r))}let s=e.serverPort;if(s!==void 0)return J(e,s,o,r)}}function q(e,t){return async(n,r)=>(X(e,n.target.selector),J(e,t,n,r))}async function J(e,t,n,r){d(t,r?.serverPort);let{serverPort:i,...a}=r??{},c=o(n.target,e.serial),l=f(s(c,n.command),{port:t}),u=b();return await u.withoutAdbCommandExecutorOverride(async()=>await u.execAdb(l,{...a,allowFailure:!0}))}function Y(e){let t=j.getStore();return t&&X(t,{kind:`serial`,serial:e.id}),t}function X(e,t){e?.serverPort!==void 0&&l(t,e.serial)}function Z(e){return n(e)===`adb`}async function ne(e,n,r){return await e(t(`adb`,`shell`,n),r)}async function re(e,n,r){return await e(t(`adb`,`exec-out`,n),r)}function Q(e){return async(t,n)=>(r(t,`adb`),await e(t,n))}function $(e){return(t,n)=>(r(t,`adb`),e(t,n))}function ie(e){return{...e,exec:Q(e.exec),...e.spawn?{spawn:$(e.spawn)}:{}}}async function ae(t,n,r){let{device:i,provider:a,...o}=r??{},s=W(i,a),c=s?.pull,l=b();if(c)return await l.withoutAdbCommandExecutorOverride(async()=>await c(t,n,o));let u=s?.exec;if(!u)throw new e(`COMMAND_FAILED`,`Android adb pull requires an adb provider`);return await l.withoutAdbCommandExecutorOverride(async()=>await u([`pull`,t,n],o))}async function oe(t,n){let{device:r,provider:i,...a}=n??{},o=W(r,i),s=o?.install,l=b();if(s)return await l.withoutAdbCommandExecutorOverride(async()=>await s(t,a));let u=o?.exec;if(!u)throw new e(`COMMAND_FAILED`,`Android adb install requires an adb provider`);let{installArgs:d,execOptions:f}=c(a);return await l.withoutAdbCommandExecutorOverride(async()=>await u([`install`,...d,t],f))}export{x as _,z as a,U as c,ne as d,G as f,b as g,ee as h,R as i,V as l,y as m,ae as n,B as o,te as p,M as r,H as s,oe as t,re as u,S as v};
|
package/dist/src/adb-failure.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime.js";import{A as t}from"./sdk-contracts.js";import{r as n}from"./exec.js";import"./command.js";var r=e({androidAdbResultError:()=>u,androidDiscoveryCommandError:()=>f,attachAdbFailureHint:()=>s,attachAndroidDiscoveryTimeout:()=>p,attachAndroidHelperInstallTimeoutHint:()=>c,classifyAndroidAdbFailure:()=>o,withAdbFailureHints:()=>d});const i=[[/device unauthorized|device still authorizing/,{reason:`device_unauthorized`,hint:`USB debugging is not authorized — accept the authorization prompt on the device screen (re-plug the cable if none appears), then retry.`}],[/device offline/,{reason:`device_offline`,hint:`The device is connected but offline — wait for it to finish booting or run adb reconnect, then retry.`,retriable:!0}],[/more than one (?:device\/emulator|device and emulator)/,{reason:`multiple_devices`,hint:`Multiple Android devices are connected — pass --serial <serial> (see adb devices) to select one.`}],[/no devices\/emulators found|no devices found/,{reason:`no_devices`,hint:`No Android devices detected — boot an emulator or connect a device and verify it appears in adb devices.`}],[/device (?:'[^']*' )?not found/,{reason:`device_not_found`,hint:`The device disconnected or is restarting — verify it is listed in adb devices, then retry.`,retriable:!0}],[/adb server version \(\d+\) doesn't match this client/,{reason:`server_version_mismatch`,hint:`Multiple adb installs conflict — adb restarts its server automatically, so retry; align PATH to a single adb to stop recurrences.`,retriable:!0}],[/transport error|connection reset|broken pipe|protocol fault/,{reason:`connection_dropped`,hint:`The adb connection dropped — retry; if it persists, run adb kill-server and reconnect the device.`,retriable:!0}],[/install_failed_insufficient_storage/,{reason:`install_insufficient_storage`,hint:`The device is out of storage — free up space or uninstall unused apps, then retry the install.`},!0],[/install_failed_update_incompatible/,{reason:`install_update_incompatible`,hint:`The installed app has an incompatible signature — uninstall the existing app first, then retry the install.`},!0],[/install_failed_version_downgrade/,{reason:`install_version_downgrade`,hint:`The APK is older than the installed app — uninstall the app first (or install with downgrade allowed), then retry.`},!0],[/install_failed_\w+|install_parse_failed_\w+/,{reason:`install_failed`,hint:`The Android package installer rejected the APK — see the INSTALL_FAILED code in the error output for the exact cause.`},!0]],a=Object.freeze({reason:`timeout`,hint:`adb timed out — the adb server may be wedged. Run adb kill-server && adb start-server, check adb devices, then retry.`});function o(e,t=``){let n=e.toLowerCase(),r=t.toLowerCase();for(let[e,t,a]of i)if(e.test(n)||a&&e.test(r))return t}function s(e){if(!(e instanceof t)||e.code!==`COMMAND_FAILED`)return e;let n=l(e);return n&&(e.details={...e.details,adbFailure:n.reason,...typeof e.details?.hint==`string`?{}:{hint:n.hint},...n.retriable!==void 0&&e.details?.retriable===void 0?{retriable:n.retriable}:{}}),e}function c(e){if(!n(e))return e;let t=e.details?.hint;if(typeof t==`string`&&t!==a.hint)return e;let r=s(e);return r.details={...r.details,hint:`The helper install timed out — some OEM builds (ColorOS is one) hold the first install of each package behind a system install-confirmation dialog and adb waits for it. Check the device screen, confirm any pending install prompt, then retry; if none is showing, run adb kill-server && adb start-server and retry.`},r}function l(e){return typeof e.details?.timeoutMs==`number`?a:o(typeof e.details?.stderr==`string`?e.details.stderr:``,typeof e.details?.stdout==`string`?e.details.stdout:``)}function u(e,n,r){let i=n.exitCode===0?{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode,...r}:{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode,processExitError:!0,...r};return s(new t(`COMMAND_FAILED`,e,i))}function d(e){return async(...t)=>{try{return await e(...t)}catch(e){throw s(e)}}}function f(e,n,r){let i=o(n.stderr,n.stdout);return new t(`COMMAND_FAILED`,e,{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode,processExitError:!0,hint:i?.hint??r,...i?{adbFailure:i.reason}:{},...i?.retriable===void 0?{}:{retriable:i.retriable}})}function p(e){return n(e)&&(e.details={...e.details,adbFailure:a.reason,...typeof e.details?.hint==`string`?{}:{hint:a.hint}}),e}export{p as a,d as c,s as i,u as n,c as o,f as r,o as s,r as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime.js";import{A as t}from"./sdk-contracts.js";import{i as n}from"./device-shell.js";var r=e({ADB_GLOBAL_OPTIONS:()=>a,ADB_MANAGED_FORBIDDEN_COMMANDS:()=>c,ADB_WAIT_STATES:()=>s,ADB_WAIT_TRANSPORTS:()=>o,adoptAndroidAdbSerial:()=>g,androidAdbHostTarget:()=>m,androidAdbInvocation:()=>h,androidAdbPayloadWithoutSerial:()=>T,androidAdbSerialTarget:()=>p,androidManagedAdbEnvironment:()=>P,applyManagedAndroidAdbServer:()=>E,lowerAndroidAdbInvocation:()=>N,normalizeAndroidAdbInstallOptions:()=>i,parseAndroidAdbArgv:()=>x,requireAndroidAdbServerPort:()=>C,requireManagedAndroidAdbAddressing:()=>k,requireManagedAndroidAdbCommand:()=>A,requireManagedAndroidAdbSerial:()=>D,requireSameAndroidAdbServer:()=>w,requireUnconflictedAndroidAdbSelector:()=>O,serializeAndroidAdbInvocation:()=>_});function i(e){let{replace:t,...n}=e??{};return{installArgs:t?[`-r`]:[],execOptions:n}}const a={"-a":0,"-d":0,"-e":0,"-s":1,"-t":1,"-H":1,"-P":1,"-L":1,"--one-device":1,"--exit-on-write-error":0},o=[``,`usb-`,`local-`,`any-`],s=[`device`,`recovery`,`bootloader`,`sideload`,`sideload-window`],c=[`nodaemon`,`server`,`fork-server`,`kill-server`,`start-server`,`connect`,`disconnect`,`reconnect`,`attach`,`detach`,`pair`],l=new Set(c);function u(e){return e.startsWith(`wait-for-`)}function d(e){if(!u(e))return;let t=e.slice(9);return o.some(e=>t.startsWith(e)&&s.includes(t.slice(e.length)))?e:void 0}function f(e){return l.has(e)}function p(e,t){return{selector:{kind:`serial`,serial:e},server:t===void 0?{kind:`ambient`}:{kind:`port`,port:t}}}function m(){return{selector:{kind:`unspecified`},server:{kind:`ambient`}}}function h(e,t,n){return{target:e,command:t,...n?{rawArgv:n}:{}}}function g(e,t){return{...e,selector:{kind:`serial`,serial:t}}}function _(e){if(e.rawArgv)return[...e.rawArgv];let{target:t,command:n}=e,r=[];return t.server.kind===`port`&&r.push(`-P`,String(t.server.port)),t.selector.kind===`serial`&&r.push(`-s`,t.selector.serial),t.hostGlobals&&r.push(...t.hostGlobals),t.waitFor&&r.push(t.waitFor),r.push(...n),r}const v={"-s":`serial`,"-P":`server`};function y(e,t){let n=e[t],r=d(n);if(r)return{kind:`wait`,waitFor:r,next:t+1};if(u(n))return{kind:`unknown-wait`,token:n,next:t+1};let i=v[n];if(i===void 0){if(!n.startsWith(`-`))return{kind:`stop`,next:t};let r=a[n]??0;return{kind:`global`,tokens:[n,...e.slice(t+1,t+1+r)],next:t+1+r}}let o=e[t+1]??``;if(i===`serial`)return{kind:`serial`,serial:o,next:t+2};let s=Number(o);return Number.isInteger(s)?{kind:`server`,port:s,next:t+2}:{kind:`global`,tokens:[n,o],next:t+2}}function b(e,t){e.kind===`wait`?t.waitFor===void 0?t.waitFor=e.waitFor:t.hostGlobals.push(e.waitFor):e.kind===`unknown-wait`?t.hostGlobals.push(e.token):e.kind===`serial`?t.selector.kind===`unspecified`?t.selector={kind:`serial`,serial:e.serial}:t.selector.serial!==e.serial&&t.hostGlobals.push(`-s`,e.serial):e.kind===`server`?t.server={kind:`port`,port:e.port}:e.kind===`global`&&t.hostGlobals.push(...e.tokens)}function x(e){let t=m(),r={selector:t.selector,server:t.server,waitFor:void 0,hostGlobals:[]},i=0;for(;;){let t=i<e.length?y(e,i):{kind:`stop`,next:i};if(t.kind===`stop`)break;b(t,r),i=t.next}let{selector:a,server:o,waitFor:s,hostGlobals:c}=r,l={selector:a,server:o,...s?{waitFor:s}:{},...c.length>0?{hostGlobals:c}:{}},u=c.length>0||s!==void 0||a.kind!==`unspecified`||o.kind===`port`;return{target:l,command:n(e,0,i),rawArgv:u?e:void 0}}function S(e){if(e.rawArgv===void 0)return e.target.server.kind===`port`?e.target.server.port:void 0}function C(e,t){return w(S(e),t?.serverPort)}function w(e,t){if(e!==void 0&&t!==void 0&&e!==t)throw M(`server`);return e??t}function T(e,t){let r=0;for(;;){let i=r<e.length?y(e,r):{kind:`stop`,next:r};if(i.kind===`stop`)return;if(i.kind===`serial`)return i.serial===t?n(e,r,2):void 0;r=i.next}}function E(e,t){let{target:n,command:r}=e;return k(n,t.port),A(r),h({selector:n.selector,server:{kind:`port`,port:t.port},...n.waitFor?{waitFor:n.waitFor}:{}},r)}function D(e,t){return O(e.selector,t),{...e,selector:{kind:`serial`,serial:t}}}function O(e,t){if(e.kind===`serial`&&e.serial!==t)throw M(`device`)}function k(e,t){if(e.hostGlobals)throw M(`target`);w(t,e.server.kind===`port`?e.server.port:void 0)}function A(e){if(f(e.find(e=>!u(e))??``))throw M(`target`)}const j={device:`Managed ADB transport cannot address another device.`,target:`Managed ADB transport cannot select another target.`,server:`Managed ADB transport cannot select another server.`};function M(e){throw new t(`COMMAND_FAILED`,j[e],{reason:`managed-device-transport-mismatch`})}function N(e,t,n){let{serverPort:r,...i}=t??{},a=C(e,t),o=a===void 0?e:E(e,{port:a}),s=a===void 0?void 0:P(o.target,n,i.env);return{args:_(o),options:{...i,...s===void 0?{}:{env:s}}}}function P(e,t,n){return e.server.kind===`port`?{...t,...n??{},ADB_SERVER_SOCKET:void 0,ANDROID_ADB_SERVER_PORT:String(e.server.port),ANDROID_ADB_SERVER_ADDRESS:`127.0.0.1`}:n}export{T as a,N as c,k as d,D as f,_ as h,h as i,i as l,O as m,g as n,p as o,w as p,m as r,E as s,r as t,x as u};
|