rho-coding-agent 3.13.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use pretty_assertions::assert_eq;
use rho_protocol::{RewindConversation, SessionRewindPreviewResponse, TreeNodeId};

use super::RewindConfirmation;
use crate::tui::{
    daemon_events::{Moved, PreviewAsked},
    tests::test_app,
    ComposerMode, PickerItem, UiPicker,
};

/// What the composer holds when a preview's answer arrives.
enum Before {
    Empty,
    Draft,
    ConfirmationOf(&'static str),
}

// Covers: a rewind preview that arrives late opens its confirmation only
// where the next Enter cannot confirm a rewind unseen (never over a draft),
// a fresh pick replaces any open confirmation, and a re-preview never
// replaces another checkpoint's.
// Owner: TUI rewind confirmation (async daemon preview)
#[test]
fn a_late_preview_opens_only_where_it_cannot_be_confirmed_unseen() {
    let confirmation = |checkpoint: &str, tip: &str| RewindConfirmation {
        checkpoint: TreeNodeId::new(checkpoint),
        tip: TreeNodeId::new(tip),
    };
    let cases = [
        (
            "picked over empty",
            Before::Empty,
            PreviewAsked::Picked,
            Some(confirmation("b", "new")),
        ),
        (
            "picked over draft",
            Before::Draft,
            PreviewAsked::Picked,
            None,
        ),
        (
            "picked over another confirmation",
            Before::ConfirmationOf("a"),
            PreviewAsked::Picked,
            Some(confirmation("b", "new")),
        ),
        (
            "again over its own confirmation",
            Before::ConfirmationOf("b"),
            PreviewAsked::Again(Moved::Conversation),
            Some(confirmation("b", "new")),
        ),
        (
            "again over another confirmation",
            Before::ConfirmationOf("a"),
            PreviewAsked::Again(Moved::Session),
            Some(confirmation("a", "old")),
        ),
    ];
    for (name, before, asked, expected) in cases {
        let mut app = test_app();
        match before {
            Before::Empty => {}
            Before::Draft => app.input_ui.set_text("draft".into()),
            Before::ConfirmationOf(checkpoint) => {
                app.input_ui
                    .set_composer(ComposerMode::Picker(UiPicker::confirm_rewind(
                        "Confirm workspace rewind",
                        vec![PickerItem::new(
                            "Confirm workspace rewind".into(),
                            confirmation(checkpoint, "old").value(),
                        )],
                    )));
            }
        }
        let preview = SessionRewindPreviewResponse::new(
            vec![TreeNodeId::new("b")],
            TreeNodeId::new("new"),
            /*uncaptured_turns*/ 0,
            Vec::new(),
            Vec::new(),
            RewindConversation::Moves {
                to: TreeNodeId::new("before"),
            },
        );

        app.show_rewind_preview(TreeNodeId::new("b"), asked, Ok(Box::new(preview)));

        assert_eq!(app.open_rewind_confirmation(), expected, "{name}");
    }
}