sacp-test 11.0.0

Test utilities and mock implementations for SACP
Documentation
//! A simple test proxy that adds `>` prefix to session update messages.
//!
//! This proxy demonstrates basic proxy functionality by intercepting
//! `session/update` notifications and prepending `>` to the content.

use sacp::schema::{ContentBlock, ContentChunk, SessionNotification, SessionUpdate};
use sacp::{Agent, Client, ConnectTo, Proxy};

/// Run the arrow proxy that adds `>` to each session update.
///
/// # Arguments
///
/// * `transport` - Component to the predecessor (conductor or another proxy)
pub async fn run_arrow_proxy(
    transport: impl ConnectTo<Proxy> + 'static,
) -> Result<(), sacp::Error> {
    Proxy
        .builder()
        .name("arrow-proxy")
        // Intercept session notifications from successor (agent) and modify them.
        // Using on_receive_notification_from(Agent, ...) automatically unwraps
        // SuccessorMessage envelopes.
        .on_receive_notification_from(
            Agent,
            async |mut notification: SessionNotification, cx| {
                // Modify the content by adding > prefix
                match &mut notification.update {
                    SessionUpdate::AgentMessageChunk(ContentChunk { content, .. }) => {
                        // Add > prefix to text content
                        if let ContentBlock::Text(text_content) = content {
                            text_content.text = format!(">{}", text_content.text);
                        }
                    }
                    _ => {
                        // Don't modify other update types
                    }
                }

                // Forward modified notification to predecessor (client)
                cx.send_notification_to(Client, notification)?;
                Ok(())
            },
            sacp::on_receive_notification!(),
        )
        .connect_to(transport)
        .await
}

#[cfg(test)]
mod tests {
    #[test]
    fn test_arrow_proxy_compiles() {
        // Basic smoke test that the arrow proxy module compiles
        // Full integration tests with conductor will be in sacp-conductor tests
    }
}