Test API #
Status: being built in pull requests stacked on the extension traits of
extension-traits.md; nothing merged. It comes before
the crate split in crate-split.md, which cannot move a
test that builds its fixture on the engine's own tree.
Decided marks what the user settled; Proposed marks my recommendations that still need a decision; Open marks questions without a decision yet.
Why #
Rust tests build their fixtures on UITree, the engine's own tree.
TestApp::with_ui_tree (crates/burokku/src/ui/host/test.rs) lends a
&mut UITree, the ui_tree! macro builds markup on it, and
docs/test/test_host.md teaches the two together.
Core's tests call with_ui_tree about 274 times and ui_tree! about 309
times; the features' tests, mostly scroll's, 27 and 33 times.
- After the split it cannot be public.
UITreebecomes private toburokku-core, and a public function cannot take a private type. Feature crates,core/tests,burokku/tests, and apps could not build a fixture at all. - It only half works even now.
ui_tree!callsappend_child, which ispub(crate)onUITree(ui_tree/hierarchy.rs), so the two compile only insidecrates/burokku. The examples' tests useevaland input alone. - Making
UITreepublic instead would publish all of it: about 50pubmethods,create_element_tag,create_element_with_style, and the revision counters among them, as stable API. A test could also build a state no app can reach.
The split only forces the fixtures. The rest of the test API has gaps the
tests work around by hand, counted in crates/burokku/src:
- Input is built by hand. 285
send_input_eventcalls pass nativeInputEvents: 130 button presses and releases, 39 cursor moves, and 21 wheels, at hand-computedPhysicalPositions (115), each withapp.window_id().unwrap(). Test modules rebuild the same builders:interaction/tests/event_order.rsdefines nine (button,press,release,motion,wheel,key,key_down,key_up,focus_next),interaction/tests/editing.rsfour. - Waiting is a workaround. 69 times a test evaluates an empty script,
app.eval::<()>(""), only so the host finishes dispatching the input before it. Tests also pick betweenrun_host_turn(197 calls) andpresent(369) by hand. - A feature's state is read through the engine's tree. About 11 tests
read a slot or an instance with
with_ui_tree(|tree| tree.slot::<T>(…)).
Decided #
Settled by the user on 2026-10-26.
- The code becomes easier to test, rather than tests being moved around
it. How is proposed under Testing in
crate-split.md.
Settled by the user on 2026-10-27:
- The test API is built now, with the extension traits, as pull requests, before the crate split. Its boundaries stay clean, following the SOLID principles as far as they apply.
- App tests may use
ui_tree!:burokku::testre-exports it, and the macro crate is published (Open item 2).
Proposed #
Two tiers #
- Public, in
burokku::test: for feature crates,core/tests,burokku/tests, and apps. It builds fixtures throughFixture, reads state through the public read-only view, and sends input through the input methods below. - Internal, for core's unit tests that need the engine's structure:
with_ui_treestays, aspub(crate), andui_tree!keeps building on&mut UITree.
Fixture #
A wrapper over the borrowed tree whose field is private, so its methods are
the only way in. Each forwards to the UITree method of the same name:
// burokku-core, public in `test` (test-support); burokku::test re-exports it
pub struct Fixture<'a> {
tree: &'a mut UITree,
}
impl Fixture<'_> {
pub fn root(&self) -> NodeId { self.tree.root() }
pub fn create_element(&mut self, tag: &str) -> Result<NodeId, FixtureError> { … }
pub fn create_text(&mut self, text: impl Into<String>) -> NodeId { … }
pub fn append_child(&mut self, parent: NodeId, child: NodeId) -> Result<(), FixtureError> { … }
pub fn set_attribute(&mut self, node: NodeId, name: String, value: String) -> Result<(), FixtureError> { … }
pub fn set_style_property(&mut self, node: NodeId, name: &str, value: &str) -> Result<(), FixtureError> { … }
}
impl TestApp {
pub fn with_fixture<R>(&mut self, f: impl FnOnce(&mut Fixture<'_>) -> R) -> R {
let driver = self.driver.borrow();
let mut state = driver.host.ui_tree_bindings.borrow_mut();
f(&mut Fixture { tree: &mut state.ui_tree })
}
}
- It offers only what an app's script can already do:
app,createElement,createTextNode,appendChild,setAttribute, andstyle.setProperty. A wrapper does not make an operation fit to publish; its methods are public API like any other. Before a method is added, ask whether script can do the same. If it can, it may go inFixture. If it cannot, decide first whether the capability belongs in the public API; if it does, it goes in the real API, not inFixture. AFixturethat wrapped internal operations, such as writingInteraction's selection directly, would be the rejected public installer ofcrate-split.mdunder another name. - It is lent through a closure, as
with_ui_treeis today: the tree sits behind the host'sRefCell, so the borrow ends before the next host turn, and the lifetime keeps theFixturefrom escaping the closure. - One
FixtureErrorkeeps core's error types private: theUITreemethods return four (ElementTagError,AttributeError,StyleError,UITreeError).
ui_tree! on Fixture #
The macro never names UITree. It evaluates the expression it is given and
calls six methods on it by name, the six Fixture has, so it works
unchanged on either tier:
let (window, scroller) = app.with_fixture(|tree| {
ui_tree!(tree,
<window var=window>
<div var=scroller style:overflow="scroll">"…"</div>
</window>
);
(window, scroller)
});
app.present().await?;
One change: the macro checks tags against a list of Burokku's own element
names at compile time (expand_element in crates/test_macro/src/lib.rs).
A test tool must not know the features, and the list keeps stand-ins and
third-party elements, such as the x-panel core's tests already register,
out of the macro. The registry checks the tag when create_element runs
instead, and the .expect message says the tag is not registered.
Reading state #
A read-only with_view(|view: &TreeView| …) lends the public TreeView.
Through it a test reads a node's slot or instance of a type it names, which
replaces the reads through with_ui_tree (gap 6). That is no new
capability: an extension already reads its own state through the public
with_slot and with_instance. presented_tree and eval stay as they
are.
As built, the slot and instance reads are TestApp methods beside
with_view, not TreeView's, for the reason under Built.
Input #
TestApp gets input methods that say what the user does, instead of
native events (gap 4):
- Pointer: press, release, move, click, drag, and wheel, at a point in logical pixels or at a node, which aims at the middle of the box the node last presented. The window is the app's window; no test names it.
- Keyboard and text: a key with modifiers, typed text, an editing command, and an IME composition.
- Each returns once its dispatch is done (see Settling), so no test waits by hand.
send_input_event, send_keyboard_event, and send_window_event stay for
what these do not cover, such as a wheel phase or a precise delta.
They replace the input helpers test modules define for themselves (send,
click, press, clicks, wheel_down); the modules' read helpers become
methods of private traits instead
(extension-traits.md).
Settling #
One step, say settle(), replaces the empty eval (gap 5): it runs host
turns until the queued input, script tasks, and microtasks are done, and
presents. Timers that are not due yet do not count, so an app with a
setInterval settles. The input methods call it. run_host_turn and
present stay for tests about turn and frame timing.
As built, the input methods do not call it; see Built.
A test app from chosen extensions #
TestBackend runs today only through Burokku::builder(), which registers
every built-in. A feature crate tests itself with nothing else, and
core/tests registers only its stand-ins, so CoreBuilder runs on
TestBackend too, with the extensions a test registers.
Fixed fonts #
Layout depends on the fonts it finds, so a test that measures text
registers its fonts through Registry::font and turns system fonts off.
Today only core can turn them off (without_system_fonts in
crates/burokku/src/ui/text/testing.rs); the public tier gets an option
for it.
Built #
Proposed: what I chose while building, beyond the items above, for review. Each pull request adds its own rows.
Pull request on feat/test-fixture (steps 1 and 2):
| Item | Choice | Why |
|---|---|---|
Fixture module |
ui/host/test/fixture.rs, apart from TestApp's own file |
building a tree is one job; test.rs drives the host |
Fixture::set_attribute |
takes impl Into<String> for the name and value |
"width" reads better than "width".to_owned(); ui_tree! passes Strings, which still fit |
Fixture::set_style_property |
returns Result<(), FixtureError>, not the tree's bool |
script's setProperty returns nothing; whether the value changed is the engine's |
FixtureError |
a tuple struct with a private String: the message script's error would carry |
one public type over core's four, and none of their variants become API |
| macro's tag error | panics with "ui_tree! needs an extension to register this element tag" | the tree checks the tag now, so the message says what to fix |
| reads module | ui/host/test/view.rs |
reading is a job apart from building |
with_view |
&self, lends the TreeView by value |
TreeView is Copy, and a read must not need &mut |
| slot and instance reads | read_slot::<T>(node, |&T| …) -> Option<R> and read_instance::<T>(node, |&T| …) -> R on TestApp, read-only |
the public with_slot lends a DispatchStep whose give changes the slot, which a read must not; and on TreeView they would let one slot's take read every other slot |
| a node holding no such instance | Decided by you (2026-10-27): read_instance panics, naming the node and T, and is #[track_caller] so the panic points at the test; read_slot stays Option |
an element keeps the instance it was created with, so a node without a T is always the wrong node or type in the test, while a missing slot is real state, before the layout that attaches it or once its condition fails. A read by type alone, with no node, was dropped: two elements can hold a T, and it would have to panic or return None on zero or two |
| first users | the eleven tests that read a slot or an instance through with_ui_tree |
they show the reads, and need no engine tree for it |
Pull request on feat/test-input (step 3):
| Item | Choice | Why |
|---|---|---|
settle |
in test.rs, beside run_host_turn and present: a host turn, then a present when there is a window, until a turn finds the frame revision it presented; fails after 32 turns |
the frame revision moves whenever the tree or the interaction state changes what a frame shows, so an unchanged one after a turn means nothing is left to show; an animation never settles, so the bound turns a hang into an error |
input methods and settle |
the input methods wait for their dispatch only, not for settle |
tests check what happens between an input and the frame that shows it, such as a triple click before the frame that shows an edit; settle presenting after every input would hide those states, and a test calls settle when it wants the frame |
| input handles | TestApp::pointer() lends a Pointer, TestApp::keyboard() a Keyboard, in ui/host/test/input.rs |
one handle per device keeps each small, and TestApp gains two methods, not thirteen |
Pointer |
move_to, press, release, click, drag, wheel; it holds its buttons between calls |
a move after a press drags, as with a mouse |
Target |
an enum, Point(x, y) in logical pixels or Node(id), with From<(f64, f64)> and From<NodeId> |
a node aims at the middle of its presented box, moved by the scrolling around it; logical pixels match the layout, and the window's scale factor makes them physical |
wheel's delta |
positive scrolls right or down, as WheelEvent.deltaY reads it; the native event gets the negation |
a test reads as the script it checks |
Keyboard |
hold(modifiers), key_down, key_up, press, type_text, command, compose; keys carry the modifiers held |
a held Shift reaches each key, as on a keyboard; the test backend binds no keys, so the command a key is bound to is its own call |
a key's code |
"Unidentified", key_code 0 |
no test reads them, and the module's helpers sent the same |
| batches | stay raw send_input_event calls where the platform delivers several events in one callback, such as a key and its text or Tab and its command |
those tests are about what was queued together, which awaiting each method in turn would change |
event_order.rs |
keeps its raw event builders and log |
its tests are the order of native events, as the platform delivers them, often several at once |
| migrated | send and clicks in editing.rs; click and the sending in moved in moves.rs; press, tab, and keys in interaction/focus.rs; wheel_down; click_at_the_input_start; pipeline_guard.rs's send |
moved and click_at_the_input_start stay helpers, since each reads the state after it too |
Pull request on feat/test-builder (step 4):
| Item | Choice | Why |
|---|---|---|
| feature extensions | TextExtension, ScrollExtension, and ResizeObserverExtension move from extension/builtin.rs into features/text.rs, features/scroll.rs, and features/resize_observer.rs; builtin.rs keeps LLRT and the UI tree |
each feature registers itself beside its code, as a feature crate will; builtin.rs only lists them |
| the extensions' names | …Extension |
inside features/scroll.rs, Scroll alone would read as the scroll state |
engine() and builtins() |
engine() is LLRT, the UI tree, and text; builtins() adds scroll and ResizeObserver |
text stays with the engine for now, as crate-split.md keeps it, since the engine edits and selects it; LLRT stays until Registry::on_shutdown exists, since shutdown calls its script |
| a test app from chosen extensions | BurokkuBuilder::core(), only with test-support, on BurokkuBuilder like new(); a test calls .extension(…) and .with_backend::<TestBackend>() after |
CoreBuilder waits for the split; gated, it adds nothing to an app's API until you decide whether apps may leave features out |
| fixed fonts | BurokkuBuilder<TestBackend>::without_system_fonts(), in test.rs beside run_test; the builder carries a system_fonts flag to load_fonts |
only a test needs it, so only the test backend's builder has it; ParagraphEngine::without_system_fonts is the one constructor, which TestParagraphs now uses too |
Pull request on refactor/feature-tests-public-api (steps 5 and 6):
| Item | Choice | Why |
|---|---|---|
| the features' tests | scrolling's and ResizeObserver's tests run on BurokkuBuilder::core() with their own extension, and build through with_fixture |
each feature's tests show that it works on the engine alone, as its crate's tests will have to |
| their slot read | scrolling's tests ask whether a node holds a ScrollState through read_slot, not with_ui_tree |
a feature crate reaches no engine tree |
| their input | presses, drags, and plain precise wheels go through pointer(); wheels with a trackpad phase or line deltas stay send_input_event |
the pointer sends a plain wheel only; a phase is a gesture's, which a test about momentum sends itself |
presented_plan |
scrolling's tests compare presented_tree results instead |
the plan is the engine's; the presented tree is what a test can see |
a_target_the_tree_frees_is_dropped |
stays a unit test on a bare UITree |
it tests the tree's freeing, which no app shows |
with_ui_tree |
#[cfg(test)] pub(crate), with its doc saying other tests use with_fixture and with_view |
core's own tests still need the engine's structure; with test-support alone nothing calls it, so it would be dead code there |
test_host.md |
documents with_fixture, the reads, settle, pointer(), keyboard(), core(), and without_system_fonts(); its examples use them |
the public tier is what an app's test reads |
Pull request on feat/test-ui-tree-export (Open item 2, decided):
| Item | Choice | Why |
|---|---|---|
| the macro crate's name | burokku-test-macro; its directory, crates/test_macro, and the dependency key test_macro stay |
crates.io has test-macro, which it counts as the same name as test_macro; the prefix follows burokku-native, and the key keeps every use test_macro::ui_tree as it is |
| its metadata | publish = false goes; a description and the MIT license, as the other crates have |
crates.io needs both |
| the dependency | burokku depends on it optionally, and test-support turns it on |
an app without test-support builds no proc macro it does not use |
| the re-export | pub use test_macro::ui_tree in burokku::test, with a doc test that builds markup through burokku::test::ui_tree |
a doc test compiles outside the crate, as an app's test does; CI runs it, since the examples turn test-support on |
| core's own tests | keep use test_macro::ui_tree through the development dependency |
the same macro either way; rewriting its 39 imports would change nothing |
Open #
- The names.
with_fixture,Fixture, andsettleare placeholders. The pull requests use them, andread_slotandread_instance(mine), until you pick others. - Whether app tests may use
ui_tree!. If they may,burokku::testre-exports it, which works for a proc macro since its expansion names no crate path, andtest_macrostops beingpublish = false. If not, it stays a workspace tool. Decided 2026-10-27, by you: re-export it (Decided item 3). Built onfeat/test-ui-tree-export; see Built.
Steps #
Proposed order:
Fixture,with_fixture, andFixtureError; the macro stops checking tags.with_view, with slot and instance reads.settle, then the input methods on it.TestBackendonCoreBuilderwith chosen extensions, and the fixed-font option.- Tests move to them, the features' tests first, since the split needs
them;
with_ui_treebecomespub(crate). docs/test/test_host.mdanddocs/test/macro.mdfollow.
As built, one pull request per step or two: steps 1 and 2 on
feat/test-fixture, 3 on feat/test-input, 4 on feat/test-builder, and 5
and 6 on refactor/feature-tests-public-api. Step 5 moved the features'
tests and the reads; core's own unit tests keep with_ui_tree, since they
test the engine's structure.