Files
boxmaker/crates/memoryd/tests/support/logs.rs
T
kyleandClaude Opus 5.5 2b3ae080b4 proto becomes bxcore, the one shared crate (M5b task 00)
Done the way the owner asked and the spike mapped: the crate and the
manifests renamed, then what the build reported fixed. Layers: 138
"proto unresolved" errors across 169 files; cargo fmt reordering
imports; six fixture paths built as strings in brokerd's and bxctl's
tests, which the compiler cannot see, and comments naming
crates/proto/; the crate-dependency check and its self-test. One more
the spike did not reach: a `\nproto =` key inside a printf format in
the self-test, which a word-boundary replacement skips because `n` and
`p` are both word characters.

make gate: gate: ok, 944 tests; no new entry in /tmp.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 01:48:38 -07:00

68 lines
2.1 KiB
Rust

//! Session logs for tests: records written as `loopd` writes them. Do not edit.
#![allow(dead_code)] // each test file uses a different part of this module
use std::path::{Path, PathBuf};
use bxcore::{CallId, DataClass, LogRecord, Timestamp, ToolCall};
pub fn at(minute: u32) -> Timestamp {
Timestamp::parse(&format!("2026-09-20T14:{minute:02}:00.000Z")).unwrap()
}
pub fn user(minute: u32, content: &str) -> LogRecord {
LogRecord::User {
time: at(minute),
content: content.to_string(),
}
}
pub fn assistant(minute: u32, content: Option<&str>, calls: &[(&str, &str)]) -> LogRecord {
LogRecord::Assistant {
time: at(minute),
content: content.map(str::to_string),
reasoning_content: Some("thinking about it".to_string()),
tool_calls: calls
.iter()
.enumerate()
.map(|(i, (name, arguments))| ToolCall {
id: format!("c{i}"),
name: name.to_string(),
arguments: arguments.to_string(),
})
.collect(),
}
}
pub fn result(minute: u32, content: &str, class: DataClass, untrusted: bool) -> LogRecord {
LogRecord::ToolResult {
time: at(minute),
call: CallId(1),
tool_call_id: "c0".to_string(),
content: content.to_string(),
class,
untrusted,
truncated: false,
}
}
/// Write `records` as `sessions/<session>/0.jsonl` under `home`.
pub fn write_log(home: &Path, session: &str, records: &[LogRecord]) -> PathBuf {
let dir = home.join("sessions").join(session);
std::fs::create_dir_all(&dir).unwrap();
let path = dir.join("0.jsonl");
let text: String = records
.iter()
.map(|r| format!("{}\n", serde_json::to_string(r).unwrap()))
.collect();
std::fs::write(&path, text).unwrap();
path
}
/// Append one record to a log.
pub fn append(path: &Path, record: &LogRecord) {
use std::io::Write;
let mut file = std::fs::OpenOptions::new().append(true).open(path).unwrap();
writeln!(file, "{}", serde_json::to_string(record).unwrap()).unwrap();
}