Skip to content

Commit 3534c02

Browse files
committed
fix(plugin): align empty name errors
1 parent 7954d02 commit 3534c02

2 files changed

Lines changed: 40 additions & 12 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: 38 additions & 9 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 EMPTY_PLUGIN_NAME_ERROR: &str = "Plugin name cannot be empty";
25+
2426
// =============================================================================
2527
// Plugin SDK Templates (embedded for standalone CLI operation)
2628
// =============================================================================
@@ -1063,10 +1065,7 @@ async fn run_list(args: PluginListArgs) -> Result<()> {
10631065
}
10641066

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

10711070
let plugins_dir = get_plugins_dir();
10721071

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

12661265
async fn run_new(args: PluginNewArgs) -> Result<()> {
1266+
validate_plugin_name_not_empty(&args.name)?;
1267+
12671268
let output_dir = args
12681269
.output
12691270
.unwrap_or_else(|| std::env::current_dir().unwrap_or_default());
12701271

1271-
// Validate plugin name
1272-
if args.name.is_empty() {
1273-
bail!("Plugin name cannot be empty");
1274-
}
1275-
12761272
if !args
12771273
.name
12781274
.chars()
@@ -1376,6 +1372,14 @@ async fn run_new(args: PluginNewArgs) -> Result<()> {
13761372
Ok(())
13771373
}
13781374

1375+
fn validate_plugin_name_not_empty(name: &str) -> Result<()> {
1376+
if name.trim().is_empty() {
1377+
bail!("{}", EMPTY_PLUGIN_NAME_ERROR);
1378+
}
1379+
1380+
Ok(())
1381+
}
1382+
13791383
// =============================================================================
13801384
// Dev Command Implementation
13811385
// =============================================================================
@@ -2432,6 +2436,31 @@ mod tests {
24322436
assert!(args.force, "force should be true");
24332437
}
24342438

2439+
#[tokio::test]
2440+
async fn test_plugin_install_and_new_empty_name_errors_match() {
2441+
let install_error = run_install(PluginInstallArgs {
2442+
name: String::new(),
2443+
version: None,
2444+
force: false,
2445+
})
2446+
.await
2447+
.expect_err("empty install plugin name should fail");
2448+
2449+
let new_error = run_new(PluginNewArgs {
2450+
name: " ".to_string(),
2451+
description: "A test plugin".to_string(),
2452+
author: None,
2453+
output: None,
2454+
advanced: false,
2455+
typescript: false,
2456+
})
2457+
.await
2458+
.expect_err("empty new plugin name should fail");
2459+
2460+
assert_eq!(install_error.to_string(), EMPTY_PLUGIN_NAME_ERROR);
2461+
assert_eq!(new_error.to_string(), EMPTY_PLUGIN_NAME_ERROR);
2462+
}
2463+
24352464
// ==========================================================================
24362465
// CLI argument parsing tests - PluginRemoveArgs
24372466
// ==========================================================================

0 commit comments

Comments
 (0)