Files
boxmaker/crates/memoryd/tests/support/turns.rs
T

64 lines
2.0 KiB
Rust

//! Session logs of turns with speakers, for the tests of deciding turns. Do not edit.
#![allow(dead_code)] // each test file uses a different part of this module
use std::path::Path;
use bxcore::{DataClass, LogRecord, SessionId, SessionStateReply, Timestamp};
use crate::logs::{assistant, result};
pub fn sid(s: &str) -> SessionId {
SessionId::new(s).unwrap()
}
pub fn clean() -> SessionStateReply {
SessionStateReply {
class: DataClass::Private,
untrusted: false,
}
}
/// A speaker's message. Its time is the last one there is, so that it is after any time sync
/// began (M5c-1 task 15); `spoken_at` gives another.
pub fn spoken(content: &str, speaker: Option<&str>) -> LogRecord {
spoken_at(Timestamp::MAX, content, speaker)
}
pub fn spoken_at(time: Timestamp, content: &str, speaker: Option<&str>) -> LogRecord {
LogRecord::User {
time,
content: content.to_string(),
speaker: speaker.map(str::to_string),
}
}
/// A finished turn: the speaker's message and the reply.
pub fn finished(speaker: Option<&str>) -> Vec<LogRecord> {
vec![spoken("hello", speaker), assistant(2, Some("hi"), &[])]
}
/// A finished turn that read an untrusted page.
pub fn fetched(speaker: Option<&str>) -> Vec<LogRecord> {
vec![
spoken("read this page", speaker),
assistant(2, None, &[("fetch", "{}")]),
result(3, "the page", DataClass::Public, true),
assistant(4, Some("it says hello"), &[]),
]
}
/// A turn still running, or one that failed: no reply.
pub fn running(speaker: Option<&str>) -> Vec<LogRecord> {
vec![
spoken("look it up", speaker),
assistant(2, None, &[("fetch", "{}")]),
]
}
/// `sessions/<session>/0.jsonl` under `home`, the turns one after another.
pub fn write_turns(home: &Path, session: &str, turns: &[Vec<LogRecord>]) {
let records: Vec<LogRecord> = turns.iter().flatten().cloned().collect();
crate::logs::write_log(home, session, &records);
}