diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 9c372cd..c6d28ce 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -1855,7 +1855,7 @@ fn k44_a_said_draft_listed_declined_is_told_as_said_only() { let posted: Vec = decision["said"].as_array().unwrap().iter().map(|line| json!({ "event": "9", "room": line["room"], "text": line["text"] })).collect(); let outcome = crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": posted, "edited": [] })).unwrap(); assert_eq!(outcome.lines(packet().forms), vec!["- #minds:gamecult.org has, from him: \"Nibu, the tag looks fine to me.\".".to_owned()]); - assert!(outcome.omitted.iter().any(|why| why.starts_with("a declined draft a receipt shows went out")), "{:?}", outcome.omitted); + assert!(outcome.omitted.iter().any(|why| why.starts_with("a declined draft of words a receipt shows reached #minds:gamecult.org")), "{:?}", outcome.omitted); // Negative: with no receipt, the decline is told as before. let unposted = crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": [], "edited": [] })).unwrap().lines(packet().forms); assert!(unposted.iter().any(|line| line.contains("he chose not to send it")), "{unposted:?}"); @@ -1939,7 +1939,7 @@ fn k44_a_refusal_of_words_a_receipt_shows_is_not_told_as_unsent() { let outcome = crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": posted, "edited": [] })).unwrap(); let told = outcome.lines(x1_packet().forms); assert!(!told.iter().any(|line| line.starts_with("- Nothing of this reached")), "{told:?}"); - assert!(outcome.omitted.iter().any(|why| why.starts_with("a refusal (\"held\") of words a receipt shows reached the room")), "{:?}", outcome.omitted); + assert!(outcome.omitted.iter().any(|why| why.starts_with("a held draft of words a receipt shows reached #minds:gamecult.org")), "{:?}", outcome.omitted); // Negative: with no receipt, the hold is told as before. let unposted = crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": [], "edited": [] })).unwrap().lines(x1_packet().forms); assert!(unposted.iter().any(|line| line == "- Nothing of this reached #minds:gamecult.org: Meta asked him to hold it, and it was not sent."), "{unposted:?}"); diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index 885db67..b9d2cc2 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -89,8 +89,9 @@ enum Part { /// choice is shown beside it, so a misread decline is a record she can see (map 16.26, 16.29.2). Declined { room: Option, text: String, thought: String }, /// A draft code did not send because someone asked her to hold what it carries there (`Held`, map 16.28.5): who asked. - /// Their words are in her "Held for others" view, never here (map 16.29.3). - HeldFor { room: Option, who: Option }, + /// Their words are in her "Held for others" view, never here (map 16.29.3). `text` is her draft, kept only so that + /// `settle` can check it against the receipts (K49); it is never rendered. + HeldFor { room: Option, who: Option, text: String }, /// A read she performed (map 16.22.3): what, in code's words; never its content, which is in her view while the /// conversation lasts (K26), and no sentence about what she lacks. Read { what: String }, @@ -159,28 +160,14 @@ pub(crate) fn outcome_of(record: &Value) -> Option { outcome.omitted.push(format!("a line said with no receipt that it went out: {}", line["text"])); } } - // Whether these words reached `room` by a receipt: a line posted there, or an addition the actuator made there. The - // receipts alone say what reached a room (I16.10), so no row tells her "Nothing of this reached" a room her words - // reached, whatever else the decision says of their draft (a decline, a second amendment, a hold). - let reached = |text: &str| { - let posted = receipts.iter().any(|posted| room.as_deref() == Some(posted.room.as_str()) && posted.text == text); - let added = decision["amended"].as_array().into_iter().flatten().any(|amended| { - amended["room"].as_str() == room.as_deref() && amended["added"].as_str() == Some(text) && record["edited"].as_array().into_iter().flatten().any(|receipt| receipt["event"] == amended["event"] && receipt["refusal"].is_null()) - }); - posted || added - }; for refusal in decision["refused"].as_array().into_iter().flatten() { - if words(&refusal["text"]).is_some_and(|text| reached(&text)) { - outcome.omitted.push(format!("a refusal ({}) of words a receipt shows reached the room: {}", refusal["reason"], refusal["text"])); - continue; - } // `Used` and `Duplicate` are the Interpreter naming one draft, or one draft's words, twice: they are not told, as // `NoDraft` is not (they fall to the last arm, and are reported). match (serde_json::from_value::(refusal["reason"].clone()), words(&refusal["text"])) { (Ok(reason @ (Refusal::Echo | Refusal::OverLines | Refusal::NoRoom | Refusal::NotQuotable | Refusal::SecondAmend)), Some(text)) => outcome.parts.push(Part::Refused { reason, room: room.clone(), text }), (Ok(Refusal::NotAmendable), Some(added)) => outcome.parts.push(Part::NotAmended { refusal: None, room: room.clone(), added }), (Ok(reason @ (Refusal::Private | Refusal::SecondNote)), Some(_)) => outcome.parts.push(Part::NoteRefused(reason)), - (Ok(Refusal::Held), Some(_)) => outcome.parts.push(Part::HeldFor { room: room.clone(), who: words(&refusal["hold"]["who"]) }), + (Ok(Refusal::Held), Some(text)) => outcome.parts.push(Part::HeldFor { room: room.clone(), who: words(&refusal["hold"]["who"]), text }), _ => outcome.omitted.push(format!("a refusal she is not told ({}): {}", refusal["reason"], refusal["why"])), } } @@ -277,8 +264,6 @@ pub(crate) fn outcome_of(record: &Value) -> Option { // superseded one is not, since a later draft or later prose of hers stands in its place. for unsent in decision["unsent"].as_array().into_iter().flatten().filter(|unsent| unsent["how"] == "declined") { match (words(&unsent["words"]), words(&unsent["quote"])) { - // A receipt says the draft went out: the receipt wins, and the decline is not told. - (Some(text), Some(_)) if reached(&text) => outcome.omitted.push(format!("a declined draft a receipt shows went out: {unsent}")), (Some(text), Some(thought)) => outcome.parts.push(Part::Declined { room: room.clone(), text, thought }), _ => outcome.omitted.push(format!("a declined draft without its words or its thought: {unsent}")), } @@ -324,11 +309,33 @@ pub(crate) fn outcome_of(record: &Value) -> Option { if words(&record["broke_after"]).is_some() { outcome.parts.push(Part::BrokeAfter { room }); } + settle(&mut outcome, &receipts, record); outcome.parts.sort_by_key(Part::rank); outcome.posted = receipts; Some(outcome) } +/// The one owner of "reached" (K49, I16.10): every row that says words of hers did not reach a room is checked against +/// the receipts, by the row's own room and text, here and nowhere else. A posted line there, or an addition there whose +/// `edited` receipt has no refusal, means her words reached it, so the row would be false: it is omitted and reported. +/// Rows that are receipts (`Said`, `Promise`, `Amended`) are untouched. +fn settle(outcome: &mut Outcome, receipts: &[Posted], record: &Value) { + let added = |room: &str, text: &str| { + record["interpreter"]["amended"].as_array().into_iter().flatten().any(|amended| { + amended["room"].as_str() == Some(room) && amended["added"].as_str() == Some(text) && record["edited"].as_array().into_iter().flatten().any(|receipt| receipt["event"] == amended["event"] && receipt["refusal"].is_null()) + }) + }; + let reached = |room: &str, text: &str| receipts.iter().any(|posted| posted.room == room && posted.text == text) || added(room, text); + let omitted = &mut outcome.omitted; + outcome.parts.retain(|part| match part.own_words() { + Some((Some(room), text)) if reached(room, text) => { + omitted.push(format!("a {} of words a receipt shows reached {room}: {text}", part.row())); + false + } + _ => true, + }); +} + /// The lines one turn may say, in words. fn lines_word() -> String { match MAX_LINES { @@ -340,6 +347,30 @@ fn lines_word() -> String { } impl Part { + /// The words of hers this row says did not reach its room, and that room (K49): what `settle` checks against the + /// receipts. None for a row that is a receipt, or that carries no words of hers. + fn own_words(&self) -> Option<(Option<&str>, &str)> { + match self { + Self::Refused { room, text, .. } | Self::Unfinished { room, text, .. } | Self::Declined { room, text, .. } | Self::HeldFor { room, text, .. } => Some((room.as_deref(), text)), + Self::Gap { room, quote: Quote::Wrote(text), .. } => Some((room.as_deref(), text)), + Self::NotAmended { room, added, .. } => Some((room.as_deref(), added)), + _ => None, + } + } + + /// The row's kind, as the report names it. + fn row(&self) -> &'static str { + match self { + Self::Refused { .. } => "refused line", + Self::Gap { .. } => "gap", + Self::Unfinished { .. } => "unfinished draft", + Self::Declined { .. } => "declined draft", + Self::HeldFor { .. } => "held draft", + Self::NotAmended { .. } => "unmade addition", + _ => "row", + } + } + /// Where the part falls in what she is told (16.20.5): what broke, then what did not happen, then promises, then what /// reached the room, then a later step that broke. fn rank(&self) -> u8 { diff --git a/crates/mind-body/src/projection/outcome/tests.rs b/crates/mind-body/src/projection/outcome/tests.rs index 983d47a..c5d1a50 100644 --- a/crates/mind-body/src/projection/outcome/tests.rs +++ b/crates/mind-body/src/projection/outcome/tests.rs @@ -347,3 +347,112 @@ fn k33_a_refused_close_and_a_held_draft_are_told() { "{omitted:?}" ); } + +// --------------------------------------------------------------------------------------------- +// K49 (map 16.30.6): "reached" is derived once, by `settle`, for every row kind with words. + +const SWARM: &str = "#swarm:gamecult.org"; + +/// Each line the decision said, as a receipt in its room. +fn posted_as_said(decision: &Value) -> Vec { + decision["said"].as_array().into_iter().flatten().enumerate().map(|(at, line)| json!({ "event": (9 + at).to_string(), "room": line["room"], "text": line["text"] })).collect() +} + +/// Soul's P4, inverted: two drafts in the same words, draft 2 said and an addressee gap naming draft 1. The receipt shows +/// the words in #minds, so the gap is not told; it is reported. +#[test] +fn k49_p4_a_gap_on_words_that_went_out_is_not_told() { + let prose = "Morning, all of you. Morning, all of you."; + let decision = answered(&packet(), prose, json!({ "say": [{ "draft": 2, "mentions": [], "in_reply_to": null, "holds": [], "promises": [] }], "gaps": [{ "kind": "addressee", "draft": 1, "quote": null, "detail": "" }] })); + let outcome = outcome_of(&json!({ "interpreter": decision, "posted": posted_as_said(&decision), "edited": [] })).unwrap(); + assert_eq!(outcome.lines(packet().forms), ["- #minds:gamecult.org has, from him: \"Morning, all of you.\"."]); + assert!(outcome.omitted.iter().any(|why| why == "a gap of words a receipt shows reached #minds:gamecult.org: Morning, all of you."), "{:?}", outcome.omitted); + // Negative: with no receipt, the gap is told. + let unposted = outcome_of(&json!({ "interpreter": decision, "posted": [], "edited": [] })).unwrap().lines(packet().forms); + assert!(unposted.iter().any(|line| line.starts_with("- Nothing reached anyone.")), "{unposted:?}"); +} + +/// A record whose decision declines `text` in #minds, with an amendment adding `text` there (event `$ev-1`), the +/// actuator's `edited` receipts, and the room's `posted` ones. +fn declined_and_added(text: &str, edited: Value, posted: Value) -> Value { + json!({ + "interpreter": { + "room": MINDS, "said": [], "refused": [], "gaps": [], + "amended": [{ "room": MINDS, "target": "a1", "draft": 1, "event": "$ev-1", "added": text }], + "unsent": [{ "draft": 1, "how": "declined", "quote": "I keep it back", "words": text }], + }, + "posted": posted, + "edited": edited, + }) +} + +fn declined_told(record: &Value) -> bool { + outcome_of(record).unwrap().lines(packet().forms).iter().any(|line| line.contains("he chose not to send it")) +} + +/// Mutant k44-reached-ignores-addition: an addition the actuator made is a receipt that her words reached the room. +#[test] +fn k49_an_addition_receipt_counts_as_reached() { + let record = declined_and_added("Sent at nine.", json!([{ "event": "$ev-1", "refusal": null }]), json!([])); + assert!(!declined_told(&record), "{:?}", outcome_of(&record).unwrap().lines(packet().forms)); + assert!(outcome_of(&record).unwrap().omitted.iter().any(|why| why == "a declined draft of words a receipt shows reached #minds:gamecult.org: Sent at nine.")); +} + +/// Mutant k44-reached-any-room: a line posted in another room is no receipt for this one. +#[test] +fn k49_a_receipt_in_another_room_does_not_count() { + let elsewhere = declined_and_added("Sent at nine.", json!([]), json!([{ "event": "40", "room": SWARM, "text": "Sent at nine." }])); + assert!(declined_told(&elsewhere), "{:?}", outcome_of(&elsewhere).unwrap().lines(packet().forms)); + let here = declined_and_added("Sent at nine.", json!([]), json!([{ "event": "40", "room": MINDS, "text": "Sent at nine." }])); + assert!(!declined_told(&here), "the same receipt in #minds counts"); +} + +/// Mutant k44-reached-added-without-receipt: an addition the actuator refused, or never answered, did not reach the room. +#[test] +fn k49_an_addition_the_actuator_refused_did_not_reach() { + for edited in [json!([{ "event": "$ev-1", "refusal": "too_long" }]), json!([{ "event": "$ev-2", "refusal": null }]), json!([])] { + let record = declined_and_added("Sent at nine.", edited.clone(), json!([])); + assert!(declined_told(&record), "{edited}: {:?}", outcome_of(&record).unwrap().lines(packet().forms)); + } +} + +/// Every row kind with words of hers that did not reach a room: with a sentinel posted in its room the row is omitted +/// and reported, and with the sentinel posted elsewhere it is told. +#[test] +fn k49_every_row_with_words_is_settled_by_its_room() { + const SENTINEL: &str = "Osprey ledger at nine."; + let decision = |extra: Value| { + let mut decision = json!({ "room": MINDS, "said": [], "refused": [], "gaps": [], "amended": [], "unsent": [] }); + for (key, value) in extra.as_object().unwrap() { + decision[key] = value.clone(); + } + decision + }; + let rows = [ + ("refused line", decision(json!({ "refused": [{ "reason": "over_lines", "text": SENTINEL, "draft": 3 }] }))), + ("gap", decision(json!({ "gaps": [{ "kind": "elsewhere", "from": "draft", "draft": 1, "words": SENTINEL }] }))), + ("unfinished draft", decision(json!({ "unfinished": SENTINEL }))), + ("unfinished draft", decision(json!({ "cut_by_cap": [SENTINEL] }))), + ("declined draft", decision(json!({ "unsent": [{ "draft": 1, "how": "declined", "quote": "I keep it back", "words": SENTINEL }] }))), + ("held draft", decision(json!({ "refused": [{ "reason": "held", "text": SENTINEL, "draft": 1, "hold": { "who": "Meta" } }] }))), + ("unmade addition", decision(json!({ "refused": [{ "reason": "not_amendable", "text": SENTINEL, "draft": 1 }] }))), + ]; + for (row, decision) in rows { + let at = |room: &str| outcome_of(&json!({ "interpreter": decision, "posted": [{ "event": "40", "room": room, "text": SENTINEL }], "edited": [] })).unwrap(); + let here = at(MINDS); + let not_reached = |outcome: &Outcome| outcome.lines(packet().forms).into_iter().filter(|line| line.starts_with("- Nothing")).count(); + assert_eq!(not_reached(&here), 0, "{row}: {:?}", here.lines(packet().forms)); + assert!(here.omitted.iter().any(|why| why == &format!("a {row} of words a receipt shows reached {MINDS}: {SENTINEL}")), "{row}: {:?}", here.omitted); + let elsewhere = at(SWARM); + assert_eq!(not_reached(&elsewhere), 1, "{row}: {:?}", elsewhere.lines(packet().forms)); + assert!(!elsewhere.omitted.iter().any(|why| why.contains("a receipt shows reached")), "{row}: {:?}", elsewhere.omitted); + } +} + +/// K49: no outcome loop decides "reached" on its own; `settle` holds the one receipt check. +#[test] +fn k49_reached_is_decided_once() { + let own = include_str!("../outcome.rs"); + assert_eq!(own.matches("reached(room, text)").count(), 1, "settle is the only place a row is checked against the receipts"); + assert!(!own.contains("let reached = |text: &str|"), "no loop-local reached check"); +}