@@ -694,12 +694,12 @@ impl Agents {
694694 /// Returns a label to describe the permission status for a given tool.
695695 pub fn display_label ( & self , tool_name : & str , origin : & ToolOrigin ) -> String {
696696 use crate :: util:: pattern_matching:: matches_any_pattern;
697-
697+
698698 let tool_trusted = self . get_active ( ) . is_some_and ( |a| {
699699 if matches ! ( origin, & ToolOrigin :: Native ) {
700700 return matches_any_pattern ( & a. allowed_tools , tool_name) ;
701701 }
702-
702+
703703 a. allowed_tools . iter ( ) . any ( |name| {
704704 name. strip_prefix ( "@" ) . is_some_and ( |remainder| {
705705 remainder
@@ -959,42 +959,62 @@ mod tests {
959959 #[ test]
960960 fn test_display_label_no_active_agent ( ) {
961961 let agents = Agents :: default ( ) ;
962-
962+
963963 let label = agents. display_label ( "fs_read" , & ToolOrigin :: Native ) ;
964964 // With no active agent, it should fall back to default permissions
965965 // fs_read has a default of "trusted"
966- assert ! ( label. contains( "trusted" ) , "fs_read should show default trusted permission, instead found: {}" , label) ;
966+ assert ! (
967+ label. contains( "trusted" ) ,
968+ "fs_read should show default trusted permission, instead found: {}" ,
969+ label
970+ ) ;
967971 }
968972
969973 #[ test]
970974 fn test_display_label_trust_all_tools ( ) {
971975 let mut agents = Agents :: default ( ) ;
972976 agents. trust_all_tools = true ;
973-
977+
974978 // Should be trusted even if not in allowed_tools
975979 let label = agents. display_label ( "random_tool" , & ToolOrigin :: Native ) ;
976- assert ! ( label. contains( "trusted" ) , "trust_all_tools should make everything trusted, instead found: {}" , label) ;
980+ assert ! (
981+ label. contains( "trusted" ) ,
982+ "trust_all_tools should make everything trusted, instead found: {}" ,
983+ label
984+ ) ;
977985 }
978986
979987 #[ test]
980988 fn test_display_label_default_permissions ( ) {
981989 let agents = Agents :: default ( ) ;
982-
990+
983991 // Test default permissions for known tools
984992 let fs_read_label = agents. display_label ( "fs_read" , & ToolOrigin :: Native ) ;
985- assert ! ( fs_read_label. contains( "trusted" ) , "fs_read should be trusted by default, instead found: {}" , fs_read_label) ;
986-
993+ assert ! (
994+ fs_read_label. contains( "trusted" ) ,
995+ "fs_read should be trusted by default, instead found: {}" ,
996+ fs_read_label
997+ ) ;
998+
987999 let fs_write_label = agents. display_label ( "fs_write" , & ToolOrigin :: Native ) ;
988- assert ! ( fs_write_label. contains( "not trusted" ) , "fs_write should not be trusted by default, instead found: {}" , fs_write_label) ;
989-
1000+ assert ! (
1001+ fs_write_label. contains( "not trusted" ) ,
1002+ "fs_write should not be trusted by default, instead found: {}" ,
1003+ fs_write_label
1004+ ) ;
1005+
9901006 let execute_bash_label = agents. display_label ( "execute_bash" , & ToolOrigin :: Native ) ;
991- assert ! ( execute_bash_label. contains( "read-only" ) , "execute_bash should show read-only by default, instead found: {}" , execute_bash_label) ;
1007+ assert ! (
1008+ execute_bash_label. contains( "read-only" ) ,
1009+ "execute_bash should show read-only by default, instead found: {}" ,
1010+ execute_bash_label
1011+ ) ;
9921012 }
9931013
9941014 #[ test]
9951015 fn test_display_label_comprehensive_patterns ( ) {
9961016 let mut agents = Agents :: default ( ) ;
997-
1017+
9981018 // Create agent with all types of patterns
9991019 let mut allowed_tools = HashSet :: new ( ) ;
10001020 // Native exact match
@@ -1007,7 +1027,7 @@ mod tests {
10071027 allowed_tools. insert ( "@server2/specific_tool" . to_string ( ) ) ;
10081028 // MCP tool wildcard
10091029 allowed_tools. insert ( "@server3/tool_*" . to_string ( ) ) ;
1010-
1030+
10111031 let agent = Agent {
10121032 schema : "test" . to_string ( ) ,
10131033 name : "test-agent" . to_string ( ) ,
@@ -1023,40 +1043,72 @@ mod tests {
10231043 use_legacy_mcp_json : false ,
10241044 path : None ,
10251045 } ;
1026-
1046+
10271047 agents. agents . insert ( "test-agent" . to_string ( ) , agent) ;
10281048 agents. active_idx = "test-agent" . to_string ( ) ;
1029-
1049+
10301050 // Test 1: Native exact match
10311051 let label = agents. display_label ( "fs_read" , & ToolOrigin :: Native ) ;
1032- assert ! ( label. contains( "trusted" ) , "fs_read should be trusted (exact match), instead found: {}" , label) ;
1033-
1052+ assert ! (
1053+ label. contains( "trusted" ) ,
1054+ "fs_read should be trusted (exact match), instead found: {}" ,
1055+ label
1056+ ) ;
1057+
10341058 // Test 2: Native wildcard match
10351059 let label = agents. display_label ( "execute_bash" , & ToolOrigin :: Native ) ;
1036- assert ! ( label. contains( "trusted" ) , "execute_bash should match execute_* pattern, instead found: {}" , label) ;
1037-
1060+ assert ! (
1061+ label. contains( "trusted" ) ,
1062+ "execute_bash should match execute_* pattern, instead found: {}" ,
1063+ label
1064+ ) ;
1065+
10381066 // Test 3: Native no match
10391067 let label = agents. display_label ( "fs_write" , & ToolOrigin :: Native ) ;
1040- assert ! ( !label. contains( "trusted" ) || label. contains( "not trusted" ) , "fs_write should not be trusted, instead found: {}" , label) ;
1041-
1068+ assert ! (
1069+ !label. contains( "trusted" ) || label. contains( "not trusted" ) ,
1070+ "fs_write should not be trusted, instead found: {}" ,
1071+ label
1072+ ) ;
1073+
10421074 // Test 4: MCP server exact match (allows any tool from server1)
10431075 let label = agents. display_label ( "any_tool" , & ToolOrigin :: McpServer ( "server1" . to_string ( ) ) ) ;
1044- assert ! ( label. contains( "trusted" ) , "Server-level permission should allow any tool, instead found: {}" , label) ;
1045-
1076+ assert ! (
1077+ label. contains( "trusted" ) ,
1078+ "Server-level permission should allow any tool, instead found: {}" ,
1079+ label
1080+ ) ;
1081+
10461082 // Test 5: MCP tool exact match
10471083 let label = agents. display_label ( "specific_tool" , & ToolOrigin :: McpServer ( "server2" . to_string ( ) ) ) ;
1048- assert ! ( label. contains( "trusted" ) , "Exact MCP tool should be trusted, instead found: {}" , label) ;
1049-
1084+ assert ! (
1085+ label. contains( "trusted" ) ,
1086+ "Exact MCP tool should be trusted, instead found: {}" ,
1087+ label
1088+ ) ;
1089+
10501090 // Test 6: MCP tool wildcard match
10511091 let label = agents. display_label ( "tool_read" , & ToolOrigin :: McpServer ( "server3" . to_string ( ) ) ) ;
1052- assert ! ( label. contains( "trusted" ) , "tool_read should match @server3/tool_* pattern, instead found: {}" , label) ;
1053-
1092+ assert ! (
1093+ label. contains( "trusted" ) ,
1094+ "tool_read should match @server3/tool_* pattern, instead found: {}" ,
1095+ label
1096+ ) ;
1097+
10541098 // Test 7: MCP tool no match
10551099 let label = agents. display_label ( "other_tool" , & ToolOrigin :: McpServer ( "server2" . to_string ( ) ) ) ;
1056- assert ! ( !label. contains( "trusted" ) || label. contains( "not trusted" ) , "Non-matching MCP tool should not be trusted, instead found: {}" , label) ;
1057-
1100+ assert ! (
1101+ !label. contains( "trusted" ) || label. contains( "not trusted" ) ,
1102+ "Non-matching MCP tool should not be trusted, instead found: {}" ,
1103+ label
1104+ ) ;
1105+
10581106 // Test 8: MCP server no match
10591107 let label = agents. display_label ( "some_tool" , & ToolOrigin :: McpServer ( "unknown_server" . to_string ( ) ) ) ;
1060- assert ! ( !label. contains( "trusted" ) || label. contains( "not trusted" ) , "Unknown server should not be trusted, instead found: {}" , label) ;
1108+ assert ! (
1109+ !label. contains( "trusted" ) || label. contains( "not trusted" ) ,
1110+ "Unknown server should not be trusted, instead found: {}" ,
1111+ label
1112+ ) ;
10611113 }
10621114}
0 commit comments