Skip to content

Commit 0ce09b4

Browse files
authored
ci fix (#2658)
1 parent 334cbd0 commit 0ce09b4

File tree

5 files changed

+94
-42
lines changed

5 files changed

+94
-42
lines changed

crates/chat-cli/src/cli/agent/mod.rs

Lines changed: 83 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

crates/chat-cli/src/cli/chat/conversation.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ impl ConversationState {
135135
current_model_id: Option<String>,
136136
os: &Os,
137137
) -> Self {
138-
139138
let model = if let Some(model_id) = current_model_id {
140139
match get_model_info(&model_id, os).await {
141140
Ok(info) => Some(info),
@@ -1279,5 +1278,4 @@ mod tests {
12791278
conversation.set_next_user_message(i.to_string()).await;
12801279
}
12811280
}
1282-
12831281
}

crates/chat-cli/src/cli/chat/tools/custom_tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use crate::mcp_client::{
3535
ToolCallResult,
3636
};
3737
use crate::os::Os;
38-
use crate::util::pattern_matching::matches_any_pattern;
3938
use crate::util::MCP_SERVER_TOOL_DELIMITER;
39+
use crate::util::pattern_matching::matches_any_pattern;
4040

4141
// TODO: support http transport type
4242
#[derive(Clone, Serialize, Deserialize, Debug, Eq, PartialEq, JsonSchema)]

crates/chat-cli/src/cli/chat/tools/knowledge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use crate::cli::agent::{
1919
};
2020
use crate::database::settings::Setting;
2121
use crate::os::Os;
22-
use crate::util::pattern_matching::matches_any_pattern;
2322
use crate::util::knowledge_store::KnowledgeStore;
23+
use crate::util::pattern_matching::matches_any_pattern;
2424

2525
/// The Knowledge tool allows storing and retrieving information across chat sessions.
2626
/// It provides semantic search capabilities for files, directories, and text content.

crates/chat-cli/src/util/pattern_matching.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::HashSet;
2+
23
use globset::Glob;
34

45
/// Check if a string matches any pattern in a set of patterns
@@ -8,28 +9,29 @@ pub fn matches_any_pattern(patterns: &HashSet<String>, text: &str) -> bool {
89
if pattern == text {
910
return true;
1011
}
11-
12+
1213
// Glob pattern match if contains wildcards
1314
if pattern.contains('*') || pattern.contains('?') {
1415
if let Ok(glob) = Glob::new(pattern) {
1516
return glob.compile_matcher().is_match(text);
1617
}
1718
}
18-
19+
1920
false
2021
})
2122
}
2223

2324
#[cfg(test)]
2425
mod tests {
25-
use super::*;
2626
use std::collections::HashSet;
2727

28+
use super::*;
29+
2830
#[test]
2931
fn test_exact_match() {
3032
let mut patterns = HashSet::new();
3133
patterns.insert("fs_read".to_string());
32-
34+
3335
assert!(matches_any_pattern(&patterns, "fs_read"));
3436
assert!(!matches_any_pattern(&patterns, "fs_write"));
3537
}
@@ -38,7 +40,7 @@ mod tests {
3840
fn test_wildcard_patterns() {
3941
let mut patterns = HashSet::new();
4042
patterns.insert("fs_*".to_string());
41-
43+
4244
assert!(matches_any_pattern(&patterns, "fs_read"));
4345
assert!(matches_any_pattern(&patterns, "fs_write"));
4446
assert!(!matches_any_pattern(&patterns, "execute_bash"));
@@ -48,7 +50,7 @@ mod tests {
4850
fn test_mcp_patterns() {
4951
let mut patterns = HashSet::new();
5052
patterns.insert("@mcp-server/*".to_string());
51-
53+
5254
assert!(matches_any_pattern(&patterns, "@mcp-server/tool1"));
5355
assert!(matches_any_pattern(&patterns, "@mcp-server/tool2"));
5456
assert!(!matches_any_pattern(&patterns, "@other-server/tool"));
@@ -58,7 +60,7 @@ mod tests {
5860
fn test_question_mark_wildcard() {
5961
let mut patterns = HashSet::new();
6062
patterns.insert("fs_?ead".to_string());
61-
63+
6264
assert!(matches_any_pattern(&patterns, "fs_read"));
6365
assert!(!matches_any_pattern(&patterns, "fs_write"));
6466
}

0 commit comments

Comments
 (0)