huskies: merge 483_bug_timer_slash_command_not_wired_up_in_web_ui
This commit is contained in:
@@ -79,6 +79,7 @@ async fn dispatch_command(
|
|||||||
"start" => dispatch_start(args, project_root, agents).await,
|
"start" => dispatch_start(args, project_root, agents).await,
|
||||||
"delete" => dispatch_delete(args, project_root, agents).await,
|
"delete" => dispatch_delete(args, project_root, agents).await,
|
||||||
"rebuild" => dispatch_rebuild(project_root, agents).await,
|
"rebuild" => dispatch_rebuild(project_root, agents).await,
|
||||||
|
"timer" => dispatch_timer(args, project_root).await,
|
||||||
// All other commands go through the synchronous command registry.
|
// All other commands go through the synchronous command registry.
|
||||||
_ => dispatch_sync(cmd, args, project_root, agents),
|
_ => dispatch_sync(cmd, args, project_root, agents),
|
||||||
}
|
}
|
||||||
@@ -186,6 +187,24 @@ async fn dispatch_rebuild(
|
|||||||
crate::chat::transport::matrix::rebuild::handle_rebuild("web-ui", project_root, agents).await
|
crate::chat::transport::matrix::rebuild::handle_rebuild("web-ui", project_root, agents).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn dispatch_timer(args: &str, project_root: &std::path::Path) -> String {
|
||||||
|
// Re-use the existing parser by constructing a synthetic message that
|
||||||
|
// looks like a bot-addressed timer command.
|
||||||
|
let synthetic = format!("__web_ui__ timer {args}");
|
||||||
|
let timer_cmd = match crate::chat::timer::extract_timer_command(
|
||||||
|
&synthetic,
|
||||||
|
"__web_ui__",
|
||||||
|
"@__web_ui__:localhost",
|
||||||
|
) {
|
||||||
|
Some(cmd) => cmd,
|
||||||
|
None => return "Usage: `/timer list`, `/timer <number> <HH:MM>`, or `/timer cancel <number>`".to_string(),
|
||||||
|
};
|
||||||
|
let store = crate::chat::timer::TimerStore::load(
|
||||||
|
project_root.join(".huskies").join("timers.json"),
|
||||||
|
);
|
||||||
|
crate::chat::timer::handle_timer_command(timer_cmd, &store, project_root).await
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Tests
|
// Tests
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -287,6 +306,24 @@ mod tests {
|
|||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn timer_list_returns_response_not_unknown_command() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let api = test_api(&dir);
|
||||||
|
let body = BotCommandRequest {
|
||||||
|
command: "timer".to_string(),
|
||||||
|
args: "list".to_string(),
|
||||||
|
};
|
||||||
|
let result = api.run_command(Json(body)).await;
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let resp = result.unwrap().0;
|
||||||
|
assert!(
|
||||||
|
!resp.response.contains("Unknown command"),
|
||||||
|
"timer list should not return 'Unknown command': {}",
|
||||||
|
resp.response
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn run_command_requires_project_root() {
|
async fn run_command_requires_project_root() {
|
||||||
// Create a context with no project root set.
|
// Create a context with no project root set.
|
||||||
|
|||||||
Reference in New Issue
Block a user