use crate::agent::tools::todo::TodoItem;
const MAX_OUTSTANDING_TITLES: usize = 10;
pub fn residual_block(board: &[TodoItem]) -> Option<String> {
if board.is_empty() {
return None;
}
let mut out = format!("Objectives still outstanding ({}):", board.len());
let shown = board.len().min(MAX_OUTSTANDING_TITLES);
for t in &board[..shown] {
out.push_str("\n- ");
out.push_str(t.content.trim());
}
if board.len() > MAX_OUTSTANDING_TITLES {
out.push_str(&format!("\n+{} more", board.len() - MAX_OUTSTANDING_TITLES));
}
Some(out)
}
#[cfg(test)]
mod tests {
use super::*;
fn item(content: &str, status: &str, priority: &str) -> TodoItem {
TodoItem {
content: content.into(),
status: status.into(),
priority: priority.into(),
}
}
#[test]
fn empty_board_is_none_so_the_notice_is_unchanged() {
assert!(residual_block(&[]).is_none());
}
#[test]
fn lists_outstanding_count_and_titles() {
let block = residual_block(&[
item("ship the residual handoff", "in_progress", "high"),
item("wire the digest reuse", "open", "normal"),
])
.expect("non-empty board yields a block");
assert!(
block.contains("Objectives still outstanding (2):"),
"headline names the count: {block}"
);
assert!(
block.contains("- ship the residual handoff"),
"first title listed: {block}"
);
assert!(
block.contains("- wire the digest reuse"),
"second title listed: {block}"
);
}
#[test]
fn caps_titles_at_ten_with_more_count() {
let board: Vec<TodoItem> = (0..12)
.map(|i| item(&format!("task {i}"), "open", "normal"))
.collect();
let block = residual_block(&board).expect("non-empty board yields a block");
assert!(
block.contains("Objectives still outstanding (12):"),
"{block}"
);
assert!(block.contains("- task 0"), "first shown: {block}");
assert!(block.contains("- task 9"), "tenth shown: {block}");
assert!(!block.contains("- task 10"), "eleventh elided: {block}");
assert!(block.contains("+2 more"), "overflow summarized: {block}");
}
#[test]
fn trims_title_whitespace() {
let block = residual_block(&[item(" padded title ", "open", "low")])
.expect("non-empty board yields a block");
assert!(block.contains("- padded title"), "trimmed: {block}");
assert!(!block.contains("padded title "), "no trailing ws: {block}");
}
}