Test rounds: lib harnesses run the runtime, logic tick runs the close path, tests follow next's async update offer and font discard pass

- bench::Driver installs the runtime and runs raw_input_hook as the shells do
- lifecycle tests use a context with the runtime installed; the logic-only tick runs App::logic's body (logic_pass), so a hidden close request reaches the runtime's close path
- the startup-prompt test ticks the updater until its offer's inspection thread answers
- font-install tests: the install pass asks egui for a discard pass, which draws with the fonts in the same frame
This commit is contained in:
aiongg
2026-11-24 20:27:51 +00:00
parent b2faa3ebaa
commit e061e0903e
6 changed files with 62 additions and 43 deletions
+1 -5
View File
@@ -188,11 +188,7 @@ impl eframe::App for EffectcraftApp {
/// refreshed. A close request must be answered while hidden too; an answered file dialog can change the project,
/// so the tick's dialog answers run first.
fn logic(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
// Never `ctx.input(|i| i.time)` here: `Context::run_logic` leaves events, pointer state and
// time at the previous full pass's values (only the viewport information is refreshed).
self.tick(ctx, frame);
self.finish_ime_logic(ctx);
self.close_path(ctx);
self.logic_pass(ctx, frame);
}
/// Draw one UI pass through `draw`.
+9
View File
@@ -167,6 +167,15 @@ impl EffectcraftApp {
}
}
/// The shared app's `App::logic`: `tick`, the IME pass's close and, last, the root window's close path.
pub(crate) fn logic_pass(&mut self, ctx: &egui::Context, frame: &eframe::Frame) {
// Never `ctx.input(|i| i.time)` here: `Context::run_logic` leaves events, pointer state and
// time at the previous full pass's values (only the viewport information is refreshed).
self.tick(ctx, frame);
self.finish_ime_logic(ctx);
self.close_path(ctx);
}
/// The app's only non-paint entry: one tick of background work.
///
/// This runs for every eframe logic callback, including the logic-only ticks of a hidden
+5 -2
View File
@@ -20,7 +20,9 @@ pub struct Driver {
impl Driver {
pub fn new(app: EffectcraftApp, size: egui::Vec2) -> Driver {
Driver { ctx: egui::Context::default(), app, frame: eframe::Frame::_new_kittest(), time: 0.0, size }
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
Driver { ctx, app, frame: eframe::Frame::_new_kittest(), time: 0.0, size }
}
/// Run one frame (layout + paint + tessellation); its wall time in ms.
@@ -30,10 +32,11 @@ impl Driver {
pub fn step_with(&mut self, events: Vec<egui::Event>) -> f64 {
self.time += 1.0 / 60.0;
let input =
let mut input =
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, self.size)), time: Some(self.time), events, ..Default::default() };
let t0 = web_time::Instant::now();
let (app, frame) = (&mut self.app, &mut self.frame);
eframe::App::raw_input_hook(app, &self.ctx, &mut input);
let mut out = self.ctx.run_ui(input, |ui| {
eframe::App::logic(app, ui.ctx(), frame);
eframe::App::ui(app, ui, frame);
+40 -24
View File
@@ -23,7 +23,14 @@ fn raw(size: egui::Vec2) -> egui::RawInput {
}
fn tick_with(app: &mut EffectcraftApp, ctx: &egui::Context, frame: &eframe::Frame, raw: &egui::RawInput) -> egui::LogicOutput {
ctx.run_logic(raw, |ctx| app.tick(ctx, frame))
ctx.run_logic(raw, |ctx| app.logic_pass(ctx, frame))
}
/// A context with the runtime installed, as the app's window has it.
fn headless() -> egui::Context {
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
ctx
}
fn hidden_tick(app: &mut EffectcraftApp, ctx: &egui::Context, frame: &eframe::Frame) {
@@ -58,7 +65,7 @@ fn send(app: &mut EffectcraftApp, method: &str, params: serde_json::Value) -> st
#[test]
fn a_logic_only_tick_installs_no_fonts_and_records_no_geometry() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
hidden_tick(&mut app, &ctx, &frame);
@@ -69,7 +76,7 @@ fn a_logic_only_tick_installs_no_fonts_and_records_no_geometry() {
#[test]
fn a_control_command_that_needs_no_ui_completes_without_a_pass() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
let reply = send(&mut app, "engine.execute", json!({"command": "comp.new", "params": {"name": "Queued", "width": 32, "height": 18, "duration": 1}}));
@@ -81,8 +88,7 @@ fn a_control_command_that_needs_no_ui_completes_without_a_pass() {
#[test]
fn a_pass_that_cannot_draw_receives_no_synthetic_input() {
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
assert!(!app.is_ready(), "a fresh app installs its fonts in its first pass");
@@ -98,7 +104,9 @@ fn a_pass_that_cannot_draw_receives_no_synthetic_input() {
assert!(app.pending_synthetic_events().is_empty());
let mut setup_pass = ctx.run_ui(setup.take(), |ui| app.draw(ui, &frame));
setup_pass.textures_delta.clear();
assert!(!app.is_ready(), "the pass that installs the fonts draws nothing");
// The font install asks egui for a discard pass, which draws with the fonts and gets no input.
assert!(app.is_ready(), "the frame that installs the fonts draws in its discard pass");
assert_eq!(app.synthetic.len(), 5, "the discard pass got no synthetic input: the whole gesture still waits");
// Once fonts are ready the click reaches the UI exactly once, one event per pass.
let mut passes = 0;
while reply.try_recv().is_err() {
@@ -114,7 +122,7 @@ fn a_pass_that_cannot_draw_receives_no_synthetic_input() {
#[test]
fn one_pending_synthetic_batch_is_never_duplicated_while_hidden() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
ready(&mut app, &ctx, &frame);
@@ -148,7 +156,7 @@ fn one_pending_synthetic_batch_is_never_duplicated_while_hidden() {
#[test]
fn geometry_epoch_tracks_size_and_scale_but_not_window_position() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
let first = ready(&mut app, &ctx, &frame);
@@ -166,7 +174,7 @@ fn geometry_epoch_tracks_size_and_scale_but_not_window_position() {
#[test]
fn only_a_viewer_that_draws_records_a_prefetch_scale() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
ready(&mut app, &ctx, &frame);
@@ -185,7 +193,7 @@ fn only_a_viewer_that_draws_records_a_prefetch_scale() {
#[test]
fn playback_advances_on_a_logic_only_tick() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
app.playback.playing = true;
@@ -218,7 +226,7 @@ fn workspace_layout_autosave_writes_on_a_hidden_tick() {
app.use_manual_clock();
app.ui.focused = PanelKind::Timeline;
app.clock_mut().advance(2.0);
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
hidden_tick(&mut app, &ctx, &frame);
assert!(store.read(WORKSPACES_FILE).is_some(), "the layout is saved while the window is hidden");
@@ -236,7 +244,7 @@ fn asks_to_close(ctx: &egui::Context, mut f: impl FnMut(&egui::Context)) -> bool
#[test]
#[cfg(not(target_arch = "wasm32"))]
fn restart_to_update_with_unsaved_changes_opens_the_unsaved_changes_prompt() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
assert!(app.session.is_dirty(), "creating a comp and a layer leaves unsaved changes");
@@ -253,7 +261,7 @@ fn restart_to_update_with_unsaved_changes_opens_the_unsaved_changes_prompt() {
#[test]
#[cfg(not(target_arch = "wasm32"))]
fn restart_to_update_with_nothing_unsaved_leaves_the_close_to_the_updater() {
let ctx = egui::Context::default();
let ctx = headless();
let mut app = app_with_comp();
app.updates_rt.manual_window_open = true;
assert!(!asks_to_close(&ctx, |ctx| updates_ui::restart_to_update(&mut app.updates_rt, ctx, true)));
@@ -263,7 +271,7 @@ fn restart_to_update_with_nothing_unsaved_leaves_the_close_to_the_updater() {
#[test]
#[cfg(not(target_arch = "wasm32"))]
fn restart_to_update_with_the_startup_prompt_open_leaves_the_window_open() {
let ctx = egui::Context::default();
let ctx = headless();
let mut app = app_with_comp();
app.updates_rt.updater.offer(craft_update::Release {
tag: "v99.0.0".into(),
@@ -272,6 +280,14 @@ fn restart_to_update_with_the_startup_prompt_open_leaves_the_window_open() {
html_url: "https://github.com/storytold/effectcraft/releases/tag/v99.0.0".into(),
..Default::default()
});
// The offer reads on a thread whether this copy installs itself; a tick opens the prompt with its answer.
for _ in 0..400 {
if app.updates_rt.updater.prompt_open() {
break;
}
std::thread::sleep(std::time::Duration::from_millis(5));
app.updates_rt.updater.tick(&ctx);
}
assert!(app.updates_rt.updater.prompt_open());
app.updates_rt.manual_window_open = true;
assert!(!asks_to_close(&ctx, |ctx| updates_ui::restart_to_update(&mut app.updates_rt, ctx, false)), "the prompt carries the restart");
@@ -281,7 +297,7 @@ fn restart_to_update_with_the_startup_prompt_open_leaves_the_window_open() {
#[test]
fn the_close_guard_answers_a_close_request_without_a_pass() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
assert!(app.session.is_dirty(), "creating a comp and a layer leaves unsaved changes");
@@ -363,7 +379,7 @@ fn image(width: usize, height: usize) -> Arc<egui::ColorImage> {
#[test]
fn a_script_file_dialog_asks_for_a_pass_while_the_window_is_hidden() {
use effectcraft_engine::scriptui::{FileDialogKind, ScriptFileDialog};
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
ready(&mut app, &ctx, &frame);
@@ -392,7 +408,7 @@ fn a_script_file_dialog_asks_for_a_pass_while_the_window_is_hidden() {
#[test]
fn a_screenshot_is_issued_only_after_settled_passes_and_writes_from_the_tick() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
ready(&mut app, &ctx, &frame);
@@ -418,7 +434,7 @@ fn a_screenshot_is_issued_only_after_settled_passes_and_writes_from_the_tick() {
#[test]
fn a_resize_between_issue_and_completion_rejects_the_pixels_and_retries() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
ready(&mut app, &ctx, &frame);
@@ -445,7 +461,7 @@ fn a_resize_between_issue_and_completion_rejects_the_pixels_and_retries() {
#[test]
fn screenshot_admission_bounds_requests_and_a_timeout_releases_its_reservation() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
ready(&mut app, &ctx, &frame);
@@ -471,7 +487,7 @@ fn screenshot_admission_bounds_requests_and_a_timeout_releases_its_reservation()
#[test]
fn a_late_callback_after_cancellation_writes_nothing_and_replies_once() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
ready(&mut app, &ctx, &frame);
@@ -500,7 +516,7 @@ fn wake_requests(ctx: &egui::Context) -> Arc<std::sync::Mutex<Vec<std::time::Dur
#[test]
fn an_issued_capture_schedules_a_wake_up_for_its_deadline() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
ready(&mut app, &ctx, &frame);
@@ -532,7 +548,7 @@ fn an_issued_capture_schedules_a_wake_up_for_its_deadline() {
#[test]
fn a_downscaled_capture_is_cropped_with_the_images_own_scale() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
let geom = ready(&mut app, &ctx, &frame);
@@ -563,7 +579,7 @@ fn a_downscaled_capture_is_cropped_with_the_images_own_scale() {
#[test]
fn a_capture_before_any_pass_never_uses_the_window_frame_rect() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
// Only the outer (title bar included) rectangle is known: it is not the captured surface.
@@ -583,7 +599,7 @@ fn a_capture_before_any_pass_never_uses_the_window_frame_rect() {
#[test]
fn an_element_that_moves_while_the_ui_settles_is_captured_where_it_is() {
let ctx = egui::Context::default();
let ctx = headless();
let frame = eframe::Frame::_new_kittest();
let mut app = app_with_comp();
let geom = ready(&mut app, &ctx, &frame);
+6 -11
View File
@@ -755,6 +755,7 @@ fn fonts_and_device_loss_all_exit_finalizers_suspend_without_allocating() {
app.ui.focused = PanelKind::Composition;
app.show_panel(PanelKind::Composition);
let ctx = egui::Context::default();
crate::framework::install_headless(&ctx);
install_hooks(&ctx);
let frame = eframe::Frame::_new_kittest();
let preview = || egui::Event::Ime(egui::ImeEvent::Preedit { text: "é".into(), active_range_chars: None });
@@ -771,19 +772,13 @@ fn fonts_and_device_loss_all_exit_finalizers_suspend_without_allocating() {
.reset_request
.expect("one request for the caret interruption");
// A real font-install pass draws nothing, but `draw` still reaches the finalizer.
// A font install asks egui for a discard pass in the same frame. The install pass draws nothing, and its
// all-exit finalizer retires the waiting guard without allocating; the discard pass draws with the fonts and
// publishes the one deferred request.
app.styled = false;
let fonts = draw_app_pass(&mut app, &ctx, &frame, vec![]);
assert!(!app.is_ready(), "the font-install pass cannot draw");
assert!(fonts.platform_output.ime.is_none(), "no custom descriptor is published");
let guard = ctx.data(|d| d.get_temp::<ResetGuard>(reset_id(egui::ViewportId::ROOT))).expect("the waiting guard");
assert!(guard.suspended && guard.request.is_none(), "the all-exit finalizer retired it without allocating");
let second = draw_app_pass(&mut app, &ctx, &frame, vec![])
.platform_output
.ime
.expect("returning to a drawing pass publishes the custom descriptor")
.reset_request
.expect("the deferred request");
assert!(app.is_ready(), "the discard pass after the font install draws");
let second = fonts.platform_output.ime.expect("the drawing discard pass publishes the custom descriptor").reset_request.expect("the deferred request");
assert_ne!(first, second);
// The device-loss early return is the other all-exit path. Preset the close bookkeeping
@@ -2,10 +2,10 @@
use std::sync::Arc;
use craft_behavior::dock::Action;
use effectcraft_engine::Session;
use effectcraft_engine::config::{ConfigStore, DirConfig, MemoryConfig};
use effectcraft_ui_egui::EffectcraftApp;
use craft_behavior::dock::Action;
use effectcraft_ui_egui::dock::{self, Node, PanelKind, SplitSize};
use effectcraft_ui_egui::state::Tool;
use egui::{Event, Id, Key, Modifiers, vec2};