use super::{BlockKind, Transcript, apply_event};
use saya_agent::AgentEvent;
#[test]
fn reasoning_text_is_silent_when_thinking_is_off() {
let mut t = Transcript::new();
apply_event(
&mut t,
AgentEvent::reasoning_text("I considered the time column"),
false,
);
assert!(
t.blocks().is_empty(),
"reasoning must not reach the transcript when thinking is off: {:?}",
t.blocks()
);
apply_event(&mut t, AgentEvent::assistant_text("the answer"), false);
apply_event(
&mut t,
AgentEvent::reasoning_text("more thinking mid-turn"),
false,
);
assert_eq!(
t.blocks().len(),
1,
"only the assistant block should be present: {:?}",
t.blocks()
);
assert_eq!(t.blocks()[0].kind, BlockKind::Assistant);
assert!(
!t.blocks()[0].text.contains("thinking"),
"reasoning must not be folded into the assistant block: {:?}",
t.blocks()[0].text
);
}
#[test]
fn reasoning_text_pushes_a_thinking_block_when_thinking_is_on() {
let mut t = Transcript::new();
apply_event(
&mut t,
AgentEvent::reasoning_text("I considered the time column"),
true,
);
assert_eq!(t.blocks().len(), 1, "one thinking block is pushed");
assert_eq!(t.blocks()[0].kind, BlockKind::Thinking);
assert_eq!(t.blocks()[0].text, "I considered the time column");
apply_event(&mut t, AgentEvent::reasoning_text(""), true);
assert_eq!(t.blocks().len(), 1, "empty reasoning pushes no block");
}
#[test]
fn reasoning_shown_on_screen_stays_out_of_the_persisted_session() {
use crate::interactive::session_state::SessionState;
let reasoning = "the secret chain-of-thought about row values 9f3a";
let mut transcript = Transcript::default();
apply_event(&mut transcript, AgentEvent::reasoning_text(reasoning), true);
apply_event(
&mut transcript,
AgentEvent::assistant_text("the answer is 42"),
true,
);
assert!(
transcript
.blocks()
.iter()
.any(|b| b.kind == BlockKind::Thinking && b.text.contains(reasoning)),
"the reasoning must be on screen for this test to prove anything"
);
let mut session = SessionState::new("s1", Some(String::from("analytics")), String::from("m"));
session.show_thinking = true;
session.record_turn("what is the answer", "the answer is 42", false, Vec::new());
let json = serde_json::to_string(&session).expect("serializes");
assert!(
!json.contains(reasoning),
"reasoning on screen leaked into the persisted session: {json}"
);
let replayed = session.provider_history();
assert!(
replayed.iter().all(|m| !m.content.contains(reasoning)),
"reasoning on screen leaked into replayed history: {replayed:?}"
);
let redacted = session.redacted();
let redacted_json = serde_json::to_string(&redacted).expect("serializes");
assert!(
!redacted_json.contains(reasoning),
"reasoning on screen leaked into the redacted session: {redacted_json}"
);
}