rho-coding-agent 3.7.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use super::*;
use crate::tui::questionnaire::QuestionnaireResponseChannel;
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
use pretty_assertions::assert_eq;
use rho_sdk::{HostChoice, HostInputRequest, HostInputResponse, HostQuestion, SelectionMode};

fn countdown() -> QuestionnaireComposer {
    let request = HostInputRequest::questionnaire(
        "Color",
        vec![HostQuestion::new(
            "color",
            "Color?",
            vec![HostChoice::new("blue", "Blue")],
            SelectionMode::One,
        )
        .unwrap()
        .allow_other()],
    )
    .unwrap()
    .with_timeout_fallback(
        HostInputResponse::new().answer("color", ["blue"]),
        "Use blue",
    )
    .unwrap();
    let (tx, _rx) = tokio::sync::oneshot::channel();
    let mut composer = QuestionnaireComposer::new(request, QuestionnaireResponseChannel::new(tx));
    composer.count_down_to_fallback(Duration::from_secs(60), Instant::now());
    composer
}

// Covers: the user's keys, pastes, and pointer pause the countdown for
// good, so the TUI holds the request; terminal housekeeping does not.
// Owner: pure questionnaire timer policy; key routing is covered through PTY.
#[test]
fn only_the_users_input_pauses_the_countdown() {
    for (event, running) in [
        (
            Event::Key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE)),
            false,
        ),
        (Event::Paste("blue".into()), false),
        (
            Event::Mouse(MouseEvent {
                kind: MouseEventKind::Moved,
                column: 0,
                row: 0,
                modifiers: KeyModifiers::NONE,
            }),
            false,
        ),
        (Event::Resize(80, 24), true),
        (Event::FocusGained, true),
    ] {
        let mut composer = countdown();
        composer.observe_input(&event);
        assert_eq!(composer.timeout_running(), running, "{event:?}");
    }
}

// Covers: a paste buffered before the form opened is applied without a new
// terminal event. The edit itself must pause the countdown so the daemon's
// fallback cannot replace it.
// Owner: questionnaire timer/edit policy.
#[test]
fn deferred_text_edits_pause_the_countdown_without_another_terminal_event() {
    for paste in [false, true] {
        let mut composer = countdown();
        let edited = if paste {
            composer.insert_text("green")
        } else {
            composer.insert_char('g')
        };
        assert_eq!((edited, composer.timeout_running()), (true, false));
    }
}