feat(desktop): fold out-of-view rows, and add app.back, clearState, sessions, and video (ENG-1533)
KD
3h ago+4481+4481+0123456789012345678901234567890123456789-1074-1074-0123456789012345678901234567890123456789
What
- A long list reads as fast as a short one: rows a scroll area holds out of view become one hidden line (
182 rows out of view) that no locator finds.scrollUntilVisible(locator)brings a row in, andselectOption(label)still reads every row. - A SwiftUI toolbar
Menu's items match once, sogetByRole('menuitem', 'By Priority').tap()needs no.first(). app.back()presses the app's Back menu item (titled Back or Go Back, else the one whose shortcut is Command-[) in the active window, and fails when the app has neither.app.clearState()andtest.setupsessions work for anapp.appPathtarget.video: 'on',--video on, andapp.startRecording()record the app's window. Without Screen Recording permission video fails as it starts, a file whose recording broke off is dropped, and a recording that got no file fails at the stop with the reason.selectOptionnames a table row by a numeric cell as every locator does.
Why
Follow-ups agreed on #2322 and #2323:
- A 200-row SwiftUI List was 1,034 nodes and 1.1 s per read.
scrollUntilVisibleto its end took 24-31 s against the 30 s default, and oneagent.actthere cost 142k tokens. app.back(),app.clearState(), sessions, and video were left out with reasons: a key that does nothing reports success, and resetting state reaches the user's own copy of an app. A screen-rectangle recording does not follow the window and records what covers it.
This layer answers each reason.
How it works
- Every request the driver makes of an element goes through a new
Accessibletrait (crates/e2e-desktop-napi/src/ax.rs:315), whichElementimplements. A fake tree for tests (src/fake.rs) implements it too.- 24 new tests cover the walk's hole handling (a stalled read, a failed
AXChildren, the depth limit, a window that closed mid-read), title-bar chrome, the scroll rule, and row refs.
- 24 new tests cover the walk's hole handling (a stalled read, a failed
- A row of a list, table, or outline that lies wholly outside its scroll area costs one frame read. A run of such rows becomes one folded node (
snapshot.rs:98). A row that holds focus or is selected is never folded (snapshot.rs:683), sogetByRole('row', { selected: true })finds the rowselectOptionchose.nodes.ts:327projects a fold as a hidden, role-less line.locateresolves on the tree without fold lines (locatable,nodes.ts:491), so no text query finds one;observeandscreen.tree()keep them. A folded row matches no locator, so an absence check on a list's rows covers only the rows read; the guide says so.- An open menu or popover under a node a scroll hides is not hidden with it (
FLOATING_ROLES,nodes.ts:436): the driver reads it as on screen, since it floats above the window. own_label(actions/select.rs) reads a text's value through the snapshot'sshown_value, soselectOption('Plan 2')finds a row whose second cell holds the number 2, and a heading's number (its level) is never part of a row's label.- A walk to the focused element that the app stalls on leaves the read incomplete (
ancestorsinsnapshot.rs), so a fold never hides a focused field in a read that says it is complete. seen(snapshot.rs:206) skips an element already read under another parent.
app.back():pressBack(actions/menu.rs:87) reads the menu bar for an item titled Back or Go Back, else one whose shortcut is Command-[ alone, and presses it withAXPress. It never sends a key.- The menu-bar walk is
back_candidates(menu.rs:173), generic overAccessibleso a fake bar drives it. An item counts as enabled only when its menu and every submenu item above it are. choose(menu.rs:67) takes the best kind of match nearest the menu bar, first in menu order. When that item is disabled it refuses, and never presses a Back in the Window menu or under Open Recent instead.- AppKit updates a menu item's enabled state about a second late, so it watches the item for 1.2 s first. A budget too short for that watch refuses with
TIMEOUTbefore the press (watch_window,menu.rs:149). - The watch reads the item and every menu and submenu item above it again (
enabled_now,menu.rs:130), so a Back under a disabled Go menu or Open Recent is never pressed.press_back(menu.rs:104) holds the whole decision, generic over the tree, so a fake menu bar drives it from the walk to the press. - The tests of
snapshot.rsandactions/mod.rslive insnapshot/tests.rsandactions/tests.rs, which keeps both files under 1000 lines. - The menu bar acts on the key window. With another window made active,
keyWindowForMenu(surface.ts:1463) refuses withNOT_ACTIONABLE; withphysicalInputit brings the active window forward first. - No item is
UNSUPPORTED_CAPABILITY; a disabled one isNOT_ACTIONABLE.
- The menu-bar walk is
app.clearState()and sessions (packages/desktop/src/state.ts). The refusals all come before anything is changed:- a
bundleIdtarget is refused; requireSole(:142) refuses while LaunchServices (bundleCopies) or Spotlight knows another copy of the bundle id, or a process the engine did not launch runs one. A Spotlight lookup that timed out fails the check (:81); Spotlight turned off finds nothing and leaves LaunchServices' answer;- a bundle id must be two or more dot-separated segments of letters, digits, hyphens, and underscores, not starting with a hyphen (
:45). So..never names a directory, and-g,-globalDomain, andNSGlobalDomainnever reachdefaults delete. - Reset (
:171) quits the app, then clears its defaults domain, itsSaved Application State/<id>.savedState, andContainers/<id>. - A session saves the defaults domain. Restore resets first and imports the defaults, since
defaults importmerges. - The state commands run within what is left of the operation's budget (
withinBudgetinsurface.ts), though each has a longer limit of its own; a budget that runs out fails withOPERATION_TIMEOUT, no directory removal starts after it, and no command starts with no time left.
- a
- Video (
crates/e2e-desktop-napi/src/video.rs,packages/desktop/src/video.ts:37): ScreenCaptureKit records only the target window and writes H.264 to.mp4throughSCRecordingOutput.- The window is chosen by id, so covering windows are not recorded and the recording follows the window when it moves.
- Each window
screenreads is its own file, and a stop goes out even when the operation was cancelled.window.activate()moves the recording at once (surface.ts:517), not at the next read. finish(video.ts:196) drops a file whose stop failed, since a recording that broke off has no index and no player opens it, and an empty one. Either loss, like a failed start, is the reasonendthrows when the video got no file.- A window whose start failed is not tried again for the rest of the video (
followinvideo.ts), unless the read's budget or a cancel cut the start off. While a start or stop is queued,followleaves the comparison with the recorded window toswitchTo, in turn. - A failed start removes the file it left, a segment's
startedAtis taken before the start goes,abandonremoves the files of a recording the attempt left running, andstartVideofails when its window lookup was cancelled or ran out of time. - It needs macOS 15 and Screen Recording, both checked in
begin(video.ts:65): earlier versions fail withUNSUPPORTED_CAPABILITY, and no permission withENGINE_FAILURE. The first window's start comes later, infollow, which never fails a read; its first failure is kept, andendthrows it when the video got no file (video.ts:118). stopcounts the 500 ms minimum length from the first frame and gives a first frame that arrives during the stop the whole deadline. A permission refusal is told bySCStreamErrorDomainandUserDeclined(declined,video.rs:153), not by its localized text.
- CI's macOS
nativejob runs the whole desktop unit suite with the addon it built, so the macOS-only state tests that guard whatclearStateremoves run in CI (spec.yml). - The new native calls (
pressBack,bundleCopies,startVideo,stopVideo) are typed inpackages/desktop/src/native.ts, which main's #2458 writes from the crate.docs/reference/desktop.mdxgets Back, Long lists, State, and Video sections, with one row each indocs/desktop.mdx's table.packages/desktop/README.md, the platform packages'THIRD_PARTY_LICENSES.md(forobjc2-screen-capture-kit), and a changeset follow.
Issue
Follow-ups agreed on #2322 and #2323.
Verified
Ran it locally: yes (macOS 27.2.1, arm64, background mode). Rebased onto main 7c1b2b258. Main's #2367 added shown_value beside the tree walk this PR makes generic, so it takes the element type too. #2448 moved the desktop guide's details into docs/reference/desktop.mdx, so this PR's docs moved there. #2458 generates the driver's types from the crate, so this PR's calls are declared in Rust, with readonly return types as main's are.
Long-list reads, TaskBoard's 200-row SwiftUI List, before (base of this layer) and after:
| before | after | |
|---|---|---|
| driver snapshot | 1.9-2.9 s, 1039 nodes | 55-87 ms, 130 nodes |
screen.tree() | 2225 ms, 1034 lines, 47.8k chars | 111 ms, 125 lines, 4.6k chars |
scrollUntilVisible to row 200 | 31.3 s | 1.4 s |
- The toolbar
Menuitem tap passes without.first()(it failed withLOCATOR_AMBIGUOUSbefore), checked live after confirming withCFEqualthat both listings are one element. app.back()on a scratch app with a Back item: two backs in a row work, a disabled Back is refused, an app without one is refused, and the app stayed in the background.clearStateand sessions on a scratch app with its own bundle id: clearState, state kept across a restart, a setup save, and two restores that replace rather than merge. A second copy registered with LaunchServices was refused with the domain unchanged, and abundleIdtarget was refused. Not run live: a sandboxed build's container removal.- Video, checked with ffprobe and stills:
- the file follows a window move;
- a full-screen window covering it is not recorded;
- a sheet is recorded with its window;
- a password field shows bullets;
- a restart inside
startRecordinggives two files. - Not checked: resize and context menus.
- Unit tests: the trait-driven walk tests, a row partly in view that is read rather than folded, the menu-bar walk on a fake bar (a title beats Command-[ on another item, a stalled menu fails),
state.test.ts(a..bundle id never reachesrm, and an empty nested dictionary survives a restore),video.test.ts(a stop goes out on a cancelled operation, no permission is refused before any start, a failed deferred start fails the stop), andnodes.test.ts(a loosegetByText('View')beside a fold matches only the button;rowsand182match nothing). The desktop unit suite passes with the native addon required. - Fixes from michal-e2e's probe comment, each with a test that fails on the code before it: the numeric row label (
names_a_row_by_a_numeric_cell_as_the_snapshot_does), the bundle id rule (state.test.ts), the selected row out of view (folds_no_row_that_holds_the_focus…), the open menu under a scrolled-out button (nodes.test.ts), Back in a non-key active window (back.test.ts), the menu walk (refuses_a_disabled_back_rather_than_press_one_in_another_menu,reads_an_item_under_a_disabled_menu_or_submenu_as_disabled), and video (video.test.ts: a failed stop, an empty file,activate()with no read, a failed window beside a recorded one). The probe's folded-row focus failures went throughholdsFocus, which main's #2374 removed: the driver now checks focus by the element, not by its box. DesktopSurface.locatewith a fold and a loose text query (surface.test.ts): puttinglocateback on the whole screen fails it.- From okwasniewski's re-review:
never_presses_a_back_its_menu_keeps_disableddrivespress_backon a fake bar with Go disabled and its Back enabled, and with Back under a disabled Open Recent. It fails when the watch reads the item alone. Two more tests cover a Back that AppKit enables, menu included, during the watch (pressed) and one it disables (refused). A liveapp.back()on the testbed app, which has no Back, is refused with nothing pressed. - This round's fixes, from CodeRabbit and cubic, each with a test that fails on the code before it, except the queued-switch check: a focus walk that stalls leaves the read incomplete; state commands stop at a 200 ms budget with
OPERATION_TIMEOUT; a failed start's file, and an abandoned recording's files, are removed; a window whose start a budget cut off is recorded on the next read; a start cancelled while it looked for the window fails withCANCELLED; an untitled heading leaves its level out of a row's label; the fake table's selection replaces the one before; no state directory removal starts once the budget ran out; a copy lookup LaunchServices did not answer fails the check. A test of two overlappingactivate()calls passed on the old code too, so the queued-switch change has none. - At this layer (
01d581dc4), with Rust 1.100.0:cargo fmt --check, clippy,cargo test(112 passed), andnative.tsregenerated with no change; the desktop suite with the addon (321 passed).pnpm run buildandpnpm checkat the top of the stack. - The desktop testbed at the top of the stack (#2358), after this round: 31 of 31, and the SwiftUI suite 18 of 18, with
--video ontoo. Two rounds before: 18 of 18 with--video on, all 21.mp4files opening inffprobe. At this layer before the round: 25 of 25, and with--video onevery test wrote its file. With video on, the Controls window tests see an extra "Window": the window macOS draws in a recorded window's title bar, which #2358 leaves out. - Not run: a refused Screen Recording permission live (this Mac has it granted; the unit test covers the refusal), and a Spotlight timeout, which is checked by reading only, as is the
EPIPElistener ondefaults import.
Checklist
- Changeset added (
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only..changeset/desktop-back-state-video.md, a patch for@e2e-dev/desktopnamingapp.back(),clearState, sessions, video, and folded rows. - Breaking change: title carries
!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it.docs/reference/desktop.mdx,docs/desktop.mdx, andpackages/desktop/README.md. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.
🤖 Generated with Claude Code
Summary by CodeRabbit
- New Features
- Added
app.back()to activate an enabled Back menu command without sending keyboard input. - Added app-state capture, restore, and reset for eligible apps launched from a path. These actions are unavailable for installed apps and require the app to be the only running copy.
- Added window video recording on macOS 15 and later, with a separate recording file for each window.
- Added
- Improvements
- Large off-screen list sections appear as row-count markers. Markers aren’t searchable or actionable; visible, selected, and focused rows remain readable.
- Improved display of numeric values in selectable rows. Open menus remain readable when their parent controls are off-screen.
- Documentation
- Updated desktop guidance for Back, app state, video, Screen Recording permission, and off-screen list behavior.