huskies: merge 629_refactor_migrate_commanddispatch_and_commandcontext_to_services_bundle
This commit is contained in:
@@ -67,11 +67,9 @@ pub(super) async fn handle_incoming_message(
|
||||
}
|
||||
|
||||
let dispatch = CommandDispatch {
|
||||
bot_name: &ctx.services.bot_name,
|
||||
bot_user_id: &ctx.services.bot_user_id,
|
||||
services: &ctx.services,
|
||||
project_root: &ctx.services.project_root,
|
||||
agents: &ctx.services.agents,
|
||||
ambient_rooms: &ctx.services.ambient_rooms,
|
||||
bot_user_id: &ctx.services.bot_user_id,
|
||||
room_id: channel,
|
||||
};
|
||||
|
||||
@@ -483,35 +481,25 @@ async fn handle_llm_message(ctx: &DiscordContext, channel: &str, user: &str, use
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Mutex;
|
||||
use std::collections::HashMap;
|
||||
use tokio::sync::Mutex as TokioMutex;
|
||||
|
||||
fn test_agents() -> Arc<crate::agents::AgentPool> {
|
||||
Arc::new(crate::agents::AgentPool::new_test(3000))
|
||||
}
|
||||
|
||||
fn test_ambient_rooms() -> Arc<Mutex<HashSet<String>>> {
|
||||
Arc::new(Mutex::new(HashSet::new()))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn command_dispatches_through_command_registry() {
|
||||
use crate::chat::commands::{CommandDispatch, try_handle_command};
|
||||
|
||||
let agents = test_agents();
|
||||
let ambient_rooms = test_ambient_rooms();
|
||||
let services = crate::services::Services::new_test(
|
||||
std::path::PathBuf::from("/tmp"),
|
||||
"Huskies".to_string(),
|
||||
);
|
||||
let room_id = "123456789".to_string();
|
||||
|
||||
let bot_name = "Huskies";
|
||||
let synthetic = format!("{bot_name} status");
|
||||
let synthetic = "Huskies status".to_string();
|
||||
|
||||
let dispatch = CommandDispatch {
|
||||
bot_name,
|
||||
services: &services,
|
||||
project_root: &services.project_root,
|
||||
bot_user_id: "discord-bot",
|
||||
project_root: std::path::Path::new("/tmp"),
|
||||
agents: &agents,
|
||||
ambient_rooms: &ambient_rooms,
|
||||
room_id: &room_id,
|
||||
};
|
||||
|
||||
|
||||
@@ -262,11 +262,9 @@ pub(super) async fn on_room_message(
|
||||
// the LLM. All commands are registered in commands.rs — no special-casing
|
||||
// needed here.
|
||||
let dispatch = super::super::commands::CommandDispatch {
|
||||
bot_name: &ctx.services.bot_name,
|
||||
bot_user_id: ctx.matrix_user_id.as_str(),
|
||||
services: &ctx.services,
|
||||
project_root: &effective_root,
|
||||
agents: &ctx.services.agents,
|
||||
ambient_rooms: &ctx.services.ambient_rooms,
|
||||
bot_user_id: ctx.matrix_user_id.as_str(),
|
||||
room_id: &room_id_str,
|
||||
};
|
||||
if let Some((response, response_html)) =
|
||||
|
||||
@@ -108,11 +108,9 @@ pub(super) async fn handle_incoming_message(
|
||||
}
|
||||
|
||||
let dispatch = CommandDispatch {
|
||||
bot_name: &ctx.services.bot_name,
|
||||
bot_user_id: &ctx.services.bot_user_id,
|
||||
services: &ctx.services,
|
||||
project_root: &ctx.services.project_root,
|
||||
agents: &ctx.services.agents,
|
||||
ambient_rooms: &ctx.services.ambient_rooms,
|
||||
bot_user_id: &ctx.services.bot_user_id,
|
||||
room_id: channel,
|
||||
};
|
||||
|
||||
@@ -533,7 +531,6 @@ async fn handle_llm_message(
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Mutex;
|
||||
|
||||
// ── Slash command types ────────────────────────────────────────────
|
||||
|
||||
@@ -611,35 +608,26 @@ mod tests {
|
||||
|
||||
// ── Slash command shares handlers with mention-based commands ──────
|
||||
|
||||
fn test_agents() -> Arc<crate::agents::AgentPool> {
|
||||
Arc::new(crate::agents::AgentPool::new_test(3000))
|
||||
}
|
||||
|
||||
fn test_ambient_rooms() -> Arc<Mutex<HashSet<String>>> {
|
||||
Arc::new(Mutex::new(HashSet::new()))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slash_command_dispatches_through_command_registry() {
|
||||
// Verify that the synthetic message built by the slash handler
|
||||
// correctly dispatches through try_handle_command.
|
||||
use crate::chat::commands::{CommandDispatch, try_handle_command};
|
||||
|
||||
let agents = test_agents();
|
||||
let ambient_rooms = test_ambient_rooms();
|
||||
let services = crate::services::Services::new_test(
|
||||
std::path::PathBuf::from("/tmp"),
|
||||
"Huskies".to_string(),
|
||||
);
|
||||
let room_id = "C01ABCDEF".to_string();
|
||||
|
||||
// Simulate what slash_command_receive does: build a synthetic message.
|
||||
let bot_name = "Huskies";
|
||||
let keyword = slash_command_to_bot_keyword("/huskies-status").unwrap();
|
||||
let synthetic = format!("{bot_name} {keyword}");
|
||||
let synthetic = format!("Huskies {keyword}");
|
||||
|
||||
let dispatch = CommandDispatch {
|
||||
bot_name,
|
||||
services: &services,
|
||||
project_root: &services.project_root,
|
||||
bot_user_id: "slack-bot",
|
||||
project_root: std::path::Path::new("/tmp"),
|
||||
agents: &agents,
|
||||
ambient_rooms: &ambient_rooms,
|
||||
room_id: &room_id,
|
||||
};
|
||||
|
||||
@@ -655,21 +643,20 @@ mod tests {
|
||||
fn slash_command_show_passes_args_through_registry() {
|
||||
use crate::chat::commands::{CommandDispatch, try_handle_command};
|
||||
|
||||
let agents = test_agents();
|
||||
let ambient_rooms = test_ambient_rooms();
|
||||
let services = crate::services::Services::new_test(
|
||||
std::path::PathBuf::from("/tmp"),
|
||||
"Huskies".to_string(),
|
||||
);
|
||||
let room_id = "C01ABCDEF".to_string();
|
||||
|
||||
let bot_name = "Huskies";
|
||||
let keyword = slash_command_to_bot_keyword("/huskies-show").unwrap();
|
||||
// Simulate /huskies-show with text "999"
|
||||
let synthetic = format!("{bot_name} {keyword} 999");
|
||||
let synthetic = format!("Huskies {keyword} 999");
|
||||
|
||||
let dispatch = CommandDispatch {
|
||||
bot_name,
|
||||
services: &services,
|
||||
project_root: &services.project_root,
|
||||
bot_user_id: "slack-bot",
|
||||
project_root: std::path::Path::new("/tmp"),
|
||||
agents: &agents,
|
||||
ambient_rooms: &ambient_rooms,
|
||||
room_id: &room_id,
|
||||
};
|
||||
|
||||
|
||||
@@ -209,11 +209,9 @@ pub async fn slash_command_receive(
|
||||
use crate::chat::commands::{CommandDispatch, try_handle_command};
|
||||
|
||||
let dispatch = CommandDispatch {
|
||||
bot_name: &ctx.services.bot_name,
|
||||
bot_user_id: &ctx.services.bot_user_id,
|
||||
services: &ctx.services,
|
||||
project_root: &ctx.services.project_root,
|
||||
agents: &ctx.services.agents,
|
||||
ambient_rooms: &ctx.services.ambient_rooms,
|
||||
bot_user_id: &ctx.services.bot_user_id,
|
||||
room_id: &payload.channel_id,
|
||||
};
|
||||
|
||||
|
||||
@@ -49,11 +49,9 @@ pub(super) async fn handle_incoming_message(
|
||||
}
|
||||
|
||||
let dispatch = CommandDispatch {
|
||||
bot_name: &ctx.services.bot_name,
|
||||
bot_user_id: &ctx.services.bot_user_id,
|
||||
services: &ctx.services,
|
||||
project_root: &ctx.services.project_root,
|
||||
agents: &ctx.services.agents,
|
||||
ambient_rooms: &ctx.services.ambient_rooms,
|
||||
bot_user_id: &ctx.services.bot_user_id,
|
||||
room_id: sender,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user