@@ -100,7 +100,7 @@ fn test_disable_route() {
100100 assert ! ( router. has_route( "async_function" ) ) ;
101101 assert ! ( router. get( "async_function" ) . is_some( ) ) ;
102102
103- router. disable_route ( "async_function" ) ;
103+ assert ! ( router. disable_route( "async_function" ) ) ;
104104
105105 assert_eq ! ( router. list_all( ) . len( ) , 3 ) ;
106106 assert ! ( !router. has_route( "async_function" ) ) ;
@@ -116,10 +116,10 @@ fn test_disable_route() {
116116#[ test]
117117fn test_enable_route ( ) {
118118 let mut router = build_router ( ) ;
119- router. disable_route ( "async_function" ) ;
119+ assert ! ( router. disable_route( "async_function" ) ) ;
120120 assert ! ( !router. has_route( "async_function" ) ) ;
121121
122- router. enable_route ( "async_function" ) ;
122+ assert ! ( router. enable_route( "async_function" ) ) ;
123123 assert ! ( router. has_route( "async_function" ) ) ;
124124 assert ! ( router. get( "async_function" ) . is_some( ) ) ;
125125 assert ! ( !router. is_disabled( "async_function" ) ) ;
@@ -143,7 +143,7 @@ fn test_with_disabled_builder() {
143143fn test_disabled_tools_survive_merge ( ) {
144144 let mut router_a = ToolRouter :: < TestHandler < ( ) > > :: new ( )
145145 . with_route ( ( async_function_tool_attr ( ) , async_function) ) ;
146- router_a. disable_route ( "async_function" ) ;
146+ assert ! ( router_a. disable_route( "async_function" ) ) ;
147147
148148 let router_b = ToolRouter :: < TestHandler < ( ) > > :: new ( )
149149 . with_route ( ( async_function2_tool_attr ( ) , async_function2) ) ;
@@ -158,22 +158,42 @@ fn test_disabled_tools_survive_merge() {
158158#[ test]
159159fn test_disable_nonexistent_tool ( ) {
160160 let mut router = build_router ( ) ;
161- // should not panic
162- router. disable_route ( "does_not_exist" ) ;
161+ // should not panic; returns true because the name is newly added to disabled set
162+ assert ! ( router. disable_route( "does_not_exist" ) ) ;
163163 assert_eq ! ( router. list_all( ) . len( ) , 4 ) ;
164164 // is_disabled returns false for tools not in the map
165165 assert ! ( !router. is_disabled( "does_not_exist" ) ) ;
166166}
167167
168168#[ test]
169- fn test_remove_route_clears_disabled_state ( ) {
169+ fn test_remove_route_preserves_disabled_state ( ) {
170170 let mut router = build_router ( ) ;
171- router. disable_route ( "async_function" ) ;
171+ assert ! ( router. disable_route( "async_function" ) ) ;
172172 assert ! ( router. is_disabled( "async_function" ) ) ;
173173
174174 router. remove_route ( "async_function" ) ;
175+ assert ! ( !router. has_route( "async_function" ) ) ;
176+ // Disabled marker is preserved — is_disabled returns false (no route in map)
177+ // but re-adding will inherit the disabled state (tested separately)
175178 assert ! ( !router. is_disabled( "async_function" ) ) ;
179+ }
180+
181+ #[ test]
182+ fn test_remove_route_then_readd_stays_disabled ( ) {
183+ let mut router = build_router ( ) ;
184+ assert ! ( router. disable_route( "async_function" ) ) ;
185+
186+ router. remove_route ( "async_function" ) ;
187+ assert ! ( !router. has_route( "async_function" ) ) ;
188+
189+ // Re-add the route — it should inherit the disabled state
190+ let other = ToolRouter :: < TestHandler < ( ) > > :: new ( )
191+ . with_route ( ( async_function_tool_attr ( ) , async_function) ) ;
192+ router. merge ( other) ;
193+
176194 assert ! ( !router. has_route( "async_function" ) ) ;
195+ assert ! ( router. is_disabled( "async_function" ) ) ;
196+ assert ! ( router. get( "async_function" ) . is_none( ) ) ;
177197}
178198
179199#[ test]
@@ -211,6 +231,42 @@ fn test_disabled_tool_invisible_across_all_queries() {
211231 assert ! ( router. get( "async_function" ) . is_none( ) ) ;
212232 // Not routable
213233 assert ! ( !router. has_route( "async_function" ) ) ;
214- // But still known as disabled
234+ // But known as disabled
215235 assert ! ( router. is_disabled( "async_function" ) ) ;
216236}
237+
238+ #[ test]
239+ fn test_disable_route_then_add_route_blocks_tool ( ) {
240+ // Full pre-disable lifecycle via runtime mutation (not builder)
241+ let mut router = ToolRouter :: < TestHandler < ( ) > > :: new ( ) ;
242+ router. disable_route ( "async_function" ) ;
243+
244+ // Add route after disabling — tool should be blocked
245+ let other = ToolRouter :: < TestHandler < ( ) > > :: new ( )
246+ . with_route ( ( async_function_tool_attr ( ) , async_function) ) ;
247+ router. merge ( other) ;
248+
249+ assert ! ( router. is_disabled( "async_function" ) ) ;
250+ assert ! ( !router. has_route( "async_function" ) ) ;
251+ assert ! ( router. get( "async_function" ) . is_none( ) ) ;
252+ assert_eq ! ( router. list_all( ) . len( ) , 0 ) ;
253+ }
254+
255+ #[ test]
256+ fn test_disable_enable_return_false_cases ( ) {
257+ let mut router = build_router ( ) ;
258+
259+ // Repeated disable returns false
260+ assert ! ( router. disable_route( "async_function" ) ) ;
261+ assert ! ( !router. disable_route( "async_function" ) ) ;
262+
263+ // Enable returns true, then false on repeat
264+ assert ! ( router. enable_route( "async_function" ) ) ;
265+ assert ! ( !router. enable_route( "async_function" ) ) ;
266+
267+ // Enable on name never disabled returns false
268+ assert ! ( !router. enable_route( "async_function2" ) ) ;
269+
270+ // Enable on unknown name returns false
271+ assert ! ( !router. enable_route( "unknown" ) ) ;
272+ }
0 commit comments