mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Drive TUI stream animation from the foreground loop (#40644)
## Why Stream animation ticks generated on a background thread can accumulate while the TUI is busy, causing stale ticks to run after the animation stops or the chat widget is replaced. ## What changed - Replace the animation thread and `CommitTick` app event with a Tokio interval owned by the foreground event loop. - Delay missed ticks instead of replaying a burst, and let pending app events run before animation work. - Drop the interval when animation stops or the chat widget is replaced, while preserving `CommitTick` session-log entries. ## Testing Add a paused-time test covering stable pacing, missed ticks, restart behavior, and chat-widget replacement. GitOrigin-RevId: d0561d3f8962b5e05a728463e76aa8ec83cd5a31
This commit is contained in:
1 parent
a9e447a69d
commit
a95391160a
9 files changed
+95
-27
No files matched your search
@@ -0,0 +1,51 @@
|
||||
use super::*;
|
||||
use futures::FutureExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn stream_animation_preserves_pacing_and_discards_stopped_ticks() -> Result<()> {
|
||||
let mut app = make_test_app().await;
|
||||
let mut app_server = start_config_write_test_app_server(&app).await?;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
let (replacement, _tx, _rx, _ops) = make_chatwidget_manual_with_sender().await;
|
||||
time::pause();
|
||||
let started_at = time::Instant::now();
|
||||
|
||||
app.handle_event(&mut tui, &mut app_server, AppEvent::StartCommitAnimation)
|
||||
.await?;
|
||||
time::advance(COMMIT_ANIMATION_TICK / 2).await;
|
||||
app.handle_event(&mut tui, &mut app_server, AppEvent::StartCommitAnimation)
|
||||
.await?;
|
||||
time::advance(COMMIT_ANIMATION_TICK).await;
|
||||
let interval = app.commit_animation.as_mut().expect("animation started");
|
||||
assert_eq!(
|
||||
interval.tick().now_or_never(),
|
||||
Some(started_at + COMMIT_ANIMATION_TICK)
|
||||
);
|
||||
|
||||
// A blocked UI consumes one overdue tick, not a burst of obsolete ticks.
|
||||
time::advance(COMMIT_ANIMATION_TICK * 4).await;
|
||||
assert!(interval.tick().now_or_never().is_some());
|
||||
assert!(interval.tick().now_or_never().is_none());
|
||||
let next_tick = time::Instant::now() + COMMIT_ANIMATION_TICK;
|
||||
time::advance(COMMIT_ANIMATION_TICK + Duration::from_millis(/*millis*/ 1)).await;
|
||||
assert_eq!(interval.tick().now_or_never(), Some(next_tick));
|
||||
|
||||
// Restart while the previous timer is overdue; only the new deadline survives.
|
||||
time::advance(COMMIT_ANIMATION_TICK * 3).await;
|
||||
app.handle_event(&mut tui, &mut app_server, AppEvent::StopCommitAnimation)
|
||||
.await?;
|
||||
assert!(app.commit_animation.is_none());
|
||||
app.handle_event(&mut tui, &mut app_server, AppEvent::StartCommitAnimation)
|
||||
.await?;
|
||||
let interval = app.commit_animation.as_mut().expect("animation restarted");
|
||||
assert!(interval.tick().now_or_never().is_none());
|
||||
let next_tick = time::Instant::now() + COMMIT_ANIMATION_TICK;
|
||||
time::advance(COMMIT_ANIMATION_TICK + Duration::from_millis(/*millis*/ 1)).await;
|
||||
assert_eq!(interval.tick().now_or_never(), Some(next_tick));
|
||||
|
||||
app.replace_chat_widget(replacement);
|
||||
assert!(app.commit_animation.is_none());
|
||||
time::resume();
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user