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 as wire;

use super::{CliPrompt, PromptBlock};
use crate::run_artifacts::AttachmentEvent;

fn png() -> PromptBlock {
    PromptBlock::Image {
        mime_type: "image/png".into(),
        data: "iVBORw0KGgo=".into(),
    }
}

fn wire_png() -> wire::ContentBlock {
    wire::ContentBlock::Image {
        mime_type: "image/png".into(),
        data: "iVBORw0KGgo=".into(),
    }
}

// Covers: multimodal prompts keep block order, keep image-only prompts free of
// phantom text blocks, prepend preambles cleanly on text-first and image-first
// prompts, and preserve AttachmentEvent::Prompt for plain single-text prompts.
// Owner: cli_runtime prompt conversion (pure unit).
#[test]
fn preamble_and_attachment_event_preserve_multimodal_blocks() {
    let cases = [
        (
            "single text stays AttachmentEvent::Prompt",
            CliPrompt::text("hello"),
            CliPrompt::text("RULES\n\nhello"),
            AttachmentEvent::Prompt("hello".into()),
            false,
        ),
        (
            "image only keeps no empty text and puts preamble first",
            CliPrompt::from_blocks(vec![png()]),
            CliPrompt::from_blocks(vec![
                PromptBlock::Text {
                    text: "RULES".into(),
                },
                png(),
            ]),
            AttachmentEvent::PromptContent(vec![wire_png()]),
            true,
        ),
        (
            "text then image keeps order and joins preamble onto leading text",
            CliPrompt::from_blocks(vec![
                PromptBlock::Text {
                    text: "look".into(),
                },
                png(),
            ]),
            CliPrompt::from_blocks(vec![
                PromptBlock::Text {
                    text: "RULES\n\nlook".into(),
                },
                png(),
            ]),
            AttachmentEvent::PromptContent(vec![
                wire::ContentBlock::Text {
                    text: "look".into(),
                },
                wire_png(),
            ]),
            true,
        ),
        (
            "empty text beside image is omitted from wire blocks",
            CliPrompt::from_blocks(vec![
                PromptBlock::Text {
                    text: String::new(),
                },
                png(),
            ]),
            CliPrompt::from_blocks(vec![
                PromptBlock::Text {
                    text: "RULES\n\n".into(),
                },
                png(),
            ]),
            AttachmentEvent::PromptContent(vec![wire_png()]),
            true,
        ),
    ];

    for (case, prompt, expected_preamble, expected_event, expected_images) in cases {
        assert_eq!(prompt.has_images(), expected_images, "{case}");
        assert_eq!(prompt.with_preamble("RULES"), expected_preamble, "{case}");
        assert_eq!(prompt.to_attachment_event(), expected_event, "{case}");
    }
}