#![cfg(feature = "mem-repo")]
use clap::{CommandFactory, Parser};
use memstead_cli::cli::{Cli, EXIT_CODES_HELP};
#[test]
fn quiet_is_accepted_in_trailing_position_like_json() {
let cli = Cli::try_parse_from(["memstead", "status", "--quiet", "--json"])
.expect("--quiet must be accepted after the subcommand (global), like --json");
assert!(cli.quiet, "--quiet must take effect in trailing position");
assert!(cli.json, "--json parity baseline");
let cli = Cli::try_parse_from(["memstead", "--quiet", "status"])
.expect("--quiet must still be accepted before the subcommand");
assert!(cli.quiet);
}
#[test]
fn exit_code_table_documents_usage_error_two() {
assert!(
EXIT_CODES_HELP.contains("2 usage error"),
"exit-code table must document the clap usage-error code; got:\n{EXIT_CODES_HELP}",
);
for line in [
"0 success",
"1 generic failure",
"3 not found",
"4 hash mismatch",
"5 validation",
] {
assert!(
EXIT_CODES_HELP.contains(line),
"exit-code `{line}` must survive"
);
}
}
fn mem_sub_help(sub: &str) -> String {
let cmd = Cli::command();
let mem = cmd.find_subcommand("mem").expect("mem subcommand present");
let s = mem
.find_subcommand(sub)
.unwrap_or_else(|| panic!("mem {sub} present"));
let about = s.get_about().map(|a| a.to_string()).unwrap_or_default();
let long = s
.get_long_about()
.map(|a| a.to_string())
.unwrap_or_default();
format!("{about}\n{long}")
}
#[test]
fn mem_unregister_help_documents_incoming_refs_refusal() {
let help = mem_sub_help("unregister");
assert!(
help.contains("MEM_HAS_INCOMING_REFS"),
"unregister help must name the incoming-refs refusal; got:\n{help}",
);
assert!(
help.to_lowercase().contains("remove") && help.to_lowercase().contains("reference"),
"unregister help must state the recovery (remove incoming references); got:\n{help}",
);
}
#[test]
fn workspace_group_help_describes_policy_configuration() {
let cmd = Cli::command();
let ws = cmd
.find_subcommand("workspace")
.expect("workspace subcommand present");
let about = ws.get_about().map(|a| a.to_string()).unwrap_or_default();
let long = ws
.get_long_about()
.map(|a| a.to_string())
.unwrap_or_default();
let help = format!("{about}\n{long}");
assert!(
!help.contains("Read-only"),
"workspace help must not mislabel the group Read-only; got:\n{help}",
);
assert!(
help.to_lowercase().contains("configure") || help.to_lowercase().contains("policy"),
"workspace help must surface that it configures policy; got:\n{help}",
);
}