From ea061d868d99795bc1823cdff0a0a7f0172b810b Mon Sep 17 00:00:00 2001 From: Dave Date: Fri, 20 Mar 2026 15:36:54 +0000 Subject: [PATCH] storkit: merge 354_story_make_help_command_output_alphabetical --- server/src/matrix/commands/help.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/server/src/matrix/commands/help.rs b/server/src/matrix/commands/help.rs index f8b47da..f31ba81 100644 --- a/server/src/matrix/commands/help.rs +++ b/server/src/matrix/commands/help.rs @@ -4,7 +4,9 @@ use super::{commands, CommandContext}; pub(super) fn handle_help(ctx: &CommandContext) -> Option { 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)); } Some(output) @@ -75,6 +77,26 @@ mod tests { 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] fn help_output_includes_ambient() { let result = try_cmd_addressed("Timmy", "@timmy:homeserver.local", "@timmy help");