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::{MessageOrigin, RhoNotice, SessionId};

use super::{user_view, DaemonView};
use crate::app::RESUME_NOTICE;

/// What a view shows: the person's row, a notice, or a card's title, the
/// subtitle it shows expanded, and its whole text.
#[derive(Debug, PartialEq)]
enum Shown {
    User(String),
    Notice(String),
    Card {
        title: String,
        subtitle: Option<String>,
        body: String,
    },
}

fn shown(view: DaemonView) -> Shown {
    match view {
        DaemonView::User(text) => Shown::User(text),
        DaemonView::Notice(text) => Shown::Notice(text),
        DaemonView::Sent(card) => Shown::Card {
            title: card.title,
            subtitle: card.subtitle,
            body: card.body,
        },
        other => panic!("not a user message's view: {other:?}"),
    }
}

// Covers: a user message shows as the person's row without an origin; as
// the restart notice for rho's restart turn; otherwise as a card titled by
// its sender and first line, as plain text: a session by its title's first line, or its
// short id without one, rho by name, and an unknown kind by no one, so it
// never passes for the person's.
// Owner: TUI transcript view of message origins (`sent_message.rs`).
#[test]
fn user_messages_show_who_wrote_them() {
    let id = "1f64ce0c-0b3a-4f0e-9c1e-2d7f5a6b8c90";
    let session = |title: Option<&str>| {
        Some(MessageOrigin::session(
            SessionId::new(id),
            title.map(str::to_owned),
        ))
    };
    let text = "\n**PR 1** is ready for review: #2339\nCI is green.";
    let card = |title: &str, subtitle: Option<String>| Shown::Card {
        title: title.to_owned(),
        subtitle,
        body: text.to_owned(),
    };
    let from = format!("from session {id}");
    let cases = [
        (None, Shown::User(text.to_owned())),
        (
            Some(MessageOrigin::rho(RhoNotice::Restart)),
            Shown::Notice(RESUME_NOTICE.to_owned()),
        ),
        (
            session(Some("ARCTIC loader\nsecond line")),
            card(
                "ARCTIC loader · PR 1 is ready for review: #2339",
                Some(from.clone()),
            ),
        ),
        (
            session(None),
            card(
                "session 1f64ce0c · PR 1 is ready for review: #2339",
                Some(from.clone()),
            ),
        ),
        (
            Some(MessageOrigin::rho(RhoNotice::Notification)),
            card(
                "rho · PR 1 is ready for review: #2339",
                Some("from rho".to_owned()),
            ),
        ),
        (
            Some(MessageOrigin::rho(RhoNotice::Unknown)),
            card(
                "rho · PR 1 is ready for review: #2339",
                Some("from rho".to_owned()),
            ),
        ),
        (
            Some(MessageOrigin::Unknown),
            card("PR 1 is ready for review: #2339", None),
        ),
    ];
    for (origin, expected) in cases {
        assert_eq!(
            shown(user_view(text.to_owned(), origin.as_ref())),
            expected,
            "{origin:?}"
        );
    }
}