use crate::brain::agent::service::helpers::{assistant_reasoning_stub, empty_reasoning_nudge};
use crate::brain::provider::{ContentBlock, Role};
#[test]
fn no_tools_yet_nudge_encourages_a_tool_call_never_suppresses_it() {
for attempt in 1..=5 {
let n = empty_reasoning_nudge(true, attempt).to_lowercase();
assert!(
n.contains("tool"),
"no-tools nudge must reference calling a tool (attempt {attempt}): {n}"
);
assert!(
!n.contains("do not call more tools")
&& !n.contains("no tool calls")
&& !n.contains("tool results above are sufficient"),
"no-tools nudge must NOT suppress tool calls (attempt {attempt}): {n}"
);
}
}
#[test]
fn tools_ran_nudge_steers_to_writing_the_answer() {
let n = empty_reasoning_nudge(false, 1).to_lowercase();
assert!(n.contains("tool results above are sufficient") || n.contains("write the answer"));
}
#[test]
fn stub_carries_reasoning_as_thinking_block() {
let msg = assistant_reasoning_stub(Some("The user wants the pricing table. I have the data."))
.expect("reasoning present, so a stub must be produced");
assert_eq!(msg.role, Role::Assistant);
match msg.content.first() {
Some(ContentBlock::Thinking { thinking, .. }) => {
assert!(thinking.contains("pricing table"));
}
other => panic!("expected a leading Thinking block, got {other:?}"),
}
}
#[test]
fn nothing_is_appended_when_there_is_no_reasoning() {
for reasoning in [None, Some(""), Some(" \n ")] {
assert!(
assistant_reasoning_stub(reasoning).is_none(),
"must append nothing when reasoning is absent/blank: {reasoning:?}"
);
}
}
use crate::brain::agent::service::helpers::fallback_messages;
use crate::brain::provider::Message;
fn convo(n: usize) -> Vec<Message> {
(0..n).map(|i| Message::user(format!("m{i}"))).collect()
}
#[test]
fn a_fallback_gets_the_conversation_from_before_the_nudging() {
let messages = convo(7);
let trimmed = fallback_messages(Some(3), &messages);
assert_eq!(trimmed.len(), 3, "scaffolding must be dropped");
}
#[test]
fn no_boundary_means_no_trimming() {
let messages = convo(5);
assert_eq!(fallback_messages(None, &messages).len(), 5);
}
#[test]
fn an_out_of_range_boundary_never_loses_history() {
let messages = convo(4);
assert_eq!(fallback_messages(Some(99), &messages).len(), 4);
}
#[test]
fn a_boundary_at_the_end_is_a_no_op() {
let messages = convo(4);
assert_eq!(fallback_messages(Some(4), &messages).len(), 4);
}
#[test]
fn a_zero_boundary_yields_an_empty_conversation() {
let messages = convo(3);
assert!(fallback_messages(Some(0), &messages).is_empty());
}