@@ -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,29 @@ impl TestAgent {
153157impl Agent for TestAgent {
154158 async fn initialize ( & self , arguments : InitializeRequest ) -> Result < InitializeResponse > {
155159 Ok ( InitializeResponse :: new ( arguments. protocol_version )
160+ #[ cfg ( feature = "unstable_logout" ) ]
161+ . agent_capabilities (
162+ AgentCapabilities :: new ( ) . auth (
163+ agent_client_protocol_schema:: AgentAuthCapabilities :: new ( )
164+ . logout ( agent_client_protocol_schema:: LogoutCapabilities :: new ( ) ) ,
165+ ) ,
166+ )
156167 . agent_info ( Implementation :: new ( "test-agent" , "0.0.0" ) . title ( "Test Agent" ) ) )
157168 }
158169
159170 async fn authenticate ( & self , _arguments : AuthenticateRequest ) -> Result < AuthenticateResponse > {
160171 Ok ( AuthenticateResponse :: default ( ) )
161172 }
162173
174+ #[ cfg( feature = "unstable_logout" ) ]
175+ async fn logout (
176+ & self ,
177+ _arguments : agent_client_protocol_schema:: LogoutRequest ,
178+ ) -> Result < agent_client_protocol_schema:: LogoutResponse > {
179+ * self . logout_count . lock ( ) . unwrap ( ) += 1 ;
180+ Ok ( agent_client_protocol_schema:: LogoutResponse :: default ( ) )
181+ }
182+
163183 async fn new_session ( & self , arguments : NewSessionRequest ) -> Result < NewSessionResponse > {
164184 let session_id = SessionId :: new ( "test-session-123" ) ;
165185 self . sessions
@@ -886,6 +906,44 @@ async fn test_session_info_update() {
886906 . await ;
887907}
888908
909+ #[ cfg( feature = "unstable_logout" ) ]
910+ #[ tokio:: test]
911+ async fn test_logout ( ) {
912+ let local_set = tokio:: task:: LocalSet :: new ( ) ;
913+ local_set
914+ . run_until ( async {
915+ let client = TestClient :: new ( ) ;
916+ let agent = TestAgent :: new ( ) ;
917+
918+ let ( agent_conn, _client_conn) = create_connection_pair ( & client, & agent) ;
919+
920+ let initialize_response =
921+ agent_conn
922+ . initialize ( InitializeRequest :: new ( ProtocolVersion :: LATEST ) . client_info (
923+ Implementation :: new ( "test-client" , "0.0.0" ) . title ( "Test Client" ) ,
924+ ) )
925+ . await
926+ . expect ( "initialize failed" ) ;
927+
928+ assert ! (
929+ initialize_response. agent_capabilities. auth. logout. is_some( ) ,
930+ "agent should advertise auth.logout capability"
931+ ) ;
932+
933+ let response = agent_conn
934+ . logout ( agent_client_protocol_schema:: LogoutRequest :: new ( ) )
935+ . await
936+ . expect ( "logout failed" ) ;
937+
938+ assert_eq ! (
939+ response,
940+ agent_client_protocol_schema:: LogoutResponse :: default ( )
941+ ) ;
942+ assert_eq ! ( * agent. logout_count. lock( ) . unwrap( ) , 1 ) ;
943+ } )
944+ . await ;
945+ }
946+
889947#[ tokio:: test]
890948async fn test_set_session_config_option ( ) {
891949 let local_set = tokio:: task:: LocalSet :: new ( ) ;
0 commit comments