diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift index 5c32808afe..4409ff03f7 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift @@ -33,7 +33,13 @@ extension RunnerTests { #if !os(macOS) switch resolveBlockingSystemModal(deadline: deadline) { case .resolved(let modal): - return runnerAlert(modal) + return runnerAlert( + root: modal.root, + ownerApp: modal.ownerApp, + actions: modal.actions, + source: .blockingSystemModal, + window: modal.window + ) case .unresolved: return nil case .absent: @@ -49,15 +55,15 @@ extension RunnerTests { // now-gone host as `activeApp`, and its `alerts` query raises // kAXErrorServerNotFound. safeElementsQuery absorbs it and reports no alert. if let alert = firstExistingElement(in: safeElementsQuery { activeApp.alerts.allElementsBoundByIndex }) { - return runnerAlert(root: alert, ownerApp: activeApp, source: .appAlert) + return runnerAlert(root: alert, ownerApp: activeApp, actions: actionableElements(in: alert), source: .appAlert) } if let dialog = firstExistingElement(in: safeElementsQuery { activeApp.otherElements.matching(identifier: AlertSurface.safariDialogIdentifier).allElementsBoundByIndex }) { - return runnerAlert(root: dialog, ownerApp: activeApp, source: .safariDialog) + return runnerAlert(root: dialog, ownerApp: activeApp, actions: actionableElements(in: dialog), source: .safariDialog) } if let popup = firstDismissPopupWindow(in: activeApp) { - return runnerAlert(root: popup, ownerApp: activeApp, source: .dismissPopup) + return runnerAlert(root: popup, ownerApp: activeApp, actions: actionableElements(in: popup), source: .dismissPopup) } return nil } @@ -232,30 +238,18 @@ extension RunnerTests { operation() } - private func runnerAlert(_ modal: ResolvedBlockingSystemModal) -> RunnerAlert? { - let buttons = modal.actions.filter { isEnabledElement($0) } - guard !buttons.isEmpty else { - return nil - } - return RunnerAlert( - root: modal.root, - ownerApp: modal.ownerApp, - buttons: buttons, - source: .blockingSystemModal, - window: modal.window - ) - } - private func runnerAlert( root: XCUIElement, ownerApp: XCUIApplication, - source: AlertSurfaceSource + actions: [XCUIElement], + source: AlertSurfaceSource, + window: XCUIElement? = nil ) -> RunnerAlert? { - let buttons = actionableElements(in: root).filter { isEnabledElement($0) } + let buttons = actions.filter { isEnabledElement($0) } guard !buttons.isEmpty else { return nil } - return RunnerAlert(root: root, ownerApp: ownerApp, buttons: buttons, source: source, window: nil) + return RunnerAlert(root: root, ownerApp: ownerApp, buttons: buttons, source: source, window: window) } private func firstExistingElement(in elements: [XCUIElement]) -> XCUIElement? { @@ -346,11 +340,7 @@ extension RunnerTests { } private func isEnabledElement(_ element: XCUIElement) -> Bool { - var enabled = false - _ = RunnerObjCExceptionCatcher.catchException({ - enabled = element.exists && element.isEnabled - }) - return enabled + safely("ALERT_BUTTON_ENABLED", false) { element.exists && element.isEnabled } } // A snapshot can expose an alert's button a beat before the owning app has made it @@ -379,10 +369,6 @@ extension RunnerTests { return override(deadline) } #endif - var hittable = false - _ = RunnerObjCExceptionCatcher.catchException({ - hittable = button.exists && button.isHittable - }) - return hittable + return safely("ALERT_BUTTON_HITTABLE", false) { button.exists && button.isHittable } } } diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift index c38ba53996..daba0f64f9 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift @@ -176,7 +176,6 @@ extension RunnerTests { private func safeIsActionableCandidate(_ candidate: XCUIElement, seen: inout Set) -> Bool { safely("MODAL_ACTION", false) { if !candidate.exists || !candidate.isHittable { return false } - if !actionableTypes.contains(candidate.elementType) { return false } let frame = candidate.frame if frame.isNull || frame.isEmpty { return false } let key = "\(candidate.elementType.rawValue)-\(frame.origin.x)-\(frame.origin.y)-\(frame.size.width)-\(frame.size.height)-\(candidate.label)" diff --git a/packages/daemon/src/execution/handlers/snapshot-alert.ts b/packages/daemon/src/execution/handlers/snapshot-alert.ts index 0e9e4f87bf..6e2aff77ce 100644 --- a/packages/daemon/src/execution/handlers/snapshot-alert.ts +++ b/packages/daemon/src/execution/handlers/snapshot-alert.ts @@ -6,7 +6,6 @@ import { MAX_ALERT_WINDOW_MS, } from '@agent-device/contracts/alert-contract'; import { AppError } from '@agent-device/kernel/errors'; -import type { BoundDeviceRuntime } from '@agent-device/contracts/platform-runtime'; import { alertAcceptUse, alertDismissUse, @@ -74,53 +73,21 @@ async function resolveBoundAlertRuntime( if (action === 'wait') { const admission = await admitRuntimeUse({ ...shared, use: alertWaitUse }); if (admission.type === 'response') return { ok: false, response: admission.response }; - const runtime = admission.runtime; - return { ok: true, execute: (input) => executeAwaitAlert(runtime, input) }; + return { ok: true, execute: (input) => admission.runtime.operations.awaitAlert(input) }; } if (action === 'accept') { const admission = await admitRuntimeUse({ ...shared, use: alertAcceptUse }); if (admission.type === 'response') return { ok: false, response: admission.response }; - const runtime = admission.runtime; - return { ok: true, execute: (input) => executeAcceptAlert(runtime, input) }; + return { ok: true, execute: (input) => admission.runtime.operations.acceptAlert(input) }; } if (action === 'dismiss') { const admission = await admitRuntimeUse({ ...shared, use: alertDismissUse }); if (admission.type === 'response') return { ok: false, response: admission.response }; - const runtime = admission.runtime; - return { ok: true, execute: (input) => executeDismissAlert(runtime, input) }; + return { ok: true, execute: (input) => admission.runtime.operations.dismissAlert(input) }; } const admission = await admitRuntimeUse({ ...shared, use: alertReadUse }); if (admission.type === 'response') return { ok: false, response: admission.response }; - const runtime = admission.runtime; - return { ok: true, execute: (input) => executeReadAlert(runtime, input) }; -} - -async function executeReadAlert( - runtime: BoundDeviceRuntime, - input: AlertRuntimeInput, -): Promise> { - return await runtime.operations.readAlert(input); -} - -async function executeAwaitAlert( - runtime: BoundDeviceRuntime, - input: AlertRuntimeInput, -): Promise> { - return await runtime.operations.awaitAlert(input); -} - -async function executeAcceptAlert( - runtime: BoundDeviceRuntime, - input: AlertRuntimeInput, -): Promise> { - return await runtime.operations.acceptAlert(input); -} - -async function executeDismissAlert( - runtime: BoundDeviceRuntime, - input: AlertRuntimeInput, -): Promise> { - return await runtime.operations.dismissAlert(input); + return { ok: true, execute: (input) => admission.runtime.operations.readAlert(input) }; } export async function handleAlertCommand(