Skip to content

Commit f5af842

Browse files
committed
fix: handle agent filter wildcard
1 parent 7954d02 commit f5af842

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/cortex-cli/src/agent_cmd/utils.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ pub fn matches_pattern(name: &str, pattern: &str) -> bool {
7272
let pattern = pattern.to_lowercase();
7373
let name = name.to_lowercase();
7474

75+
if pattern == "*" {
76+
return true;
77+
}
78+
7579
// Handle simple glob patterns
7680
if pattern.starts_with('*') && pattern.ends_with('*') {
7781
// *pattern* - contains
@@ -212,8 +216,8 @@ mod tests {
212216
assert!(matches_pattern("", ""));
213217
// Empty pattern doesn't match non-empty name
214218
assert!(!matches_pattern("anything", ""));
215-
// Note: Single "*" glob pattern has a bug in production code that causes a panic,
216-
// so we don't test that edge case here. Use "*pattern" or "pattern*" instead.
219+
// A single "*" matches any agent name.
220+
assert!(matches_pattern("anything", "*"));
217221
}
218222

219223
// ===========================================
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use std::process::Command;
2+
3+
#[test]
4+
fn agent_list_single_wildcard_filter_does_not_panic() {
5+
let home = tempfile::tempdir().expect("temp home");
6+
let output = Command::new(env!("CARGO_BIN_EXE_Cortex"))
7+
.args(["agent", "list", "--filter", "*", "--json"])
8+
.env("HOME", home.path())
9+
.env("USERPROFILE", home.path())
10+
.output()
11+
.expect("run Cortex agent list");
12+
13+
let stdout = String::from_utf8_lossy(&output.stdout);
14+
let stderr = String::from_utf8_lossy(&output.stderr);
15+
16+
assert!(
17+
output.status.success(),
18+
"agent list should accept a single wildcard filter\nstdout:\n{stdout}\nstderr:\n{stderr}"
19+
);
20+
serde_json::from_slice::<serde_json::Value>(&output.stdout)
21+
.expect("agent list --json should emit valid JSON");
22+
assert!(
23+
!stderr.contains("panicked"),
24+
"single wildcard filter should not panic\nstdout:\n{stdout}\nstderr:\n{stderr}"
25+
);
26+
}

0 commit comments

Comments
 (0)