From 63d21e1e30224d2465095c1f464c092841a2d424 Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Fri, 27 Nov 2026 19:06:12 +0900 Subject: [PATCH 01/12] fix(desktop): let a scroll area scroll itself only with a scroll bar for the axis SwiftUI gives every scroll area the AXScroll*ByPage actions, also one whose content fits or that scrolls only along the other axis. `scroll` counted the page action for the direction as "scrolls itself", so a swipe down on a horizontal carousel inside a vertical page sent AXScrollDownByPage to the carousel, moved nothing, and answered success. `scrolls_itself` now uses the rule the snapshot offers `Scroll` with: a scroll bar for the axis, or, for any role but a scroll area, the page action. A scroll area without that bar hands the swipe to the scroll area above it, and with none is refused as "nothing here scrolls". Review: michal-e2e on #2322 at e7a74d44e (must fix). Co-Authored-By: Claude Opus 5.5 --- crates/e2e-desktop-napi/src/actions/mod.rs | 14 ++++++++++++ crates/e2e-desktop-napi/src/actions/scroll.rs | 22 +++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/crates/e2e-desktop-napi/src/actions/mod.rs b/crates/e2e-desktop-napi/src/actions/mod.rs index e759db3630..367120f874 100644 --- a/crates/e2e-desktop-napi/src/actions/mod.rs +++ b/crates/e2e-desktop-napi/src/actions/mod.rs @@ -1114,4 +1114,18 @@ mod tests { let unreadable = press_to_state(1, None, || Ok(()), || None); assert!(!unreadable.unwrap()); } + + #[test] + fn lets_a_scroll_area_scroll_itself_only_with_a_scroll_bar_for_the_axis() { + let pages = |names: &[&str]| names.iter().map(|name| (*name).to_owned()).collect::>(); + let swiftui = pages(&["AXScrollDownByPage", "AXScrollUpByPage", "AXScrollLeftByPage", "AXScrollRightByPage"]); + // A SwiftUI scroll area offers every page action: only its scroll bar for the axis says it scrolls along it. + assert!(!super::scroll::scrolls_itself("scrollarea", false, &swiftui, "down")); + assert!(super::scroll::scrolls_itself("scrollarea", true, &swiftui, "down")); + assert!(super::scroll::scrolls_itself("scrollarea", true, &[], "left")); + // Any other role scrolls itself by the page action for the direction. + assert!(super::scroll::scrolls_itself("list", false, &pages(&["AXScrollDownByPage"]), "down")); + assert!(!super::scroll::scrolls_itself("list", false, &pages(&["AXScrollDownByPage"]), "right")); + assert!(!super::scroll::scrolls_itself("list", false, &[], "up")); + } } diff --git a/crates/e2e-desktop-napi/src/actions/scroll.rs b/crates/e2e-desktop-napi/src/actions/scroll.rs index 199475656c..450b7ae8b9 100644 --- a/crates/e2e-desktop-napi/src/actions/scroll.rs +++ b/crates/e2e-desktop-napi/src/actions/scroll.rs @@ -20,10 +20,10 @@ pub fn scroll_bar(element: &Element, vertical: bool) -> Option { /// Scrolls a scroll area by moving its scroll bar, `pages` of its visible size. pub(super) fn scroll(element: &Element, direction: &str, pages: f64) -> Outcome<()> { let vertical = matches!(direction, "up" | "down"); - // A node that scrolls itself (a scroll bar of its own, or the page action for the direction) is the one moved; one - // with neither, a list or table, scrolls through the scroll area that holds it. The enclosing pane comes last, so a - // swipe on a nested list never moves the pane around it. - let own = scroll_bar(element, vertical).is_some() || action_names(element, "scroll")?.iter().any(|name| name == page_action(direction)); + // A node that scrolls itself along the axis is the one moved; one that does not, a list or table, scrolls through the + // scroll area that holds it. The enclosing pane comes last, so a swipe on a nested list never moves the pane around it. + let (_, role) = role_of(element, "scroll")?; + let own = scrolls_itself(role, scroll_bar(element, vertical).is_some(), &action_names(element, "scroll")?, direction); let target = if own { None } else { enclosing_scroll_area(element, vertical) }; scroll_by(target.as_ref().unwrap_or(element), direction, pages).map_err(|failure| { // An element that takes none of the ways to scroll: say so, not which attribute it lacks. @@ -35,6 +35,14 @@ pub(super) fn scroll(element: &Element, direction: &str, pages: f64) -> Outcome< }) } +/// Whether a node scrolls itself along `direction`, by the rule the snapshot offers `Scroll` with: a scroll bar for the +/// axis, or, for any role but a scroll area, the page action for the direction. SwiftUI gives every scroll area the page +/// actions, also one whose content fits or that scrolls only along the other axis, and the action then moves nothing +/// while it answers success. +pub(super) fn scrolls_itself(role: &str, bar: bool, actions: &[String], direction: &str) -> bool { + bar || (role != "scrollarea" && actions.iter().any(|name| name == page_action(direction))) +} + /// The nearest scroll area above `element`, a few levels up, with a scroll bar for the axis. pub(super) fn enclosing_scroll_area(element: &Element, vertical: bool) -> Option { let mut current = element.element("AXParent")?; @@ -99,9 +107,9 @@ pub(super) fn scroll_by(element: &Element, direction: &str, pages: f64) -> Outco return repeat(&bar, if forward { "AXIncrement" } else { "AXDecrement" }, ((pages * LINES_PER_PAGE).round() as usize).max(1)); } let names = action_names(element, "scroll")?; - let action = page_action(direction); - if names.iter().any(|name| name == action) { - return repeat(element, action, (pages.round() as usize).max(1)); + let (_, role) = role_of(element, "scroll")?; + if scrolls_itself(role, false, &names, direction) { + return repeat(element, page_action(direction), (pages.round() as usize).max(1)); } Err(Failure::refused(codes::ACTION_NOT_SUPPORTED, format!("nothing here scrolls {direction}"))) } From d72ae9698eff1e0c435cb4bfdca124ce1af7ce36 Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Fri, 27 Nov 2026 19:06:18 +0900 Subject: [PATCH 02/12] fix(desktop): read focus before a key as a stall, and check frontmost last The focus reads before a key went through `Element::element()`, which drops a stall: an app slow to answer AXFocusedUIElement or AXFocusedWindow got "the field lost keyboard focus", a refusal the engine does not retry, where every other stalled read is a retryable APP_UNRESPONSIVE. `element_attribute` keeps the stall, and `type`, `press`, and `key_window` read focus through it. Past the first typed key, an unanswered read still only shortens the wait for the next key. A headed `type` also re-read the field's focus after its AXFrontmost check for the first key. That read waits on the app, and another app that came forward meanwhile would take the key. The frontmost check is now the last read before the first physical key, as it is for `press`. Review: michal-e2e on #2322 at e7a74d44e (optional). Co-Authored-By: Claude Opus 5.5 --- crates/e2e-desktop-napi/src/actions/mod.rs | 16 ++++++++-- crates/e2e-desktop-napi/src/actions/typing.rs | 29 ++++++++++++------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/crates/e2e-desktop-napi/src/actions/mod.rs b/crates/e2e-desktop-napi/src/actions/mod.rs index 367120f874..01883c5a7b 100644 --- a/crates/e2e-desktop-napi/src/actions/mod.rs +++ b/crates/e2e-desktop-napi/src/actions/mod.rs @@ -113,6 +113,16 @@ fn unread(error: AXError, what: &str) -> Failure { } } +/// The element an attribute names, such as the app's focused element or key window. A read the app did not answer in +/// time fails as a stall, which a retry may get past, never as focus that moved; any other failure reads as none. +fn element_attribute(element: &Element, name: &str, what: &str) -> Outcome> { + match element.attribute(name) { + Ok(value) => Ok(value.element().cloned()), + Err(ax::AX_CANNOT_COMPLETE) => Err(unread(ax::AX_CANNOT_COMPLETE, what)), + Err(_) => Ok(None), + } +} + /// Whether an attribute can be set. A stall fails, so a busy app does not read as one whose control takes no input; /// any other failure reads as not settable. fn settable(element: &Element, name: &str, what: &str) -> Outcome { @@ -513,7 +523,7 @@ pub fn press(pid: i32, window: u32, combo: &str, physical: bool, focused: Option // The control a locator's key is for must hold the app's focus, read after the window check: a sheet that opened // during it took the focus, and its default button would take the key. if let Some(entry) = &control - && Element::application(pid).element("AXFocusedUIElement").as_ref() != Some(&entry.element) + && element_attribute(&Element::application(pid), "AXFocusedUIElement", "press")?.as_ref() != Some(&entry.element) { return Err(Failure::refused(codes::ACTION_FAILED, "the control lost keyboard focus before the key was sent, so nothing was sent")); } @@ -538,7 +548,9 @@ fn frontmost(pid: i32) -> Outcome { /// Refuses unless `window` is the app's key window, or holds the focused sheet or alert: a key or text sent to the app /// goes to its key window, and would land in another one. fn key_window(pid: i32, window: &Element) -> Outcome<()> { - if Element::application(pid).element("AXFocusedWindow").is_some_and(|focused| windows::holds_focus(&focused, window)) { + if element_attribute(&Element::application(pid), "AXFocusedWindow", "read the app's key window")? + .is_some_and(|focused| windows::holds_focus(&focused, window)) + { return Ok(()); } Err(Failure::refused(codes::ACTION_FAILED, "the window is not the app's key window, so a key sent to the app would land elsewhere") diff --git a/crates/e2e-desktop-napi/src/actions/typing.rs b/crates/e2e-desktop-napi/src/actions/typing.rs index 44ffbc9254..1b3579a119 100644 --- a/crates/e2e-desktop-napi/src/actions/typing.rs +++ b/crates/e2e-desktop-napi/src/actions/typing.rs @@ -29,13 +29,13 @@ pub(super) fn type_text(entry: &Entry, text: &str, physical: bool, deadline: Ins // window, a sheet on this one included, or another app must not take the rest of the text with it. A field in a sheet // that was there from the start keeps its sheet. Read before the field's own check, so a window a focus handler opens // after it shows as a change at the first key, and one it opened before fails that check. - let typing_in = Element::application(entry.pid).element("AXFocusedWindow"); + let typing_in = element_attribute(&Element::application(entry.pid), "AXFocusedWindow", "type")?; if typing_in.as_ref().is_some_and(|start| !windows::holds_focus(start, &window)) { return Err(Failure::refused(codes::ACTION_FAILED, "another window took the keyboard before typing began, so nothing was typed")); } // Coming forward can run a handler that opens a sheet or another window, and the app can move focus on: the keys // would then go there. The field itself must hold the app's focus before the first key. - if Element::application(entry.pid).element("AXFocusedUIElement").as_ref() != Some(&entry.element) { + if element_attribute(&Element::application(entry.pid), "AXFocusedUIElement", "type")?.as_ref() != Some(&entry.element) { return Err(Failure::refused(codes::ACTION_FAILED, "the field lost keyboard focus before typing began, so nothing was typed")); } // What an element holds, in characters, as the app answers it: a change says the app took the key sent last. @@ -44,6 +44,8 @@ pub(super) fn type_text(entry: &Entry, text: &str, physical: bool, deadline: Ins _ => None, }; let focused_element = || Element::application(entry.pid).element("AXFocusedUIElement"); + // The same read for a check a key waits on: a stall fails it, as a retry may get past it, never as focus that moved. + let focused_checked = || element_attribute(&Element::application(entry.pid), "AXFocusedUIElement", "type"); // The element that held the keyboard when the last key went, and its length then; unset before the first key. It is // the field typing began in until a Tab, or a code field's next box, takes the keys within the window. let sent_to: std::cell::RefCell, Option)>> = std::cell::RefCell::new(None); @@ -76,23 +78,30 @@ pub(super) fn type_text(entry: &Entry, text: &str, physical: bool, deadline: Ins } // The element the key will reach, read before the checks below, so nothing reads the app between them and the // key: focus that moves while they run is caught by them, not followed. The first key goes only to the field. - let target = focused_element(); + // Past the first key, an unanswered read only shortens the wait for the next key's effect. + let target = if last.is_none() { focused_checked()? } else { focused_element() }; let count = target.as_ref().and_then(&length); if last.is_none() && target.as_ref() != Some(&entry.element) { return Err(Failure::refused(codes::ACTION_FAILED, "the field lost keyboard focus before typing began, so nothing was typed")); } - let app = Element::application(entry.pid); - let focused = app.element("AXFocusedWindow"); + let focused = element_attribute(&Element::application(entry.pid), "AXFocusedWindow", "type")?; let held = match &typing_in { Some(start) => focused.as_ref() == Some(start), None => focused.is_some_and(|focused| windows::holds_focus(&focused, &window)), }; - let forward = !physical || app.boolean("AXFrontmost") == Some(true); + let forward = !physical || frontmost(entry.pid)?; if held && forward { - // The first key goes only to the field, read once more as the last read before it: the reads above wait on - // the app, and a handler that moved focus to another field of the window meanwhile would take the key. - if last.is_none() && focused_element().as_ref() != Some(&entry.element) { - return Err(Failure::refused(codes::ACTION_FAILED, "the field lost keyboard focus before typing began, so nothing was typed")); + if last.is_none() { + // The first key goes only to the field, read once more: the reads above wait on the app, and a handler that + // moved focus to another field of the window meanwhile would take the key. + if focused_checked()?.as_ref() != Some(&entry.element) { + return Err(Failure::refused(codes::ACTION_FAILED, "the field lost keyboard focus before typing began, so nothing was typed")); + } + // That read waits on the app too, and a physical key goes to whatever app is frontmost: the frontmost check + // is the last read before it, as for `press`, so another app that came forward meanwhile is still caught. + if physical && !frontmost(entry.pid)? { + return Err(Failure::refused(codes::ACTION_FAILED, "another app came forward before typing began, so nothing was typed")); + } } sent_to.replace(Some((target, count))); Ok(()) From 3dc6e5ce0815c3279bfa47162e259153707a4aa9 Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Fri, 27 Nov 2026 19:06:25 +0900 Subject: [PATCH 03/12] fix(desktop): refuse scrollTo on a gone element as a stale ref `read_frame` and the parent reads in `placement` read AX_INVALID_ELEMENT as no frame and no parent, so a gone element was `Placement::Shown` and `scrollTo` answered success before any scroll. Before the reveal rewrite, AXScrollToVisible refused a gone element as stale. `read_frame` and `placement` now pass AX_INVALID_ELEMENT up as they pass a stall, and `reveal` maps it to the retryable STALE_REF. `frame()` still reads any failure as no frame. Review: michal-e2e on #2322 at e7a74d44e (optional). Co-Authored-By: Claude Opus 5.5 --- crates/e2e-desktop-napi/src/ax.rs | 6 +++--- crates/e2e-desktop-napi/src/snapshot.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/e2e-desktop-napi/src/ax.rs b/crates/e2e-desktop-napi/src/ax.rs index 901e8c9d74..5232e717cc 100644 --- a/crates/e2e-desktop-napi/src/ax.rs +++ b/crates/e2e-desktop-napi/src/ax.rs @@ -359,12 +359,12 @@ impl Element { self.read_frame().ok().flatten() } - /// `frame`, failing with `AX_CANNOT_COMPLETE` when the app did not answer in time: a stall is no proof the element - /// has no frame. Any other error reads as none. + /// `frame`, failing with `AX_CANNOT_COMPLETE` when the app did not answer in time, and with `AX_INVALID_ELEMENT` when + /// the element is gone: neither is proof the element has no frame. Any other error reads as none. pub fn read_frame(&self) -> Result, AXError> { let values = match self.attributes(&["AXPosition", "AXSize"]) { Ok(values) => values, - Err(AX_CANNOT_COMPLETE) => return Err(AX_CANNOT_COMPLETE), + Err(error @ (AX_CANNOT_COMPLETE | AX_INVALID_ELEMENT)) => return Err(error), Err(_) => return Ok(None), }; Ok(match (&values[0], &values[1]) { diff --git a/crates/e2e-desktop-napi/src/snapshot.rs b/crates/e2e-desktop-napi/src/snapshot.rs index d9102f9d36..ec55d8a088 100644 --- a/crates/e2e-desktop-napi/src/snapshot.rs +++ b/crates/e2e-desktop-napi/src/snapshot.rs @@ -322,7 +322,7 @@ pub(crate) enum Placement { /// Where an element is now, by the test the snapshot reads `offscreen` with: its frame against the window and every /// scroll area it is in, up to a menu or popover, which floats above the window. A minimized window shows nothing, /// whatever its frames say. An element with no frame has no place to judge, and shows. `Err` when the app did not -/// answer in time. +/// answer in time, or with `AX_INVALID_ELEMENT` when the element or an ancestor is gone: a gone element shows nowhere. pub(crate) fn placement(element: &Element) -> Result { // Every frame is read so that a stall fails the placement: a frame the app did not answer is no proof it shows. let frame = element.read_frame()?; @@ -332,7 +332,7 @@ pub(crate) fn placement(element: &Element) -> Result { // A count the app did not answer in time is no proof the control holds nothing. let empty = match element.count("AXChildren") { Ok(count) => count == 0, - Err(ax::AX_CANNOT_COMPLETE) => return Err(ax::AX_CANNOT_COMPLETE), + Err(error @ (ax::AX_CANNOT_COMPLETE | ax::AX_INVALID_ELEMENT)) => return Err(error), Err(_) => true, }; if empty { @@ -344,7 +344,7 @@ pub(crate) fn placement(element: &Element) -> Result { // the walk as if the window were reached. let parent_of = |element: &Element| match element.attribute("AXParent") { Ok(Value::Element(parent)) => Ok(Some(parent)), - Err(ax::AX_CANNOT_COMPLETE) => Err(ax::AX_CANNOT_COMPLETE), + Err(error @ (ax::AX_CANNOT_COMPLETE | ax::AX_INVALID_ELEMENT)) => Err(error), _ => Ok(None), }; let mut next = parent_of(element)?; @@ -352,7 +352,7 @@ pub(crate) fn placement(element: &Element) -> Result { let Some(parent) = next else { break }; let role = match parent.attribute("AXRole") { Ok(value) => value.text().unwrap_or_default().to_owned(), - Err(ax::AX_CANNOT_COMPLETE) => return Err(ax::AX_CANNOT_COMPLETE), + Err(error @ (ax::AX_CANNOT_COMPLETE | ax::AX_INVALID_ELEMENT)) => return Err(error), Err(_) => String::new(), }; if floats(roles::role(&role, None)) { From 93b1688e825903b94abf869369e2afa9d3c33a31 Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Fri, 27 Nov 2026 19:06:31 +0900 Subject: [PATCH 04/12] fix(desktop): do not confirm a secure fill by a field that went away A secure fill checks AXNumberOfCharacters after the write. A field that a change handler replaced answers AX_INVALID_ELEMENT there, which read as "counts none", so the fill succeeded unchecked. `secure_count` now treats a gone field like a stall: no proof the field counts none, so the fill ends unconfirmed unless the count shows the whole text, as a plain field's fill does. Review: michal-e2e on #2322 at e7a74d44e (optional). Co-Authored-By: Claude Opus 5.5 --- crates/e2e-desktop-napi/src/actions/mod.rs | 10 ++++++++++ crates/e2e-desktop-napi/src/actions/values.rs | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/crates/e2e-desktop-napi/src/actions/mod.rs b/crates/e2e-desktop-napi/src/actions/mod.rs index 01883c5a7b..6c460a535a 100644 --- a/crates/e2e-desktop-napi/src/actions/mod.rs +++ b/crates/e2e-desktop-napi/src/actions/mod.rs @@ -1140,4 +1140,14 @@ mod tests { assert!(!super::scroll::scrolls_itself("list", false, &pages(&["AXScrollDownByPage"]), "right")); assert!(!super::scroll::scrolls_itself("list", false, &[], "up")); } + + #[test] + fn confirms_no_secure_fill_by_a_field_that_went_away_or_did_not_answer() { + use crate::ax::{AX_ATTRIBUTE_UNSUPPORTED, AX_CANNOT_COMPLETE, AX_INVALID_ELEMENT, Value}; + assert_eq!(super::secure_count(Ok(Value::Number(8.0))), Ok(Some(8))); + // A field that counts none is taken at the write's word. + assert_eq!(super::secure_count(Err(AX_ATTRIBUTE_UNSUPPORTED)), Ok(None)); + assert_eq!(super::secure_count(Err(AX_CANNOT_COMPLETE)), Err(())); + assert_eq!(super::secure_count(Err(AX_INVALID_ELEMENT)), Err(())); + } } diff --git a/crates/e2e-desktop-napi/src/actions/values.rs b/crates/e2e-desktop-napi/src/actions/values.rs index 0615439288..c33b3640ce 100644 --- a/crates/e2e-desktop-napi/src/actions/values.rs +++ b/crates/e2e-desktop-napi/src/actions/values.rs @@ -287,12 +287,7 @@ pub(super) fn set_value(element: &Element, text: &str, deadline: Instant) -> Out if secure { // A secure field shows no value, but counts its characters: the count says the text landed whole (one a // formatter cut short does not), with no secret read. A field that counts none is taken at the write's word. - // `Err` for a read the app did not answer in time, which is no proof the field counts none: it is read again. - let count = || match element.attribute("AXNumberOfCharacters") { - Ok(Value::Number(count)) => Ok(Some(count as usize)), - Err(ax::AX_CANNOT_COMPLETE) => Err(()), - _ => Ok(None), - }; + let count = || secure_count(element.attribute("AXNumberOfCharacters")); let wanted = text.encode_utf16().count(); if count() == Ok(None) || until(deadline, || count() == Ok(Some(wanted))) { return Ok(()); @@ -309,6 +304,17 @@ pub(super) fn set_value(element: &Element, text: &str, deadline: Instant) -> Out if until(deadline, shown) { Ok(()) } else { Err(Failure::unconfirmed(codes::ACTION_FAILED, "the value did not change to the text set")) } } +/// What a secure field's character count answers: `Ok(None)` for a field that counts none, which is taken at the write's +/// word. `Err` for a read the app did not answer in time, or for a field gone since the write (a change handler that +/// replaced it): neither is proof the field counts none, so the fill is not confirmed by it, as a plain field's is not. +pub(super) fn secure_count(answer: Result) -> Result, ()> { + match answer { + Ok(Value::Number(count)) => Ok(Some(count as usize)), + Err(ax::AX_CANNOT_COMPLETE | ax::AX_INVALID_ELEMENT) => Err(()), + _ => Ok(None), + } +} + /// Selects all the text of a field through accessibility. A select-all key (Cmd+A) sent to an app in the background /// goes to its menu bar, not the field, so the delete after it would remove one character. pub(super) fn select_all(element: &Element, deadline: Instant) -> Outcome<()> { From a8b9549b6344ac0aaef3cd9d7e58770e99c485ee Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Fri, 27 Nov 2026 19:06:37 +0900 Subject: [PATCH 05/12] fix(desktop): retry a stepper whose value read stalls A fill on a stepper whose AXValue cannot be written reads the value to see that it shows a number. A read the app did not answer in time fell through to "the value of this stepper cannot be set", a non-retryable ACTION_NOT_SUPPORTED. It is now the retryable APP_UNRESPONSIVE (and a gone element a stale ref), as every other stalled read is. Review: michal-e2e on #2322 at e7a74d44e (follow-up). Co-Authored-By: Claude Opus 5.5 --- crates/e2e-desktop-napi/src/actions/values.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/e2e-desktop-napi/src/actions/values.rs b/crates/e2e-desktop-napi/src/actions/values.rs index c33b3640ce..67355fefb4 100644 --- a/crates/e2e-desktop-napi/src/actions/values.rs +++ b/crates/e2e-desktop-napi/src/actions/values.rs @@ -230,7 +230,16 @@ pub(super) fn set_value(element: &Element, text: &str, deadline: Instant) -> Out // A stepper whose value cannot be written still steps toward a number. let names = action_names(element, "set value")?; let steps = names.iter().any(|name| name == "AXIncrement" || name == "AXDecrement"); - if let (true, Ok(Value::Number(_)), Ok(target)) = (steps, element.attribute("AXValue"), finite(text)) { + // A value the app did not answer in time is no proof the stepper shows no number: a stall, which a retry may get past. + let current = if steps { + match element.attribute("AXValue") { + Err(error @ (ax::AX_CANNOT_COMPLETE | ax::AX_INVALID_ELEMENT)) => return Err(unread(error, "set value")), + current => Some(current), + } + } else { + None + }; + if let (Some(Ok(Value::Number(_))), Ok(target)) = (current, finite(text)) { // A value outside the range the stepper reports is one no step reaches: refused before any press. let bound = |name: &str| match element.attribute(name) { Ok(Value::Number(number)) => Some(number), From 5c35f30f7daab5f54b8007b9cdc8bb630fe32448 Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Fri, 27 Nov 2026 19:06:43 +0900 Subject: [PATCH 06/12] fix(desktop): name no value in a stepper's failure messages The stepper's failures printed the fill text and the parsed target, and the engine copies the driver's message into the step's error. The secret ledger matches a secret in every spelling a serializer gives it, but not re-parsed as a number, so a secret `0042` filled into a stepper would print as `42`. The five messages (out of range, stopped short, wraps, already showed, steps past) now say "the value" and "where it started" instead of numbers. Review: michal-e2e on #2322 at e7a74d44e (for the maintainer). Co-Authored-By: Claude Opus 5.5 --- crates/e2e-desktop-napi/src/actions/mod.rs | 3 ++- crates/e2e-desktop-napi/src/actions/values.rs | 17 ++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/e2e-desktop-napi/src/actions/mod.rs b/crates/e2e-desktop-napi/src/actions/mod.rs index 6c460a535a..6057a82927 100644 --- a/crates/e2e-desktop-napi/src/actions/mod.rs +++ b/crates/e2e-desktop-napi/src/actions/mod.rs @@ -649,7 +649,8 @@ mod tests { ); let failure = past.expect_err("2 does not divide 3"); assert_eq!(failure.delivery, crate::failure::Delivery::Unknown); - assert!(failure.message.contains("stepped back to 0"), "{}", failure.message); + assert!(failure.message.contains("stepped back to where it started"), "{}", failure.message); + assert!(!failure.message.contains('3'), "names no value: {}", failure.message); assert_eq!(value.get(), 0.0); let count = Cell::new(0); let stuck = step_to( diff --git a/crates/e2e-desktop-napi/src/actions/values.rs b/crates/e2e-desktop-napi/src/actions/values.rs index 67355fefb4..777d27cd2c 100644 --- a/crates/e2e-desktop-napi/src/actions/values.rs +++ b/crates/e2e-desktop-napi/src/actions/values.rs @@ -132,6 +132,9 @@ pub(super) fn same(a: f64, b: f64, step: Option) -> bool { /// /// A start within rounding of the target, but not equal to it, may be the target summed by earlier steps or a value a /// small step away from it: one step tells which, and when it was the target, a step back puts it as it was. +/// +/// Its failures name no value: the target may be a secret, and the ledger that redacts one does not match it re-parsed as +/// a number (`0042` as `42`), nor the stepper's values a step from it. pub(super) fn step_to( target: f64, shown: Option, @@ -170,7 +173,7 @@ pub(super) fn step_to( if (up && next < now) || (!up && next > now) { return Err(Failure::unconfirmed( codes::ACTION_FAILED, - format!("the stepper went from {now} to {next} on a step toward {target}: it wraps, and cannot reach the value"), + "the stepper went the other way on a step toward the value: it wraps, and cannot reach the value", )); } size = Some((next - now).abs()); @@ -194,15 +197,15 @@ pub(super) fn step_to( } else { Err(Failure::unconfirmed( codes::ACTION_FAILED, - format!("the stepper already showed {start}; a step to tell it from {target} left it at {value}"), + "the stepper already showed about the value; a step to tell it from the value left it changed", )) }; } - let failure = Failure::unconfirmed(codes::ACTION_FAILED, format!("the stepper steps from {now} to {next}, past {target}")); + let failure = Failure::unconfirmed(codes::ACTION_FAILED, "the stepper's step goes past the value"); return Err(if same(value, start, size) { - Failure { message: format!("{}; it was stepped back to {start}", failure.message), ..failure } + Failure { message: format!("{}; it was stepped back to where it started", failure.message), ..failure } } else { - Failure { message: format!("{}, and could not be stepped back to {start}", failure.message), ..failure } + Failure { message: format!("{}, and could not be stepped back to where it started", failure.message), ..failure } }); } now = next; @@ -246,7 +249,7 @@ pub(super) fn set_value(element: &Element, text: &str, deadline: Instant) -> Out _ => None, }; if outside(target, bound("AXMinValue"), bound("AXMaxValue")) { - return Err(Failure::refused(codes::ACTION_FAILED, format!("{} is outside the range of this {role}", text.trim()))); + return Err(Failure::refused(codes::ACTION_FAILED, format!("the value is outside the range of this {role}"))); } let number = || match element.attribute("AXValue") { Ok(Value::Number(number)) => Some(number), @@ -265,7 +268,7 @@ pub(super) fn set_value(element: &Element, text: &str, deadline: Instant) -> Out shown }, )?; - return if reached { Ok(()) } else { Err(Failure::unconfirmed(codes::ACTION_FAILED, format!("the {role} stopped short of {}", text.trim()))) }; + return if reached { Ok(()) } else { Err(Failure::unconfirmed(codes::ACTION_FAILED, format!("the {role} stopped short of the value"))) }; } return Err(Failure::refused(codes::ACTION_NOT_SUPPORTED, format!("the value of this {role} cannot be set"))); } From 166cb249dd16d9892a0720477ec6a95e263f5f8d Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Fri, 27 Nov 2026 19:06:49 +0900 Subject: [PATCH 07/12] fix(desktop): name a list row for select as the snapshot names it `row_texts` stopped at a text child and read only that child's own label, while the snapshot walks into it and names the row from every text below. A row holding "Invoice" and an untitled heading over "Paid" was "Invoice Paid" to a locator but "Invoice" to `select`. `gather_texts` now walks the way the snapshot gathers a name from content: every level, a text's children before the text itself, and no scroll bar's parts. It takes the tree reads as closures, so a unit test pins the order on a fake tree. Review: michal-e2e on #2322 at e7a74d44e (optional). Co-Authored-By: Claude Opus 5.5 --- crates/e2e-desktop-napi/src/actions/mod.rs | 35 +++++++++++++ crates/e2e-desktop-napi/src/actions/select.rs | 52 +++++++++++++------ 2 files changed, 70 insertions(+), 17 deletions(-) diff --git a/crates/e2e-desktop-napi/src/actions/mod.rs b/crates/e2e-desktop-napi/src/actions/mod.rs index 6057a82927..7fed50ad9c 100644 --- a/crates/e2e-desktop-napi/src/actions/mod.rs +++ b/crates/e2e-desktop-napi/src/actions/mod.rs @@ -1151,4 +1151,39 @@ mod tests { assert_eq!(super::secure_count(Err(AX_CANNOT_COMPLETE)), Err(())); assert_eq!(super::secure_count(Err(AX_INVALID_ELEMENT)), Err(())); } + + /// A node of a fake accessibility tree, for the text gathering that names a row. + #[derive(Clone)] + struct Fake { + role: &'static str, + label: Option<&'static str>, + children: Vec, + } + + fn fake(role: &'static str, label: Option<&'static str>, children: Vec) -> Fake { + Fake { role, label, children } + } + + fn gathered(row: &Fake) -> Option { + let mut texts = Vec::new(); + super::gather_texts(row, 0, &mut texts, &|node: &Fake| Ok(node.children.clone()), &|node: &Fake| Ok(node.role), &|node: &Fake| { + Ok(node.label.map(str::to_owned)) + }) + .expect("read"); + crate::snapshot::content_name(&texts) + } + + #[test] + fn names_a_row_from_the_texts_under_its_texts_as_the_snapshot_does() { + // An untitled heading over "Paid": the snapshot walks into it, and so does the row's name. + let row = fake("row", None, vec![fake("statictext", Some("Invoice"), vec![]), fake("heading", None, vec![fake("statictext", Some("Paid"), vec![])])]); + assert_eq!(gathered(&row).as_deref(), Some("Invoice Paid")); + // A titled text comes after the texts inside it, in the snapshot's order. + let titled = fake("row", None, vec![fake("heading", Some("Total"), vec![fake("statictext", Some("42"), vec![])])]); + assert_eq!(gathered(&titled).as_deref(), Some("42 Total")); + // A scroll bar's parts are not read. + let scrolled = + fake("row", None, vec![fake("statictext", Some("Notes"), vec![]), fake("scrollbar", None, vec![fake("statictext", Some("50%"), vec![])])]); + assert_eq!(gathered(&scrolled).as_deref(), Some("Notes")); + } } diff --git a/crates/e2e-desktop-napi/src/actions/select.rs b/crates/e2e-desktop-napi/src/actions/select.rs index 7ca8457b8d..0d307560db 100644 --- a/crates/e2e-desktop-napi/src/actions/select.rs +++ b/crates/e2e-desktop-napi/src/actions/select.rs @@ -65,26 +65,44 @@ pub(super) fn own_label(element: &Element) -> Result, AXError> { /// The texts inside an element, in reading order, as the snapshot gathers a row's name from them. pub(super) fn row_texts(element: &Element, depth: usize, texts: &mut Vec) -> Result<(), AXError> { // Every child is read, as the snapshot reads them: a label cut short could match a prefix of the one asked for. - let children = match element.elements("AXChildren", crate::snapshot::MAX_CHILDREN) { - Ok(children) => children, - Err(ax::AX_CANNOT_COMPLETE) => return Err(ax::AX_CANNOT_COMPLETE), - Err(_) => Vec::new(), + let children = |element: &Element| match element.elements("AXChildren", crate::snapshot::MAX_CHILDREN) { + Ok(children) => Ok(children), + Err(ax::AX_CANNOT_COMPLETE) => Err(ax::AX_CANNOT_COMPLETE), + Err(_) => Ok(Vec::new()), + }; + let role = |element: &Element| match element.attribute("AXRole") { + Ok(value) => Ok(roles::role(value.text().unwrap_or_default(), None)), + Err(ax::AX_CANNOT_COMPLETE) => Err(ax::AX_CANNOT_COMPLETE), + Err(_) => Ok(roles::role("", None)), }; - if !children.is_empty() && depth >= ROW_TEXT_DEPTH { + gather_texts(element, depth, texts, &children, &role, &own_label) +} + +/// The texts under `node`, gathered as the snapshot's walk gathers them for a name from content: every level is read, +/// a text's own children before the text itself, so a row holding "Invoice" and an untitled heading over "Paid" is +/// "Invoice Paid" here as it is in the snapshot. A scroll bar's parts are not read, as the snapshot reads none. A node +/// deeper than `ROW_TEXT_DEPTH` with children counts as a read the app did not answer. +pub(super) fn gather_texts( + node: &T, + depth: usize, + texts: &mut Vec, + children: &dyn Fn(&T) -> Result, AXError>, + role: &dyn Fn(&T) -> Result<&'static str, AXError>, + label: &dyn Fn(&T) -> Result, AXError>, +) -> Result<(), AXError> { + let below = children(node)?; + if !below.is_empty() && depth >= ROW_TEXT_DEPTH { return Err(ax::AX_CANNOT_COMPLETE); } - for child in children { - let role = match child.attribute("AXRole") { - Ok(value) => value.text().unwrap_or_default().to_owned(), - Err(ax::AX_CANNOT_COMPLETE) => return Err(ax::AX_CANNOT_COMPLETE), - Err(_) => String::new(), - }; - if roles::text(roles::role(&role, None)) { - if let Some(text) = own_label(&child)? { - texts.push(text); - } - } else { - row_texts(&child, depth + 1, texts)?; + for child in below { + let kind = role(&child)?; + if kind != "scrollbar" { + gather_texts(&child, depth + 1, texts, children, role, label)?; + } + if roles::text(kind) + && let Some(text) = label(&child)? + { + texts.push(text); } } Ok(()) From 0248ba657696c84e63b578913fe80a89389f6e6d Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Fri, 27 Nov 2026 21:45:29 +0900 Subject: [PATCH 08/12] fix(desktop): stop waiting on a row the list replaced as it scrolled it in After `AXScrollToVisible`, `reveal` polled until the element read as shown. Since the gone-element fix, `placement` answers a replaced element with `AX_INVALID_ELEMENT`, which never reads as shown, so a tap, check, or scrollIntoView on a row the list replaces as it scrolls in waited out the poll and then failed as "still off screen". It now ends the poll at once with `STALE_REF`, delivered like any failure after that scroll, as `after_scroll` counts it. Found by michal-e2e's review of #2353. Co-Authored-By: Claude Opus 5.5 --- crates/e2e-desktop-napi/src/actions/mod.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/e2e-desktop-napi/src/actions/mod.rs b/crates/e2e-desktop-napi/src/actions/mod.rs index 7fed50ad9c..1b0af176eb 100644 --- a/crates/e2e-desktop-napi/src/actions/mod.rs +++ b/crates/e2e-desktop-napi/src/actions/mod.rs @@ -358,7 +358,20 @@ fn reveal(element: &Element, deadline: Instant, what: &str) -> Outcome { return Err(Failure::refused(codes::ACTION_FAILED, "the element is off screen and cannot be scrolled into view; scroll its list first")); } perform(element, "AXScrollToVisible", "scroll into view")?; - if until(deadline, || placement(element) == Ok(Placement::Shown)) { + // A list can replace a row's element as it scrolls the row in: the element is gone then, and no wait shows it. + let mut gone = false; + let shown = until(deadline, || match placement(element) { + Ok(Placement::Shown) => true, + Err(ax::AX_INVALID_ELEMENT) => { + gone = true; + true + } + _ => false, + }); + if gone { + return Err(Failure::unconfirmed(codes::STALE_REF, "the list replaced the element as it scrolled it into view")); + } + if shown { return Ok(true); } Err(Failure::unconfirmed(codes::ACTION_FAILED, "the element is still off screen after it was scrolled into view")) From 1366a7bddc1b784e0ecf031ea9068f1296ff10d8 Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Fri, 27 Nov 2026 21:45:35 +0900 Subject: [PATCH 09/12] fix(desktop): step a stepper from the number its first read showed `set_value` mapped a stalled first `AXValue` read to a retryable stall, then read `AXValue` again for the number to step from, a read that turned a stall into no number. `step_to` then returned without a step, and the fill failed unconfirmed as "stopped short of the value" with nothing pressed. The first read's number is now where stepping starts. The read is split into `shown_number`, so a unit test feeds it a stall and a gone element. Found by michal-e2e's review of #2353. Co-Authored-By: Claude Opus 5.5 --- crates/e2e-desktop-napi/src/actions/mod.rs | 14 ++++++++++ crates/e2e-desktop-napi/src/actions/values.rs | 26 +++++++++++-------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/crates/e2e-desktop-napi/src/actions/mod.rs b/crates/e2e-desktop-napi/src/actions/mod.rs index 1b0af176eb..81029dbd09 100644 --- a/crates/e2e-desktop-napi/src/actions/mod.rs +++ b/crates/e2e-desktop-napi/src/actions/mod.rs @@ -1115,6 +1115,20 @@ mod tests { assert_eq!(gone_wait_end(now, Some(soon)), now + Duration::from_millis(40)); } + #[test] + fn fails_a_stepper_value_read_that_stalled_or_went_away_before_any_step() { + use super::shown_number; + use crate::ax::{AX_CANNOT_COMPLETE, AX_FAILURE, AX_INVALID_ELEMENT, Value}; + use crate::failure::{Delivery, codes}; + assert_eq!(shown_number(Ok(Value::Number(4.0)), "set value").unwrap(), Some(4.0)); + assert_eq!(shown_number(Ok(Value::Text("four".into())), "set value").unwrap(), None); + assert_eq!(shown_number(Err(AX_FAILURE), "set value").unwrap(), None); + let stall = shown_number(Err(AX_CANNOT_COMPLETE), "set value").expect_err("a stall"); + assert_eq!((stall.code, stall.delivery), (codes::APP_UNRESPONSIVE, Delivery::NotDelivered)); + let gone = shown_number(Err(AX_INVALID_ELEMENT), "set value").expect_err("gone"); + assert_eq!((gone.code, gone.delivery), (codes::STALE_REF, Delivery::NotDelivered)); + } + #[test] fn takes_only_a_finite_number() { assert_eq!(super::finite(" 3 "), Ok(3.0)); diff --git a/crates/e2e-desktop-napi/src/actions/values.rs b/crates/e2e-desktop-napi/src/actions/values.rs index 777d27cd2c..eb96f67066 100644 --- a/crates/e2e-desktop-napi/src/actions/values.rs +++ b/crates/e2e-desktop-napi/src/actions/values.rs @@ -213,6 +213,16 @@ pub(super) fn step_to( Ok(same(now, target, size)) } +/// The number a stepper shows, from its `AXValue` read. A read the app did not answer in time, or of an element that +/// is gone, is no proof the stepper shows no number: it fails before anything is sent, a stall as one a retry may get +/// past. A value that is no number is `None`. +pub(super) fn shown_number(read: Result, what: &str) -> Outcome> { + match read { + Ok(Value::Number(number)) => Ok(Some(number)), + Err(error @ (ax::AX_CANNOT_COMPLETE | ax::AX_INVALID_ELEMENT)) => Err(unread(error, what)), + _ => Ok(None), + } +} /// Whether a stepper's target lies outside the range it reports: below `min` or above `max`. A bound it does not report /// limits nothing. pub(super) fn outside(target: f64, min: Option, max: Option) -> bool { @@ -233,16 +243,8 @@ pub(super) fn set_value(element: &Element, text: &str, deadline: Instant) -> Out // A stepper whose value cannot be written still steps toward a number. let names = action_names(element, "set value")?; let steps = names.iter().any(|name| name == "AXIncrement" || name == "AXDecrement"); - // A value the app did not answer in time is no proof the stepper shows no number: a stall, which a retry may get past. - let current = if steps { - match element.attribute("AXValue") { - Err(error @ (ax::AX_CANNOT_COMPLETE | ax::AX_INVALID_ELEMENT)) => return Err(unread(error, "set value")), - current => Some(current), - } - } else { - None - }; - if let (Some(Ok(Value::Number(_))), Ok(target)) = (current, finite(text)) { + let current = if steps { shown_number(element.attribute("AXValue"), "set value")? } else { None }; + if let (Some(first), Ok(target)) = (current, finite(text)) { // A value outside the range the stepper reports is one no step reaches: refused before any press. let bound = |name: &str| match element.attribute(name) { Ok(Value::Number(number)) => Some(number), @@ -255,7 +257,9 @@ pub(super) fn set_value(element: &Element, text: &str, deadline: Instant) -> Out Ok(Value::Number(number)) => Some(number), _ => None, }; - let mut shown = number(); + // The number read above, not a second read, which a stall would turn into no number and a fill that stops + // short without a step. + let mut shown = Some(first); let reached = step_to( target, shown, From 23719dc91073d52663b79651b6a28d0ebb45d452 Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Fri, 27 Nov 2026 21:45:43 +0900 Subject: [PATCH 10/12] fix(desktop): read a stall as one in raise, focus, and the window list The stall fix covered the five focus reads #2322's review named. Four more places still read a stall as an answer: `raise` read a stalled `AXFrontmost` or `AXFocusedWindow` as "could not be brought forward"; `focus` read a stalled `AXFocusedUIElement` as no focus; `holds_focus` read a stalled sheet `AXParent` as another window, so a key for a field in a sheet got a non-retryable "not the app's key window"; and `windows::list` listed every window as unfocused. Each now fails with the retryable `APP_UNRESPONSIVE`, before anything is sent where the read comes first. `stalled` is the one mapping they share, and a unit test feeds it `AX_CANNOT_COMPLETE`. Found by michal-e2e's review of #2353. Co-Authored-By: Claude Opus 5.5 --- crates/e2e-desktop-napi/src/actions/mod.rs | 92 +++++++++++++++---- .../e2e-desktop-napi/src/actions/pointer.rs | 5 +- crates/e2e-desktop-napi/src/actions/typing.rs | 9 +- crates/e2e-desktop-napi/src/windows.rs | 24 +++-- 4 files changed, 103 insertions(+), 27 deletions(-) diff --git a/crates/e2e-desktop-napi/src/actions/mod.rs b/crates/e2e-desktop-napi/src/actions/mod.rs index 81029dbd09..6c5beb254d 100644 --- a/crates/e2e-desktop-napi/src/actions/mod.rs +++ b/crates/e2e-desktop-napi/src/actions/mod.rs @@ -102,7 +102,7 @@ fn cancelled() -> bool { /// The failure for a read that failed before anything was sent: nothing reached the app. A read the app did not answer /// in time is a stall, which a retry may get past. -fn unread(error: AXError, what: &str) -> Failure { +pub(crate) fn unread(error: AXError, what: &str) -> Failure { match error { ax::AX_CANNOT_COMPLETE => { Failure::refused(codes::APP_UNRESPONSIVE, format!("{what}: the app did not answer in time")).with_details(serde_json::json!({ "retryable": true })) @@ -113,16 +113,27 @@ fn unread(error: AXError, what: &str) -> Failure { } } -/// The element an attribute names, such as the app's focused element or key window. A read the app did not answer in -/// time fails as a stall, which a retry may get past, never as focus that moved; any other failure reads as none. -fn element_attribute(element: &Element, name: &str, what: &str) -> Outcome> { - match element.attribute(name) { - Ok(value) => Ok(value.element().cloned()), - Err(ax::AX_CANNOT_COMPLETE) => Err(unread(ax::AX_CANNOT_COMPLETE, what)), +/// A read whose only failure that counts is a stall: the app did not answer in time, which says nothing about the +/// answer and passes up as `AX_CANNOT_COMPLETE`. Any other failure reads as no answer. +pub(crate) fn stalled(read: Result) -> Result, AXError> { + match read { + Ok(value) => Ok(Some(value)), + Err(ax::AX_CANNOT_COMPLETE) => Err(ax::AX_CANNOT_COMPLETE), Err(_) => Ok(None), } } +/// The element an attribute names, such as the app's focused element or key window. A read the app did not answer in +/// time fails as a stall, which a retry may get past, never as focus that moved; any other failure reads as none. +pub(crate) fn element_attribute(element: &Element, name: &str, what: &str) -> Outcome> { + Ok(stalled(element.attribute(name)).map_err(|error| unread(error, what))?.and_then(|value| value.element().cloned())) +} + +/// Whether `focused`, the app's focused window, holds `window`'s focus (`windows::holds_focus`). A stall fails as one. +pub(crate) fn holds(focused: &Element, window: &Element, what: &str) -> Outcome { + windows::holds_focus(focused, window).map_err(|error| unread(error, what)) +} + /// Whether an attribute can be set. A stall fails, so a busy app does not read as one whose control takes no input; /// any other failure reads as not settable. fn settable(element: &Element, name: &str, what: &str) -> Outcome { @@ -310,10 +321,28 @@ pub fn raise(pid: i32, window: &Element) -> Outcome<()> { go("bring the window forward")?; let _ = window.set_bool("AXMain", true); let deadline = Instant::now() + Duration::from_millis(1_500); - let forward = until(deadline, || { - app.boolean("AXFrontmost") == Some(true) && app.element("AXFocusedWindow").is_some_and(|focused| windows::holds_focus(&focused, window)) + let mut last = Ok(false); + until(deadline, || { + last = forward(&app, window); + last == Ok(true) }); - if forward { Ok(()) } else { Err(Failure::refused(codes::ACTION_FAILED, "the window could not be brought forward")) } + match last { + Ok(true) => Ok(()), + // An app that did not answer in time may have come forward: no proof it did not, and a retry may get past it. + Err(error) => Err(unread(error, "bring the window forward")), + Ok(false) => Err(Failure::refused(codes::ACTION_FAILED, "the window could not be brought forward")), + } +} + +/// Whether the app is frontmost with `window` holding its focus. A stall fails as `AX_CANNOT_COMPLETE`. +fn forward(app: &Element, window: &Element) -> Result { + if stalled(app.attribute("AXFrontmost"))?.and_then(|value| value.boolean()) != Some(true) { + return Ok(false); + } + match stalled(app.attribute("AXFocusedWindow"))?.and_then(|value| value.element().cloned()) { + Some(focused) => windows::holds_focus(&focused, window), + None => Ok(false), + } } /// Waits a moment for a menu an action opened to show, so the next read finds it; an action that opens none waits it out and is still done. @@ -441,18 +470,32 @@ fn click_shown(entry: &Entry, deadline: Instant) -> Outcome<()> { fn focus(element: &Element, deadline: Instant) -> Outcome<()> { // The app's focused element is the one source, as the snapshot reads it: a table's cell reports the table's focus as // its own `AXFocused`. - let holds = || match element.pid() { - Some(pid) => Element::application(pid).element("AXFocusedUIElement").as_ref() == Some(element), - None => element.boolean("AXFocused") == Some(true), + let holds = || -> Result { + Ok(match element.pid() { + Some(pid) => { + stalled(Element::application(pid).attribute("AXFocusedUIElement"))?.and_then(|value| value.element().cloned()).as_ref() == Some(element) + } + None => stalled(element.attribute("AXFocused"))?.and_then(|value| value.boolean()) == Some(true), + }) }; - if holds() { + // A stall before the write is no proof the element lacks focus: nothing is sent, and a retry may get past it. + if holds().map_err(|error| unread(error, "focus"))? { return Ok(()); } go("focus")?; // A focus write that failed after the app took it (a focus handler that replaced the element) may have run its // handlers: only a refusal shows nothing was sent, as for `set_value`. element.set_bool("AXFocused", true).map_err(|error| write_failed(error, "focus"))?; - if until(deadline, holds) { Ok(()) } else { Err(Failure::unconfirmed(codes::ACTION_FAILED, "focus: the element did not take keyboard focus")) } + let mut last = Ok(false); + until(deadline, || { + last = holds(); + last == Ok(true) + }); + match last { + Ok(true) => Ok(()), + Err(_) => Err(Failure::unconfirmed(codes::APP_UNRESPONSIVE, "focus: the app did not answer in time after the element was focused")), + Ok(false) => Err(Failure::unconfirmed(codes::ACTION_FAILED, "focus: the element did not take keyboard focus")), + } } /// Runs `work` as the action `input_id` names: until it returns, every input it sends first checks that the action was @@ -561,8 +604,8 @@ fn frontmost(pid: i32) -> Outcome { /// Refuses unless `window` is the app's key window, or holds the focused sheet or alert: a key or text sent to the app /// goes to its key window, and would land in another one. fn key_window(pid: i32, window: &Element) -> Outcome<()> { - if element_attribute(&Element::application(pid), "AXFocusedWindow", "read the app's key window")? - .is_some_and(|focused| windows::holds_focus(&focused, window)) + if let Some(focused) = element_attribute(&Element::application(pid), "AXFocusedWindow", "read the app's key window")? + && holds(&focused, window, "read the app's key window")? { return Ok(()); } @@ -1129,6 +1172,21 @@ mod tests { assert_eq!((gone.code, gone.delivery), (codes::STALE_REF, Delivery::NotDelivered)); } + #[test] + fn reads_a_stall_as_one_and_any_other_failure_as_no_answer() { + use super::stalled; + use crate::ax::{AX_CANNOT_COMPLETE, AX_FAILURE, AX_INVALID_ELEMENT, AX_NO_VALUE}; + assert_eq!(stalled(Ok(3)), Ok(Some(3))); + assert_eq!(stalled::(Err(AX_CANNOT_COMPLETE)), Err(AX_CANNOT_COMPLETE)); + for none in [AX_FAILURE, AX_INVALID_ELEMENT, AX_NO_VALUE] { + assert_eq!(stalled::(Err(none)), Ok(None), "{none}"); + } + // The stall reaches the engine as one it may retry. + let failure = super::unread(AX_CANNOT_COMPLETE, "type"); + assert_eq!((failure.code, failure.delivery), (crate::failure::codes::APP_UNRESPONSIVE, crate::failure::Delivery::NotDelivered)); + assert_eq!(failure.details, Some(serde_json::json!({ "retryable": true }))); + } + #[test] fn takes_only_a_finite_number() { assert_eq!(super::finite(" 3 "), Ok(3.0)); diff --git a/crates/e2e-desktop-napi/src/actions/pointer.rs b/crates/e2e-desktop-napi/src/actions/pointer.rs index 9af554965f..a4d071a183 100644 --- a/crates/e2e-desktop-napi/src/actions/pointer.rs +++ b/crates/e2e-desktop-napi/src/actions/pointer.rs @@ -184,7 +184,10 @@ pub(super) fn window_takes_point(target: &PointTarget, x: f64, y: f64) -> Outcom Err(error) if error == ax::AX_CANNOT_COMPLETE => return Err(unread(error, "read the app's focused window")), _ => None, }; - let holds = focused.as_ref().is_some_and(|focused| windows::holds_focus(focused, &window)); + let holds = match &focused { + Some(focused) => super::holds(focused, &window, "read the app's focused window")?, + None => false, + }; let now = match focused.filter(|focused| *focused != window) { None => Sheet::None, Some(on) => Sheet::Key(on.sheet_key()), diff --git a/crates/e2e-desktop-napi/src/actions/typing.rs b/crates/e2e-desktop-napi/src/actions/typing.rs index 1b3579a119..cbaeaeba28 100644 --- a/crates/e2e-desktop-napi/src/actions/typing.rs +++ b/crates/e2e-desktop-napi/src/actions/typing.rs @@ -30,7 +30,9 @@ pub(super) fn type_text(entry: &Entry, text: &str, physical: bool, deadline: Ins // that was there from the start keeps its sheet. Read before the field's own check, so a window a focus handler opens // after it shows as a change at the first key, and one it opened before fails that check. let typing_in = element_attribute(&Element::application(entry.pid), "AXFocusedWindow", "type")?; - if typing_in.as_ref().is_some_and(|start| !windows::holds_focus(start, &window)) { + if let Some(start) = &typing_in + && !holds(start, &window, "type")? + { return Err(Failure::refused(codes::ACTION_FAILED, "another window took the keyboard before typing began, so nothing was typed")); } // Coming forward can run a handler that opens a sheet or another window, and the app can move focus on: the keys @@ -87,7 +89,10 @@ pub(super) fn type_text(entry: &Entry, text: &str, physical: bool, deadline: Ins let focused = element_attribute(&Element::application(entry.pid), "AXFocusedWindow", "type")?; let held = match &typing_in { Some(start) => focused.as_ref() == Some(start), - None => focused.is_some_and(|focused| windows::holds_focus(&focused, &window)), + None => match &focused { + Some(focused) => holds(focused, &window, "type")?, + None => false, + }, }; let forward = !physical || frontmost(entry.pid)?; if held && forward { diff --git a/crates/e2e-desktop-napi/src/windows.rs b/crates/e2e-desktop-napi/src/windows.rs index e25109c406..46652d6adc 100644 --- a/crates/e2e-desktop-napi/src/windows.rs +++ b/crates/e2e-desktop-napi/src/windows.rs @@ -174,9 +174,13 @@ fn system_dialog(identifiers: &[String]) -> bool { } /// Whether `window` holds the app's focused window: is it, or carries it as a sheet or an alert. The app's focused window -/// is the sheet then, and keys reach the window through it. -pub fn holds_focus(focused: &Element, window: &Element) -> bool { - focused == window || focused.element("AXParent").as_ref() == Some(window) +/// is the sheet then, and keys reach the window through it. A parent the app did not answer for in time is no proof +/// either way: it fails as `AX_CANNOT_COMPLETE`. +pub fn holds_focus(focused: &Element, window: &Element) -> Result { + if focused == window { + return Ok(true); + } + Ok(crate::actions::stalled(focused.attribute("AXParent"))?.and_then(|parent| parent.element().cloned()).as_ref() == Some(window)) } /// The windows of one process: every accessibility window, and every @@ -187,7 +191,9 @@ pub fn list(pid: i32) -> Outcome> { } let app = Element::application(pid); let accessible = ax_windows(&app)?; - let focused = app.element("AXFocusedWindow"); + // The app's focus decides which window is focused: a stall reading it fails the list, which a retry may get past, + // rather than list every window as unfocused. + let focused = crate::actions::element_attribute(&app, "AXFocusedWindow", "list windows")?; let server: Vec = server_windows().into_iter().filter(|window| window.pid == pid).collect(); let mut out = Vec::new(); let mut listed = Vec::new(); @@ -213,13 +219,17 @@ pub fn list(pid: i32) -> Outcome> { (Some(ax::Value::Point(x, y)), Some(ax::Value::Size(width, height))) => Some(Rect { x: *x, y: *y, width: *width, height: *height }), _ => None, }; + let holds = match &focused { + Some(focused) => crate::actions::holds(focused, element, "list windows")?, + None => false, + }; listed.push(id); out.push(WindowInfo { id: id.to_string(), title: title.or_else(|| entry.and_then(|window| window.title.clone())), - is_focused: focused.as_ref().is_some_and(|focused| holds_focus(focused, element)), - sheet_focused: focused.as_ref().is_some_and(|focused| focused != element && holds_focus(focused, element)), - sheet_id: focused.as_ref().filter(|focused| *focused != element && holds_focus(focused, element)).map(Element::sheet_key), + is_focused: holds, + sheet_focused: holds && focused.as_ref() != Some(element), + sheet_id: focused.as_ref().filter(|focused| holds && *focused != element).map(Element::sheet_key), is_main: values[5].as_ref().and_then(|value| value.boolean()).unwrap_or(false), visible: entry.is_some_and(|window| window.onscreen), accessible: true, From 786e2907a644da58a1e28ac05e147cd8fa1ed4ae Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Fri, 27 Nov 2026 21:45:51 +0900 Subject: [PATCH 11/12] fix(desktop): refuse a swipe with nothing to scroll as not actionable A node swipe where nothing scrolls along the axis failed with `ACTION_NOT_SUPPORTED`, which the engine reads as `UNSUPPORTED_CAPABILITY` and an agent step reports as `POLICY_DENIED`. A window swipe with nothing to scroll already fails as `NOT_ACTIONABLE`; the node swipe now does too (`ACTION_FAILED`), with the same "nothing here scrolls" message. Raised by michal-e2e's review of #2353. Co-Authored-By: Claude Opus 5.5 --- crates/e2e-desktop-napi/src/actions/scroll.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/e2e-desktop-napi/src/actions/scroll.rs b/crates/e2e-desktop-napi/src/actions/scroll.rs index 450b7ae8b9..8da6c31a86 100644 --- a/crates/e2e-desktop-napi/src/actions/scroll.rs +++ b/crates/e2e-desktop-napi/src/actions/scroll.rs @@ -26,9 +26,10 @@ pub(super) fn scroll(element: &Element, direction: &str, pages: f64) -> Outcome< let own = scrolls_itself(role, scroll_bar(element, vertical).is_some(), &action_names(element, "scroll")?, direction); let target = if own { None } else { enclosing_scroll_area(element, vertical) }; scroll_by(target.as_ref().unwrap_or(element), direction, pages).map_err(|failure| { - // An element that takes none of the ways to scroll: say so, not which attribute it lacks. + // An element that takes none of the ways to scroll: say so, not which attribute it lacks. Like a window with + // nothing to scroll, it is not actionable, not a capability the engine lacks. if failure.code == codes::ACTION_NOT_SUPPORTED && failure.delivery == Delivery::NotDelivered { - Failure::refused(codes::ACTION_NOT_SUPPORTED, format!("nothing here scrolls {direction}")) + Failure::refused(codes::ACTION_FAILED, format!("nothing here scrolls {direction}")) } else { failure } @@ -111,5 +112,5 @@ pub(super) fn scroll_by(element: &Element, direction: &str, pages: f64) -> Outco if scrolls_itself(role, false, &names, direction) { return repeat(element, page_action(direction), (pages.round() as usize).max(1)); } - Err(Failure::refused(codes::ACTION_NOT_SUPPORTED, format!("nothing here scrolls {direction}"))) + Err(Failure::refused(codes::ACTION_FAILED, format!("nothing here scrolls {direction}"))) } From 8ea401cdb9a1ad0e44a62aa3a5027f14beb1edda Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Fri, 27 Nov 2026 21:46:11 +0900 Subject: [PATCH 12/12] test(desktop): check that no stepper failure names a value The doc comment on `step_to` promises its failures name no value, since a secret filled into a stepper could come back re-parsed (`0042` as `42`), where the ledger would not redact it. Only the "steps past" message was checked. The test now drives every failure `step_to` gives: a wrap, a step past and back, a step past that cannot go back, a probe that left the value changed, and one out of time. It asserts no ASCII digit appears in any of them. Asked for by michal-e2e's review of #2353. Co-Authored-By: Claude Opus 5.5 --- crates/e2e-desktop-napi/src/actions/mod.rs | 74 +++++++++++++++++++ crates/e2e-desktop-napi/src/actions/values.rs | 1 + 2 files changed, 75 insertions(+) diff --git a/crates/e2e-desktop-napi/src/actions/mod.rs b/crates/e2e-desktop-napi/src/actions/mod.rs index 6c5beb254d..803cc0af27 100644 --- a/crates/e2e-desktop-napi/src/actions/mod.rs +++ b/crates/e2e-desktop-napi/src/actions/mod.rs @@ -1187,6 +1187,80 @@ mod tests { assert_eq!(failure.details, Some(serde_json::json!({ "retryable": true }))); } + #[test] + fn names_no_value_in_any_stepper_failure() { + let digitless = |failure: crate::failure::Failure| { + assert!(!failure.message.chars().any(|c| c.is_ascii_digit()), "names a value: {}", failure.message); + }; + // Wraps: one step up from 42 goes to 0. + let value = Cell::new(42.0); + digitless( + step_to( + 43.0, + Some(42.0), + later(), + |_| { + value.set(0.0); + Ok(()) + }, + || Some(value.get()), + ) + .expect_err("wraps"), + ); + // Steps past and back: 40, 42, 44 past 43, then back to 40. + let value = Cell::new(40.0); + digitless( + step_to( + 43.0, + Some(40.0), + later(), + |up| { + value.set(value.get() + if up { 2.0 } else { -2.0 }); + Ok(()) + }, + || Some(value.get()), + ) + .expect_err("past"), + ); + // Steps past and cannot go back. + let value = Cell::new(40.0); + digitless( + step_to( + 43.0, + Some(40.0), + later(), + |up| { + if up { + value.set(value.get() + 2.0) + } + Ok(()) + }, + || Some(value.get()), + ) + .expect_err("stuck past"), + ); + // Already showed the target up to rounding, and the step to tell it left it changed. + let summed = 0.1 + 0.1 + 0.1; + let value = Cell::new(summed); + digitless( + step_to( + 0.3, + Some(summed), + later(), + |up| { + if !up { + value.set(value.get() - 0.1) + } + Ok(()) + }, + || Some(value.get()), + ) + .expect_err("left changed"), + ); + // Out of time before the first step. + digitless(step_to(43.0, Some(40.0), Instant::now(), |_| Ok(()), || Some(40.0)).expect_err("no time")); + } + #[test] fn takes_only_a_finite_number() { assert_eq!(super::finite(" 3 "), Ok(3.0)); diff --git a/crates/e2e-desktop-napi/src/actions/values.rs b/crates/e2e-desktop-napi/src/actions/values.rs index eb96f67066..496c5c9ad5 100644 --- a/crates/e2e-desktop-napi/src/actions/values.rs +++ b/crates/e2e-desktop-napi/src/actions/values.rs @@ -223,6 +223,7 @@ pub(super) fn shown_number(read: Result, what: &str) -> Outcome< _ => Ok(None), } } + /// Whether a stepper's target lies outside the range it reports: below `min` or above `max`. A bound it does not report /// limits nothing. pub(super) fn outside(target: f64, min: Option, max: Option) -> bool {