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:
@@ -49,9 +49,15 @@ fn conclude(peer: &str, text: &str) -> Action {
|
||||
}
|
||||
}
|
||||
|
||||
/// The deletion of the owner's conclusion `text` (a `user.md` entry dropped).
|
||||
fn unconclude(text: &str) -> Action {
|
||||
unconclude_about("kyle", text)
|
||||
}
|
||||
|
||||
fn unconclude_about(peer: &str, text: &str) -> Action {
|
||||
Action::Unconclude {
|
||||
workspace: Workspace::Trusted,
|
||||
peer: peer.to_string(),
|
||||
text: text.to_string(),
|
||||
}
|
||||
}
|
||||
@@ -144,7 +150,8 @@ fn a_conclusion_goes_into_the_sessions_memory_session() {
|
||||
);
|
||||
let sync = home.sync.lock().unwrap();
|
||||
assert_eq!(
|
||||
sync.ledger().conclusion(Workspace::Trusted, "Prefers UTC."),
|
||||
sync.ledger()
|
||||
.conclusion(Workspace::Trusted, "kyle", "Prefers UTC."),
|
||||
Some((edit("e1", 0), CONCLUSION.to_string()))
|
||||
);
|
||||
}
|
||||
@@ -204,9 +211,12 @@ fn a_replace_deletes_then_makes_and_an_undo_reverses_it() {
|
||||
Some(vec![CONCLUSION.to_string()])
|
||||
);
|
||||
let sync = home.sync.lock().unwrap();
|
||||
assert_eq!(sync.ledger().conclusion(Workspace::Trusted, "new"), None);
|
||||
assert_eq!(
|
||||
sync.ledger().conclusion(Workspace::Trusted, "old"),
|
||||
sync.ledger().conclusion(Workspace::Trusted, "kyle", "new"),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
sync.ledger().conclusion(Workspace::Trusted, "kyle", "old"),
|
||||
Some((edit("e3", 1), CONCLUSION.to_string()))
|
||||
);
|
||||
}
|
||||
@@ -238,6 +248,57 @@ fn a_deletion_with_nothing_to_delete_is_sent_with_no_id() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_same_text_about_another_peer_is_not_deleted() {
|
||||
// "Uses tabs." is in user.md (about the owner) and in memory.md (about the agent); the
|
||||
// user.md entry is removed: only the owner's conclusion goes.
|
||||
let fake = FakeHoncho::start();
|
||||
let home = Home::new("edits-peers");
|
||||
decide(&home, edit("e1", 0), conclude("kyle", "Uses tabs."));
|
||||
decide(&home, edit("e2", 0), conclude("boxmaker0", "Uses tabs."));
|
||||
decide(&home, edit("e3", 0), unconclude_about("kyle", "Uses tabs."));
|
||||
let mut w = home.worker(&fake, FAST);
|
||||
for _ in 0..3 {
|
||||
assert_eq!(w.step(), Step::Done);
|
||||
}
|
||||
let sync = home.sync.lock().unwrap();
|
||||
assert_eq!(
|
||||
sync.ledger()
|
||||
.conclusion(Workspace::Trusted, "kyle", "Uses tabs."),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
sync.ledger()
|
||||
.conclusion(Workspace::Trusted, "boxmaker0", "Uses tabs."),
|
||||
Some((edit("e2", 0), CONCLUSION.to_string()))
|
||||
);
|
||||
assert_eq!(
|
||||
sent_ids(&home, &edit("e3", 0)),
|
||||
Some(vec![CONCLUSION.to_string()])
|
||||
);
|
||||
// Nothing about the owner is left to delete for this text any more.
|
||||
drop(sync);
|
||||
decide(&home, edit("e4", 0), unconclude_about("kyle", "Uses tabs."));
|
||||
fake.clear();
|
||||
assert_eq!(w.step(), Step::Done);
|
||||
assert!(fake.requests().is_empty(), "{:?}", fake.requests());
|
||||
// The memory.md entry removed: the agent's conclusion goes.
|
||||
decide(
|
||||
&home,
|
||||
edit("e5", 0),
|
||||
unconclude_about("boxmaker0", "Uses tabs."),
|
||||
);
|
||||
assert_eq!(w.step(), Step::Done);
|
||||
assert_eq!(fake.requests().len(), 1, "{:?}", fake.requests());
|
||||
assert_eq!(fake.requests()[0].method, "DELETE");
|
||||
let sync = home.sync.lock().unwrap();
|
||||
assert_eq!(
|
||||
sync.ledger()
|
||||
.conclusion(Workspace::Trusted, "boxmaker0", "Uses tabs."),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_404_on_delete_is_done() {
|
||||
let fake = FakeHoncho::start();
|
||||
|
||||
Reference in New Issue
Block a user