Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/cortex-cli/src/agent_cmd/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
#[cfg(test)]
mod tests {
use crate::agent_cmd::cli::{CopyArgs, ExportArgs};
use crate::agent_cmd::loader::{
load_builtin_agents, parse_frontmatter, read_file_with_encoding,
};
use crate::agent_cmd::loader::{load_builtin_agents, parse_frontmatter};
use crate::agent_cmd::types::AgentMode;
use crate::utils::file::read_file_with_encoding;

#[test]
fn test_read_file_with_utf8() {
Expand Down
31 changes: 28 additions & 3 deletions src/cortex-cli/src/plugin_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use std::process::{Command, Stdio};
use std::sync::mpsc;
use std::time::Duration;

const PLUGIN_LIST_FILTER_CONFLICT: &str = "Cannot specify both --enabled and --disabled. Choose one filter or use neither for all plugins.";

// =============================================================================
// Plugin SDK Templates (embedded for standalone CLI operation)
// =============================================================================
Expand Down Expand Up @@ -959,9 +961,14 @@ impl PluginCli {
async fn run_list(args: PluginListArgs) -> Result<()> {
// Validate mutually exclusive flags
if args.enabled && args.disabled {
bail!(
"Cannot specify both --enabled and --disabled. Choose one filter or use neither for all plugins."
);
if args.json {
println!(
"{}",
serde_json::to_string_pretty(&plugin_list_filter_conflict_error())?
);
std::process::exit(1);
}
bail!(PLUGIN_LIST_FILTER_CONFLICT);
}

let plugins_dir = get_plugins_dir();
Expand Down Expand Up @@ -1062,6 +1069,12 @@ async fn run_list(args: PluginListArgs) -> Result<()> {
Ok(())
}

fn plugin_list_filter_conflict_error() -> serde_json::Value {
serde_json::json!({
"error": PLUGIN_LIST_FILTER_CONFLICT
})
}

async fn run_install(args: PluginInstallArgs) -> Result<()> {
// Validate plugin name is not empty (Issue #3700)
if args.name.trim().is_empty() {
Expand Down Expand Up @@ -2370,6 +2383,18 @@ mod tests {
assert!(args.disabled, "disabled filter should be true when set");
}

#[test]
fn test_plugin_list_filter_conflict_error_serializes_as_json() {
let error = plugin_list_filter_conflict_error();
let json = serde_json::to_string(&error).expect("should serialize conflict error");

assert!(json.contains("error"), "JSON should contain error field");
assert!(
json.contains(PLUGIN_LIST_FILTER_CONFLICT),
"JSON should contain conflict message"
);
}

// ==========================================================================
// CLI argument parsing tests - PluginInstallArgs
// ==========================================================================
Expand Down