Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion crates/gitlawb-node/src/api/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,17 @@ pub async fn create_task(
Ok((StatusCode::CREATED, Json(task_to_json(&task))))
}

const MAX_TASK_LIMIT: i64 = 200;

/// GET /api/v1/tasks
pub async fn list_tasks(
State(state): State<AppState>,
Query(q): Query<ListTasksQuery>,
) -> Result<Json<Value>, (StatusCode, Json<Value>)> {
let limit = q.limit.clamp(1, MAX_TASK_LIMIT);
let tasks = state
.db
.list_tasks(q.status.as_deref(), q.assignee_did.as_deref(), q.limit)
.list_tasks(q.status.as_deref(), q.assignee_did.as_deref(), limit)
.await
.map_err(|e| {
(
Expand Down Expand Up @@ -297,3 +300,17 @@ pub async fn fail_task(
});
Ok(Json(task_to_json(&task)))
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_list_tasks_query_limit_clamping() {
assert_eq!((-1i64).clamp(1, MAX_TASK_LIMIT), 1);
assert_eq!((0i64).clamp(1, MAX_TASK_LIMIT), 1);
assert_eq!((50i64).clamp(1, MAX_TASK_LIMIT), 50);
assert_eq!((500i64).clamp(1, MAX_TASK_LIMIT), 200);
assert_eq!(i64::MAX.clamp(1, MAX_TASK_LIMIT), 200);
Comment on lines +309 to +314

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test duplicates clamp implementation

The test invokes i64::clamp directly instead of the production limit-normalization path, so it remains green if list_tasks stops enforcing the intended bounds and does not provide effective regression coverage.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

}
}