Skip to content

testing: Driver, an interactive test driver behind the driver feature (#373, PR B) - #413

Merged
samitbasu merged 6 commits into
mainfrom
driver-373b
Nov 19, 2026
Merged

samitbasu merged 6 commits into
mainfrom
driver-373b

Conversation

@samitbasu

@samitbasu samitbasu commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Part of #373 (PR B of the split in the design note). Fixes #301. Fixes #374.

Built on #408 (PR A), now merged.

What

testing::Driver, behind a new opt-in driver feature. It implements the note's §1, with the user's decisions on #373.

  • Construction.
    • Driver::new(app, view) takes a view.
    • Driver::whole_frame(app, frame) takes a frame that draws itself. Its closure answers the PlacedFrame its layout's Placed::draw(..) answered, and the driver keeps it for its queries.
    • The builder takes size, theme, pixels_per_point, step (default 1/60 s), motion (default Animation::Full), base_text, setup, after (default After::Settle), settle_within (default 2 s), reports (default Reports::Guarded) and with_harness.
  • No second event pump. The driver wraps kittest's Harness: every event goes through harness.event, and every frame through step / run_steps / run_ok. harness() and harness_mut() stay open.
  • Targets.
    • A typed Path: d.path(K).at(..) hashes each key as the builder does and borrows nothing.
    • Target::suffix: exactly one node must match, and a whole path wins over the paths it ends.
    • Target::role(role, name), through kittest's query.
    • Target::text, as Query::text.
    • An Id, or a point.
    • A miss panics with Query::at's message. A press outside the window panics with the target's rect.
  • Actions. Each runs one frame per event, then the After policy:
    • pointer: click, click_with, double_click, hover, drag, lift, carry_to, pointer_down / pointer_up, wheel;
    • keys: press (a Key, KeyboardShortcut or Chord), type_text, select_all, tab_to;
    • window: window_focus, hover_files / drop_files, resize, set_theme;
    • other: focus, event.
  • Time.
    • settle runs kittest's run_ok, with the cap as max_steps. Past the cap it panics with the repaint causes: did not settle within …; still repainting: [file:line …]. try_settle returns Unsettled { frames, clock, causes } instead.
    • advance(Duration) and frames(n) run frames.
    • now() is the time since the driver was built.
  • Queries.
    • frame() is the last PlacedFrame drawn, kept through testing: split a closure-free PlacedFrame out of Placed (#373, PR A) #408's hand-off.
    • rect / find / exists answer for a target.
    • focused() returns Focused::Node(path) or Focused::Widget { within }.
    • painted() lists the texts drawn: text, all, shows, expect. Each PaintedText gives rect, clip, color, galley, pos, rows, elided, part_rect and fits.
  • The report guard (testing: a harness guard that asserts no reports on drop #301).
    • A Reports::Guarded driver asserts, when dropped, that the view reported nothing it did not claim. It skips the check while the thread is panicking.
    • expect_reported(problem) returns the report and claims that problem for the driver's life.
    • Reports::Unchecked turns the check off.
  • text_findings() (Text audit: Placed::text_findings() for wrapped, clipped or elided text #374). Each painted text that does not fit (it wraps, is elided, or overruns its clip), joined to the node that shows it. It reports and does not fail.
  • Assertions and options. Assertion helpers are #[track_caller] and carry #[expect(clippy::panic, reason = "an assertion fails the test")]. find, try_* and exists never panic.

Cargo

  • driver = ["dep:egui_kittest"]. egui_kittest moves out of the Linux-only table as an optional dependency.
  • screenshots keeps egui_kittest/wgpu and its Linux gate.
  • eggshell's own tests enable driver through a dev-dependency on the crate itself (eggshell-ui = { path = ".", features = ["driver"] }), so cargo test needs no flag.

Deviations from the note, each for a reason

  • The whole-frame constructor is Driver::whole_frame. Driver::frame is taken by the query, and Rust has no overloading.
  • expect_reported claims the problem rather than taking the report. A misuse reported every frame comes back as a new report in the next frame, and a take would let it fail the guard.
  • Focused::Widget { within: Option<String> }: a widget outside every node has no path.
  • Only the point a press lands on must be inside the window. A move, a release or a drag's end may go past the edge, as a real held drag does; the migration showed tests that need this.
  • Added during the migration (C–E):
    • Driver::set_motion, for tests that switch motion off mid-run;
    • Driver::layout(), for a test clipboard and tracked_layout_nodes;
    • PaintedText::pos().

Update after #408's rework

#408 merged with Placed::draw(..) answering its PlacedFrame, as the user asked, in place of the keep_frames / take_frame hand-over this PR was first built on. Main is merged in, and the driver follows:

  • Driver::whole_frame's closure now answers the frame (FnMut(&mut Ui, &mut A, &mut LayoutState) -> PlacedFrame). Before, it answered nothing and the driver took the frame from the hand-over. This changes the approved API, for you to check. A whole-frame closure ends with its layout's .draw(app, ui).
  • Driver::new's closure answers its view's frame the same way.
  • The driver stores the answered frame in its stage each frame. Driver::frame's panic doc now says only "no frame drawn yet", which the first frame of build rules out.
  • LayoutState::scope goes, because only the hand-over used it.
  • The one merge conflict, in pipeline.rs, was that accessor.

Checks

  • tests/it/driver.rs proves each action through a real view:
    • a click increments, and every kind of target names the same button;
    • a drag moves a splitter, and a held drag may leave the window;
    • typing reaches a text_field, and select_all replaces the text;
    • tab_to reaches a node;
    • a blur closes an open menu, and a menu item is picked by role;
    • a tooltip opens after advance and not after settle;
    • the clock moves one step a frame;
    • a forever-spinner fails settle, naming its request_repaint call site;
    • a missing path and an ambiguous suffix panic with their candidates;
    • a press outside the window panics;
    • an unclaimed report fails on drop, a claimed one passes, and an Unchecked driver leaves reports to the test;
    • text_findings names the wrapped label;
    • part_rect works.
  • Doctests on Driver show a click and the advance-versus-settle rule for a tooltip.
  • cargo xtask ci before the merge: exit 0.
  • Test outcomes, sorted test … ok|FAILED|ignored lines before and after: only additions. No existing test changes outcome. Diff against origin/main:
    • 22 new driver::* tests, all ok;
    • 2 new testing::driver::Driver doctests.
  • After the merge with main (by cargo test --workspace --no-fail-fast through the build queue): 2316 outcomes, none failed. Against this branch before the merge, every difference comes from main:
  • After the merge, clippy (workspace, all targets, all features) is clean. GitHub's checks are the gate.

New public docs are marked TODO(prose) for your wording.

No UI change, so there is nothing to try by hand.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up

samitbasu and others added 4 commits November 18, 2026 18:32
…re (#373, PR B)

eggshell's tests and its consumers each carry private copies of the same
helpers: click a node by path, press a key and run N frames, type, drag,
wait for a tooltip, read painted text. `testing::Driver` is that surface
once, as the design note on #373 lays out and the user decided:

- It wraps kittest's `Harness`: every event goes through the harness's
  queue and every frame through its step, so there is no second event
  pump, and `harness()` stays open for kittest's queries.
- Targets: a typed `Path` (`d.path(K).at(..)`), a unique path suffix,
  role and name (through kittest), text, `Id`, a point. A miss fails with
  `Query::at`'s message; a pointer action fails on a point outside the
  window.
- Actions: click, click_with, double_click, hover, drag, lift, carry_to,
  pointer_down/up, wheel, press (`Key`, `KeyboardShortcut` or `Chord`),
  type_text, select_all, tab_to, window_focus, hover/drop_files, resize,
  set_theme, focus, event. Each runs a frame per event, then the
  driver's `After` policy: settle by default, or a fixed frame count.
- `settle` runs kittest's `run_ok` with the cap as `max_steps`, and fails
  naming the repaint causes; `advance(Duration)` waits on the clock.
- Queries: the last frame drawn (`PlacedFrame`, kept through PR A's
  hand-off), `rect`/`find`/`exists`, `focused`, `painted()` with
  `PaintedText::fits`, and `text_findings()` (#374), which joins each
  painted text that does not fit to the node that shows it.
- The report guard (#301): a driver checks on drop, unless the thread is
  already panicking, that the view reported nothing it did not claim
  with `expect_reported`; `Reports::Unchecked` opts out.

Defaults are an app's, not kittest's: a 1/60 s step, full motion, a
2 s settle cap.

`egui_kittest` moves out of the Linux-only table as an optional
dependency; `driver` enables it, and eggshell's own tests enable it
through a dev-dependency on the crate itself, so `cargo test` needs no
flag. `screenshots` keeps its Linux gate.

Deviations from the note: the constructor for a view that draws the
whole frame is `Driver::whole_frame`, since `Driver::frame` is the query;
`expect_reported` claims the problem for the driver's life rather than
taking the report, because a misuse reported every frame would come back
the next frame; `Focused::Widget` carries `within: Option<String>`, since
a widget outside every node holds no path; `Driver::set_motion` is added
for tests that switch motion off mid-run.

No behaviour change to existing tests; new API only.

Part of #373. Fixes #301. Fixes #374.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
… PaintedText::pos, galley borrowed from the frame

A held drag, a move or a release may go past the window's edge, as a real
one does; only a press must land on a point egui does not clip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
…s egui's trait asks there

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
samitbasu and others added 2 commits November 19, 2026 13:00
…nswers

#408 landed with Placed::draw answering its PlacedFrame, and without the
keep_frames / take_frame hand-over this branch was built on. The driver
now stores the frame its draw closure answers: Driver::whole_frame's
closure answers the frame its layout's draw answered, and Driver::new's
does so for the view. LayoutState::scope, which only the hand-over used,
is gone with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o
@samitbasu

Copy link
Copy Markdown
Owner Author

Approved by the user on its tests, including the whole_frame closure returning the PlacedFrame after #408 (2026-11-19). GitHub's required checks pass on the branch merged with current main. Merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text audit: Placed::text_findings() for wrapped, clipped or elided text testing: a harness guard that asserts no reports on drop

1 participant