rho-coding-agent 3.10.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use std::sync::Arc;

use pretty_assertions::assert_eq;
use rho_protocol::{
    self as wire, BrowserFrameAckParams, BrowserWatchId, BrowserWatchParams, ErrorCode,
};
use tempfile::TempDir;

use super::super::{test_sessions::load_browsing, Sessions};
use crate::{
    app::{
        daemon_host::jobs::{JobRegistry, JobStore},
        pull_requests::ScriptedForge,
    },
    browser::Browsers,
};

// Covers: what a watch the daemon cannot start answers, as the protocol
// documents: a frame size with no room or a tab the session does not have
// is `InvalidParams`, a session saved nowhere is `SessionNotFound`, and an
// ack for a watch that does not run is `InvalidParams`. A client would
// otherwise read a refused watch as a missing daemon feature, or wait for
// frames that never come.
// Owner: daemon browser watches
#[tokio::test]
async fn a_watch_the_daemon_cannot_start_says_why() {
    let (root, home) = (TempDir::new().unwrap(), TempDir::new().unwrap());
    let sessions = Sessions::new(
        Arc::new(JobRegistry::open(JobStore::open(home.path()).unwrap())),
        home.path(),
        ScriptedForge::new(),
    );
    let browser =
        Browsers::session(sessions.browsers.as_ref(), &rho_sdk::SessionId::new()).unwrap();
    let loaded = load_browsing(&sessions, &root, browser).await;
    let loaded = wire::SessionId::new(loaded.id.to_string());
    let nowhere = wire::SessionId::new(rho_sdk::SessionId::new().to_string());
    let watch = |session: &wire::SessionId, width| {
        BrowserWatchParams::new(session.clone(), "tab-1", width, 900)
    };
    let cases = [
        ("no room", watch(&loaded, 0), ErrorCode::InvalidParams),
        (
            "a session saved nowhere",
            watch(&nowhere, 800),
            ErrorCode::SessionNotFound,
        ),
        (
            "a tab the session lacks",
            watch(&loaded, 800),
            ErrorCode::InvalidParams,
        ),
    ];
    let mut answered = Vec::new();
    for (case, params, _) in &cases {
        let refused = sessions.watch_browser(params.clone()).await.err();
        answered.push((*case, refused.and_then(|error| error.error_code())));
    }
    let ack = BrowserFrameAckParams::new(BrowserWatchId::new("gone"), 1);
    answered.push((
        "an ack for no watch",
        sessions
            .ack_browser_frame(ack)
            .err()
            .and_then(|error| error.error_code()),
    ));

    let mut expected: Vec<_> = cases
        .iter()
        .map(|(case, _, code)| (*case, Some(*code)))
        .collect();
    expected.push(("an ack for no watch", Some(ErrorCode::InvalidParams)));
    assert_eq!(answered, expected);
}