@@ -133,6 +133,8 @@ struct TestAgent {
133133 sessions : Arc < Mutex < std:: collections:: HashMap < SessionId , std:: path:: PathBuf > > > ,
134134 prompts_received : Arc < Mutex < Vec < PromptReceived > > > ,
135135 cancellations_received : Arc < Mutex < Vec < SessionId > > > ,
136+ #[ cfg( feature = "unstable_logout" ) ]
137+ logout_count : Arc < Mutex < u32 > > ,
136138 extension_notifications : Arc < Mutex < Vec < ( String , ExtNotification ) > > > ,
137139}
138140
@@ -144,6 +146,8 @@ impl TestAgent {
144146 sessions : Arc :: new ( Mutex :: new ( std:: collections:: HashMap :: new ( ) ) ) ,
145147 prompts_received : Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ,
146148 cancellations_received : Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ,
149+ #[ cfg( feature = "unstable_logout" ) ]
150+ logout_count : Arc :: new ( Mutex :: new ( 0 ) ) ,
147151 extension_notifications : Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ,
148152 }
149153 }
@@ -153,13 +157,28 @@ impl TestAgent {
153157impl Agent for TestAgent {
154158 async fn initialize ( & self , arguments : InitializeRequest ) -> Result < InitializeResponse > {
155159 Ok ( InitializeResponse :: new ( arguments. protocol_version )
160+ . agent_capabilities (
161+ AgentCapabilities :: new ( ) . auth (
162+ agent_client_protocol_schema:: AgentAuthCapabilities :: new ( )
163+ . logout ( agent_client_protocol_schema:: LogoutCapabilities :: new ( ) ) ,
164+ ) ,
165+ )
156166 . agent_info ( Implementation :: new ( "test-agent" , "0.0.0" ) . title ( "Test Agent" ) ) )
157167 }
158168
159169 async fn authenticate ( & self , _arguments : AuthenticateRequest ) -> Result < AuthenticateResponse > {
160170 Ok ( AuthenticateResponse :: default ( ) )
161171 }
162172
173+ #[ cfg( feature = "unstable_logout" ) ]
174+ async fn logout (
175+ & self ,
176+ _arguments : agent_client_protocol_schema:: LogoutRequest ,
177+ ) -> Result < agent_client_protocol_schema:: LogoutResponse > {
178+ * self . logout_count . lock ( ) . unwrap ( ) += 1 ;
179+ Ok ( agent_client_protocol_schema:: LogoutResponse :: default ( ) )
180+ }
181+
163182 async fn new_session ( & self , arguments : NewSessionRequest ) -> Result < NewSessionResponse > {
164183 let session_id = SessionId :: new ( "test-session-123" ) ;
165184 self . sessions
@@ -886,6 +905,44 @@ async fn test_session_info_update() {
886905 . await ;
887906}
888907
908+ #[ cfg( feature = "unstable_logout" ) ]
909+ #[ tokio:: test]
910+ async fn test_logout ( ) {
911+ let local_set = tokio:: task:: LocalSet :: new ( ) ;
912+ local_set
913+ . run_until ( async {
914+ let client = TestClient :: new ( ) ;
915+ let agent = TestAgent :: new ( ) ;
916+
917+ let ( agent_conn, _client_conn) = create_connection_pair ( & client, & agent) ;
918+
919+ let initialize_response =
920+ agent_conn
921+ . initialize ( InitializeRequest :: new ( ProtocolVersion :: LATEST ) . client_info (
922+ Implementation :: new ( "test-client" , "0.0.0" ) . title ( "Test Client" ) ,
923+ ) )
924+ . await
925+ . expect ( "initialize failed" ) ;
926+
927+ assert ! (
928+ initialize_response. agent_capabilities. auth. logout. is_some( ) ,
929+ "agent should advertise auth.logout capability"
930+ ) ;
931+
932+ let response = agent_conn
933+ . logout ( agent_client_protocol_schema:: LogoutRequest :: new ( ) )
934+ . await
935+ . expect ( "logout failed" ) ;
936+
937+ assert_eq ! (
938+ response,
939+ agent_client_protocol_schema:: LogoutResponse :: default ( )
940+ ) ;
941+ assert_eq ! ( * agent. logout_count. lock( ) . unwrap( ) , 1 ) ;
942+ } )
943+ . await ;
944+ }
945+
889946#[ tokio:: test]
890947async fn test_set_session_config_option ( ) {
891948 let local_set = tokio:: task:: LocalSet :: new ( ) ;
0 commit comments