From 1e6543528f30d470853b4bf11dd86fa6a4bb3918 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sun, 19 Apr 2026 12:02:19 -0400 Subject: [PATCH] fix(server): satisfy workspace clippy --- lib/crates/fabro-server/src/demo/mod.rs | 140 ++++++++++++------------ lib/crates/fabro-server/src/server.rs | 6 +- 2 files changed, 76 insertions(+), 70 deletions(-) diff --git a/lib/crates/fabro-server/src/demo/mod.rs b/lib/crates/fabro-server/src/demo/mod.rs index 609eafe07..3905f02f8 100644 --- a/lib/crates/fabro-server/src/demo/mod.rs +++ b/lib/crates/fabro-server/src/demo/mod.rs @@ -644,6 +644,7 @@ fn ts(s: &str) -> DateTime { mod runs { use std::collections::HashMap; use std::str::FromStr; + use std::time::Duration; use fabro_api::types::*; @@ -675,7 +676,7 @@ mod runs { StoreRunSummary { created_at: ts(created_at), - duration_ms: elapsed_secs.map(|secs| (secs * 1000.0).round() as i64), + duration_ms: elapsed_secs.and_then(duration_ms_from_secs), elapsed_secs, goal: goal.into(), host_repo_path: Some(format!("/demo/{repo_name}")), @@ -699,6 +700,11 @@ mod runs { StatusReason::from_str(reason).ok() } + fn duration_ms_from_secs(secs: f64) -> Option { + let duration = Duration::try_from_secs_f64(secs).ok()?; + duration.as_millis().try_into().ok() + } + fn take_summary( summaries: &mut HashMap, run_id: &str, @@ -952,72 +958,6 @@ mod runs { ] } - #[cfg(test)] - mod tests { - use super::*; - - #[test] - fn summary_parses_known_status_reason_values() { - let summary = summary( - "run-test", - "demo-repo", - "implement", - "Implement", - "Goal", - Some("failed"), - "2026-03-06T14:30:00Z", - Some(1.0), - Some("cancelled"), - None, - None, - &[], - ); - - assert_eq!(summary.status_reason, Some(StatusReason::Cancelled)); - } - - #[test] - fn summary_ignores_unknown_status_reason() { - let summary = summary( - "run-test", - "demo-repo", - "implement", - "Implement", - "Goal", - Some("failed"), - "2026-03-06T14:30:00Z", - Some(1.0), - Some("unexpected_reason"), - None, - None, - &[], - ); - - assert_eq!(summary.status_reason, None); - } - - #[test] - fn summary_derives_title_like_server() { - let goal = format!("## Plan: {}", "a".repeat(120)); - let summary = summary( - "run-test", - "demo-repo", - "implement", - "Implement", - &goal, - Some("running"), - "2026-03-06T14:30:00Z", - Some(1.0), - None, - None, - None, - &[], - ); - - assert_eq!(summary.title, format!("{}...", "a".repeat(97))); - } - } - pub(super) fn stages() -> Vec { vec![ RunStage { @@ -1284,6 +1224,72 @@ mod runs { } }) } + + #[cfg(test)] + mod tests { + use super::*; + + #[test] + fn summary_parses_known_status_reason_values() { + let summary = summary( + "run-test", + "demo-repo", + "implement", + "Implement", + "Goal", + Some("failed"), + "2026-03-06T14:30:00Z", + Some(1.0), + Some("cancelled"), + None, + None, + &[], + ); + + assert_eq!(summary.status_reason, Some(StatusReason::Cancelled)); + } + + #[test] + fn summary_ignores_unknown_status_reason() { + let summary = summary( + "run-test", + "demo-repo", + "implement", + "Implement", + "Goal", + Some("failed"), + "2026-03-06T14:30:00Z", + Some(1.0), + Some("unexpected_reason"), + None, + None, + &[], + ); + + assert_eq!(summary.status_reason, None); + } + + #[test] + fn summary_derives_title_like_server() { + let goal = format!("## Plan: {}", "a".repeat(120)); + let summary = summary( + "run-test", + "demo-repo", + "implement", + "Implement", + &goal, + Some("running"), + "2026-03-06T14:30:00Z", + Some(1.0), + None, + None, + None, + &[], + ); + + assert_eq!(summary.title, format!("{}...", "a".repeat(97))); + } + } } mod billing { diff --git a/lib/crates/fabro-server/src/server.rs b/lib/crates/fabro-server/src/server.rs index 807943106..163dcfdb6 100644 --- a/lib/crates/fabro-server/src/server.rs +++ b/lib/crates/fabro-server/src/server.rs @@ -2685,7 +2685,7 @@ async fn board_run_metadata( metadata } -fn paginate_items(items: Vec, pagination: PaginationParams) -> (Vec, bool) { +fn paginate_items(items: Vec, pagination: &PaginationParams) -> (Vec, bool) { let limit = pagination.limit.clamp(1, 100) as usize; let offset = pagination.offset as usize; let mut data: Vec<_> = items.into_iter().skip(offset).take(limit + 1).collect(); @@ -2718,7 +2718,7 @@ async fn list_board_runs( Some((summary, column)) }) .collect(); - let (page_summaries, has_more) = paginate_items(board_summaries, pagination); + let (page_summaries, has_more) = paginate_items(board_summaries, &pagination); let mut data = Vec::with_capacity(page_summaries.len()); for (summary, column) in page_summaries { @@ -2756,7 +2756,7 @@ async fn list_runs( .into_iter() .map(summary_to_api_run_summary) .collect::>(); - let (data, has_more) = paginate_items(items, pagination); + let (data, has_more) = paginate_items(items, &pagination); ( StatusCode::OK, Json(serde_json::json!({