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
47 changes: 38 additions & 9 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 EMPTY_PLUGIN_NAME_ERROR: &str = "Plugin name cannot be empty";

// =============================================================================
// Plugin SDK Templates (embedded for standalone CLI operation)
// =============================================================================
Expand Down Expand Up @@ -1063,10 +1065,7 @@ async fn run_list(args: PluginListArgs) -> Result<()> {
}

async fn run_install(args: PluginInstallArgs) -> Result<()> {
// Validate plugin name is not empty (Issue #3700)
if args.name.trim().is_empty() {
bail!("Plugin name cannot be empty. Please provide a valid plugin name.");
}
validate_plugin_name_not_empty(&args.name)?;

let plugins_dir = get_plugins_dir();

Expand Down Expand Up @@ -1264,15 +1263,12 @@ async fn run_show(args: PluginShowArgs) -> Result<()> {
// =============================================================================

async fn run_new(args: PluginNewArgs) -> Result<()> {
validate_plugin_name_not_empty(&args.name)?;

let output_dir = args
.output
.unwrap_or_else(|| std::env::current_dir().unwrap_or_default());

// Validate plugin name
if args.name.is_empty() {
bail!("Plugin name cannot be empty");
}

if !args
.name
.chars()
Expand Down Expand Up @@ -1376,6 +1372,14 @@ async fn run_new(args: PluginNewArgs) -> Result<()> {
Ok(())
}

fn validate_plugin_name_not_empty(name: &str) -> Result<()> {
if name.trim().is_empty() {
bail!("{}", EMPTY_PLUGIN_NAME_ERROR);
}

Ok(())
}

// =============================================================================
// Dev Command Implementation
// =============================================================================
Expand Down Expand Up @@ -2432,6 +2436,31 @@ mod tests {
assert!(args.force, "force should be true");
}

#[tokio::test]
async fn test_plugin_install_and_new_empty_name_errors_match() {
let install_error = run_install(PluginInstallArgs {
name: String::new(),
version: None,
force: false,
})
.await
.expect_err("empty install plugin name should fail");

let new_error = run_new(PluginNewArgs {
name: " ".to_string(),
description: "A test plugin".to_string(),
author: None,
output: None,
advanced: false,
typescript: false,
})
.await
.expect_err("empty new plugin name should fail");

assert_eq!(install_error.to_string(), EMPTY_PLUGIN_NAME_ERROR);
assert_eq!(new_error.to_string(), EMPTY_PLUGIN_NAME_ERROR);
}

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