use super::super::{LIVE, rows};
use crate::reply::stream::{Delta, Stream};
use crate::reply::transcript::{Block, Entry, EntryKind, Transcript, Usage};
use crate::reply::{Read, Reply};
use crate::test_support::window::said;
use crate::ui::{Channel, Model};
fn fold(text: &str) -> Stream {
Stream {
text: Some(text.to_owned()),
thinking: None,
last_delta: Some(Delta::Text),
tools: Vec::new(),
}
}
fn in_flight(text: &str) -> Transcript {
Transcript {
entries: vec![
said("op", "port it"),
Entry {
name: LIVE.to_owned(),
raw: text.to_owned(),
kind: EntryKind::Streaming {
thinking: String::new(),
text: text.to_owned(),
},
},
],
}
}
#[test]
fn a_live_fold_replaces_the_streaming_entry_rather_than_standing_beside_it() {
let committed = in_flight("half a");
let shown = rows(&committed, Some(&fold("half a sentence")));
assert_eq!(shown.len(), 2, "{shown:?}");
assert_eq!(shown[1].said, "half a sentence");
assert_eq!(rows(&committed, None)[1].said, "half a");
}
#[test]
fn a_committed_turn_retires_the_fold_that_was_folding_it() {
let channel = Channel::default();
let mut model = Model::default();
model.absorb(&channel, Read::Answer(Reply::Transcript(in_flight("po"))));
model.absorb(&channel, Read::Answer(Reply::Follow(fold("pong"))));
let flying = rows(&model.transcript, model.live.as_ref());
assert_eq!(flying[1].said, "pong", "{flying:?}");
let committed = Transcript {
entries: vec![
said("op", "port it"),
Entry {
name: "002-model-a.json".to_owned(),
raw: "{}".to_owned(),
kind: EntryKind::Model {
model_id: "model-a".to_owned(),
blocks: vec![Block::Text("pong".to_owned())],
usage: Usage::new(),
},
},
],
};
model.absorb(&channel, Read::Answer(Reply::Transcript(committed)));
assert!(model.live.is_some(), "the fold still stands in the model");
let shown = rows(&model.transcript, model.live.as_ref());
let answers: Vec<&str> = shown
.iter()
.filter(|row| row.said == "pong")
.map(|row| row.who.as_str())
.collect();
assert_eq!(answers, vec!["model-a"], "{shown:?}");
assert!(!shown.iter().any(|row| row.who.contains(LIVE)), "{shown:?}");
}