From 832caea15d779768577971cd63160c838f5b6ff5 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 3 Oct 2026 00:14:03 -0700 Subject: [PATCH] Avoid irrelevant scroll-action searches in Mac snapshots (#24731) Check the current pure action name before searching for vertical scroll actions in the same immutable array. --- .../SnapshotRendering.swift | 4 +-- .../SnapshotRenderingTests.swift | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/native/computer-use-macos/Sources/OrcaComputerUseMacOSCore/SnapshotRendering.swift b/native/computer-use-macos/Sources/OrcaComputerUseMacOSCore/SnapshotRendering.swift index e5de36b48b2..615c988ad69 100644 --- a/native/computer-use-macos/Sources/OrcaComputerUseMacOSCore/SnapshotRendering.swift +++ b/native/computer-use-macos/Sources/OrcaComputerUseMacOSCore/SnapshotRendering.swift @@ -109,8 +109,8 @@ public enum SnapshotRenderHeuristics { return action != "AXCancel" && action != "AXPick" } if role == "AXScrollArea", - (rawActions.contains("AXScrollUpByPage") || rawActions.contains("AXScrollDownByPage")), - action == "AXScrollLeftByPage" || action == "AXScrollRightByPage" { + action == "AXScrollLeftByPage" || action == "AXScrollRightByPage", + (rawActions.contains("AXScrollUpByPage") || rawActions.contains("AXScrollDownByPage")) { return false } return true diff --git a/native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/SnapshotRenderingTests.swift b/native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/SnapshotRenderingTests.swift index dce1bdc304c..4ecf99d0ac8 100644 --- a/native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/SnapshotRenderingTests.swift +++ b/native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/SnapshotRenderingTests.swift @@ -74,6 +74,34 @@ final class SnapshotRenderingTests: XCTestCase { XCTAssertEqual(SnapshotRenderHeuristics.meaningfulActions(node.rawActions, role: node.role), ["AXScrollUpByPage", "AXScrollDownByPage"]) } + func testKeepsHorizontalOnlyActionsInTheirOriginalOrder() { + let actions = ["AXScrollRightByPage", "AXPress", "AXScrollLeftByPage", "AXScrollRightByPage"] + let node = SnapshotRenderNode(role: "AXScrollArea", rawActions: actions) + + XCTAssertEqual( + SnapshotRenderHeuristics.meaningfulActions(actions, role: node.role), + ["AXScrollRightByPage", "AXScrollLeftByPage", "AXScrollRightByPage"] + ) + XCTAssertEqual( + SnapshotRenderHeuristics.line(index: 2, node: node), + "2 scroll area, Secondary Actions: scroll right, scroll left, scroll right" + ) + } + + func testKeepsMixedScrollActionsOutsideScrollAreas() { + let actions = ["AXScrollLeftByPage", "AXScrollDownByPage", "AXScrollRightByPage", "AXCancel"] + let node = SnapshotRenderNode(role: "AXMenu", rawActions: actions) + + XCTAssertEqual( + SnapshotRenderHeuristics.meaningfulActions(actions, role: node.role), + ["AXScrollLeftByPage", "AXScrollDownByPage", "AXScrollRightByPage"] + ) + XCTAssertEqual( + SnapshotRenderHeuristics.line(index: 3, node: node), + "3 menu, Secondary Actions: scroll left, scroll down, scroll right" + ) + } + func testTextFieldsKeepDistinctValueAndPlaceholder() { let node = SnapshotRenderNode( role: "AXTextField",