From 9881481b94067969b6fc0ce8a689387f08631f00 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 28 Nov 2026 05:56:32 +0100 Subject: [PATCH] persona tests: the write ahead of a send is a write; the surface says NotSent and the poll's count Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/heartbeat/tests.rs | 10 +++++----- crates/mind-body/src/persona/drain_tests.rs | 7 +++---- crates/mind-body/src/projection/turn/tests.rs | 2 +- crates/mind-body/tests/public_surface.txt | 5 +++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/mind-body/src/heartbeat/tests.rs b/crates/mind-body/src/heartbeat/tests.rs index 681c684..de70a07 100644 --- a/crates/mind-body/src/heartbeat/tests.rs +++ b/crates/mind-body/src/heartbeat/tests.rs @@ -1314,7 +1314,7 @@ fn the_beat_does_not_start_a_mind_that_is_cooling() { /// Soul's q3 and s8 held-sibling-restart-storm: her answer was decided and its send is owed (the answer was lost), her unit ended and nothing new arrives. The /// next poll starts her, and only her, so the send is retried well inside the 30 minutes a homeserver remembers its id, in a quiet room, with the beat's turn /// on the far side of the first poll. A start that leaves it owed is waited out like a failed wake, 20 s doubling to the beat, by the poll's own count of them: -/// over 30 minutes of one-minute polls she is started 7 times, not 30. +/// over the 30 minutes a homeserver remembers an id, of one-minute polls, she is started 7 times, not 29. #[test] fn t_l3_an_owed_send_with_nothing_new_starts_her_at_the_next_poll_and_no_one_else() { let rig = quiet_rig(); @@ -1323,7 +1323,7 @@ fn t_l3_an_owed_send_with_nothing_new_starts_her_at_the_next_poll_and_no_one_els rig.end_unit(ANN); rig.traces[ANN].rows.borrow_mut().push(serde_json::json!({ "held": ["$e1"], "owed": [{ "id": "l$e1:s0", "room": "!op", "text": "On it." }], "at": rig.now().to_rfc3339() })); let mut starts: Vec = Vec::new(); - for minute in 1..=30 { + for minute in 1..=29 { rig.advance(60); let Outcome::Polled { launched } = rig.poll() else { panic!("held") }; assert!(launched.iter().all(|slug| slug.0 == "ann" || slug.0 == "bob" && minute >= 15), "minute {minute}: {launched:?}"); @@ -1333,7 +1333,7 @@ fn t_l3_an_owed_send_with_nothing_new_starts_her_at_the_next_poll_and_no_one_els rig.end_unit(ANN); } assert_eq!(starts.first(), Some(&1), "her, at the first poll after it was owed: {starts:?}"); - assert_eq!(starts, [1, 2, 3, 5, 8, 14, 24], "20 s doubling to the beat, and still retried inside the dedupe window at minute 24"); + assert_eq!(starts, [1, 2, 3, 5, 8, 14, 25], "20 s doubling to the beat, and still retried inside the dedupe window at minute 25"); } /// Soul s7 unwritable-owed-wakes-every-poll. A trace that takes no writes (her state disk full) carries no failed record, so the poll's backoff cannot @@ -1355,8 +1355,8 @@ fn t_l3_a_trace_that_takes_no_writes_is_still_backed_off_by_the_polls_own_count_ rig.end_unit(ANN); rig.advance(30); assert!(!started(&rig), "the second doubles it to 40 s"); - // The send settles: her trace holds it posted, and the count ends. - rig.traces[ANN].rows.borrow_mut().push(serde_json::json!({ "held": ["$e1"], "posted": [{ "event": "$sent-1", "room": "!op", "text": "On it." }], "at": rig.now().to_rfc3339() })); + // The send settles: her trace holds its record rewritten, posted, and the count ends. + rig.traces[ANN].rows.borrow_mut()[0] = serde_json::json!({ "held": ["$e1"], "posted": [{ "event": "$sent-1", "room": "!op", "text": "On it." }], "at": rig.now().to_rfc3339() }); rig.advance(1); assert!(!started(&rig), "nothing is owed"); assert!(rig.store.state.borrow().as_ref().is_some_and(|state| state.owed_starts.is_empty()), "the count of starts for a send owed ended with it"); diff --git a/crates/mind-body/src/persona/drain_tests.rs b/crates/mind-body/src/persona/drain_tests.rs index ca875f2..07170d1 100644 --- a/crates/mind-body/src/persona/drain_tests.rs +++ b/crates/mind-body/src/persona/drain_tests.rs @@ -315,7 +315,7 @@ fn t_l2_drain_acks_after_decision() { assert_eq!(*rig.mouth.acks.borrow(), [1, 3], "each ack stops below the first waking line of a room not yet decided"); let log = rig.log(); let events: Vec<&str> = log.iter().map(String::as_str).filter(|event| *event != "put").collect(); - assert_eq!(events, ["trace", "send", "trace", "ack", "trace", "send", "trace", "ack"], "each turn's record is written before its send, receipts follow, and the ack follows them: {log:?}"); + assert_eq!(events, ["trace", "trace", "send", "trace", "ack", "trace", "trace", "send", "trace", "ack"], "each turn's record is written before its send, the send's mark just before the mouth, receipts follow, and the ack follows them: {log:?}"); let ids: Vec = rig.mouth.sent.borrow().iter().map(|request| request.request_id.clone()).collect(); assert_eq!(ids.len(), 2); assert_eq!(ids, ["l$e1:s0", "l$e2:s0"], "a send is named by the line it answers"); @@ -910,7 +910,7 @@ fn t_l2_a_send_that_did_not_answer_goes_out_again_as_recorded_and_the_model_is_n #[test] fn t_l2_a_trace_that_dies_after_the_send_repeats_the_recorded_words_not_new_ones() { let rig = Rig::new(vec![line(1, &room(1), META, "hello")]); - rig.trace.allow.set(1); + rig.trace.allow.set(2); // the decision and the mark land; the receipts do not rig.run(varying()); rig.trace.allow.set(usize::MAX); let first = texts(&rig, &room(1)); @@ -1032,7 +1032,7 @@ fn t_l3_words_in_the_room_are_never_a_receipt() { for (name, said, owed) in [("prefix", "Thanks!", "Thanks! I will read the PR tonight."), ("identical", "On it.", "On it."), ("ellipsis-only", "\u{2026}", "Anything at all."), ("clipped-real", "Thanks! I will read\u{2026}", "Thanks! I will read the PR tonight.")] { let rig = Rig::new(vec![line(1, &room(1), META, "hello")]); let at = Utc.timestamp_millis_opt(i64::try_from(BASE_MS).unwrap()).unwrap(); - rig.trace.rows.borrow_mut().push(("n0-t0".into(), json!({ "key": "n0-t0", "room": room(1), "held": ["$e1"], "owed": [{ "id": "l$e1:s0", "room": room(1), "text": owed }], "posted": [], "refused_sends": [], "at": at.to_rfc3339() }))); + rig.trace.rows.borrow_mut().push(("n0-t0".into(), json!({ "key": "n0-t0", "room": room(1), "held": ["$e1"], "owed": [{ "id": "l$e1:s0", "room": room(1), "text": owed, "handed": true }], "posted": [], "refused_sends": [], "at": at.to_rfc3339() }))); rig.mouth.tail.borrow_mut().push(crate::chat_client::TailLine { room: room(1), event_id: "$later".into(), at_unix_ms: BASE_MS + 600_000, sender: "@eureka:gamecult.org".into(), form: Form::Message, basis: None, body: said.into(), reply_to: Default::default() }); rig.mouth.forgot.set(true); rig.ticks.set(3600); @@ -1375,7 +1375,6 @@ fn t_l3_after_an_unknown_in_her_dm_every_later_reply_posts() { // And again, a later line and her reply to it. rig.mouth.held.borrow_mut().push(line(2, &room(1), META, "are you there?")); rig.run(scripted(false)); - rig.run(Never); let rows: Vec = rig.trace.rows.borrow().iter().map(|(_, record)| record.clone()).collect(); let said = texts(&rig, &room(1)); assert_eq!(said.len(), 3, "the newer line, her reply to the first line and her reply to the second: {said:?}"); diff --git a/crates/mind-body/src/projection/turn/tests.rs b/crates/mind-body/src/projection/turn/tests.rs index afa8949..b117595 100644 --- a/crates/mind-body/src/projection/turn/tests.rs +++ b/crates/mind-body/src/projection/turn/tests.rs @@ -286,7 +286,7 @@ fn t_l3_every_refusal_kind_is_placed_for_a_first_send_and_for_a_repeat() { (Refusal::RoomMoved, "refused", "unknown"), (Refusal::UnknownKind, "refused", "unknown"), ]; - assert_eq!(kinds.map(|(refusal, ..)| refusal), Refusal::ALL, "every kind the mouth names is in the table, in order"); + assert!(Refusal::ALL.iter().all(|each| kinds.iter().any(|(refusal, ..)| refusal == each)) && kinds.len() == Refusal::ALL.len(), "every kind the mouth names is in the table, once"); for (refusal, first, repeat) in kinds { let chat = FakeChat::new(Some(refusal)); let mut taken = warm_turn(&mouth(&chat)); diff --git a/crates/mind-body/tests/public_surface.txt b/crates/mind-body/tests/public_surface.txt index 01a867c..9c285d9 100644 --- a/crates/mind-body/tests/public_surface.txt +++ b/crates/mind-body/tests/public_surface.txt @@ -19,7 +19,7 @@ mind_body::chat_client: # [derive (Clone , Copy , Debug , PartialEq , Eq)] pub e mind_body::chat_client: # [derive (Clone , Copy , Debug , PartialEq , Eq)] pub enum DirectOutcome { Opened , Existing , Brake , PersonaMismatch , UnknownPersona , EmptyText , ForeignUser , NotAPerson , NoSuchUser , InvitePending , Declined , DailyLimit , SendFailed , } mind_body::chat_client: # [derive (Clone , Copy , Debug , PartialEq , Eq)] pub enum FetchOutcome { Stored , StoredUnverified , NotAMember , BridgedRoom , TooLarge , TypeRefused , NoAttachment , HashMismatch , RateLimited , Brake , PersonaMismatch , UnknownPersona , FetchFailed , StoreFailed , } mind_body::chat_client: # [derive (Clone , Copy , Debug , PartialEq , Eq)] pub enum ReceiptMode { Posted , Existing , } -mind_body::chat_client: # [derive (Clone , Copy , Debug , PartialEq , Eq)] pub enum Refusal { Brake , PersonaMismatch , UnknownRoom , EmptyText , SendFailed , UnknownPersona , RoomMoved , ResendUnknown , UnknownKind , } +mind_body::chat_client: # [derive (Clone , Copy , Debug , PartialEq , Eq)] pub enum Refusal { Brake , PersonaMismatch , UnknownRoom , EmptyText , SendFailed , NotSent , UnknownPersona , RoomMoved , ResendUnknown , UnknownKind , } mind_body::chat_client: # [derive (Clone , Copy , Debug , PartialEq , Eq)] pub enum ReplyViolation { NotATriple , BadEventId , BadSenderId , ExcerptNotText , ExcerptTooLong , } mind_body::chat_client: # [derive (Clone , Debug , Default , PartialEq , Eq)] pub enum ReplyLink { # [default] Absent , Quote (ReplyTo) , Dropped (ReplyViolation) , } mind_body::chat_client: const ACK : & str @@ -56,6 +56,7 @@ mind_body::chat_client: impl Form: fn name (self) -> & 'static str mind_body::chat_client: impl ReceiptMode mind_body::chat_client: impl ReceiptMode: fn name (self) -> & 'static str mind_body::chat_client: impl Refusal +mind_body::chat_client: impl Refusal: const ALL : [Self ; 10] mind_body::chat_client: impl Refusal: fn name (self) -> & 'static str mind_body::chat_client: impl ReplyLink mind_body::chat_client: impl ReplyLink: fn quote (& self) -> Option < & ReplyTo > @@ -176,7 +177,7 @@ mind_body::heartbeat: struct Addressing # [derive (Clone , Debug , Default , Par mind_body::heartbeat: struct Config # [derive (Clone , Debug , PartialEq , Eq)] pub-fields[personas: Vec < PersonaId >, operators: Vec < String >, beat_s: u32] mind_body::heartbeat: struct FileControl pub-fields[] mind_body::heartbeat: struct FileStore pub-fields[] -mind_body::heartbeat: struct HeartbeatState # [derive (Clone , Debug , PartialEq , Eq , DatabaseEntry)] pub-fields[last_beat_at: DateTime < Utc >, handled_mentions: Vec < String >, last_turn_at: BTreeMap < String , DateTime < Utc > >] +mind_body::heartbeat: struct HeartbeatState # [derive (Clone , Debug , PartialEq , Eq , DatabaseEntry)] pub-fields[last_beat_at: DateTime < Utc >, handled_mentions: Vec < String >, last_turn_at: BTreeMap < String , DateTime < Utc > >, owed_starts: BTreeMap < String , u32 >] mind_body::heartbeat: struct InstanceTrace # [derive (Clone , Debug , PartialEq , Eq , serde :: Serialize , serde :: Deserialize)] pub-fields[instance: String, vote_beat_s: Option < u32 >, urgency_permille: u16, addressed: bool, busy: bool, released: bool, idle_s: i64, score: String, note: String] mind_body::heartbeat: struct Organs< 'a > pub-fields[seats: & 'a [Seat < 'a >], control: & 'a dyn Control, launcher: & 'a dyn Launcher, clock: & 'a dyn Clock, store: & 'a dyn Store] mind_body::heartbeat: struct PersonaId # [derive (Clone , Debug , PartialEq , Eq)] pub-fields[slug: Slug, public_name: String, handle: String, matrix_id: String, huginn: SocketAddr]