Skip to main content

TestUi

Struct TestUi 

Source
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>
where B::Error: Debug,

Source

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.

Source

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.

Source

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.

Source

pub fn deliver_result(&mut self, result: CommandResult)

Source

pub fn executor(&self) -> &FakeExecutor

Commands emitted by the public application boundary, in order.

Source

pub fn executor_mut(&mut self) -> &mut FakeExecutor

Source

pub fn take_commands(&mut self) -> Vec<Command>

Source

pub fn next_command(&mut self) -> Option<Command>

Source

pub fn next_agent_command(&mut self) -> Option<AgentCommand>

Source

pub fn backend(&self) -> &B

Source

pub fn backend_mut(&mut self) -> &mut B

Source

pub fn viewport_area(&mut self) -> Rect

Source

pub fn viewport_height(&mut self) -> u16

Source

pub fn composer_layout(&mut self, width: u16) -> ComposerLayout

Measures the composer at width with the active theme.

Source

pub fn draw(&mut self)

Draws one frame, like the event loop does after every input batch.

Source

pub fn try_draw(&mut self) -> Result<(), RenderError<B::Error>>

Source

pub fn render_stats(&mut self) -> RenderStats

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn terminal_event(&mut self, event: Event)

Routes a terminal event (key, paste, mouse, resize) the way the event loop does.

Source

pub fn key(&mut self, key: KeyEvent)

Source

pub fn type_text(&mut self, text: &str)

Source

pub fn submit(&mut self, text: &str)

Types text and submits it with Enter.

Source

pub fn paste(&mut self, text: &str)

Source

pub fn acp_event(&mut self, event: AcpEvent)

Source

pub fn begin_resume(&mut self, session_id: &str, cwd: &str)

Source

pub fn complete_prompt(&mut self, stop_reason: StopReason)

Source

pub fn tick(&mut self, now: Instant)

Source

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>

Source

pub fn new() -> Self

The default scenario: 40x15 terminal, plain app, recording prompt handle.

Source

pub fn with_dimensions(width: u16, height: u16) -> Self

Source

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>
where B: Backend + BuffersReader, B::Error: Debug,

Source

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.

Source

pub fn history(&mut self) -> Buffer

The terminal’s own native scrollback containing committed conversation rows, after drawing a frame.

Source

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.

Source

pub fn viewport_text(&mut self) -> String

Source

pub fn history_text(&mut self) -> String

Source

pub fn conversation_text(&mut self) -> String

Source

pub fn viewport_row(&mut self, needle: &str) -> Option<u16>

Row (within the viewport buffer) of the first line containing needle.

Source

pub fn assert_viewport_contains(&mut self, needle: &str)

Source

pub fn assert_viewport_not_contains(&mut self, needle: &str)

Source

pub fn assert_history_contains(&mut self, needle: &str)

Source

pub fn assert_history_not_contains(&mut self, needle: &str)

Source

pub fn assert_conversation_contains(&mut self, needle: &str)

Source

pub fn assert_conversation_not_contains(&mut self, needle: &str)

Source

pub fn assert_viewport<S: AsRef<str>>(&mut self, expected: &[S])

Asserts the viewport’s visible text matches expected row-by-row.

Source

pub fn assert_history<S: AsRef<str>>(&mut self, expected: &[S])

Asserts the committed history’s visible text matches expected row-by-row.

Source

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§

Source§

impl Default for TestUi<TestBackend>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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>
where Terminal<B>: Freeze,

§

impl<B> Unpin for TestUi<B>
where Terminal<B>: Unpin,

§

impl<B> UnsafeUnpin for TestUi<B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoMaybeUndefined<T> for T

Source§

fn into_maybe_undefined(self) -> MaybeUndefined<T>

Converts this value into a three-state builder argument.
Source§

impl<T> IntoOption<T> for T

Source§

fn into_option(self) -> Option<T>

Converts this value into an optional builder argument.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more