Skip to content

Commit 97ff33a

Browse files
committed
fix(plugin): emit json for list filter conflict
1 parent 7954d02 commit 97ff33a

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
#[cfg(test)]
44
mod tests {
55
use crate::agent_cmd::cli::{CopyArgs, ExportArgs};
6-
use crate::agent_cmd::loader::{
7-
load_builtin_agents, parse_frontmatter, read_file_with_encoding,
8-
};
6+
use crate::agent_cmd::loader::{load_builtin_agents, parse_frontmatter};
97
use crate::agent_cmd::types::AgentMode;
8+
use crate::utils::file::read_file_with_encoding;
109

1110
#[test]
1211
fn test_read_file_with_utf8() {

src/cortex-cli/src/plugin_cmd.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use std::process::{Command, Stdio};
2121
use std::sync::mpsc;
2222
use std::time::Duration;
2323

24+
const PLUGIN_LIST_FILTER_CONFLICT: &str = "Cannot specify both --enabled and --disabled. Choose one filter or use neither for all plugins.";
25+
2426
// =============================================================================
2527
// Plugin SDK Templates (embedded for standalone CLI operation)
2628
// =============================================================================
@@ -959,9 +961,14 @@ impl PluginCli {
959961
async fn run_list(args: PluginListArgs) -> Result<()> {
960962
// Validate mutually exclusive flags
961963
if args.enabled && args.disabled {
962-
bail!(
963-
"Cannot specify both --enabled and --disabled. Choose one filter or use neither for all plugins."
964-
);
964+
if args.json {
965+
println!(
966+
"{}",
967+
serde_json::to_string_pretty(&plugin_list_filter_conflict_error())?
968+
);
969+
std::process::exit(1);
970+
}
971+
bail!(PLUGIN_LIST_FILTER_CONFLICT);
965972
}
966973

967974
let plugins_dir = get_plugins_dir();
@@ -1062,6 +1069,12 @@ async fn run_list(args: PluginListArgs) -> Result<()> {
10621069
Ok(())
10631070
}
10641071

1072+
fn plugin_list_filter_conflict_error() -> serde_json::Value {
1073+
serde_json::json!({
1074+
"error": PLUGIN_LIST_FILTER_CONFLICT
1075+
})
1076+
}
1077+
10651078
async fn run_install(args: PluginInstallArgs) -> Result<()> {
10661079
// Validate plugin name is not empty (Issue #3700)
10671080
if args.name.trim().is_empty() {
@@ -2370,6 +2383,18 @@ mod tests {
23702383
assert!(args.disabled, "disabled filter should be true when set");
23712384
}
23722385

2386+
#[test]
2387+
fn test_plugin_list_filter_conflict_error_serializes_as_json() {
2388+
let error = plugin_list_filter_conflict_error();
2389+
let json = serde_json::to_string(&error).expect("should serialize conflict error");
2390+
2391+
assert!(json.contains("error"), "JSON should contain error field");
2392+
assert!(
2393+
json.contains(PLUGIN_LIST_FILTER_CONFLICT),
2394+
"JSON should contain conflict message"
2395+
);
2396+
}
2397+
23732398
// ==========================================================================
23742399
// CLI argument parsing tests - PluginInstallArgs
23752400
// ==========================================================================

0 commit comments

Comments
 (0)