@@ -84,3 +84,133 @@ fn test_tool_router_list_all_is_sorted() {
8484 "list_all() should return tools sorted alphabetically by name"
8585 ) ;
8686}
87+
88+ fn build_router ( ) -> ToolRouter < TestHandler < ( ) > > {
89+ ToolRouter :: < TestHandler < ( ) > > :: new ( )
90+ . with_route ( ( async_function_tool_attr ( ) , async_function) )
91+ . with_route ( ( async_function2_tool_attr ( ) , async_function2) )
92+ + TestHandler :: < ( ) > :: test_router_1 ( )
93+ + TestHandler :: < ( ) > :: test_router_2 ( )
94+ }
95+
96+ #[ test]
97+ fn test_disable_route ( ) {
98+ let mut router = build_router ( ) ;
99+ assert_eq ! ( router. list_all( ) . len( ) , 4 ) ;
100+ assert ! ( router. has_route( "async_function" ) ) ;
101+ assert ! ( router. get( "async_function" ) . is_some( ) ) ;
102+
103+ router. disable_route ( "async_function" ) ;
104+
105+ assert_eq ! ( router. list_all( ) . len( ) , 3 ) ;
106+ assert ! ( !router. has_route( "async_function" ) ) ;
107+ assert ! ( router. get( "async_function" ) . is_none( ) ) ;
108+ assert ! ( router. is_disabled( "async_function" ) ) ;
109+
110+ // other tools unaffected
111+ assert ! ( router. has_route( "async_function2" ) ) ;
112+ assert ! ( router. get( "async_function2" ) . is_some( ) ) ;
113+ assert ! ( !router. is_disabled( "async_function2" ) ) ;
114+ }
115+
116+ #[ test]
117+ fn test_enable_route ( ) {
118+ let mut router = build_router ( ) ;
119+ router. disable_route ( "async_function" ) ;
120+ assert ! ( !router. has_route( "async_function" ) ) ;
121+
122+ router. enable_route ( "async_function" ) ;
123+ assert ! ( router. has_route( "async_function" ) ) ;
124+ assert ! ( router. get( "async_function" ) . is_some( ) ) ;
125+ assert ! ( !router. is_disabled( "async_function" ) ) ;
126+ assert_eq ! ( router. list_all( ) . len( ) , 4 ) ;
127+ }
128+
129+ #[ test]
130+ fn test_with_disabled_builder ( ) {
131+ let router = build_router ( )
132+ . with_disabled ( "async_function" )
133+ . with_disabled ( "sync_method" ) ;
134+
135+ assert_eq ! ( router. list_all( ) . len( ) , 2 ) ;
136+ assert ! ( !router. has_route( "async_function" ) ) ;
137+ assert ! ( !router. has_route( "sync_method" ) ) ;
138+ assert ! ( router. has_route( "async_function2" ) ) ;
139+ assert ! ( router. has_route( "async_method" ) ) ;
140+ }
141+
142+ #[ test]
143+ fn test_disabled_tools_survive_merge ( ) {
144+ let mut router_a = ToolRouter :: < TestHandler < ( ) > > :: new ( )
145+ . with_route ( ( async_function_tool_attr ( ) , async_function) ) ;
146+ router_a. disable_route ( "async_function" ) ;
147+
148+ let router_b = ToolRouter :: < TestHandler < ( ) > > :: new ( )
149+ . with_route ( ( async_function2_tool_attr ( ) , async_function2) ) ;
150+
151+ router_a. merge ( router_b) ;
152+
153+ assert_eq ! ( router_a. list_all( ) . len( ) , 1 ) ;
154+ assert ! ( router_a. is_disabled( "async_function" ) ) ;
155+ assert ! ( router_a. has_route( "async_function2" ) ) ;
156+ }
157+
158+ #[ test]
159+ fn test_disable_nonexistent_tool ( ) {
160+ let mut router = build_router ( ) ;
161+ // should not panic
162+ router. disable_route ( "does_not_exist" ) ;
163+ assert_eq ! ( router. list_all( ) . len( ) , 4 ) ;
164+ // is_disabled returns false for tools not in the map
165+ assert ! ( !router. is_disabled( "does_not_exist" ) ) ;
166+ }
167+
168+ #[ test]
169+ fn test_remove_route_clears_disabled_state ( ) {
170+ let mut router = build_router ( ) ;
171+ router. disable_route ( "async_function" ) ;
172+ assert ! ( router. is_disabled( "async_function" ) ) ;
173+
174+ router. remove_route ( "async_function" ) ;
175+ assert ! ( !router. is_disabled( "async_function" ) ) ;
176+ assert ! ( !router. has_route( "async_function" ) ) ;
177+ }
178+
179+ #[ test]
180+ fn test_into_iter_skips_disabled ( ) {
181+ let router = build_router ( ) . with_disabled ( "async_function" ) ;
182+ let names: Vec < _ > = router
183+ . into_iter ( )
184+ . map ( |r| r. attr . name . to_string ( ) )
185+ . collect ( ) ;
186+ assert_eq ! ( names. len( ) , 3 ) ;
187+ assert ! ( !names. contains( & "async_function" . to_string( ) ) ) ;
188+ }
189+
190+ #[ test]
191+ fn test_pre_disable_before_add_route ( ) {
192+ // Disabling a name before adding a route with that name should
193+ // result in the route being disabled once added.
194+ let router = ToolRouter :: < TestHandler < ( ) > > :: new ( )
195+ . with_disabled ( "async_function" )
196+ . with_route ( ( async_function_tool_attr ( ) , async_function) ) ;
197+
198+ assert_eq ! ( router. list_all( ) . len( ) , 0 ) ;
199+ assert ! ( router. is_disabled( "async_function" ) ) ;
200+ assert ! ( !router. has_route( "async_function" ) ) ;
201+ }
202+
203+ #[ test]
204+ fn test_disabled_tool_invisible_across_all_queries ( ) {
205+ let router = build_router ( ) . with_disabled ( "async_function" ) ;
206+
207+ // Not listed
208+ let names: Vec < _ > = router. list_all ( ) . iter ( ) . map ( |t| t. name . clone ( ) ) . collect ( ) ;
209+ assert ! ( !names. contains( & "async_function" . into( ) ) ) ;
210+ // Not retrievable
211+ assert ! ( router. get( "async_function" ) . is_none( ) ) ;
212+ // Not routable
213+ assert ! ( !router. has_route( "async_function" ) ) ;
214+ // But still known as disabled
215+ assert ! ( router. is_disabled( "async_function" ) ) ;
216+ }
0 commit comments