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:
2026-09-28 13:40:48 -07:00
co-authored by ornith-1.5-35b-a3b
parent fb2afa1979
commit 5f4e0d9997
25 changed files with 720 additions and 80 deletions
+20
View File
@@ -28,6 +28,14 @@ impl Home {
Ledger::open(&self.path).unwrap()
}
/// A new ledger that has begun (`began()`): what `memoryd` makes at its first start, and so
/// what a test that reads its ledger back needs (M5c-1 task 15).
pub fn begun(&self) -> Ledger {
let mut ledger = self.open();
ledger.append(began()).unwrap();
ledger
}
/// 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()
@@ -85,13 +93,25 @@ pub fn conclude(workspace: Workspace, text: &str) -> Action {
}
}
/// The deletion of the owner's (`kyle`'s) conclusion `text`, as `conclude` makes it.
pub fn unconclude(workspace: Workspace, text: &str) -> Action {
Action::Unconclude {
workspace,
peer: "kyle".to_string(),
text: text.to_string(),
}
}
/// When sync began, `TIME`.
pub fn began() -> Record {
Record::Began { time: time() }
}
/// `began()`'s line.
pub fn began_line() -> String {
line(&began())
}
pub fn decided(item: &Item, action: Action) -> Record {
Record::Decided {
time: time(),
+9 -3
View File
@@ -4,9 +4,9 @@
use std::path::Path;
use bxcore::{DataClass, LogRecord, SessionId, SessionStateReply};
use bxcore::{DataClass, LogRecord, SessionId, SessionStateReply, Timestamp};
use crate::logs::{assistant, at, result};
use crate::logs::{assistant, result};
pub fn sid(s: &str) -> SessionId {
SessionId::new(s).unwrap()
@@ -19,9 +19,15 @@ pub fn clean() -> SessionStateReply {
}
}
/// 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: at(1),
time,
content: content.to_string(),
speaker: speaker.map(str::to_string),
}
+18 -2
View File
@@ -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()
}