Files
boxmaker/crates/loopd/tests/tool_summary_messages.rs
2026-10-03 13:51:03 -07:00

89 lines
2.4 KiB
Rust

//! Tests that `messages()` ignores `ToolSummary`. Do not edit.
use bxcore::{CallId, DataClass, Epoch, Hash32, LogRecord, SessionId, Timestamp};
use loopd::baseline::{Baseline, messages};
use loopd::llama::ChatMessage;
use loopd::llama::ToolSchema;
fn ts() -> Timestamp {
Timestamp::parse("2026-09-18T08:00:00.000Z").unwrap()
}
fn baseline() -> Baseline {
Baseline {
system: "sys".to_string(),
tools: vec![ToolSchema {
name: "clock".to_string(),
description: "t".to_string(),
parameters: serde_json::json!({"type": "object", "properties": {}}),
}],
}
}
fn user(content: &str) -> LogRecord {
LogRecord::User {
time: ts(),
content: content.to_string(),
speaker: None,
}
}
fn result() -> LogRecord {
LogRecord::ToolResult {
time: ts(),
call: CallId(1),
tool_call_id: "c".to_string(),
content: "raw body".to_string(),
class: DataClass::Public,
untrusted: false,
truncated: false,
}
}
fn summary() -> LogRecord {
LogRecord::ToolSummary {
time: ts(),
call: CallId(1),
tool_call_id: "c".to_string(),
content: "a short account".to_string(),
class: DataClass::Public,
untrusted: false,
}
}
#[test]
fn messages_ignore_tool_summary() {
let start = LogRecord::SessionStart {
time: ts(),
session: SessionId::new("a").unwrap(),
epoch: Epoch(0),
slot: 0,
baseline: Hash32::ZERO,
};
let without = messages(&baseline(), &[start.clone(), user("hi"), result()]);
let with = messages(&baseline(), &[start, user("hi"), result(), summary()]);
assert_eq!(without, with);
assert!(
!with
.iter()
.any(|m| matches!(m, ChatMessage::User { content } if content == "a short account")),
"{with:?}"
);
}
#[test]
fn a_summary_is_not_replayed_as_a_tool_message() {
let msgs = messages(&baseline(), &[summary()]);
assert_eq!(msgs.len(), 1, "only the system message");
assert!(matches!(msgs[0], ChatMessage::System { .. }));
}
#[test]
fn inserting_a_summary_does_not_break_prefix_extension() {
let a = vec![user("hi"), result()];
let b = vec![user("hi"), result(), summary(), user("next")];
let ma = messages(&baseline(), &a);
let mb = messages(&baseline(), &b);
assert_eq!(&mb[..ma.len()], &ma[..]);
}