Files
orca/native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/SyntheticMouseClickDeliveryTests.swift
Brennan Benson c2da0e47f9 fix(computer): deliver macOS coordinate clicks via the HID event tap (STA-3433) (#12839)
Mouse events posted with CGEventPostToPid reach the target app with no
window association, so AppKit never routes the press to a view: hover
states fire but the control is never activated, and the mouseUp is
dropped outright when posted back-to-back. Post click events to the HID
event tap instead (as keyboard synthesis already does), pace them, and
stamp mouseEventClickState so multi-clicks register.

Synthetic clicks now also report verification unverified/synthetic_input
from the helper itself, matching the other synthetic actions.
2026-08-05 22:14:18 -07:00

44 lines
1.6 KiB
Swift

import XCTest
@testable import OrcaComputerUseMacOSCore
final class SyntheticMouseClickDeliveryTests: XCTestCase {
func testSingleClickPlanPairsDownAndUpAfterMove() {
XCTAssertEqual(
SyntheticMouseClickDelivery.steps(clickCount: 1),
[.move, .buttonDown(pressIndex: 1), .buttonUp(pressIndex: 1)]
)
}
func testMultiClickPlanNumbersEachPressForClickState() {
XCTAssertEqual(
SyntheticMouseClickDelivery.steps(clickCount: 2),
[
.move,
.buttonDown(pressIndex: 1), .buttonUp(pressIndex: 1),
.buttonDown(pressIndex: 2), .buttonUp(pressIndex: 2),
]
)
}
func testNonPositiveClickCountStillDeliversOnePress() {
for count in [0, -3] {
XCTAssertEqual(
SyntheticMouseClickDelivery.steps(clickCount: count),
[.move, .buttonDown(pressIndex: 1), .buttonUp(pressIndex: 1)]
)
}
}
func testClickStateMatchesPressIndexAndSkipsMove() {
XCTAssertEqual(SyntheticMouseClickDelivery.clickState(for: .move), 0)
XCTAssertEqual(SyntheticMouseClickDelivery.clickState(for: .buttonDown(pressIndex: 1)), 1)
XCTAssertEqual(SyntheticMouseClickDelivery.clickState(for: .buttonUp(pressIndex: 2)), 2)
}
func testInterEventPauseIsNonZero() {
// Unpaced posts race the window server and the mouseUp is dropped,
// turning the click into a hover-only no-op (STA-3433).
XCTAssertGreaterThan(SyntheticMouseClickDelivery.interEventPauseMicroseconds, 0)
}
}