From 0f44329c10803d83cd862ec18c668cca4fa7dfd7 Mon Sep 17 00:00:00 2001 From: Oz Date: Mon, 13 Jul 2026 21:47:40 +0000 Subject: [PATCH] Stabilize TUI diff pipeline test Co-Authored-By: Oz --- .../warp_tui/src/tui_file_edits_view_tests.rs | 58 ++++++++++++------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/crates/warp_tui/src/tui_file_edits_view_tests.rs b/crates/warp_tui/src/tui_file_edits_view_tests.rs index d847a7de99f..1b5bdd55fd9 100644 --- a/crates/warp_tui/src/tui_file_edits_view_tests.rs +++ b/crates/warp_tui/src/tui_file_edits_view_tests.rs @@ -100,29 +100,43 @@ fn diff_pipeline_computes_added_lines_and_ghost_blocks() { }); }); rx.await.expect("diff computation should complete"); - - editor.update(&mut app, |editor, ctx| editor.expand_diffs(ctx)); - - // Ghost blocks land via the render state's async layout channel; poll - // until the spawned handler has stored them. - let mut ghosts = Vec::new(); - for _ in 0..100 { - ghosts = app.read(|app| { - editor - .as_ref(app) - .render_state() - .as_ref(app) - .char_cell() - .expect("TUI editor renders in char-cell mode") - .display_lattice(&[]) - .ghosts() - .to_vec() + // Ghost blocks land via the render state's async layout channel. Wait + // for the layout event that exposes them instead of relying on an + // arbitrary number of executor yields. + let render_state = app.read(|app| editor.as_ref(app).render_state().clone()); + let (tx, rx) = oneshot::channel(); + app.update(|ctx| { + let mut tx = Some(tx); + ctx.subscribe_to_model(&editor, move |_, event, ctx| { + if matches!(event, CodeEditorModelEvent::LayoutInvalidated) + && !render_state + .as_ref(ctx) + .char_cell() + .expect("TUI editor renders in char-cell mode") + .display_lattice(&[]) + .ghosts() + .is_empty() + { + if let Some(tx) = tx.take() { + let _ = tx.send(()); + } + } }); - if !ghosts.is_empty() { - break; - } - futures_lite::future::yield_now().await; - } + editor.update(ctx, |editor, ctx| editor.expand_diffs(ctx)); + }); + rx.await.expect("ghost block layout should complete"); + + let ghosts = app.read(|app| { + editor + .as_ref(app) + .render_state() + .as_ref(app) + .char_cell() + .expect("TUI editor renders in char-cell mode") + .display_lattice(&[]) + .ghosts() + .to_vec() + }); assert_eq!(ghosts.len(), 1); assert_eq!(ghosts[0].content, "old\n");