Skip to content

Commit 5ee3dc7

Browse files
JasonVMoCopilotCopilot
authored
Fix macOS physical-input postconditions and add an advisory physical CI lane (#4500)
* Fix macOS physical-input postconditions and add advisory CI lane Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Select macOS text without menu commands and keep previews scrollable Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Await native pointer placement without replaying physical input Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Backport upstream Fabric native-props synchronization Minimal backport of MIT-licensed upstream React Native code by OrfeasZ from 923e7ddcaf4d2de45ca7dedafbb84c6b87dbffc4 (react/react-native#52646). Original source copyright and license remain intact. F16 defect 1's oversized-preview qualification exposed the renderer race in the unchanged PGB-006 NativeSemantics window-resize callback. Both Fabric full lanes lost the app; a clean native rebuild still failed. The owned ASan report fabric-progress-asan-report.86816 records BUS while ShadowNode::clone copies nativeProps_DEPRECATED during AppKit layout. Guard both writers and the cloning reader with the upstream family mutex and preserve props precedence. Validated after fresh Pods and a clean Fabric native build with ASan retained: forced PGB-006 1/1, run 61d2dce4-5980-49b9-a727-412da47fca71; Apple module and Office-style bridging-header probe 3/3. Evidence: artifacts/desktop/f16-macos-physical/native-props-clean-build-green.log. FluentTester and other native app hosts were not built locally. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Backport upstream Fabric native-props synchronization Minimal backport of MIT-licensed upstream React Native code by OrfeasZ from 923e7ddcaf4d2de45ca7dedafbb84c6b87dbffc4 (react/react-native#52646). Original source copyright and license remain intact. F16 defect 1's oversized-preview qualification exposed the renderer race in the unchanged PGB-006 NativeSemantics window-resize callback. Both Fabric full lanes lost the app; a clean native rebuild still failed. The owned ASan report fabric-progress-asan-report.86816 records BUS while ShadowNode::clone copies nativeProps_DEPRECATED during AppKit layout. Guard both writers and the cloning reader with the upstream family mutex and preserve props precedence. Validated after fresh Pods and a clean Fabric native build with ASan retained: forced PGB-006 1/1, run 61d2dce4-5980-49b9-a727-412da47fca71; Apple module and Office-style bridging-header probe 3/3. Evidence: artifacts/desktop/f16-macos-physical/native-props-clean-build-green.log. FluentTester and other native app hosts were not built locally. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Record standalone native-props backport qualification Document the observed failing reader, inferred concurrent writer, complete Fabric regression results, and immutable-install/fresh-native-build evidence for the independent lower branch. No E driver or runtime implementation is present in this layer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Record macOS physical-input and stacked backport qualification Part of #4441 and #4435. Record both renderers full physical/accessibility passes, real MCP receipts, strict keyboard clear, unchanged callbacks, final native contracts, standalone lower-layer evidence, and serial-mode aggregate acceptance. Preserve earlier failures and unqualified host/occlusion limits; no source assertions or deadlines were relaxed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * docs(native-core): keep backport qualification durable Move session-only run details out of the published reference into ignored private PR evidence. Preserve upstream attribution, lock scope, renderer diagnosis, and the qualified native-host boundary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(storybook): scope the scroll viewport to macOS Restore the shared Windows decorator's original non-scrolling layout. Keep the overflow repair in a macOS platform entrypoint and add explicit macOS/Windows viewport regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(desktop-driver): refuse same-process covering windows before activation Reserve foreign hit identities for proven different-process owners. Same-process and unproven owners retain the target's no-activation obstruction scope, preventing popup dismissal or window reordering. Add failing native owner regressions and an agent effect-none/no-input check; label the prior serial buildci run diagnostic only. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * docs(desktop-driver): record reviewed native requalification Record the macOS-only viewport and no-activation occlusion regressions, signed helper qualification, both real-descriptor reproductions, and complete physical/access lanes without promoting the serial aggregate diagnostic to PR-gate acceptance. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * docs(desktop-driver): record plain-gate baseline comparison Clarify the process-owner hit-test policy and retain both untouched-main comparison results without treating serial diagnostics as gate acceptance. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(storybook): size macOS physical runs inside visible screen bounds Prepare a verified 1024x768 window through the existing driver window-rect API before physical traversal or attached callbacks. Clamp its origin to a fitting visible screen, fail if the display or host cannot accommodate it, and preserve accessible/compatibility geometry and native occlusion checks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Center macOS physical preset inside visible screen bounds A real off-screen-window qualification showed the boundary-aligned resize being adjusted to 1024x767. Center the fixed preset within the fitting visible screen, preserving strict geometry verification and physical-only scope. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Record hosted physical-window qualification and console limit Retain the complete Fabric physical and forced-small-window passes, Paper native-build success and locked-console qualification gap, and the unchanged WDIO deadline failure in the plain aggregate. No hosted success or Paper GUI pass is inferred. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Resolve environment-selected smoke lane before window setup Reuse the existing wdio input resolver for traversal so DESKTOP_INPUT=physical receives the same macOS window preparation as an explicit flag. Regress the env-only path and preserve explicit accessible precedence; leave geometry policy and native assertions unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Record portable qualification of environment-selected smoke sizing Keep prior explicit-input Fabric native evidence attributed to cc96a3a, record the red/green env-only regression and owning-package results, and preserve the known plain-aggregate fixture failure and locked-console native gap. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Clamp physical Storybook window to visible screen Co-authored with the Copilot CLI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(desktop-driver): omit WebDriver error stacks Co-authored-by: JasonVMo <35609178+JasonVMo@users.noreply.github.com> * docs(desktop-driver): format merged status ledger Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 1b42a88 commit 5ee3dc7

30 files changed

Lines changed: 1787 additions & 171 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fluentui-react-native/storybook-desktop-runtime': patch
3+
---
4+
5+
Keep oversized macOS LiteUI stories within a scrollable viewport, matching Win32, so their first controls are not centered behind Storybook chrome and native keyboard focus can scroll later controls into view. Preserve Windows' existing non-scrolling story layout.

‎.changeset/tidy-physical-window.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@fluentui-react-native/storybook-desktop': patch
3+
---
4+
5+
Establish and verify a centered macOS physical-lane Storybook window up to 1024x768, clamped within the largest visible screen frame with a one-point inset on each edge. Fail when no positive window fits or the host does not establish the exact requested rectangle. Leave accessible and compatibility lanes, native occlusion detection, and story assertions unchanged.
6+
7+
Use the effective smoke input lane, including `DESKTOP_INPUT=physical` when no `--input` flag is supplied. Explicit input flags retain precedence over the environment.

‎.changeset/warm-hits-clear.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fluentui-react-native/desktop-driver': patch
3+
---
4+
5+
Keep hit-test windows from other macOS processes distinct while refusing same-process and unproven obstructions before activation, fall back to workspace activation when an acknowledged Accessibility request does not establish foreground state, wait for pointer placement without replaying motion, and use menu-independent document selection with verified focus, selection, and empty-value postconditions before reporting keyboard-clear success.

‎.github/workflows/pr.yml‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,58 @@ jobs:
231231
apps/storybook/artifacts/desktop
232232
${{ steps.desktop-driver.outputs.doctor-path }}
233233
234+
# An advisory pilot outside the aggregate PR check: hosted physical input is not yet qualified (#4441).
235+
macos-storybook-physical:
236+
name: macOS Storybook PR (physical)
237+
runs-on: macos-26
238+
timeout-minutes: 40
239+
steps:
240+
- name: Checkout
241+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
242+
243+
- name: Set up toolchain
244+
uses: microsoft/react-native-test-app/.github/actions/setup-toolchain@1c99dd2947a77097bf937701e3dcc90aa109d17e # 5.4.15
245+
with:
246+
platform: macos
247+
node-version: 22
248+
249+
- name: Install dependencies
250+
run: yarn
251+
252+
- name: Build packages
253+
run: yarn build
254+
255+
- name: Set up macOS Desktop Driver
256+
id: desktop-driver
257+
uses: ./.github/actions/setup-desktop-driver
258+
with:
259+
platform: macos
260+
261+
- name: Bundle macOS
262+
run: yarn storybook bundle --macos
263+
working-directory: apps/storybook
264+
265+
- name: Pod install
266+
run: yarn storybook prep --macos
267+
working-directory: apps/storybook
268+
269+
- name: Smoke test macOS Storybook physical input
270+
run: yarn storybook smoke --macos --mode stories-and-tests --input physical
271+
working-directory: apps/storybook
272+
env:
273+
CCACHE_DISABLE: 1
274+
275+
- name: Upload macOS Storybook physical artifacts
276+
if: ${{ always() }}
277+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
278+
with:
279+
name: Storybook_macos_fabric_physical_${{ github.run_id }}_${{ github.run_attempt }}
280+
path: |
281+
apps/storybook/artifacts/macos
282+
apps/storybook/artifacts/desktop
283+
${{ steps.desktop-driver.outputs.doctor-path }}
284+
if-no-files-found: warn
285+
234286
macos-paper-storybook:
235287
name: macOS Paper Storybook PR
236288
runs-on: macos-26

‎packages/agentic/desktop-driver/native/PROTOCOL.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,15 @@ the element:
453453
the fallback. A check that refuses, such as `input-unavailable`, dispatches
454454
nothing and is `none`.
455455

456+
The macOS helper requires a readable value before keyboard input and verifies
457+
that it becomes empty before returning success. It confirms keyboard focus
458+
and selects the document with Command-Up followed by Command-Shift-Down,
459+
without relying on the application's Select All menu command. When exposed,
460+
the selected text range must cover the complete value before Delete.
461+
Unacknowledged selection or retained text fails `input-failed`; already-posted
462+
keys retain their partial effect. These bounded reads do not replay input or
463+
permit a semantic fallback for `keyboard`.
464+
456465
Any other `mechanism`, including one that is not a string, fails
457466
`invalid-params` with effect `none`. Node never sends `mechanism` unless the
458467
feature is negotiated, and treats a result without a recognized `mechanism`,

‎packages/agentic/desktop-driver/native/macos/README.md‎

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Accessibility.
2121
| `Sources/DesktopDriverHost/main.swift` | Helper modes and top-level error handling |
2222
| `Host.swift` | FDR1 hello, request queue, framing, cancellation, and disposal |
2323
| `Driver.swift` | Command dispatch, capability reporting, and physical-input scopes |
24+
| `ApplicationActivation.swift` | Foreground postcondition and one workspace fallback after AX activation |
25+
| `KeyboardClear.swift` | Keyboard focus, selection acknowledgment, and empty-value verification |
2426
| `Application.swift` | Launch/attach leases, exact process/window identity, and ownership |
2527
| `ApplicationTermination.swift` | `terminateOwned`: quit, wait, kill, and verify the exit of an owned process |
2628
| `ApplicationIncarnation.swift` | One-shot `--application-incarnation`: whether a recorded process exited |
@@ -39,6 +41,7 @@ Accessibility.
3941
| `ObservationSelfTest.swift` | Synthetic-tree, randomized differential, and command checks for `observe` |
4042
| `ServiceIdentitySelfTest.swift` | URL, claim, listener-policy, and live describe/verify checks |
4143
| `InputIntegritySelfTest.swift` | Recorded input: counted buttons and drags, cancelled clicks, fail-closed |
44+
| `PhysicalInputSelfTest.swift` | Hit-owner scope, foreground fallback, and verified keyboard clear |
4245
| `HostLifecycleSelfTest.swift` | In-process host: end of input, write failure, invalid JSON, queued work |
4346
| `ApplicationTerminationSelfTest.swift` | Termination verification against fake and real child processes |
4447
| `CaptureSelectionSelfTest.swift` | Pure capture-window selection and `visible` without geometry |
@@ -388,17 +391,37 @@ accessibility activation and reports physical success. A positive wheel
388391
`deltaX` scrolls right and a positive `deltaY` scrolls down, as on Windows. Quartz
389392
scrolls left and up for positive values, so both deltas are negated.
390393

394+
After posting a pointer-move sequence, the helper allows about 200 ms of
395+
bounded position reads for the OS to acknowledge its destination. It never
396+
reposts the move to force acknowledgment. An unreadable or unsettled pointer
397+
fails `input-failed`; a click never posts its button press before the position
398+
is verified. Cancellation stops these reads and preserves the posted effect.
399+
391400
The helper advertises `strictClear`. `clear` writes an empty `AXValue` when
392401
`AXUIElementIsAttributeSettable` reports the value settable, and otherwise
393-
activates the application, focuses the element, and presses Command-A and
394-
Delete under the physical input lock. A request may name `mechanism`:
402+
activates the application, focuses the element, selects the document with
403+
Command-Up then Command-Shift-Down, and presses Delete under the physical
404+
input lock. A request may name `mechanism`:
395405
`semantic` only writes `AXValue` and fails `element-not-interactable` with
396406
effect `none` when the value is not settable, and `keyboard` skips the write
397407
and needs the same physical input authority as the fallback. Every successful
398408
clear returns `{ "mechanism": "semantic" | "keyboard" }`. The `probe` feature
399409
is `true` even without Accessibility trust, because each mechanism reports its
400410
own refusal.
401411

412+
Keyboard clear requires a readable value before posting input. It waits up to
413+
200 ms for native keyboard focus and posts the two document-navigation chords
414+
once, rather than relying on an application-provided Select All menu command.
415+
Paper's focused `NSTextField` can ignore Command-A even though the menu item
416+
is present; document navigation reaches the field editor without that menu
417+
route. When the provider exposes `AXSelectedTextRange`, clear waits up to
418+
200 ms for the complete UTF-16 value to be selected before posting Delete
419+
once. It then verifies an empty value for up to one second. An unreadable
420+
value is unsupported; missing focus fails before keys are posted.
421+
Unacknowledged selection or retained text fails `input-failed`, with the
422+
posted input's partial effect. Verification never replays keys or substitutes
423+
a semantic clear.
424+
402425
A locked screen or a login session that is not the active console prevents
403426
applications from publishing complete accessibility windows and from receiving
404427
physical input. Launch, attach, window discovery, and new pointer, keyboard,
@@ -408,9 +431,11 @@ window-enumeration error. Physical input fails closed: a login session or pointe
408431
position the helper cannot read is a failure, not permission to proceed. Key and
409432
button releases remain allowed so recovery can complete while the session is locked.
410433

411-
Activation sets the application's `AXFrontmost` attribute, which a trusted
412-
client applies immediately, and falls back to `NSRunningApplication.activate`
413-
only if that fails. Cooperative workspace activation was observed to wait about
434+
Activation first sets the application's `AXFrontmost` attribute and checks
435+
the foreground postcondition, not just the setter's acknowledgment. It falls
436+
back once to `NSRunningApplication.activate` when the write fails **or** the
437+
application is still not frontmost. The latter path is journaled as
438+
`accessibility+workspace`. Cooperative workspace activation was observed to wait about
414439
a second for the active application to yield. Activation completes when the
415440
application reports `AXFrontmost` and the primary window reports `AXMain`;
416441
a timeout names the application that kept keyboard focus. The window is also
@@ -423,6 +448,15 @@ A physical click first hit-tests its target. When another element owns the
423448
point, `element click intercepted` names the occluding element, or the external
424449
application and process that own it.
425450

451+
Only a hit proven to belong to another process has an opaque window identity
452+
distinct from the target, allowing the agent to activate the target and recheck.
453+
A same-process covering window, or a hit whose owner cannot be established,
454+
retains the target's obstruction scope and is refused before activation, with
455+
effect `none`. Raising through a same-application popup could dismiss or reorder
456+
it, so that is not a physical click. A hit on the target's
457+
own window or chrome is not proof that its descendants receive input:
458+
genuinely covered or clipped controls remain refused.
459+
426460
React Native macOS does not move keyboard focus on ordinary mouse-down. Portable
427461
tests should assert the platform's actual activation behavior rather than
428462
copying a Windows focus expectation.

‎packages/agentic/desktop-driver/native/macos/Sources/DesktopDriverHost/Accessibility.swift‎

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,21 @@ final class AccessibilityEngine {
329329
return axNumber(try copyOptionalAXAttribute(record.element, kAXFocusedAttribute))?.boolValue ?? false
330330
}
331331

332+
func selectedTextRange(_ elementID: String) throws -> CFRange? {
333+
let record = try requireRecord(elementID)
334+
try validateLive(record)
335+
guard
336+
let raw = try copyOptionalAXAttribute(record.element, kAXSelectedTextRangeAttribute),
337+
CFGetTypeID(raw) == AXValueGetTypeID()
338+
else {
339+
return nil
340+
}
341+
let value = unsafeBitCast(raw, to: AXValue.self)
342+
guard AXValueGetType(value) == .cfRange else { return nil }
343+
var range = CFRange()
344+
return AXValueGetValue(value, .cfRange, &range) ? range : nil
345+
}
346+
332347
func accessibilityClick(_ elementID: String, token: CancellationToken) throws {
333348
try requireAccessibility("Accessibility click")
334349
try token.throwIfCancelled()
@@ -995,23 +1010,29 @@ final class AccessibilityEngine {
9951010
knownRecord(element)?.parentID
9961011
}
9971012

998-
private func externalWindowSnapshot(
1013+
func externalWindowSnapshot(
9991014
window: WindowRecord,
10001015
hit: AXUIElement
10011016
) -> ElementSnapshot {
1017+
let externalID = IdentifierGenerator.shared.next("external-window")
10021018
let screenRect = (try? axFrame(hit)) ?? .zero
10031019
let windowFrame = (try? window.currentFrame()) ?? .zero
10041020
var ownerID: pid_t = 0
10051021
var name = "External desktop window"
1006-
if AXUIElementGetPid(hit, &ownerID) == .success {
1007-
let owner = processIdentity(ownerID)
1008-
let ownerName = owner["name"] as? String ?? "unknown application"
1009-
name = ownerID == window.processID
1010-
? "Another window of the target application"
1011-
: "External desktop window of \(ownerName) (pid \(ownerID))"
1022+
// Same-process and unproven owners retain the agent's no-activation obstruction scope.
1023+
var hitWindowID = window.id
1024+
if AXUIElementGetPid(hit, &ownerID) == .success && ownerID > 0 {
1025+
if ownerID == window.processID {
1026+
name = "Another window of the target application"
1027+
} else {
1028+
let owner = processIdentity(ownerID)
1029+
let ownerName = owner["name"] as? String ?? "unknown application"
1030+
name = "External desktop window of \(ownerName) (pid \(ownerID))"
1031+
hitWindowID = externalID
1032+
}
10121033
}
10131034
return ElementSnapshot(
1014-
id: IdentifierGenerator.shared.next("external-window"),
1035+
id: externalID,
10151036
automationID: nil,
10161037
checked: .unsupported("An external desktop window does not expose checked state."),
10171038
enabled: .supported(true),
@@ -1032,7 +1053,7 @@ final class AccessibilityEngine {
10321053
text: nil,
10331054
value: nil,
10341055
visible: .supported(true),
1035-
windowID: window.id
1056+
windowID: hitWindowID
10361057
)
10371058
}
10381059

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import ApplicationServices
2+
3+
struct ApplicationActivation {
4+
let method: String
5+
let accessibilityError: AXError?
6+
}
7+
8+
func activateApplication(
9+
isFrontmost: () -> Bool,
10+
accessibility: () -> AXError,
11+
workspace: () -> Void
12+
) -> ApplicationActivation {
13+
if isFrontmost() {
14+
return ApplicationActivation(method: "already-frontmost", accessibilityError: nil)
15+
}
16+
let error = accessibility()
17+
if error != .success {
18+
workspace()
19+
return ApplicationActivation(method: "workspace", accessibilityError: error)
20+
}
21+
if !isFrontmost() {
22+
workspace()
23+
return ApplicationActivation(method: "accessibility+workspace", accessibilityError: nil)
24+
}
25+
return ApplicationActivation(method: "accessibility", accessibilityError: nil)
26+
}

‎packages/agentic/desktop-driver/native/macos/Sources/DesktopDriverHost/Driver.swift‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -381,17 +381,16 @@ final class Driver {
381381
func isFrontmost() -> Bool {
382382
axNumber(try? copyOptionalAXAttribute(applicationElement, kAXFrontmostAttribute))?.boolValue == true
383383
}
384-
if !isFrontmost() {
385-
// Trusted Accessibility clients activate immediately. NSRunningApplication activation is cooperative on current
386-
// macOS releases and was observed to wait about a second for the active application to yield.
387-
let frontmostError = AXUIElementSetAttributeValue(applicationElement, kAXFrontmostAttribute as CFString, kCFBooleanTrue)
388-
diagnostics["method"] = frontmostError == .success ? "accessibility" : "workspace"
389-
if frontmostError != .success {
390-
diagnostics["accessibilityError"] = axErrorName(frontmostError)
391-
_ = application.activate(options: [])
392-
}
393-
} else {
394-
diagnostics["method"] = "already-frontmost"
384+
let activation = activateApplication(
385+
isFrontmost: isFrontmost,
386+
accessibility: {
387+
AXUIElementSetAttributeValue(applicationElement, kAXFrontmostAttribute as CFString, kCFBooleanTrue)
388+
},
389+
workspace: { _ = application.activate(options: []) }
390+
)
391+
diagnostics["method"] = activation.method
392+
if let error = activation.accessibilityError {
393+
diagnostics["accessibilityError"] = axErrorName(error)
395394
}
396395
_ = AXUIElementSetAttributeValue(window.element, kAXMainAttribute as CFString, kCFBooleanTrue)
397396
let raised = AXUIElementPerformAction(window.element, kAXRaiseAction as CFString)
@@ -582,9 +581,16 @@ final class Driver {
582581
}
583582
try withPhysicalInput(token: token) {
584583
try activate(window, token: token)
585-
try accessibility.setFocus(elementID)
586-
try token.wait(milliseconds: 16)
587-
try input.pressCommandADelete(token: token)
584+
try clearWithKeyboard(
585+
token: token,
586+
focus: { try accessibility.setFocus(elementID) },
587+
hasFocus: { try accessibility.hasFocus(elementID) },
588+
value: { try accessibility.snapshot(elementID: elementID, window: window, token: token).value },
589+
selectedRange: { try accessibility.selectedTextRange(elementID) },
590+
selectAll: { try input.selectAll(token: token) },
591+
delete: { try input.deleteSelection(token: token) },
592+
wait: { try token.wait(milliseconds: $0) }
593+
)
588594
}
589595
return "keyboard"
590596
}

‎packages/agentic/desktop-driver/native/macos/Sources/DesktopDriverHost/Input.swift‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,17 @@ final class InputController {
120120
}
121121
pointer = target
122122
try token.wait(milliseconds: 16)
123-
guard let observed = environment.pointerLocation() else {
124-
try fail(ErrorCode.inputFailed, "macOS did not report the pointer position, so the move to the requested native element coordinate is unverified.")
125-
}
126-
if abs(observed.x - target.x) > 2 || abs(observed.y - target.y) > 2 {
127-
try fail(ErrorCode.inputFailed, "macOS did not move the pointer to the requested native element coordinate.")
123+
for attempt in 0..<12 {
124+
try token.throwIfCancelled()
125+
guard let observed = environment.pointerLocation() else {
126+
try fail(ErrorCode.inputFailed, "macOS did not report the pointer position, so the move to the requested native element coordinate is unverified.")
127+
}
128+
if abs(observed.x - target.x) <= 2 && abs(observed.y - target.y) <= 2 {
129+
return
130+
}
131+
if attempt + 1 < 12 { try token.wait(milliseconds: 16) }
128132
}
133+
try fail(ErrorCode.inputFailed, "macOS did not move the pointer to the requested native element coordinate.")
129134
}
130135

131136
func pointerDown(_ button: Int, token: CancellationToken) throws {
@@ -230,8 +235,13 @@ final class InputController {
230235
}
231236
}
232237

233-
func pressCommandADelete(token: CancellationToken) throws {
234-
try chord([.keyCode(55), .keyCode(0)], token: token)
238+
func selectAll(token: CancellationToken) throws {
239+
// Text-system navigation does not depend on the application's Select All menu command.
240+
try chord([.keyCode(55), .keyCode(126)], token: token)
241+
try chord([.keyCode(55), .keyCode(56), .keyCode(125)], token: token)
242+
}
243+
244+
func deleteSelection(token: CancellationToken) throws {
235245
try chord([.keyCode(51)], token: token)
236246
}
237247

0 commit comments

Comments
 (0)