style: fix rustfmt formatting

Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
Zaki
2026-03-07 18:02:45 -08:00
co-authored by Claude Opus 4.6
parent c41e9c899f
commit 8731bb68ae
3 changed files with 25 additions and 40 deletions
+12 -26
View File
@@ -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);
+1 -4
View File
@@ -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 };
+12 -10
View File
@@ -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")
);
}
}