memoryd: a staged write's id counts every write staged that day

This commit is contained in:
2026-09-25 16:41:44 -07:00
parent 81107bc5c6
commit 34dbbb27be
3 changed files with 82 additions and 3 deletions
+3 -3
View File
@@ -92,8 +92,8 @@ pub fn submit(
) -> Result<String, String> {
// 1. `args.check()?`.
// 2. `day` is the first 10 characters of `ctx.now.to_rfc3339()`. `taken` = how many Waiting
// lines have an id starting format!("p-{day}-"). The id is format!("p-{day}-{:04}", taken +
// 1).
// lines of `lines(store)?`, done or not, have an id starting format!("p-{day}-"): an id is
// never used twice. The id is format!("p-{day}-{:04}", taken + 1).
// 3. `add` a Waiting line: id, time `ctx.now.to_rfc3339()`, session, call and taint from ctx,
// arguments as given.
// 4. Ok(format!("waiting for the owner's review ({id}); nothing is changed until it is
@@ -101,7 +101,7 @@ pub fn submit(
args.check()?;
let rfc = ctx.now.to_rfc3339();
let day = rfc.get(..10).unwrap_or("0000-00-00");
let taken = waiting(store)?
let taken = lines(store)?
.iter()
.filter(|line| match line {
Line::Waiting { id, .. } => id.starts_with(&format!("p-{day}-")),
+78
View File
@@ -0,0 +1,78 @@
//! A staged write's id is never one used before that day, so a write staged after another was
//! accepted or rejected stays waiting and can be accepted (M5a spec, section 5; review of
//! 2026-09-24). Do not edit.
#[path = "support/tmp.rs"]
mod tmp;
use memoryd::edit::Context;
use memoryd::files::Store;
use memoryd::review;
use proto::{DataClass, MemoryArgs, MemoryFile, Timestamp};
use tmp::TempDir;
fn now() -> Timestamp {
Timestamp::parse("2026-09-24T20:14:37.123Z").unwrap()
}
fn setup(tag: &str) -> (TempDir, Store) {
let dir = TempDir::new(tag);
let starter = dir.write("etc/soul.md", "Soul.\n");
let store = Store::new(&dir.path().join("memory"));
store.init(&starter).unwrap();
(dir, store)
}
fn ctx() -> Context {
Context {
session: "mm-s1".to_string(),
call: 7,
taint: DataClass::Private,
untrusted: false,
now: now(),
}
}
/// Stage an add of `text` to memory.md; the answer.
fn stage(store: &Store, text: &str) -> String {
let json = format!(r#"{{"action":"add","file":"memory","text":"{text}"}}"#);
let args: MemoryArgs = serde_json::from_str(&json).unwrap();
review::submit(store, &args, &json, &ctx()).unwrap()
}
fn waiting_as(id: &str) -> String {
format!("waiting for the owner's review ({id}); nothing is changed until it is accepted")
}
#[test]
fn a_write_staged_after_an_accepted_one_gets_a_new_id_and_can_be_accepted() {
let (_dir, store) = setup("review-ids-accepted");
assert_eq!(stage(&store, "a"), waiting_as("p-2026-09-24-0001"));
review::accept(&store, "p-2026-09-24-0001", now()).unwrap();
assert_eq!(stage(&store, "b"), waiting_as("p-2026-09-24-0002"));
let listed = review::list(&store).unwrap();
assert_eq!(listed.lines().count(), 1, "{listed}");
assert!(
listed.starts_with("p-2026-09-24-0002 mm-s1 {"),
"{listed}"
);
review::accept(&store, "p-2026-09-24-0002", now()).unwrap();
assert_eq!(store.entries(MemoryFile::Memory).unwrap(), ["a", "b"]);
}
#[test]
fn ids_count_every_write_staged_that_day_waiting_or_done() {
let (_dir, store) = setup("review-ids-mixed");
stage(&store, "a");
stage(&store, "b");
stage(&store, "c");
review::reject(&store, "p-2026-09-24-0001", now()).unwrap();
review::accept(&store, "p-2026-09-24-0003", now()).unwrap();
assert_eq!(stage(&store, "d"), waiting_as("p-2026-09-24-0004"));
let listed = review::list(&store).unwrap();
let ids: Vec<&str> = listed
.lines()
.filter_map(|line| line.split(" ").next())
.collect();
assert_eq!(ids, ["p-2026-09-24-0002", "p-2026-09-24-0004"], "{listed}");
}