use clap::{Arg, ArgAction, Command};
use brontes::Error;
fn permissive_editor_root(name: &str) -> Command {
Command::new(name.to_string())
.subcommand_required(false)
.arg_required_else_help(false)
.subcommand(
Command::new("enable")
.arg(Arg::new("config-path").long("config-path"))
.arg(Arg::new("server-name").long("server-name"))
.arg(Arg::new("env").long("env").action(ArgAction::Append))
.arg(Arg::new("log-level").long("log-level"))
.arg(
Arg::new("workspace")
.long("workspace")
.action(ArgAction::SetTrue),
),
)
.subcommand(Command::new("disable"))
.subcommand(Command::new("list"))
.subcommand(Command::new("madeup-leaf"))
}
fn parse_with_leaf(editor: &str, argv: &[&str]) -> clap::ArgMatches {
let cmd = permissive_editor_root(editor);
let mut full: Vec<&str> = vec![editor];
full.extend_from_slice(argv);
cmd.try_get_matches_from(full).expect("parses")
}
#[test]
fn claude_run_rejects_unknown_leaf_with_editor_specific_message() {
let matches = parse_with_leaf("claude", &["madeup-leaf"]);
let cli = Command::new("hostc").subcommand(brontes::command(None));
let result = brontes::__test_internal::editor_run("claude", &matches, &cli);
let err = result.expect_err("unknown leaf must error");
let msg = err.to_string();
assert!(
msg.contains("unknown mcp claude subcommand") && msg.contains("madeup-leaf"),
"got: {msg}"
);
assert!(matches!(err, Error::Config(_)));
}
#[test]
fn claude_run_rejects_missing_leaf_with_editor_specific_message() {
let matches = parse_with_leaf("claude", &[]);
let cli = Command::new("hostc").subcommand(brontes::command(None));
let result = brontes::__test_internal::editor_run("claude", &matches, &cli);
let err = result.expect_err("missing leaf must error");
assert!(
err.to_string()
.contains("no mcp claude subcommand selected")
);
}
#[test]
fn cursor_run_rejects_unknown_leaf_with_editor_specific_message() {
let matches = parse_with_leaf("cursor", &["madeup-leaf"]);
let cli = Command::new("hostc").subcommand(brontes::command(None));
let err = brontes::__test_internal::editor_run("cursor", &matches, &cli)
.expect_err("unknown leaf must error");
let msg = err.to_string();
assert!(
msg.contains("unknown mcp cursor subcommand") && msg.contains("madeup-leaf"),
"got: {msg}"
);
}
#[test]
fn cursor_run_rejects_missing_leaf_with_editor_specific_message() {
let matches = parse_with_leaf("cursor", &[]);
let cli = Command::new("hostc").subcommand(brontes::command(None));
let err = brontes::__test_internal::editor_run("cursor", &matches, &cli)
.expect_err("missing leaf must error");
assert!(
err.to_string()
.contains("no mcp cursor subcommand selected")
);
}
#[test]
fn vscode_run_rejects_unknown_leaf_with_editor_specific_message() {
let matches = parse_with_leaf("vscode", &["madeup-leaf"]);
let cli = Command::new("hostc").subcommand(brontes::command(None));
let err = brontes::__test_internal::editor_run("vscode", &matches, &cli)
.expect_err("unknown leaf must error");
let msg = err.to_string();
assert!(
msg.contains("unknown mcp vscode subcommand") && msg.contains("madeup-leaf"),
"got: {msg}"
);
}
#[test]
fn vscode_run_rejects_missing_leaf_with_editor_specific_message() {
let matches = parse_with_leaf("vscode", &[]);
let cli = Command::new("hostc").subcommand(brontes::command(None));
let err = brontes::__test_internal::editor_run("vscode", &matches, &cli)
.expect_err("missing leaf must error");
assert!(
err.to_string()
.contains("no mcp vscode subcommand selected")
);
}
#[test]
fn zed_run_rejects_unknown_leaf_with_editor_specific_message() {
let matches = parse_with_leaf("zed", &["madeup-leaf"]);
let cli = Command::new("hostc").subcommand(brontes::command(None));
let err = brontes::__test_internal::editor_run("zed", &matches, &cli)
.expect_err("unknown leaf must error");
let msg = err.to_string();
assert!(
msg.contains("unknown mcp zed subcommand") && msg.contains("madeup-leaf"),
"got: {msg}"
);
}
#[test]
fn zed_run_rejects_missing_leaf_with_editor_specific_message() {
let matches = parse_with_leaf("zed", &[]);
let cli = Command::new("hostc").subcommand(brontes::command(None));
let err = brontes::__test_internal::editor_run("zed", &matches, &cli)
.expect_err("missing leaf must error");
assert!(err.to_string().contains("no mcp zed subcommand selected"));
}
#[test]
fn editor_run_helper_rejects_unrecognized_editor_name() {
let matches = parse_with_leaf("madeup", &["enable"]);
let cli = Command::new("hostc").subcommand(brontes::command(None));
let err = brontes::__test_internal::editor_run("madeup-editor", &matches, &cli)
.expect_err("unknown editor must error");
let msg = err.to_string();
assert!(
msg.contains("editor_run: unknown editor") && msg.contains("madeup-editor"),
"got: {msg}"
);
}