storkit: merge 354_story_make_help_command_output_alphabetical

This commit is contained in:
Dave
2026-03-20 15:36:54 +00:00
parent 6a03ca725e
commit ea061d868d

View File

@@ -4,7 +4,9 @@ use super::{commands, CommandContext};
pub(super) fn handle_help(ctx: &CommandContext) -> Option<String> { pub(super) fn handle_help(ctx: &CommandContext) -> Option<String> {
let mut output = format!("**{} Commands**\n\n", ctx.bot_name); let mut output = format!("**{} Commands**\n\n", ctx.bot_name);
for cmd in commands() { let mut sorted: Vec<_> = commands().iter().collect();
sorted.sort_by_key(|c| c.name);
for cmd in sorted {
output.push_str(&format!("- **{}** — {}\n", cmd.name, cmd.description)); output.push_str(&format!("- **{}** — {}\n", cmd.name, cmd.description));
} }
Some(output) Some(output)
@@ -75,6 +77,26 @@ mod tests {
assert!(output.contains("status"), "help should list status command: {output}"); assert!(output.contains("status"), "help should list status command: {output}");
} }
#[test]
fn help_output_is_alphabetical() {
let result = try_cmd_addressed("Timmy", "@timmy:homeserver.local", "@timmy help");
let output = result.unwrap();
// Search for **name** (bold markdown) to avoid substring matches in descriptions.
let mut positions: Vec<(usize, &str)> = commands()
.iter()
.map(|c| {
let marker = format!("**{}**", c.name);
let pos = output.find(&marker).expect("command must appear in help as **name**");
(pos, c.name)
})
.collect();
positions.sort_by_key(|(pos, _)| *pos);
let names_in_order: Vec<&str> = positions.iter().map(|(_, n)| *n).collect();
let mut sorted = names_in_order.clone();
sorted.sort();
assert_eq!(names_in_order, sorted, "commands must appear in alphabetical order");
}
#[test] #[test]
fn help_output_includes_ambient() { fn help_output_includes_ambient() {
let result = try_cmd_addressed("Timmy", "@timmy:homeserver.local", "@timmy help"); let result = try_cmd_addressed("Timmy", "@timmy:homeserver.local", "@timmy help");