pub struct TestUi<B: Backend = TestBackend> { /* private fields */ }Expand description
A whole UI scenario: the app, the renderer that owns its scrollback, the terminal it draws into, and the receiver for the commands the app sends.
Construct through TestUi::new, TestUi::with_dimensions, or
TestUiBuilder. Input, ACP events, ticks, and task results are routed the
same way the event loop routes them, and drawing happens against the same
renderer instance every frame so committed scrollback survives.
Implementations§
Source§impl<B: Backend> TestUi<B>
impl<B: Backend> TestUi<B>
Sourcepub fn with_backend(backend: B) -> Self
pub fn with_backend(backend: B) -> Self
Builds a UI around an arbitrary backend (e.g. a recording backend that
asserts on frame-level terminal commands). The app is the default
scenario; configure anything else through TestUiBuilder.
Sourcepub fn app(&self) -> &App
pub fn app(&self) -> &App
The app under test, for the read-only queries assertions are built from. Drive it through this harness rather than mutating it directly, so the commands it emits still reach the fake runtime.
Sourcepub fn deliver(&mut self, message: Message)
pub fn deliver(&mut self, message: Message)
Delivers one message through the public application boundary and records every command it emits in the fake runtime.
pub fn deliver_result(&mut self, result: CommandResult)
Sourcepub fn executor(&self) -> &FakeExecutor
pub fn executor(&self) -> &FakeExecutor
Commands emitted by the public application boundary, in order.
pub fn executor_mut(&mut self) -> &mut FakeExecutor
pub fn take_commands(&mut self) -> Vec<Command>
pub fn next_command(&mut self) -> Option<Command>
pub fn next_agent_command(&mut self) -> Option<AgentCommand>
pub fn backend(&self) -> &B
pub fn backend_mut(&mut self) -> &mut B
pub fn viewport_area(&mut self) -> Rect
pub fn viewport_height(&mut self) -> u16
Sourcepub fn composer_layout(&mut self, width: u16) -> ComposerLayout
pub fn composer_layout(&mut self, width: u16) -> ComposerLayout
Measures the composer at width with the active theme.
pub fn try_draw(&mut self) -> Result<(), RenderError<B::Error>>
pub fn render_stats(&mut self) -> RenderStats
Sourcepub fn opened_urls(&self) -> Vec<String>
pub fn opened_urls(&self) -> Vec<String>
URLs elicitation prompts asked to open, in order. The harness records them instead of spawning a browser, so no test touches the host.
Sourcepub fn seed_long_history(&mut self, turns: usize)
pub fn seed_long_history(&mut self, turns: usize)
Seeds a deterministic long conversation: turns completed turns of
user messages, thoughts, markdown prose with fenced code, bash and edit
tool calls with diffs, and a sub-agent tree every eighth turn — drawing
after each turn so scrollback commits exactly like a live session.
Sourcepub fn stream_message(
&mut self,
content: StreamContent,
total_bytes: usize,
chunk_bytes: usize,
)
pub fn stream_message( &mut self, content: StreamContent, total_bytes: usize, chunk_bytes: usize, )
Streams one assistant message of total_bytes in chunk_bytes chunks,
drawing after every chunk the way the event loop draws after every
wakeup. The message stays one open item while it streams.
Sourcepub fn settle(&mut self)
pub fn settle(&mut self)
Finishes the in-flight turn and advances synthetic time past every grace period, leaving a session that owes the event loop nothing.
Sourcepub fn terminal_event(&mut self, event: Event)
pub fn terminal_event(&mut self, event: Event)
Routes a terminal event (key, paste, mouse, resize) the way the event loop does.
pub fn key(&mut self, key: KeyEvent)
pub fn type_text(&mut self, text: &str)
pub fn paste(&mut self, text: &str)
pub fn acp_event(&mut self, event: AcpEvent)
pub fn begin_resume(&mut self, session_id: &str, cwd: &str)
pub fn complete_prompt(&mut self, stop_reason: StopReason)
pub fn tick(&mut self, now: Instant)
Sourcepub fn settle_tasks(&mut self)
pub fn settle_tasks(&mut self)
Completes the commands configured on the fake executor without touching the real filesystem, Git repository, terminal, or ACP connection.
Source§impl TestUi<TestBackend>
impl TestUi<TestBackend>
pub fn with_dimensions(width: u16, height: u16) -> Self
Sourcepub fn resize(&mut self, width: u16, height: u16)
pub fn resize(&mut self, width: u16, height: u16)
Resizes the backing terminal. The next Self::draw re-measures the
inline viewport the way Renderer::draw does in the event loop.
Source§impl<B> TestUi<B>
impl<B> TestUi<B>
Sourcepub fn viewport(&mut self) -> Buffer
pub fn viewport(&mut self) -> Buffer
What the inline viewport currently shows: the composer, status line, and the live tail of the conversation. Draws a frame first, so asserting right after an input never reads a stale screen.
Sourcepub fn history(&mut self) -> Buffer
pub fn history(&mut self) -> Buffer
The terminal’s own native scrollback containing committed conversation rows, after drawing a frame.
Sourcepub fn conversation(&mut self) -> Buffer
pub fn conversation(&mut self) -> Buffer
Self::history stacked on Self::viewport: everything the
conversation has shown, oldest at the top, after drawing a frame.
pub fn viewport_text(&mut self) -> String
pub fn history_text(&mut self) -> String
pub fn conversation_text(&mut self) -> String
Sourcepub fn viewport_row(&mut self, needle: &str) -> Option<u16>
pub fn viewport_row(&mut self, needle: &str) -> Option<u16>
Row (within the viewport buffer) of the first line containing needle.
pub fn assert_viewport_contains(&mut self, needle: &str)
pub fn assert_viewport_not_contains(&mut self, needle: &str)
pub fn assert_history_contains(&mut self, needle: &str)
pub fn assert_history_not_contains(&mut self, needle: &str)
pub fn assert_conversation_contains(&mut self, needle: &str)
pub fn assert_conversation_not_contains(&mut self, needle: &str)
Sourcepub fn assert_viewport<S: AsRef<str>>(&mut self, expected: &[S])
pub fn assert_viewport<S: AsRef<str>>(&mut self, expected: &[S])
Asserts the viewport’s visible text matches expected row-by-row.
Sourcepub fn assert_history<S: AsRef<str>>(&mut self, expected: &[S])
pub fn assert_history<S: AsRef<str>>(&mut self, expected: &[S])
Asserts the committed history’s visible text matches expected row-by-row.
Sourcepub fn assert_conversation<S: AsRef<str>>(&mut self, expected: &[S])
pub fn assert_conversation<S: AsRef<str>>(&mut self, expected: &[S])
Asserts the stitched conversation’s visible text matches expected row-by-row.
Trait Implementations§
Auto Trait Implementations§
impl<B = TestBackend> !RefUnwindSafe for TestUi<B>
impl<B = TestBackend> !Send for TestUi<B>
impl<B = TestBackend> !Sync for TestUi<B>
impl<B = TestBackend> !UnwindSafe for TestUi<B>
impl<B> Freeze for TestUi<B>
impl<B> Unpin for TestUi<B>
impl<B> UnsafeUnpin for TestUi<B>where
Terminal<B>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more