From ff1de3ca62ec18cec84580fc1e12c58f426ac129 Mon Sep 17 00:00:00 2001 From: Simon Klee Date: Wed, 18 Nov 2026 21:07:39 +0100 Subject: [PATCH] test(cli-rs): check mini history on both sides of its limit appended_and_loaded_histories_keep_the_same_recent_prompts exercises both public entry points. Whitespace and adjacent duplicates do not consume history slots; nonadjacent repeats survive. Check the actual sequence below, at and above 200 entries for both append and load. --- .../cli-rs/crates/mini/src/prompt/history.rs | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/packages/cli-rs/crates/mini/src/prompt/history.rs b/packages/cli-rs/crates/mini/src/prompt/history.rs index 1729fcf9326..f0736062898 100644 --- a/packages/cli-rs/crates/mini/src/prompt/history.rs +++ b/packages/cli-rs/crates/mini/src/prompt/history.rs @@ -77,26 +77,16 @@ impl History { mod tests { use super::*; - fn texts(history: &History) -> Vec<&str> { - history.items.iter().map(|item| item.text.as_str()).collect() - } - #[test] - fn entries_drop_empties_and_adjacent_repeats() { - let history = History::new(&[ - RunPrompt::text("a"), - RunPrompt::text(" "), - RunPrompt::text("a"), - RunPrompt::text("b"), - RunPrompt::text("a"), - ]); - assert_eq!(texts(&history), ["a", "b", "a"]); - assert_eq!(texts(&history.push(&RunPrompt::text("a"))), ["a", "b", "a"]); - assert_eq!(texts(&history.push(&RunPrompt::text("c"))), ["a", "b", "a", "c"]); - let many: Vec = (0..205).map(|i| RunPrompt::text(i.to_string())).collect(); - let history = History::new(&many); - assert_eq!(history.items.len(), 200); - assert_eq!(history.items[0].text, "5"); + fn appended_and_loaded_histories_keep_the_same_recent_prompts() { + for n in [0usize, 1, 2, 3, 199, 200, 201, 205] { + let distinct: Vec<_> = (0..n).map(|i| RunPrompt::text((i % 3).to_string())).collect(); + let noisy: Vec<_> = distinct.iter().flat_map(|p| [p.clone(), RunPrompt::text(" "), p.clone()]).collect(); + let appended = noisy.iter().fold(History::default(), |history, prompt| history.push(prompt)); + let expected = &distinct[n.saturating_sub(200)..]; + assert_eq!(History::new(&noisy).items, expected, "load {n}"); + assert_eq!(appended.items, expected, "append {n}"); + } } #[test]