From 8731bb68aee6781eebaabbd0a60b2212e5c05337 Mon Sep 17 00:00:00 2001 From: Zaki Date: Sat, 7 Mar 2026 18:02:45 -0800 Subject: [PATCH] style: fix rustfmt formatting Co-Authored-By: Claude Opus 4.6 --- src/channels/web/handlers/webhooks.rs | 38 +++++++++------------------ src/channels/web/server.rs | 5 +--- src/tools/builtin/time.rs | 22 +++++++++------- 3 files changed, 25 insertions(+), 40 deletions(-) diff --git a/src/channels/web/handlers/webhooks.rs b/src/channels/web/handlers/webhooks.rs index a9bfb8a4..95c4115b 100644 --- a/src/channels/web/handlers/webhooks.rs +++ b/src/channels/web/handlers/webhooks.rs @@ -42,9 +42,7 @@ pub async fn webhook_trigger_handler( return false; } match &r.trigger { - Trigger::Webhook { - path: Some(wp), .. - } => *wp == path, + Trigger::Webhook { path: Some(wp), .. } => *wp == path, Trigger::Webhook { path: None, .. } => path == r.id.to_string(), _ => false, } @@ -66,12 +64,11 @@ pub async fn webhook_trigger_handler( .and_then(|v| v.to_str().ok()) .unwrap_or(""); - if !bool::from( - provided_secret - .as_bytes() - .ct_eq(expected_secret.as_bytes()), - ) { - return Err((StatusCode::UNAUTHORIZED, "Invalid webhook secret".to_string())); + if !bool::from(provided_secret.as_bytes().ct_eq(expected_secret.as_bytes())) { + return Err(( + StatusCode::UNAUTHORIZED, + "Invalid webhook secret".to_string(), + )); } } @@ -89,8 +86,7 @@ pub async fn webhook_trigger_handler( routine.id, chrono::Utc::now().timestamp_millis() ); - let msg = - IncomingMessage::new("gateway", &routine.user_id, content).with_thread(thread_id); + let msg = IncomingMessage::new("gateway", &routine.user_id, content).with_thread(thread_id); let tx_guard = state.msg_tx.read().await; let tx = tx_guard.as_ref().ok_or(( @@ -123,21 +119,15 @@ mod tests { // Matching secret let provided = "my-secret-token"; - assert!(bool::from( - provided.as_bytes().ct_eq(expected.as_bytes()) - )); + assert!(bool::from(provided.as_bytes().ct_eq(expected.as_bytes()))); // Wrong secret let wrong = "wrong-secret"; - assert!(!bool::from( - wrong.as_bytes().ct_eq(expected.as_bytes()) - )); + assert!(!bool::from(wrong.as_bytes().ct_eq(expected.as_bytes()))); // Empty secret let empty = ""; - assert!(!bool::from( - empty.as_bytes().ct_eq(expected.as_bytes()) - )); + assert!(!bool::from(empty.as_bytes().ct_eq(expected.as_bytes()))); } /// Verify that webhook path matching logic works for both explicit paths @@ -177,18 +167,14 @@ mod tests { // Explicit path match let matches_explicit = match &routine.trigger { - Trigger::Webhook { - path: Some(wp), .. - } => *wp == "my-hook", + Trigger::Webhook { path: Some(wp), .. } => *wp == "my-hook", _ => false, }; assert!(matches_explicit); // Should NOT match wrong path let matches_wrong = match &routine.trigger { - Trigger::Webhook { - path: Some(wp), .. - } => *wp == "other-hook", + Trigger::Webhook { path: Some(wp), .. } => *wp == "other-hook", _ => false, }; assert!(!matches_wrong); diff --git a/src/channels/web/server.rs b/src/channels/web/server.rs index 5eca6a37..74a0a065 100644 --- a/src/channels/web/server.rs +++ b/src/channels/web/server.rs @@ -202,10 +202,7 @@ pub async fn start_server( let public = Router::new() .route("/api/health", get(health_handler)) .route("/oauth/callback", get(oauth_callback_handler)) - .route( - "/api/webhooks/{path}", - post(webhook_trigger_handler), - ); + .route("/api/webhooks/{path}", post(webhook_trigger_handler)); // Protected routes (require auth) let auth_state = AuthState { token: auth_token }; diff --git a/src/tools/builtin/time.rs b/src/tools/builtin/time.rs index 85b46f0c..d81f8fc8 100644 --- a/src/tools/builtin/time.rs +++ b/src/tools/builtin/time.rs @@ -32,15 +32,12 @@ fn parse_input_timestamp( for fmt in &["%Y-%m-%dT%H:%M:%S", "%Y-%m-%d %H:%M:%S"] { if let Ok(naive) = chrono::NaiveDateTime::parse_from_str(input, fmt) { let tz = default_tz.unwrap_or(Tz::UTC); - let local = naive - .and_local_timezone(tz) - .single() - .ok_or_else(|| { - ToolError::InvalidParameters(format!( - "Ambiguous or invalid datetime '{}' in timezone '{}'", - input, tz - )) - })?; + let local = naive.and_local_timezone(tz).single().ok_or_else(|| { + ToolError::InvalidParameters(format!( + "Ambiguous or invalid datetime '{}' in timezone '{}'", + input, tz + )) + })?; return Ok(local.fixed_offset()); } } @@ -429,6 +426,11 @@ mod tests { .execute(json!({"operation": "explode"}), &test_ctx()) .await; assert!(result.is_err()); - assert!(result.unwrap_err().to_string().contains("unknown operation")); + assert!( + result + .unwrap_err() + .to_string() + .contains("unknown operation") + ); } }