fix(server): satisfy workspace clippy

This commit is contained in:
Bryan Helmkamp 2026-04-19 12:02:19 -04:00
parent a086a694f1
commit 1e6543528f
No known key found for this signature in database
2 changed files with 76 additions and 70 deletions

View file

@ -644,6 +644,7 @@ fn ts(s: &str) -> DateTime<Utc> {
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<i64> {
let duration = Duration::try_from_secs_f64(secs).ok()?;
duration.as_millis().try_into().ok()
}
fn take_summary(
summaries: &mut HashMap<String, StoreRunSummary>,
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<RunStage> {
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 {

View file

@ -2685,7 +2685,7 @@ async fn board_run_metadata(
metadata
}
fn paginate_items<T>(items: Vec<T>, pagination: PaginationParams) -> (Vec<T>, bool) {
fn paginate_items<T>(items: Vec<T>, pagination: &PaginationParams) -> (Vec<T>, 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::<Vec<_>>();
let (data, has_more) = paginate_items(items, pagination);
let (data, has_more) = paginate_items(items, &pagination);
(
StatusCode::OK,
Json(serde_json::json!({