From af35eb8400820f4a67a55b3a61b7982bf8be7904 Mon Sep 17 00:00:00 2001 From: yumi Date: Tue, 3 Nov 2026 16:42:18 +0800 Subject: [PATCH 1/3] feat(windows): expose Chromium toolbar popovers --- apps/docs/content/docs/surfaces.mdx | 2 +- crates/windows/src/system/adapter.rs | 4 +- crates/windows/src/system/adapter_tests.rs | 1 + crates/windows/src/system/window/mod.rs | 1 + .../src/system/window/window_popover.rs | 113 ++++++++++++++++++ .../src/system/window/window_popover_tests.rs | 40 +++++++ crates/windows/src/tree/surfaces.rs | 16 ++- .../src/tree/surfaces_advertising_tests.rs | 1 + skills/agent-desktop-windows/SKILL.md | 2 +- 9 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 crates/windows/src/system/window/window_popover.rs create mode 100644 crates/windows/src/system/window/window_popover_tests.rs diff --git a/apps/docs/content/docs/surfaces.mdx b/apps/docs/content/docs/surfaces.mdx index 1e45d641f8..260380f8bd 100644 --- a/apps/docs/content/docs/surfaces.mdx +++ b/apps/docs/content/docs/surfaces.mdx @@ -33,7 +33,7 @@ Each platform supports a subset: macOSwindow, focused, menu, menubar, sheet, popover, alert, dock, menu-bar-extras - Windowswindow, focused, sheet, menu, start-menu, taskbar, system-tray, system-tray-overflow, action-center + Windowswindow, focused, sheet, menu, popover, start-menu, taskbar, system-tray, system-tray-overflow, action-center Linuxwindow, sheet, alert, menu, plus GNOME Shell kinds the session can resolve diff --git a/crates/windows/src/system/adapter.rs b/crates/windows/src/system/adapter.rs index 0fb197d843..575b040e4c 100644 --- a/crates/windows/src/system/adapter.rs +++ b/crates/windows/src/system/adapter.rs @@ -103,7 +103,8 @@ impl SystemOps for WindowsAdapter { } /// The surfaces this adapter can observe: a named window, the focused - /// window, a Chromium modal-as-sheet, an open application menu, and the + /// window, a Chromium modal-as-sheet, an open application menu, a popup + /// window the requested window owns (a Chromium toolbar bubble), and the /// shell kinds the shell-surface resolver reaches on this build. Core /// validates the requested surface against this list before the adapter /// is ever called (the mirror of macOS `supported_surfaces`), so a kind @@ -119,6 +120,7 @@ impl SystemOps for WindowsAdapter { SnapshotSurface::Focused, SnapshotSurface::Sheet, SnapshotSurface::Menu, + SnapshotSurface::Popover, SnapshotSurface::StartMenu, SnapshotSurface::Taskbar, SnapshotSurface::SystemTray, diff --git a/crates/windows/src/system/adapter_tests.rs b/crates/windows/src/system/adapter_tests.rs index 1d31009bc1..50406d8f3d 100644 --- a/crates/windows/src/system/adapter_tests.rs +++ b/crates/windows/src/system/adapter_tests.rs @@ -158,6 +158,7 @@ fn supported_surfaces_advertises_window_focused_sheet_menu_and_shell_kinds() { SnapshotSurface::Focused, SnapshotSurface::Sheet, SnapshotSurface::Menu, + SnapshotSurface::Popover, SnapshotSurface::StartMenu, SnapshotSurface::Taskbar, SnapshotSurface::SystemTray, diff --git a/crates/windows/src/system/window/mod.rs b/crates/windows/src/system/window/mod.rs index 752ace5502..6fef8aaa54 100644 --- a/crates/windows/src/system/window/mod.rs +++ b/crates/windows/src/system/window/mod.rs @@ -8,4 +8,5 @@ pub(crate) mod window_op_readback; pub(crate) mod window_op_verb; pub(crate) mod window_op_wait; pub(crate) mod window_ops; +pub(crate) mod window_popover; pub(crate) mod window_resolve; diff --git a/crates/windows/src/system/window/window_popover.rs b/crates/windows/src/system/window/window_popover.rs new file mode 100644 index 0000000000..f031ed3660 --- /dev/null +++ b/crates/windows/src/system/window/window_popover.rs @@ -0,0 +1,113 @@ +//! The popover surface: a popup window an application owns beside the window +//! it was opened from. +//! +//! Chromium draws its toolbar bubbles (the Edge and Chrome extensions menu, a +//! site-permission prompt, a profile menu) as a separate `WS_POPUP` window +//! owned by the browser frame and styled as a tool window. The window census +//! drops tool windows and the frame's own UIA tree does not contain the +//! bubble, so neither `list-windows` nor `snapshot --surface window` can reach +//! it. A popover is found instead by ownership: a visible, uncloaked popup of +//! the same process whose owner chain leads to the requested window. Chromium +//! also keeps tooltip popups under the same owner; they are click-through +//! (`WS_EX_TRANSPARENT`) and take no input, so they are never candidates. Of +//! what remains, the largest window is the one rooted. + +use agent_desktop_core::{AdapterError, ProcessId, Rect}; + +use super::window_enum::{EnumeratedWindow, WindowHandle, enumerate_top_level}; +use super::window_identity::live_window_owner; + +const OWNER_CHAIN_LIMIT: usize = 8; + +pub(crate) fn locate_popover(owner: WindowHandle) -> Result, AdapterError> { + let Some(pid) = live_window_owner(owner) else { + return Ok(None); + }; + let mut candidates = Vec::new(); + enumerate_top_level(|window| { + if window.handle != owner && is_popover_of(&window, owner, pid) { + candidates.push((window.handle, window.rect)); + } + true + })?; + Ok(largest_window(candidates)) +} + +pub(crate) fn largest_window( + candidates: impl IntoIterator, +) -> Option { + let mut best: Option<(WindowHandle, f64)> = None; + for (handle, rect) in candidates { + let area = rect.width * rect.height; + if best.is_none_or(|(_, largest)| area > largest) { + best = Some((handle, area)); + } + } + best.map(|(handle, _)| handle) +} + +fn is_popover_of(window: &EnumeratedWindow, owner: WindowHandle, pid: ProcessId) -> bool { + window.visible + && !window.cloaked + && !window.iconic + && !window.is_zero_sized() + && live_window_owner(window.handle) == Some(pid) + && is_popup(window.handle) + && !is_click_through(window.handle) + && owner_chain_reaches(window.handle, owner) +} + +#[cfg(target_os = "windows")] +fn is_popup(handle: WindowHandle) -> bool { + use windows_sys::Win32::UI::WindowsAndMessaging::{GWL_STYLE, GetWindowLongW, WS_POPUP}; + + let style = unsafe { GetWindowLongW(handle, GWL_STYLE) } as u32; + style & WS_POPUP != 0 +} + +#[cfg(not(target_os = "windows"))] +fn is_popup(_handle: WindowHandle) -> bool { + false +} + +#[cfg(target_os = "windows")] +fn is_click_through(handle: WindowHandle) -> bool { + use windows_sys::Win32::UI::WindowsAndMessaging::{ + GWL_EXSTYLE, GetWindowLongW, WS_EX_TRANSPARENT, + }; + + let ex_style = unsafe { GetWindowLongW(handle, GWL_EXSTYLE) } as u32; + ex_style & WS_EX_TRANSPARENT != 0 +} + +#[cfg(not(target_os = "windows"))] +fn is_click_through(_handle: WindowHandle) -> bool { + false +} + +#[cfg(target_os = "windows")] +fn owner_chain_reaches(handle: WindowHandle, owner: WindowHandle) -> bool { + use windows_sys::Win32::UI::WindowsAndMessaging::{GW_OWNER, GetWindow}; + + let mut current = handle; + for _ in 0..OWNER_CHAIN_LIMIT { + current = unsafe { GetWindow(current, GW_OWNER) }; + if current.is_null() { + return false; + } + if current == owner { + return true; + } + } + false +} + +#[cfg(not(target_os = "windows"))] +fn owner_chain_reaches(_handle: WindowHandle, _owner: WindowHandle) -> bool { + let _ = OWNER_CHAIN_LIMIT; + false +} + +#[cfg(test)] +#[path = "window_popover_tests.rs"] +mod tests; diff --git a/crates/windows/src/system/window/window_popover_tests.rs b/crates/windows/src/system/window/window_popover_tests.rs new file mode 100644 index 0000000000..23cf496112 --- /dev/null +++ b/crates/windows/src/system/window/window_popover_tests.rs @@ -0,0 +1,40 @@ +use super::*; + +fn handle(value: usize) -> WindowHandle { + value as WindowHandle +} + +fn rect(width: f64, height: f64) -> Rect { + Rect { + x: 0.0, + y: 0.0, + width, + height, + } +} + +#[test] +fn no_candidate_roots_nothing() { + assert!(largest_window(Vec::new()).is_none()); +} + +#[test] +fn the_bubble_wins_over_the_tooltip_it_owns() { + let tooltip = (handle(1), rect(136.0, 25.0)); + let bubble = (handle(2), rect(384.0, 678.0)); + assert_eq!(largest_window(vec![tooltip, bubble]), Some(handle(2))); + assert_eq!(largest_window(vec![bubble, tooltip]), Some(handle(2))); +} + +#[test] +fn an_equal_area_keeps_the_first_window_enumerated() { + let first = (handle(1), rect(100.0, 100.0)); + let second = (handle(2), rect(100.0, 100.0)); + assert_eq!(largest_window(vec![first, second]), Some(handle(1))); +} + +#[cfg(target_os = "windows")] +#[test] +fn a_window_that_does_not_exist_owns_no_popover() { + assert!(matches!(locate_popover(std::ptr::null_mut()), Ok(None))); +} diff --git a/crates/windows/src/tree/surfaces.rs b/crates/windows/src/tree/surfaces.rs index c70e18d1ba..1c3d8159e1 100644 --- a/crates/windows/src/tree/surfaces.rs +++ b/crates/windows/src/tree/surfaces.rs @@ -7,8 +7,9 @@ use super::element::UIAElement; use super::properties::property_ids::TreeProperty; #[cfg(target_os = "windows")] use super::properties::read_one; -use crate::system::window::window_enum::enumerate_top_level; +use crate::system::window::window_enum::{WindowHandle, enumerate_top_level}; use crate::system::window::window_ops::{parse_window_id, passes_filter}; +use crate::system::window::window_popover::locate_popover; /// Resolves the element an observation root names, per-surface (`Window` /// resolves the named window directly; `Focused` composes the focused-only @@ -61,6 +62,19 @@ pub(crate) fn surface_root( })?; root_from_hwnd(location.root_handle(), deadline) } + (ObservationRoot::Window(window), SnapshotSurface::Popover) => { + let owner = parse_window_id(&window.id)?; + let popover = locate_popover(owner as WindowHandle)?.ok_or_else(|| { + AdapterError::new( + ErrorCode::ElementNotFound, + "No popover owned by this window is open", + ) + .with_suggestion( + "Open the popup first, for example a browser toolbar button, then read --surface popover again.", + ) + })?; + root_from_hwnd(popover as isize, deadline) + } (ObservationRoot::Window(window), SnapshotSurface::StartMenu) | (ObservationRoot::Window(window), SnapshotSurface::Taskbar) | (ObservationRoot::Window(window), SnapshotSurface::SystemTray) diff --git a/crates/windows/src/tree/surfaces_advertising_tests.rs b/crates/windows/src/tree/surfaces_advertising_tests.rs index 3b7fac13c2..368d4cacf5 100644 --- a/crates/windows/src/tree/surfaces_advertising_tests.rs +++ b/crates/windows/src/tree/surfaces_advertising_tests.rs @@ -28,6 +28,7 @@ const SURFACE_ROOT_RESOLVABLE: &[SnapshotSurface] = &[ SnapshotSurface::Focused, SnapshotSurface::Sheet, SnapshotSurface::Menu, + SnapshotSurface::Popover, SnapshotSurface::StartMenu, SnapshotSurface::Taskbar, SnapshotSurface::SystemTray, diff --git a/skills/agent-desktop-windows/SKILL.md b/skills/agent-desktop-windows/SKILL.md index e93d2a730e..0f4ed39904 100644 --- a/skills/agent-desktop-windows/SKILL.md +++ b/skills/agent-desktop-windows/SKILL.md @@ -29,7 +29,7 @@ observation, actions and capture there fail or return nothing. | Group | Commands | Status on Windows | |-------|----------|-------------------| -| Observation | `snapshot`, `find`, `get`, `is`, `screenshot` | Works. Surfaces are `window`, `focused`, a Chromium modal as `sheet`, and an open application menu as `menu` | +| Observation | `snapshot`, `find`, `get`, `is`, `screenshot` | Works. Surfaces are `window`, `focused`, a Chromium modal as `sheet`, an open application menu as `menu`, and a popup window the requested window owns (a Chromium toolbar bubble such as the Edge extensions menu) as `popover` | | Surfaces | `list-surfaces` | Works. Lists `window`, `focused` and `sheet` per process, plus `menu` with `item_count` while a menu is open | | Shell surfaces | `open-system-surface` | Works for `start-menu`, `taskbar`, `system-tray`, `system-tray-overflow` and `action-center`, and returns the window `snapshot --surface ` reads. `quick-settings` returns `INVALID_ARGS` naming `action-center` | | Ref interaction | `click`, `right-click`, `type`, `set-value`, `clear`, `select`, `toggle`, `check`, `uncheck`, `expand`, `collapse`, `scroll`, `scroll-to` | Works, semantic in headless and `--headed` mode. `right-click` and `type` need `--headed` and return `POLICY_DENIED` headless | From e627fb4b3a90ee6d639ec8f31f53247815d5f918 Mon Sep 17 00:00:00 2001 From: yumi Date: Tue, 3 Nov 2026 16:49:35 +0800 Subject: [PATCH 2/3] test(windows): cover live popover surface resolution --- .../src/system/window/window_popover_tests.rs | 30 ++++++++++++++ .../src/tree/fixture/fixture_popover.rs | 39 +++++++++++++++++++ crates/windows/src/tree/fixture/mod.rs | 2 + crates/windows/src/tree/surfaces_tests.rs | 9 +++++ 4 files changed, 80 insertions(+) create mode 100644 crates/windows/src/tree/fixture/fixture_popover.rs diff --git a/crates/windows/src/system/window/window_popover_tests.rs b/crates/windows/src/system/window/window_popover_tests.rs index 23cf496112..9eefe139e6 100644 --- a/crates/windows/src/system/window/window_popover_tests.rs +++ b/crates/windows/src/system/window/window_popover_tests.rs @@ -38,3 +38,33 @@ fn an_equal_area_keeps_the_first_window_enumerated() { fn a_window_that_does_not_exist_owns_no_popover() { assert!(matches!(locate_popover(std::ptr::null_mut()), Ok(None))); } + +#[cfg(target_os = "windows")] +#[test] +fn an_owned_tool_popup_roots_and_a_hidden_or_click_through_popup_does_not() { + use crate::tree::fixture::{bootstrap, fixture_popover::PopoverFixture}; + use windows_sys::Win32::UI::WindowsAndMessaging::{ + GWL_EXSTYLE, SW_HIDE, SW_SHOWNOACTIVATE, SetWindowLongW, ShowWindow, WS_EX_TOOLWINDOW, + WS_EX_TRANSPARENT, + }; + + bootstrap(); + let fixture = PopoverFixture::create().expect("the popover fixture opens"); + let owner = fixture.owner_handle() as WindowHandle; + let popup = fixture.popup_handle() as WindowHandle; + assert_eq!(locate_popover(owner).unwrap(), Some(popup)); + assert_eq!(locate_popover(popup).unwrap(), None); + + unsafe { ShowWindow(popup, SW_HIDE) }; + assert_eq!(locate_popover(owner).unwrap(), None); + unsafe { ShowWindow(popup, SW_SHOWNOACTIVATE) }; + assert_eq!(locate_popover(owner).unwrap(), Some(popup)); + unsafe { + SetWindowLongW( + popup, + GWL_EXSTYLE, + (WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT) as i32, + ); + } + assert_eq!(locate_popover(owner).unwrap(), None); +} diff --git a/crates/windows/src/tree/fixture/fixture_popover.rs b/crates/windows/src/tree/fixture/fixture_popover.rs new file mode 100644 index 0000000000..d0c62d94aa --- /dev/null +++ b/crates/windows/src/tree/fixture/fixture_popover.rs @@ -0,0 +1,39 @@ +use super::LocalFixture; +use windows_sys::Win32::UI::WindowsAndMessaging::{ + GWL_EXSTYLE, GWL_STYLE, GWLP_HWNDPARENT, GetWindowLongPtrW, GetWindowLongW, SetWindowLongPtrW, + SetWindowLongW, WS_EX_TOOLWINDOW, WS_POPUP, WS_VISIBLE, +}; + +pub(crate) struct PopoverFixture { + popup: LocalFixture, + owner: LocalFixture, +} + +impl PopoverFixture { + pub(crate) fn create() -> Result { + let owner = LocalFixture::create()?; + let (left, top) = owner.origin(); + let popup = LocalFixture::create_at(left + 40, top + 40)?; + let hwnd = popup.handle() as _; + unsafe { + SetWindowLongW(hwnd, GWL_STYLE, (WS_POPUP | WS_VISIBLE) as i32); + SetWindowLongW(hwnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW as i32); + SetWindowLongPtrW(hwnd, GWLP_HWNDPARENT, owner.handle()); + if GetWindowLongPtrW(hwnd, GWLP_HWNDPARENT) != owner.handle() + || GetWindowLongW(hwnd, GWL_STYLE) as u32 & WS_POPUP == 0 + || GetWindowLongW(hwnd, GWL_EXSTYLE) as u32 & WS_EX_TOOLWINDOW == 0 + { + return Err("the fixture did not become an owned tool popup".into()); + } + } + Ok(Self { popup, owner }) + } + + pub(crate) fn owner_handle(&self) -> isize { + self.owner.handle() + } + + pub(crate) fn popup_handle(&self) -> isize { + self.popup.handle() + } +} diff --git a/crates/windows/src/tree/fixture/mod.rs b/crates/windows/src/tree/fixture/mod.rs index 8d9a6af2ac..63c04834b3 100644 --- a/crates/windows/src/tree/fixture/mod.rs +++ b/crates/windows/src/tree/fixture/mod.rs @@ -367,6 +367,8 @@ pub(crate) mod fixture_overlay; #[cfg(all(test, target_os = "windows"))] pub(crate) mod fixture_pattern; #[cfg(all(test, target_os = "windows"))] +pub(crate) mod fixture_popover; +#[cfg(all(test, target_os = "windows"))] pub(crate) mod fixture_spawn; #[cfg(all(test, target_os = "windows"))] pub(crate) mod fixture_window; diff --git a/crates/windows/src/tree/surfaces_tests.rs b/crates/windows/src/tree/surfaces_tests.rs index a002a8d03f..7b5b0a1743 100644 --- a/crates/windows/src/tree/surfaces_tests.rs +++ b/crates/windows/src/tree/surfaces_tests.rs @@ -72,6 +72,7 @@ mod shell_surfaces { use crate::system::shell::shell_surface::resolve_surface; use crate::system::shell::shell_surface_open::{close_surface, open_surface}; use crate::tree::fixture::fixture_menu::MenuFixture; + use crate::tree::fixture::fixture_popover::PopoverFixture; use crate::tree::fixture::fixture_window; use crate::tree::test_support::rooted_child_count; use agent_desktop_core::{InteractionPolicy, ObservationOps, ProcessId, SystemOps, WindowInfo}; @@ -268,6 +269,14 @@ mod shell_surfaces { skipped.push(SnapshotSurface::Sheet); } } + { + let popover = PopoverFixture::create().expect("the popover fixture opens"); + assert_roots_non_empty( + SnapshotSurface::Popover, + &window_info(popover.owner_handle(), std::process::id()), + ); + covered.push(SnapshotSurface::Popover); + } stage_and_assert_shell_kinds(&advertised, &mut covered, &mut skipped); stage_and_assert_menu(&advertised, &mut covered); From b20716dd8121885de0b2798d62c519e643dc995f Mon Sep 17 00:00:00 2001 From: yumi Date: Tue, 3 Nov 2026 17:55:05 +0800 Subject: [PATCH 3/3] fix(windows): preserve popover refs during resolution --- crates/windows/src/tree/observe.rs | 4 +- crates/windows/src/tree/resolve/mod.rs | 4 + .../src/tree/resolve/resolve_popover_tests.rs | 79 +++++++++++++++++++ crates/windows/src/tree/walk/walker.rs | 3 +- crates/windows/src/tree/walk/walker_fake.rs | 22 ++++-- crates/windows/src/tree/walk/walker_source.rs | 12 ++- 6 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 crates/windows/src/tree/resolve/resolve_popover_tests.rs diff --git a/crates/windows/src/tree/observe.rs b/crates/windows/src/tree/observe.rs index e4a6985bea..3acb8fdcfa 100644 --- a/crates/windows/src/tree/observe.rs +++ b/crates/windows/src/tree/observe.rs @@ -9,7 +9,7 @@ use serde_json::json; use super::chromium; use super::surfaces::surface_root; use super::walk::walker::{DEFAULT_MAX_RAW_DEPTH, WalkBudget, WalkOutcome}; -use super::walk::walker_source::walk_uia_subtree; +use super::walk::walker_source::walk_uia_subtree_on_surface; /// Runs one observation: resolve the root, walk it, detect a Chromium shell, /// and report completeness honestly. @@ -55,7 +55,7 @@ pub(crate) fn observe_tree( let budget = WalkBudget::new(request.max_logical_depth, request.deadline) .with_max_raw_depth(request.max_raw_depth.min(DEFAULT_MAX_RAW_DEPTH)); let walk_started = Instant::now(); - let outcome = walk_uia_subtree(&element, &root, budget)?; + let outcome = walk_uia_subtree_on_surface(&element, &root, request.surface, budget)?; finish_observation( root, request, diff --git a/crates/windows/src/tree/resolve/mod.rs b/crates/windows/src/tree/resolve/mod.rs index 29dddd8b9e..9b44aa328b 100644 --- a/crates/windows/src/tree/resolve/mod.rs +++ b/crates/windows/src/tree/resolve/mod.rs @@ -165,3 +165,7 @@ pub(crate) mod resolve_search; #[cfg(all(test, target_os = "windows"))] #[path = "resolve_tests.rs"] mod windows_only; + +#[cfg(all(test, target_os = "windows"))] +#[path = "resolve_popover_tests.rs"] +mod popover_tests; diff --git a/crates/windows/src/tree/resolve/resolve_popover_tests.rs b/crates/windows/src/tree/resolve/resolve_popover_tests.rs new file mode 100644 index 0000000000..c3278a63bb --- /dev/null +++ b/crates/windows/src/tree/resolve/resolve_popover_tests.rs @@ -0,0 +1,79 @@ +use super::resolve_anchor::resolve_locator_anchor; +use crate::system::window::window_identity::live_window_owner; +use crate::tree::fixture::{ensure_test_apartment, fixture_popover::PopoverFixture}; +use crate::tree::walk::walker::WalkBudget; +use crate::tree::walk::walker_source::UiaTreeSource; +use agent_desktop_core::{Deadline, SnapshotSurface}; +use std::ops::ControlFlow; + +#[test] +fn a_ref_from_a_live_popover_resolves_back_into_that_popover() { + ensure_test_apartment(); + let fixture = PopoverFixture::create().expect("the owned popup fixture starts"); + let owner_pid = live_window_owner(fixture.owner_handle() as _) + .expect("the owner window belongs to a live process"); + let token = crate::system::process_identity::token_for_pid(owner_pid) + .expect("the owner process token is readable") + .expect("the owner process is live"); + let owner = agent_desktop_core::WindowInfo { + id: format!("w-{}", fixture.owner_handle()), + title: String::new(), + app: String::new(), + pid: owner_pid, + process_instance: Some(token.clone()), + bounds: None, + state: Default::default(), + }; + let deadline = Deadline::after(10_000).expect("the resolution deadline is valid"); + let popup = crate::tree::automation::root_from_hwnd(fixture.popup_handle(), deadline) + .expect("the popup HWND roots a UI Automation element"); + let source = UiaTreeSource::for_root(&popup).expect("the popup provider resolves"); + let prepared = source + .prepare_root(&popup) + .expect("the popup root is prepared"); + let target = crate::tree::walk::walker_fake::scan_subtree( + &source, + &prepared, + &WalkBudget::new(10, deadline), + 10, + &mut |path, _, evidence, _| { + if evidence + .name + .known() + .is_some_and(|name| name == "fixture-button") + { + ControlFlow::Break((path.to_vec(), evidence)) + } else { + ControlFlow::Continue(()) + } + }, + ) + .expect("the popup tree can be scanned") + .expect("the popup exposes its button"); + let (path, evidence) = target; + let mut entry = crate::tree::walk::walker_fake::ref_entry( + evidence.role.known().expect("the button role is known"), + ); + entry.identity.name = Some("fixture-button".into()); + entry.identity.native_id = evidence.identifiers.preferred_identifier().cloned(); + entry.scope.path = path.into(); + entry.process = agent_desktop_core::RefProcess { + pid: owner_pid, + process_instance: Some(token), + }; + entry.identity.unique_at_capture = true; + entry.source.source_app = Some(String::new()); + entry.source.source_window_id = Some(owner.id.clone()); + entry.source.source_window_title = Some(String::new()); + entry.source.source_surface = SnapshotSurface::Popover; + entry.scope.path_is_absolute = true; + + let resolved = resolve_locator_anchor(&entry, deadline) + .expect("a ref captured on a popover must resolve against the same popover"); + + assert!( + resolved + .downcast_ref::() + .is_some() + ); +} diff --git a/crates/windows/src/tree/walk/walker.rs b/crates/windows/src/tree/walk/walker.rs index d289fefbb2..fbea8acaf3 100644 --- a/crates/windows/src/tree/walk/walker.rs +++ b/crates/windows/src/tree/walk/walker.rs @@ -137,6 +137,7 @@ pub fn walk_from_root( source: &S, root: &S::Node, root_source: &ObservationRoot<'_>, + surface: agent_desktop_core::SnapshotSurface, budget: WalkBudget, ) -> Result { let mut walk = TreeWalk::new(source, budget); @@ -145,7 +146,7 @@ pub fn walk_from_root( let root_subtree = root_subtree.ok_or_else(|| root_missing_error(&stats))?; let tree = ObservedTree::from_roots( vec![root_subtree], - ObservationSource::from_root(root_source, root_source.surface()), + ObservationSource::from_root(root_source, surface), stats.clone(), structurally_complete, )?; diff --git a/crates/windows/src/tree/walk/walker_fake.rs b/crates/windows/src/tree/walk/walker_fake.rs index 10e4a2dce3..feefa98da8 100644 --- a/crates/windows/src/tree/walk/walker_fake.rs +++ b/crates/windows/src/tree/walk/walker_fake.rs @@ -237,17 +237,29 @@ pub(crate) fn window() -> WindowInfo { pub(crate) fn walk(fake: &FakeTree, budget: WalkBudget) -> WalkOutcome { let window = window(); - walk_from_root(fake, &1, &ObservationRoot::Window(&window), budget) - .expect("the walk assembles an observation") + walk_from_root( + fake, + &1, + &ObservationRoot::Window(&window), + agent_desktop_core::SnapshotSurface::Window, + budget, + ) + .expect("the walk assembles an observation") } /// Runs a walk that is expected not to assemble an observation at all, so the /// error the caller receives can be asserted. pub(crate) fn walk_expecting_failure(fake: &FakeTree, budget: WalkBudget) -> AdapterError { let window = window(); - walk_from_root(fake, &1, &ObservationRoot::Window(&window), budget) - .err() - .expect("the walk was expected to fail") + walk_from_root( + fake, + &1, + &ObservationRoot::Window(&window), + agent_desktop_core::SnapshotSurface::Window, + budget, + ) + .err() + .expect("the walk was expected to fail") } #[cfg(target_os = "windows")] diff --git a/crates/windows/src/tree/walk/walker_source.rs b/crates/windows/src/tree/walk/walker_source.rs index 9feff85072..f36032daaa 100644 --- a/crates/windows/src/tree/walk/walker_source.rs +++ b/crates/windows/src/tree/walk/walker_source.rs @@ -356,10 +356,20 @@ pub fn walk_uia_subtree( root: &UIAElement, root_source: &ObservationRoot<'_>, budget: WalkBudget, +) -> Result { + walk_uia_subtree_on_surface(root, root_source, root_source.surface(), budget) +} + +/// Walks a resolved surface while retaining its identity in every materialized ref. +pub fn walk_uia_subtree_on_surface( + root: &UIAElement, + root_source: &ObservationRoot<'_>, + surface: agent_desktop_core::SnapshotSurface, + budget: WalkBudget, ) -> Result { let source = UiaTreeSource::for_root(root)?; let prepared = source.prepare_root(root)?; - walk_from_root(&source, &prepared, root_source, budget) + walk_from_root(&source, &prepared, root_source, surface, budget) } #[cfg(test)]