1- use crate :: session_id:: AcpSessionId ;
21use agent_client_protocol:: { Client , SessionNotification } ;
3- use tracing:: { info , instrument, warn} ;
2+ use tracing:: { instrument, warn} ;
43
5- #[ instrument( name = "acp.client.session.update" , skip( payload, client) , fields( session_id = %session_id) ) ]
6- pub async fn handle < C : Client > ( payload : & [ u8 ] , client : & C , session_id : & AcpSessionId ) {
7- info ! ( session_id = %session_id, "Forwarding session update to client" ) ;
4+ #[ instrument( name = "acp.client.session.update" , skip( payload, client) ) ]
5+ pub async fn handle < C : Client > ( payload : & [ u8 ] , client : & C , has_reply : bool ) {
6+ if has_reply {
7+ warn ! ( "Unexpected reply subject on notification request" ) ;
8+ }
89 match serde_json:: from_slice :: < SessionNotification > ( payload) {
910 Ok ( notification) => {
1011 if let Err ( e) = client. session_notification ( notification) . await {
@@ -21,17 +22,12 @@ pub async fn handle<C: Client>(payload: &[u8], client: &C, session_id: &AcpSessi
2122mod tests {
2223 use super :: * ;
2324 use agent_client_protocol:: {
24- ContentBlock , ContentChunk , RequestPermissionRequest , RequestPermissionResponse ,
25- SessionUpdate ,
25+ ContentBlock , ContentChunk , RequestPermissionOutcome , RequestPermissionRequest ,
26+ RequestPermissionResponse , SessionUpdate ,
2627 } ;
2728 use async_trait:: async_trait;
2829 use std:: cell:: RefCell ;
2930
30- fn session_id ( s : & str ) -> AcpSessionId {
31- AcpSessionId :: new ( s) . unwrap ( )
32- }
33-
34- #[ derive( Debug ) ]
3531 struct MockClient {
3632 notifications_received : RefCell < Vec < String > > ,
3733 should_fail : bool ,
@@ -62,7 +58,7 @@ mod tests {
6258 async fn session_notification (
6359 & self ,
6460 notification : SessionNotification ,
65- ) -> Result < ( ) , agent_client_protocol :: Error > {
61+ ) -> agent_client_protocol :: Result < ( ) > {
6662 if self . should_fail {
6763 return Err ( agent_client_protocol:: Error :: new ( -1 , "mock failure" ) ) ;
6864 }
@@ -75,57 +71,43 @@ mod tests {
7571 async fn request_permission (
7672 & self ,
7773 _: RequestPermissionRequest ,
78- ) -> Result < RequestPermissionResponse , agent_client_protocol:: Error > {
79- Err ( agent_client_protocol:: Error :: new (
80- -32603 ,
81- "not implemented in test mock" ,
74+ ) -> agent_client_protocol:: Result < RequestPermissionResponse > {
75+ Ok ( RequestPermissionResponse :: new (
76+ RequestPermissionOutcome :: Cancelled ,
8277 ) )
8378 }
8479 }
8580
8681 #[ tokio:: test]
87- async fn session_update_forwards_notification_to_client ( ) {
82+ async fn forwards_notification_to_client ( ) {
8883 let client = MockClient :: new ( ) ;
8984 let notification = SessionNotification :: new (
9085 "session-001" ,
9186 SessionUpdate :: AgentMessageChunk ( ContentChunk :: new ( ContentBlock :: from ( "hello" ) ) ) ,
9287 ) ;
9388 let payload = serde_json:: to_vec ( & notification) . unwrap ( ) ;
9489
95- handle ( & payload, & client, & session_id ( "session-001" ) ) . await ;
90+ super :: handle ( & payload, & client, false ) . await ;
9691
9792 assert_eq ! ( client. notification_count( ) , 1 ) ;
9893 }
9994
10095 #[ tokio:: test]
101- async fn session_update_invalid_payload_does_not_panic ( ) {
96+ async fn invalid_payload_does_not_panic ( ) {
10297 let client = MockClient :: new ( ) ;
103- handle ( b"not json" , & client, & session_id ( "session-001" ) ) . await ;
98+ super :: handle ( b"not json" , & client, false ) . await ;
10499 assert_eq ! ( client. notification_count( ) , 0 ) ;
105100 }
106101
107102 #[ tokio:: test]
108- async fn session_update_client_error_does_not_panic ( ) {
103+ async fn client_error_does_not_panic ( ) {
109104 let client = MockClient :: failing ( ) ;
110105 let notification = SessionNotification :: new (
111106 "session-001" ,
112107 SessionUpdate :: AgentMessageChunk ( ContentChunk :: new ( ContentBlock :: from ( "hello" ) ) ) ,
113108 ) ;
114109 let payload = serde_json:: to_vec ( & notification) . unwrap ( ) ;
115110
116- handle ( & payload, & client, & session_id ( "session-001" ) ) . await ;
117- }
118-
119- #[ tokio:: test]
120- async fn mock_client_request_permission_returns_err ( ) {
121- let client = MockClient :: new ( ) ;
122- let req: RequestPermissionRequest = serde_json:: from_value ( serde_json:: json!( {
123- "sessionId" : "sess-1" ,
124- "toolCall" : { "toolCallId" : "call-1" } ,
125- "options" : [ ]
126- } ) )
127- . unwrap ( ) ;
128- let result = client. request_permission ( req) . await ;
129- assert ! ( result. is_err( ) ) ;
111+ super :: handle ( & payload, & client, false ) . await ;
130112 }
131113}
0 commit comments