rho-coding-agent 3.11.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use super::*;
use crate::cli_runtime::parent_messages::{message_channel, Delivered};
use pretty_assertions::assert_eq;

// Covers: a steer outside a turn, or into a run that takes no more
// messages, reaches no turn; one in a turn is recorded, once the agent took
// it, under the id it answered with, and its unsteer says how far it got:
// sent, then taken by the agent; an id the turn never had is not found.
// Owner: daemon ACP steer port (acp_steer.rs).
#[tokio::test]
async fn a_steer_reaches_the_running_turn_and_says_how_far_it_got() {
    let steers = AcpSteers::default();
    let content = || CliPrompt::text("go left");
    let outside = steers.steer(content());

    let (messages, mut inbox) = message_channel();
    steers.open(messages);
    let id = steers.steer(content()).unwrap();
    let taken = inbox.recv().await.unwrap();
    let sent = steers.unsteer(&id);
    let shown = taken.settle(Delivered::Steered);
    let applied = steers.unsteer(&id);
    let unknown = steers.unsteer(&SteerId::new("acp-steer-other"));
    inbox.seal();
    let sealed = steers.steer(content());
    steers.close();

    assert_eq!(
        (outside, sent, applied, unknown, shown, sealed),
        (
            Err(AcpSteerError::NoTurn),
            Ok(UnsteerOutcome::Delivered),
            Ok(UnsteerOutcome::Applied),
            Ok(UnsteerOutcome::NotFound),
            vec![AttachmentEvent::Steered {
                steer: id,
                content: content().to_wire_blocks(),
            }],
            Err(AcpSteerError::NoTurn),
        )
    );
}

// Covers: a turn's run holds at most STEER_SLOTS steers it has not taken,
// withdrawn ones until it skips them, so the place background results take
// in the shared queue stays free; a steer past that is refused as such, and
// one goes in again once the run skipped a withdrawn one.
// Owner: daemon ACP steer port (acp_steer.rs).
#[tokio::test]
async fn steers_leave_the_queue_a_place_for_background_results() {
    let steers = AcpSteers::default();
    let (messages, mut inbox) = message_channel();
    steers.open(messages.clone());
    let ids: Vec<_> = (0..STEER_SLOTS)
        .map(|_| steers.steer(CliPrompt::text("go")).unwrap())
        .collect();
    let withdrawn = steers.unsteer(&ids[0]);
    let past_the_limit = steers.steer(CliPrompt::text("one more"));
    let (result, _) = ParentMessage::hosted("result".into(), Vec::new(), String::new());
    let background = messages.send_message(result);
    // The run skips the withdrawn steer as it takes the next.
    inbox.recv().await.unwrap();
    let after_the_skip = steers.steer(CliPrompt::text("one more")).map(drop);

    assert_eq!(
        (withdrawn, past_the_limit, background, after_the_skip),
        (
            Ok(UnsteerOutcome::Withdrawn),
            Err(AcpSteerError::QueueFull),
            Ok(()),
            Ok(()),
        )
    );
}