storkit: merge 402_bug_whatsapp_and_slack_missing_rebuild_command_handler
This commit is contained in:
Generated
+703
-231
File diff suppressed because it is too large
Load Diff
@@ -842,6 +842,27 @@ async fn handle_incoming_message(
|
||||
return;
|
||||
}
|
||||
|
||||
if crate::chat::transport::matrix::rebuild::extract_rebuild_command(
|
||||
message,
|
||||
&ctx.bot_name,
|
||||
&ctx.bot_user_id,
|
||||
)
|
||||
.is_some()
|
||||
{
|
||||
slog!("[slack] Handling rebuild command from {user} in {channel}");
|
||||
let ack = "Rebuilding server… this may take a moment.";
|
||||
let _ = ctx.transport.send_message(channel, ack, "").await;
|
||||
let response = crate::chat::transport::matrix::rebuild::handle_rebuild(
|
||||
&ctx.bot_name,
|
||||
&ctx.project_root,
|
||||
&ctx.agents,
|
||||
)
|
||||
.await;
|
||||
let response = markdown_to_slack(&response);
|
||||
let _ = ctx.transport.send_message(channel, &response, "").await;
|
||||
return;
|
||||
}
|
||||
|
||||
// No command matched — forward to LLM for conversational response.
|
||||
slog!("[slack] No command matched, forwarding to LLM for {user} in {channel}");
|
||||
handle_llm_message(ctx, channel, user, message).await;
|
||||
@@ -1671,4 +1692,37 @@ mod tests {
|
||||
fn slack_empty_string_unchanged() {
|
||||
assert_eq!(markdown_to_slack(""), "");
|
||||
}
|
||||
|
||||
// ── rebuild command extraction ─────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn rebuild_command_extracted_from_slack_message() {
|
||||
let result = crate::chat::transport::matrix::rebuild::extract_rebuild_command(
|
||||
"Storkit rebuild",
|
||||
"Storkit",
|
||||
"slack-bot",
|
||||
);
|
||||
assert!(result.is_some(), "'Storkit rebuild' should be recognised");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rebuild_command_extracted_plain_no_mention() {
|
||||
// Slack slash-command synthetic messages may not include a bot mention.
|
||||
let result = crate::chat::transport::matrix::rebuild::extract_rebuild_command(
|
||||
"rebuild",
|
||||
"Storkit",
|
||||
"slack-bot",
|
||||
);
|
||||
assert!(result.is_some(), "plain 'rebuild' should be recognised");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_rebuild_slack_message_not_extracted() {
|
||||
let result = crate::chat::transport::matrix::rebuild::extract_rebuild_command(
|
||||
"Storkit status",
|
||||
"Storkit",
|
||||
"slack-bot",
|
||||
);
|
||||
assert!(result.is_none(), "'status' should not be recognised as rebuild");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1104,6 +1104,26 @@ async fn handle_incoming_message(ctx: &WhatsAppWebhookContext, sender: &str, mes
|
||||
return;
|
||||
}
|
||||
|
||||
if crate::chat::transport::matrix::rebuild::extract_rebuild_command(
|
||||
message,
|
||||
&ctx.bot_name,
|
||||
&ctx.bot_user_id,
|
||||
)
|
||||
.is_some()
|
||||
{
|
||||
slog!("[whatsapp] Handling rebuild command from {sender}");
|
||||
let ack = "Rebuilding server… this may take a moment.";
|
||||
let _ = ctx.transport.send_message(sender, ack, "").await;
|
||||
let response = crate::chat::transport::matrix::rebuild::handle_rebuild(
|
||||
&ctx.bot_name,
|
||||
&ctx.project_root,
|
||||
&ctx.agents,
|
||||
)
|
||||
.await;
|
||||
let _ = ctx.transport.send_message(sender, &response, "").await;
|
||||
return;
|
||||
}
|
||||
|
||||
// No command matched — forward to LLM for conversational response.
|
||||
slog!("[whatsapp] No command matched, forwarding to LLM for {sender}");
|
||||
handle_llm_message(ctx, sender, message).await;
|
||||
@@ -2018,6 +2038,40 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
// ── rebuild command extraction ─────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn rebuild_command_extracted_from_plain_message() {
|
||||
// WhatsApp messages arrive without a bot mention prefix.
|
||||
// extract_rebuild_command must recognise "rebuild" by itself.
|
||||
let result = crate::chat::transport::matrix::rebuild::extract_rebuild_command(
|
||||
"rebuild",
|
||||
"Timmy",
|
||||
"@timmy:home.local",
|
||||
);
|
||||
assert!(result.is_some(), "plain 'rebuild' should be recognised");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rebuild_command_extracted_with_bot_name_prefix() {
|
||||
let result = crate::chat::transport::matrix::rebuild::extract_rebuild_command(
|
||||
"Timmy rebuild",
|
||||
"Timmy",
|
||||
"@timmy:home.local",
|
||||
);
|
||||
assert!(result.is_some(), "'Timmy rebuild' should be recognised");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_rebuild_whatsapp_message_not_extracted() {
|
||||
let result = crate::chat::transport::matrix::rebuild::extract_rebuild_command(
|
||||
"status",
|
||||
"Timmy",
|
||||
"@timmy:home.local",
|
||||
);
|
||||
assert!(result.is_none(), "'status' should not be recognised as rebuild");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_whatsapp_history_returns_empty_when_file_missing() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user