rpi-cli 0.23.0

Terminal coding-agent CLI (the `rpi` binary) built on the rpi-* library crates
Documentation
//! Test-only source-order acceptance for native event/reload retirement.
//!
//! This does not open a terminal or run the live event loop. It protects the
//! host's existing cleanup tail while keeping PTY and delivery claims out of
//! the bounded slice.

const HOST_SOURCE: &str = include_str!("../../interactive_tui.rs");

// Source-order checks must be independent of Git's Windows line-ending
// checkout policy; the contract is about ordering, not CRLF versus LF.
fn normalized_host_source() -> String {
    HOST_SOURCE.replace("\r\n", "\n")
}

fn after_shutdown(needle: &str) -> usize {
    let source = normalized_host_source();
    let shutdown = source
        .rfind("    // ---- Shutdown ----")
        .expect("interactive TUI shutdown tail must remain present");
    source[shutdown..]
        .find(needle)
        .map(|offset| shutdown + offset)
        .unwrap_or_else(|| panic!("shutdown source is missing marker: {needle:?}"))
}

#[test]
fn event_and_reload_handles_retire_only_after_native_settlement() {
    let settle = after_shutdown(
        "settlement::settle_native(harness, state.session_write_tasks.seal()).await",
    );
    let tick = after_shutdown("tick_handle.abort();");
    let drain = after_shutdown("if let Some(handle) = drain_handle");
    let mailbox = after_shutdown("reload_context.mailbox.clear();");
    let reload = after_shutdown("reload_bridge_handle.abort();");
    let tui = after_shutdown("tui.stop(Default::default());");

    assert!(settle < tick);
    assert!(tick < drain);
    assert!(drain < mailbox);
    assert!(mailbox < reload);
    assert!(reload < tui);
}

#[test]
fn reload_bridge_is_installed_before_its_shutdown_cleanup() {
    let source = normalized_host_source();
    let install = source
        .find("reload_context.mailbox.install(reload_sig_tx);")
        .expect("reload mailbox installation must remain present");
    let bridge = source
        .find("let reload_bridge_handle = tokio::spawn(async move {")
        .expect("reload bridge task must remain present");
    let clear = after_shutdown("reload_context.mailbox.clear();");
    let abort = after_shutdown("reload_bridge_handle.abort();");

    assert!(install < bridge);
    assert!(clear < abort);
}

#[test]
fn event_consumer_is_kept_live_through_native_settlement() {
    let source = normalized_host_source();
    assert!(source.contains("the streaming event consumer stays live through producer settlement"));

    let settle = after_shutdown(
        "settlement::settle_native(harness, state.session_write_tasks.seal()).await",
    );
    let event_abort = after_shutdown("if let Some(handle) = drain_handle");
    assert!(settle < event_abort);
}