rho-coding-agent 3.11.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use pretty_assertions::assert_eq;
use rho_protocol::{ProtocolVersion, RestartCost, VersionFix, VersionMismatch, PROTOCOL_VERSION};
use serde_json::json;
use tempfile::TempDir;

use super::StartReport;
use crate::{
    app::daemon_cli::Unreachable,
    daemon::{
        connect_or_spawn, test_support::RefusingListener, ConnectAs, DaemonPaths, ProcessSpawner,
        RunFrom,
    },
};

// Covers: `rho daemon start --json` reports an older daemon someone uses,
// which refuses the handshake and is left running, with the refusal's data
// and restart cost as `rho/hello` sends them, so a client that starts a
// daemon over ssh can offer the restart (#1997).
// Owner: daemon start CLI report.
#[tokio::test]
async fn start_reports_the_refusal_of_an_older_daemon_in_use() {
    let root = TempDir::new().unwrap();
    let paths = DaemonPaths::resolve(root.path(), |_| None).unwrap();
    let mut listener = RefusingListener::bind(&paths);
    let refusal = VersionMismatch {
        daemon: ProtocolVersion::new(0, 0),
        client: PROTOCOL_VERSION,
        fix: VersionFix::RestartDaemon,
        restart: Some(RestartCost {
            in_progress: 1,
            clients: 0,
        }),
    };
    let daemon = tokio::spawn(async move { listener.refuse_next(refusal).await });
    // A daemon in use is never replaced, so nothing is spawned.
    let spawner = ProcessSpawner::new("rho-is-not-run".into(), RunFrom::Installed);

    let connected = connect_or_spawn(&paths, ConnectAs::Command.hello(), &spawner)
        .await
        .map_err(|error| Unreachable::of_spawn(&error));
    daemon.await.unwrap();

    assert_eq!(
        serde_json::to_value(StartReport::of(&connected)).unwrap(),
        json!({
            "outcome": "refused",
            "mismatch": {
                "daemon": {"major": 0, "minor": 0},
                "client": PROTOCOL_VERSION,
                "fix": "restart_daemon",
                "restart": {"in_progress": 1, "clients": 0},
            },
        })
    );
}