persona tests: the stamp on a write ahead, and an answer with neither event nor refusal
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9881481b94
commit
1ff3eb9ae0
2 changed files with 33 additions and 2 deletions
|
|
@ -1405,3 +1405,18 @@ fn t_l3_a_held_sibling_stays_owed_unhanded_until_the_window_and_is_then_told_as_
|
|||
let rows: Vec<Value> = rig.trace.rows.borrow().iter().map(|(_, record)| record.clone()).collect();
|
||||
assert!(!crate::projection::owes(&rows) && rows[0]["refused_sends"][0]["refusal"] == "not_sent_past_the_window", "{}", rows[0]);
|
||||
}
|
||||
|
||||
/// A start killed after a write ahead still tells her of an unknown the same record held by then: the write carries the stamp the final rewrite would.
|
||||
#[test]
|
||||
fn t_l3_a_write_ahead_carries_the_stamp_of_an_unknown_the_record_already_holds() {
|
||||
let rig = Rig::new(vec![]);
|
||||
rig.mouth.resend_unknown.set(true);
|
||||
rig.trace.rows.borrow_mut().push(("n0-t0".into(), json!({ "key": "n0-t0", "room": room(1), "held": [], "owed": [
|
||||
{ "id": "la:s0", "room": room(1), "text": "one", "handed": true }, { "id": "la:s1", "room": room(2), "text": "two" }], "posted": [], "refused_sends": [], "edited": [],
|
||||
"at": (Utc.timestamp_millis_opt(i64::try_from(BASE_MS).unwrap()).unwrap() - Duration::seconds(60)).to_rfc3339() })));
|
||||
rig.trace.allow.set(1); // the write ahead of the second send lands, and the rewrite after it does not
|
||||
let Outcome::Failed(_) = rig.run(Never) else { panic!("the rewrite cannot land") };
|
||||
let record = rig.trace.rows.borrow()[0].1.clone();
|
||||
assert_eq!(record["unknown_sends"][0]["text"], "one", "{record}");
|
||||
assert!(record["unknown_at"].is_string(), "the unknown is told even if the start dies here: {record}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,13 @@ use crate::projection::{Answer, Failed, Model, Organs, Through};
|
|||
struct FakeChat {
|
||||
sent: RefCell<Vec<ChatSendRequest>>,
|
||||
refusal: Option<Refusal>,
|
||||
/// Answers with neither an event nor a refusal.
|
||||
bare: bool,
|
||||
}
|
||||
|
||||
impl FakeChat {
|
||||
fn new(refusal: Option<Refusal>) -> Self {
|
||||
Self { sent: RefCell::default(), refusal }
|
||||
Self { sent: RefCell::default(), refusal, bare: false }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -32,7 +34,7 @@ impl Chat for FakeChat {
|
|||
}
|
||||
fn send(&self, request: &ChatSendRequest) -> Result<ChatSendReceipt> {
|
||||
self.sent.borrow_mut().push(request.clone());
|
||||
let event_id = self.refusal.is_none().then(|| format!("$sent-{}", self.sent.borrow().len()));
|
||||
let event_id = (self.refusal.is_none() && !self.bare).then(|| format!("$sent-{}", self.sent.borrow().len()));
|
||||
Ok(ChatSendReceipt { request_id: request.request_id.clone(), event_id, refusal: self.refusal, newer: vec![] })
|
||||
}
|
||||
fn open_direct(&self, _: &ChatOpenDirectRequest) -> Result<ChatOpenDirectReceipt> {
|
||||
|
|
@ -346,6 +348,20 @@ fn t_l3_a_send_never_handed_over_goes_out_as_a_first_send_and_only_a_handed_one_
|
|||
assert!(record["owed"].as_array().unwrap().iter().all(|send| send.get("handed").is_none()), "{record}");
|
||||
}
|
||||
|
||||
/// A mouth that answers with neither an event nor a refusal made no post a first send can lean on: a first send is refused `no_event`, and a repeat, which
|
||||
/// may have posted on its first try, is unknown.
|
||||
#[test]
|
||||
fn t_l3_an_answer_with_neither_event_nor_refusal_is_refused_for_a_first_send_and_unknown_for_a_repeat() {
|
||||
let mut chat = FakeChat::new(None);
|
||||
chat.bare = true;
|
||||
let mut first = json!({ "owed": [{ "id": "k:s0", "room": "!a:b", "text": "one" }], "posted": [], "refused_sends": [], "edited": [] });
|
||||
deliver(&mouth(&chat), &mut first, Pass::Within, &mut BTreeSet::new(), &mut |_| true);
|
||||
assert_eq!(settled(&first), "refused", "{first}");
|
||||
let mut repeat = json!({ "owed": [{ "id": "k:s0", "room": "!a:b", "text": "one", "handed": true }], "posted": [], "refused_sends": [], "edited": [] });
|
||||
deliver(&mouth(&chat), &mut repeat, Pass::Within, &mut BTreeSet::new(), &mut |_| true);
|
||||
assert_eq!(settled(&repeat), "unknown", "{repeat}");
|
||||
}
|
||||
|
||||
/// A send of a record past the window is unknown when it was handed over and refused as not sent when it was not: the first may have posted, the second
|
||||
/// cannot have.
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue