memoryd: sync begins when Honcho is turned on, and conclusions are matched by peer
Co-Authored-By: ornith-1.5-35b-a3b <agent@wntrmute.dev>
This commit is contained in:
@@ -28,6 +28,18 @@ pub const FAST: Tuning = Tuning {
|
||||
idle: Duration::from_millis(1),
|
||||
};
|
||||
|
||||
/// When the tests' ledgers began: before every turn they log (`spoken`).
|
||||
pub const BEGAN: &str = "2026-09-28T09:00:00.000Z";
|
||||
|
||||
pub fn began() -> Timestamp {
|
||||
Timestamp::parse(BEGAN).unwrap()
|
||||
}
|
||||
|
||||
/// The ledger line of `BEGAN`, for a test that writes a ledger itself.
|
||||
pub fn began_line() -> String {
|
||||
format!(r#"{{"type":"began","time":"{BEGAN}"}}"#)
|
||||
}
|
||||
|
||||
pub fn config(url: &str) -> HonchoConfig {
|
||||
HonchoConfig {
|
||||
url: url.to_string(),
|
||||
@@ -50,12 +62,15 @@ pub struct Home {
|
||||
}
|
||||
|
||||
impl Home {
|
||||
/// A home whose ledger has begun, at `BEGAN`, as `memoryd` makes it at its first start.
|
||||
pub fn new(tag: &str) -> Home {
|
||||
let dir = TempDir::new(tag);
|
||||
std::fs::create_dir_all(dir.path().join("memory")).unwrap();
|
||||
let mut ledger = Ledger::open(&dir.path().join("memory").join(LEDGER)).unwrap();
|
||||
ledger.append(Record::Began { time: began() }).unwrap();
|
||||
Home {
|
||||
sync: Arc::new(Mutex::new(TurnSync::new(
|
||||
Ledger::open(&dir.path().join("memory").join(LEDGER)).unwrap(),
|
||||
ledger,
|
||||
"boxmaker0",
|
||||
&dir.path().join("sessions"),
|
||||
))),
|
||||
@@ -118,12 +133,13 @@ impl Home {
|
||||
)
|
||||
}
|
||||
|
||||
/// Every record of the ledger on disk, in order.
|
||||
/// Every record of the ledger on disk but its `Began`, in order.
|
||||
pub fn records(&self) -> Vec<Record> {
|
||||
std::fs::read_to_string(self.ledger_path())
|
||||
.unwrap_or_default()
|
||||
.lines()
|
||||
.map(|l| serde_json::from_str(l).unwrap())
|
||||
.filter(|r| !matches!(r, Record::Began { .. }))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user