memoryd: the Honcho ledger, decided, sent and failed, read through at start
Co-Authored-By: ornith-1.5-35b-a3b <agent@wntrmute.dev>
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
//! Records for the Honcho ledger's tests, and a ledger in a directory of its own. Do not edit.
|
||||
|
||||
#![allow(dead_code)] // each test file uses a different part of this module
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use bxcore::{SessionId, Timestamp};
|
||||
use memoryd::honcho::ledger::{Action, Item, Ledger, Record, Workspace};
|
||||
|
||||
use crate::tmp::TempDir;
|
||||
|
||||
/// A ledger file that does not exist yet, in a directory removed on drop.
|
||||
pub struct Home {
|
||||
pub path: PathBuf,
|
||||
pub dir: TempDir,
|
||||
}
|
||||
|
||||
impl Home {
|
||||
pub fn new(tag: &str) -> Home {
|
||||
let dir = TempDir::new(tag);
|
||||
Home {
|
||||
path: dir.path().join("honcho.jsonl"),
|
||||
dir,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open(&self) -> Ledger {
|
||||
Ledger::open(&self.path).unwrap()
|
||||
}
|
||||
|
||||
/// The file's bytes as text; "" when there is no file.
|
||||
pub fn text(&self) -> String {
|
||||
std::fs::read_to_string(&self.path).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Writes `text` as the whole file.
|
||||
pub fn write(&self, text: &str) {
|
||||
std::fs::write(&self.path, text).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub const TIME: &str = "2026-09-28T10:00:00.000Z";
|
||||
|
||||
pub fn time() -> Timestamp {
|
||||
Timestamp::parse(TIME).unwrap()
|
||||
}
|
||||
|
||||
pub fn sid(s: &str) -> SessionId {
|
||||
SessionId::new(s).unwrap()
|
||||
}
|
||||
|
||||
pub fn turn(session: &str, turn: u64) -> Item {
|
||||
Item::Turn {
|
||||
session: sid(session),
|
||||
turn,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn edit(id: &str, part: u32) -> Item {
|
||||
Item::Edit {
|
||||
id: id.to_string(),
|
||||
part,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_trusted(speaker: &str) -> Action {
|
||||
Action::Turn {
|
||||
workspace: Workspace::Trusted,
|
||||
speaker: speaker.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn skip(why: &str) -> Action {
|
||||
Action::Skip {
|
||||
why: why.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn conclude(workspace: Workspace, text: &str) -> Action {
|
||||
Action::Conclude {
|
||||
workspace,
|
||||
peer: "kyle".to_string(),
|
||||
session: sid("chat-1"),
|
||||
text: text.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unconclude(workspace: Workspace, text: &str) -> Action {
|
||||
Action::Unconclude {
|
||||
workspace,
|
||||
text: text.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decided(item: &Item, action: Action) -> Record {
|
||||
Record::Decided {
|
||||
time: time(),
|
||||
item: item.clone(),
|
||||
action,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sent(item: &Item, ids: &[&str]) -> Record {
|
||||
Record::Sent {
|
||||
time: time(),
|
||||
item: item.clone(),
|
||||
ids: ids.iter().map(|s| s.to_string()).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn failed(item: &Item, status: Option<u16>) -> Record {
|
||||
Record::Failed {
|
||||
time: time(),
|
||||
item: item.clone(),
|
||||
status,
|
||||
kind: "refused".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// `record`'s line, as `append` writes it.
|
||||
pub fn line(record: &Record) -> String {
|
||||
format!("{}\n", serde_json::to_string(record).unwrap())
|
||||
}
|
||||
Reference in New Issue
Block a user