From 263c903508ec7e463cdaf12eabd5bb0f5dad4487 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 28 Nov 2026 07:10:40 +0100 Subject: [PATCH] persona tests: the told items come from the one derivation; the untold items of her trace, stamped once, kept on rewrite Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/persona/drain_tests.rs | 4 +-- crates/mind-body/src/projection/outcome.rs | 2 +- .../mind-body/src/projection/outcome/tests.rs | 29 +++++++++++++------ crates/mind-body/src/projection/turn.rs | 2 +- crates/mind-body/src/projection/turn/tests.rs | 3 +- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/crates/mind-body/src/persona/drain_tests.rs b/crates/mind-body/src/persona/drain_tests.rs index 8e08ed4..1c31275 100644 --- a/crates/mind-body/src/persona/drain_tests.rs +++ b/crates/mind-body/src/persona/drain_tests.rs @@ -1150,7 +1150,7 @@ fn t_l3_an_unknown_send_is_told_at_her_next_real_turn_exactly_once_though_a_line assert_eq!(set_aside(&rig), aside, "the struck line was set aside before the turn"); let all = records(&rig); let before_turn: Vec = all.iter().filter(|record| record["room"] != json!(room(3))).cloned().collect(); - let told = |records: &[Value]| crate::projection::history(records).last_outcome.map(|last| last["unknown"].clone()); + let told = |records: &[Value]| crate::projection::history(records).last_outcome.map(|last| last["untold"].clone()); assert_eq!(told(&before_turn), Some(json!([{ "room": MINDS, "text": rig.mouth.sent.borrow()[0].text }])), "aside={aside}: told at her next turn"); rig.run(scripted(false)); assert_eq!(told(&records(&rig)), Some(Value::Null), "aside={aside}: told once"); @@ -1418,7 +1418,7 @@ fn t_l3_a_refusal_answered_to_a_resend_is_unknown_and_told_and_to_a_first_send_i assert!(rows[0]["refused_sends"] == json!([]) && rows[0].get("owed").is_none(), "{}: not told as unsent: {}", refusal.name(), rows[0]); assert_eq!(rows[1]["refused_sends"][0]["refusal"], refusal.name(), "a first send stays refused: {}", rows[1]); assert!(rows[1].get("unknown_sends").is_none()); - assert!(crate::projection::history(&rows).last_outcome.is_some_and(|last| last["unknown"][0]["text"] == "handed over"), "she is told it is unknown"); + assert!(crate::projection::history(&rows).last_outcome.is_some_and(|last| last["untold"][0]["text"] == "handed over"), "she is told it is unknown"); } } diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index c7624de..971ddf3 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -309,7 +309,7 @@ pub(crate) fn outcome_of(record: &Value) -> Option { let room = words(&item["room"]); match (item["kind"].as_str(), words_of(&item["text"])) { (Some("unknown"), Some(text)) => outcome.parts.push(Part::Unknown { room, text }), - (Some("unsent"), Some(text)) => outcome.parts.push(Part::Unsent { room, text, reach: false }), + (Some("refused"), Some(text)) => outcome.parts.push(Part::Unsent { room, text, reach: false }), (Some("set_aside"), text) => outcome.parts.push(Part::SetAside { room, line: words(&item["sender"]).zip(text) }), (Some("not_kept"), _) => outcome.parts.push(Part::NotKept), _ => outcome.omitted.push(format!("an untold item she cannot be told truly: {item}")), diff --git a/crates/mind-body/src/projection/outcome/tests.rs b/crates/mind-body/src/projection/outcome/tests.rs index 5cd3057..b6fce18 100644 --- a/crates/mind-body/src/projection/outcome/tests.rs +++ b/crates/mind-body/src/projection/outcome/tests.rs @@ -18,6 +18,16 @@ fn told(record: &Value) -> (Vec, Vec) { (outcome.lines(packet().forms), outcome.omitted) } +/// What she is told after `record` alone is her trace: the items it holds that she has not been told come from the one derivation, not from the record's own fields. +fn outcome_trace(record: &Value) -> Outcome { + crate::projection::history(std::slice::from_ref(record)).last_outcome.and_then(|last| outcome_of(&last)).expect("a record") +} + +fn told_trace(record: &Value) -> (Vec, Vec) { + let outcome = outcome_trace(record); + (outcome.lines(packet().forms), outcome.omitted) +} + #[test] fn a_line_that_went_out_is_told_as_the_room_having_it() { let (lines, omitted) = told(&record("I nod. Hi Nibu.\n\nGood tag.", json!({ "say": [{ "draft": 1 }], "gaps": [] }), &["Hi Nibu.\n\nGood tag."])); @@ -632,23 +642,23 @@ fn t6_a_refused_send_is_told_as_not_gone_out() { let refused = |posted: Value, gaps: Value| { let mut record = record(&format!("{text}"), json!({ "say": [{ "draft": 1 }], "gaps": gaps }), &[]); record["posted"] = posted; - record["refused_sends"] = json!([{ "room": MINDS, "text": text, "in_reply_to": "$gone", "refusal": "reply_target_not_in_room" }]); + record["refused_sends"] = json!([{ "room": MINDS, "text": text, "in_reply_to": "$gone", "refusal": "reply_target_not_in_room", "at": "2026-11-27T10:00:00Z" }]); record }; - let (lines, omitted) = told(&refused(json!([]), json!([]))); + let (lines, omitted) = told_trace(&refused(json!([]), json!([]))); assert_eq!(lines, [format!("- He had drafted {}, and it did not go out.", crate::projection::select::spoken(text))], "{omitted:?}"); assert!(omitted.is_empty(), "{omitted:?}"); - let outcome = outcome_of(&refused(json!([]), json!([]))).unwrap(); + let outcome = outcome_trace(&refused(json!([]), json!([]))).unwrap(); assert_eq!(outcome.event(0, packet().forms, &[]), "- He had drafted a line, and it did not go out."); - let (reach, _) = told(&refused(json!([]), json!([{ "kind": "missing_affordance", "draft": 1, "quote": null, "detail": "" }]))); + let (reach, _) = told_trace(&refused(json!([]), json!([{ "kind": "missing_affordance", "draft": 1, "quote": null, "detail": "" }]))); assert_eq!(reach, [format!("- He had drafted {}, and it did not go out. It reaches for something he has no way to do from here.", crate::projection::select::spoken(text))]); // The receipt decides what reached the room: a line with one is told as the room having it, whatever else says not. - let (lines, _) = told(&refused(json!([{ "event": "40", "room": MINDS, "text": text }]), json!([]))); + let (lines, _) = told_trace(&refused(json!([{ "event": "40", "room": MINDS, "text": text }]), json!([]))); assert!(lines.iter().all(|line| !line.contains("did not go out")), "{lines:?}"); // Mutant (match a refused send by text alone): a refusal in another room tells nothing here. let mut elsewhere = refused(json!([]), json!([])); elsewhere["refused_sends"][0]["room"] = json!("#elsewhere:gamecult.org"); - let (lines, omitted) = told(&elsewhere); + let (lines, omitted) = told_trace(&elsewhere); assert!(lines.is_empty() && omitted[0].contains("no receipt"), "{lines:?} {omitted:?}"); } @@ -656,9 +666,10 @@ fn t6_a_refused_send_is_told_as_not_gone_out() { fn a_put_refused_twice_and_a_set_aside_line_are_told_plainly() { let mut refused = record("Hi Nibu.", json!({ "say": [{ "draft": 1 }], "gaps": [] }), &["Hi Nibu."]); refused["put_refused"] = json!("stale again"); - assert_eq!(told(&refused).0, ["- What he meant to keep from that turn was not kept.", "- #minds:gamecult.org has, from him: \"Hi Nibu.\"."], "the refusal's words are the mind's, not hers: she is told only that it was not kept"); + refused["put_refused_at"] = json!("2026-11-27T10:00:00Z"); + assert_eq!(told_trace(&refused).0, ["- What he meant to keep from that turn was not kept.", "- #minds:gamecult.org has, from him: \"Hi Nibu.\"."], "the refusal's words are the mind's, not hers: she is told only that it was not kept"); let aside = json!({ "set_aside": [{ "room": MINDS, "event": "$e1", "sender": "Nibu", "text": "are you there" }], "at": "2026-11-27T10:00:00Z" }); - assert_eq!(told(&aside).0, ["- Nothing reached #minds:gamecult.org. His turn on Nibu's line \"are you there\" failed twice, so it was set aside."]); + assert_eq!(told_trace(&aside).0, ["- Nothing reached #minds:gamecult.org. His turn on Nibu's line \"are you there\" failed twice, so it was set aside."]); let unnamed = json!({ "set_aside": [{ "room": MINDS, "event": "$e1" }], "at": "2026-11-27T10:00:00Z" }); - assert_eq!(told(&unnamed).0, ["- Nothing reached #minds:gamecult.org. His turn on a line there failed twice, so it was set aside."]); + assert_eq!(told_trace(&unnamed).0, ["- Nothing reached #minds:gamecult.org. His turn on a line there failed twice, so it was set aside."]); } diff --git a/crates/mind-body/src/projection/turn.rs b/crates/mind-body/src/projection/turn.rs index 8ed4d58..87b7276 100644 --- a/crates/mind-body/src/projection/turn.rs +++ b/crates/mind-body/src/projection/turn.rs @@ -314,7 +314,7 @@ fn untold(records: &[Value]) -> Vec { let fresh = |stamp: &Value| at(stamp).is_some_and(|made| last_start.is_none_or(|start| start <= made)); let mut told = Vec::new(); for record in records.iter().filter(|record| record.get("failed").is_none()) { - for (kind, field) in [("unknown", "unknown_sends"), ("unsent", "refused_sends")] { + for (kind, field) in [("unknown", "unknown_sends"), ("refused", "refused_sends")] { told.extend(record[field].as_array().into_iter().flatten().filter(|sent| fresh(&sent["at"])).map(|sent| json!({ "kind": kind, "room": sent["room"], "text": sent["text"] }))); } if fresh(&record["at"]) { diff --git a/crates/mind-body/src/projection/turn/tests.rs b/crates/mind-body/src/projection/turn/tests.rs index d4d6b20..dd550af 100644 --- a/crates/mind-body/src/projection/turn/tests.rs +++ b/crates/mind-body/src/projection/turn/tests.rs @@ -399,7 +399,8 @@ fn t_l3_past_the_window_a_handed_send_is_unknown_and_one_never_handed_is_refused let mut record = json!({ "owed": [{ "id": "k:s0", "room": "!a:b", "text": "handed", "handed": true }, { "id": "k:s1", "room": "!c:d", "text": "never" }], "posted": [], "refused_sends": [], "edited": [] }); deliver(&mouth(&chat), &mut record, Pass::Past, Utc::now(), &mut BTreeSet::new(), &mut |_| true); assert!(chat.sent.borrow().is_empty(), "nothing is made past the window"); - assert_eq!(record["unknown_sends"], json!([{ "room": "!a:b", "text": "handed" }])); + assert_eq!(record["unknown_sends"].as_array().map(|sends| sends.iter().map(|sent| (sent["room"].clone(), sent["text"].clone())).collect::>()), Some(vec![(json!("!a:b"), json!("handed"))])); + assert!(record["unknown_sends"][0]["at"].is_string() && record["refused_sends"][0]["at"].is_string(), "each is stamped when it is made: {record}"); assert_eq!(record["refused_sends"][0]["refusal"], "not_sent_past_the_window"); assert!(record.get("owed").is_none()); }