B6: an outside put wins on any field it changed: the commit compares the whole entry with the turn's starting copy the packet listed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-20 22:57:42 +01:00
commit 433243c8b9
4 changed files with 32 additions and 7 deletions

View file

@ -84,8 +84,9 @@ pub(crate) enum Refusal {
NoSuchPromise,
/// The entry is gone from her state: an outside put removed it (4.4 rule 4).
OutsidePutRemovedTarget,
/// The entry changed outside her turn after she was shown it: the outside put wins this turn (4.4 rule 3).
OutsidePutSameField,
/// The entry changed outside her turn after she was shown it, in any field: the outside put wins this turn (4.4 rule
/// 3, B6).
OutsidePutChanged,
/// Closed already, this turn.
AlreadyClosed,
/// The same promise to the same person from the same line is open already.
@ -272,8 +273,10 @@ fn apply_one(state: &mut Value, proposal: &Proposal, record: &Value, prose: &str
if closed(&status) && applied.closed.iter().any(|done| done["entry"]["id"] == entry["id"]) {
return Err(Refusal::AlreadyClosed);
}
if Some(status.as_str()) != listed["status"].as_str() {
return Err(Refusal::OutsidePutSameField);
// The whole entry against the turn's starting copy: an outside put wins on any field it changed (B6). A listing
// without the copy fails closed.
if listed["held"] != *entry {
return Err(Refusal::OutsidePutChanged);
}
let (act, event, words, who) = match (how, resolved) {
(How::Kept, _) if status == "blocked" => return Err(Refusal::BlockedNotKeepable),

View file

@ -48,8 +48,9 @@ fn holding(status: &str) -> Value {
json!({ "commitments": [{ "id": "c-r1-t1-1", "to": META, "room": MINDS, "event": "7", "madeAt": now().to_rfc3339(), "words": "send the render tonight", "status": status, "closedAt": null, "closedBy": null, "extensions": {} }] })
}
/// The Interpreter's list as a packet shows the entry `holding(status)` holds: with the whole entry as the turn began.
fn shown(status: &str) -> Value {
json!([{ "id": "c1", "entry": "c-r1-t1-1", "status": status, "to": META, "to_name": "Meta", "place": "in #minds:gamecult.org", "made": "just now", "words": "send the render tonight" }])
json!([{ "id": "c1", "entry": "c-r1-t1-1", "status": status, "to": META, "to_name": "Meta", "place": "in #minds:gamecult.org", "made": "just now", "words": "send the render tonight", "held": holding(status)["commitments"][0] }])
}
fn reasons(applied: &Applied) -> Vec<Value> {
@ -117,7 +118,7 @@ fn an_outside_put_survives_her_commit_and_wins_on_its_entry() {
let (state, applied) = apply(&unblocked, &record(json!([to_kiko]), shown("blocked"), true), PROSE, "r1-t2", now());
assert_eq!((state["commitments"][0]["status"].as_str(), state["commitments"][1]["status"].as_str()), (Some("open"), Some("blocked")), "{applied:?}");
let (state, applied) = apply(&unblocked, &record(json!([close(How::Withdrawn, Evidence::Draft(1))]), shown("blocked"), true), PROSE, "r1-t2", now());
assert_eq!((state["commitments"][0]["status"].as_str(), reasons(&applied)), (Some("open"), vec![json!("outside_put_same_field")]));
assert_eq!((state["commitments"][0]["status"].as_str(), reasons(&applied)), (Some("open"), vec![json!("outside_put_changed")]));
let (state, applied) = apply(&json!({ "commitments": [] }), &record(json!([close(How::Withdrawn, Evidence::Draft(1))]), shown("open"), true), PROSE, "r1-t2", now());
assert_eq!((state["commitments"].as_array().map(Vec::len), reasons(&applied)), (Some(0), vec![json!("outside_put_removed_target")]));
}
@ -198,3 +199,20 @@ fn b5_a_close_counts_only_where_the_person_promised_can_read_it() {
rec["posted"][0]["room"] = json!("#general:gamecult.org");
assert_eq!(reasons(&apply(&to_room, &rec, PROSE, "r1-t2", now()).1), vec![json!("not_where_promised")]);
}
/// B6: an outside put wins on any field it changed, not only the status: the whole entry is compared with the turn's
/// starting copy, and a listing without one fails closed.
#[test]
fn b6_an_outside_put_wins_on_any_field_it_changed() {
let mut readdressed = holding("open");
readdressed["commitments"][0]["to"] = json!(KIKO);
readdressed["commitments"][0]["words"] = json!("ask Kiko for the render");
let (state, applied) = apply(&readdressed, &record(json!([close(How::Withdrawn, Evidence::Draft(1))]), shown("open"), true), PROSE, "r1-t2", now());
assert_eq!((state["commitments"][0].clone(), reasons(&applied)), (readdressed["commitments"][0].clone(), vec![json!("outside_put_changed")]));
let mut bare = shown("open");
bare[0].as_object_mut().unwrap().remove("held");
assert_eq!(reasons(&apply(&holding("open"), &record(json!([close(How::Withdrawn, Evidence::Draft(1))]), bare, true), PROSE, "r1-t2", now()).1), vec![json!("outside_put_changed")]);
// Unchanged, it closes.
let (state, _) = apply(&holding("open"), &record(json!([close(How::Withdrawn, Evidence::Draft(1))]), shown("open"), true), PROSE, "r1-t2", now());
assert_eq!(state["commitments"][0]["status"], "withdrawn");
}

View file

@ -235,7 +235,7 @@ pub(crate) fn outcome_of(record: &Value) -> Option<Outcome> {
for refused in record["committed"]["refused"].as_array().into_iter().flatten() {
let listed = decision["promises"].as_array().into_iter().flatten().find(|listed| listed["id"] == refused["proposal"]["promise"]);
match (serde_json::from_value::<StateRefusal>(refused["reason"].clone()), listed) {
(Ok(reason @ (StateRefusal::DraftNotSent | StateRefusal::BlockedNotKeepable | StateRefusal::ReleaseNotByPromisee | StateRefusal::ReleaseBeforePromise | StateRefusal::NotWherePromised | StateRefusal::OutsidePutSameField)), Some(listed)) if refused["proposal"]["kind"] == "promise_close" => {
(Ok(reason @ (StateRefusal::DraftNotSent | StateRefusal::BlockedNotKeepable | StateRefusal::ReleaseNotByPromisee | StateRefusal::ReleaseBeforePromise | StateRefusal::NotWherePromised | StateRefusal::OutsidePutChanged)), Some(listed)) if refused["proposal"]["kind"] == "promise_close" => {
outcome.parts.push(Part::StillOpen { reason, to: listed["to_name"].as_str().unwrap_or("the room").to_owned(), words: listed["words"].as_str().unwrap_or_default().to_owned() });
}
_ => outcome.omitted.push(format!("a state change the commit refused that she is not told ({}): {}", refused["reason"], refused["proposal"])),

View file

@ -385,6 +385,9 @@ pub(crate) struct Promised {
pub place: String,
pub made: String,
pub words: String,
/// The entry whole, as her state held it when the packet was built: the turn's starting copy, which the commit
/// compares the entry against, so an outside put wins on any field it changed (4.4, B6). Never shown to a model.
pub held: Value,
}
/// A line of her domain as this packet shows it (map 16.22.2): by `id` (`d1`, `d2`) in the Interpreter's view only, so a
@ -1793,6 +1796,7 @@ fn open_promises(inputs: &Inputs, her: Forms, bodies: &[String], context: &mut C
place: if room_kind(inputs, room) == RoomKind::Direct { "in a direct message".to_owned() } else { format!("in {room}") },
made: ago(inputs.now, *at),
words: text(entry, &["words"]).to_owned(),
held: (*entry).clone(),
}
})
.collect();