diff --git a/crates/mind-body/src/projection/commit.rs b/crates/mind-body/src/projection/commit.rs index 1661a17..c339549 100644 --- a/crates/mind-body/src/projection/commit.rs +++ b/crates/mind-body/src/projection/commit.rs @@ -220,8 +220,9 @@ pub(crate) enum Refusal { NotWherePromised, /// A reopen whose words are not at least `PROSE_MIN_WORDS` words standing in her prose this turn (map 16.28.3). ReopenUnquoted, - /// A reopen of a release: the other person's act, never hers to undo (map 16.28.3). - ReleasedNotReopenable, + /// A reopen of a close her own line did not make (map 16.28.1, 16.29.4): a release, the other person's act, or an + /// outside put's close; only a close whose `closedBy.act` is `said` or `amended` is hers to reopen. + NotHerClose, /// A reopen of an entry closed earlier in the same turn. ClosedThisTurn, /// A second hold from the same line. @@ -247,7 +248,7 @@ pub(crate) enum Refusal { /// | `promise_close` kept | `Draft` | the line went out; `needs` typed; for a `Read` need, a read of its target behind the line: this wake before the draft was typed, this conversation, or the entry's receipt | not a blocked entry; a line in the promise's room or a direct message with the person | /// | `promise_close` withdrawn | `Draft` | the line went out | a blocked entry too: a line telling the person she cannot do it; in the promise's room or a direct message with the person | /// | `promise_close` released | `Heard` | — | from the person promised, after the promise | -/// | `promise_reopen` | her words, located in her prose (no `Evidence`) | at least `PROSE_MIN_WORDS` words | a `kept` or `withdrawn` entry listed to her, not closed this turn | +/// | `promise_reopen` | her words, located in her prose (no `Evidence`) | at least `PROSE_MIN_WORDS` words | a closed entry listed to her that her own line closed (`closedBy.act` `said` or `amended`), not closed this turn | /// | `hold_open` | `Heard` | `words` located in that line | one hold per line; anyone she heard may ask (Q-J (a), `may_hold`) | /// | `hold_release` | `Heard` | a line from the asker after the ask | an open hold listed to her | fn accepts(proposal: &Proposal, evidence: &Evidence) -> bool { @@ -489,15 +490,17 @@ fn needed_read(entry: &Value) -> Option { } } -/// The read a reaffirmation's `needs` narrows the entry's need to, when it does (map 16.28.6): the entry needs a search, -/// and `needs` is a read of one thing that is no search, in the same repo. Invariant: a search need changes only through -/// a line of hers to the person that named the narrower thing. +/// The read a reaffirmation's `needs` narrows the entry's need to, when it does (map 16.28.6, 16.29.4): the entry needs a +/// search, and `needs` is a read of one thing in the same repo, a file, a pull request or a commit: no search, and not the +/// repo itself, whose root read lists its pull requests and would answer the need without reading the thing. Invariant: a +/// search need narrows only to one thing in its repo, and only through a line of hers to the person that named it. fn narrows(entry: &Value, needs: &Needs) -> Option { let Ok(Needs::Read { request: need }) = serde_json::from_value::(entry["needs"].clone()) else { return None }; let Needs::Read { request: named } = needs else { return None }; let (ReadRequest::Repo(searched), ReadRequest::Repo(target)) = (&need, named) else { return None }; - let same = repo_name(searched).is_some_and(|repo| repo_name(target).as_deref() == Some(repo.as_str())); - (need.search() && !named.search() && same).then(|| named.clone()) + let repo = repo_name(searched).filter(|repo| repo_name(target).as_deref() == Some(repo.as_str()))?; + let one_thing = named.normal() != format!("repo:gamecult/{repo}"); + (need.search() && !named.search() && one_thing).then(|| named.clone()) } /// The normal form of what a read's receipt read. @@ -767,7 +770,8 @@ struct Reopen<'a> { } /// `promise_reopen` (map 16.28.3): her own words this turn say a close she can see was wrong. Code checks only what it can -/// see: the words stand in her prose, the entry is listed to her as closed, she closed it herself, and not this turn. The +/// see: the words stand in her prose, the entry is listed to her as closed, her own line closed it (`closedBy.act` `said` +/// or `amended`, map 16.29.4), and not this turn. The /// entry goes back to open or blocked by `opens`, its close and its receipt are cleared, so the read that kept it falsely /// keeps it no more, and `reopened` records her words. Whether the words say "not done" is the Interpreter's reading. fn reopen(state: &mut Value, started: &Value, record: &Value, prose: &str, now: DateTime, applied: &mut Applied, proposed: Reopen) -> Result<(), Refusal> { @@ -780,10 +784,11 @@ fn reopen(state: &mut Value, started: &Value, record: &Value, prose: &str, now: if !held(listed, started) { return Err(Refusal::OutsidePutChanged); } - match entry["status"].as_str().unwrap_or_default() { - "kept" | "withdrawn" => {} - "released" => return Err(Refusal::ReleasedNotReopenable), - _ => return Err(Refusal::AlreadyOpen), + if !closed(entry["status"].as_str().unwrap_or_default()) { + return Err(Refusal::AlreadyOpen); + } + if !matches!(entry["closedBy"]["act"].as_str(), Some("said" | "amended")) { + return Err(Refusal::NotHerClose); } let quote = proposed.words.trim(); let located = (words(quote) >= PROSE_MIN_WORDS).then(|| SourceSpan::locate(prose, quote)).flatten().ok_or(Refusal::ReopenUnquoted)?; diff --git a/crates/mind-body/src/projection/commit/tests.rs b/crates/mind-body/src/projection/commit/tests.rs index 2dde5c6..8b2752d 100644 --- a/crates/mind-body/src/projection/commit/tests.rs +++ b/crates/mind-body/src/projection/commit/tests.rs @@ -832,11 +832,13 @@ fn k36_reopen_words_must_be_hers_this_turn() { assert_eq!(f2_r9(&f2_after_r8("kept"), json!([reopening(thought, Some(Needs::Lacking), false)])).0["commitments"][0]["status"], "blocked"); } +/// K40 (map 16.29.4): a release is the other person's act, so it is not hers to reopen. Replaces K36's +/// `k36_a_release_is_not_reopened`, whose `ReleasedNotReopenable` folds into `NotHerClose`. #[test] -fn k36_a_release_is_not_reopened() { +fn k40_a_release_is_not_hers() { let (state, applied) = f2_r9(&f2_after_r8("released"), json!([reopening(F2_R9_WORDS, None, true)])); - assert_eq!((state["commitments"][0]["status"].as_str(), reasons(&applied)), (Some("released"), vec![json!("released_not_reopenable")])); - // A withdrawal reopens. + assert_eq!((state["commitments"][0]["status"].as_str(), reasons(&applied)), (Some("released"), vec![json!("not_her_close")])); + // A withdrawal her own line made reopens. assert_eq!(f2_r9(&f2_after_r8("withdrawn"), json!([reopening(F2_R9_WORDS, None, true)])).0["commitments"][0]["status"], "open"); } @@ -1002,3 +1004,43 @@ fn k36_a_reopen_spends_the_read_that_kept_it() { received["commitments"][0]["readOf"] = json!("repo:gamecult/bifrost#85"); assert_eq!(apply(&received, &keeping_c1(&received, json!([])), F2_PROSE, "r1-t20", later).0["commitments"][0]["status"], "kept"); } + +// --------------------------------------------------------------------------------------------- +// K40 (map 16.29.4): the commit's last edges. A reaffirmation narrows a search need only to one thing in its repo, and +// she reopens only a close her own line made. F.2 r7 is R13's verbatim, as K35's. + +#[test] +fn k40_a_bare_repo_reaffirm_does_not_widen_a_search() { + let need = read_need("GameCult/Bifrost?q=passkey enrolment"); + let (state, applied) = f2_r7(&need, Some(read_need("GameCult/Bifrost"))); + assert_eq!((state["commitments"][0]["needs"].clone(), applied.reaffirmed.len(), applied.refused.len()), (json!(need), 1, 0), "the need is unchanged: {state}"); + // A root read of Bifrost, a list of its pull requests, then keeps nothing. + let (after, kept) = apply(&state, &keeping_c1(&state, json!([returned(1, "GameCult/Bifrost", "Bifrost: open pull requests #84, #85, #86", Some(0))])), F2_PROSE, "r1-t16", now()); + assert_eq!((after["commitments"][0]["status"].as_str(), reasons(&kept)), (Some("open"), vec![json!("needs_unread")]), "{kept:?}"); + // The same repo spelled otherwise is still the repo itself. + for bare in ["gamecult/bifrost", "GameCult/BIFROST"] { + assert_eq!(f2_r7(&need, Some(read_need(bare))).0["commitments"][0]["needs"], json!(need), "{bare}"); + } +} + +#[test] +fn k40_an_item_reaffirm_still_narrows() { + for item in ["GameCult/Bifrost#85", "GameCult/Bifrost/src/passkey.rs", "GameCult/Bifrost@0123abcd"] { + let (state, applied) = f2_r7(&read_need("GameCult/Bifrost?q=passkey enrolment"), Some(read_need(item))); + assert_eq!((state["commitments"][0]["needs"].clone(), applied.reaffirmed.len()), (json!(read_need(item)), 1), "{item}: {state}"); + } +} + +#[test] +fn k40_an_outside_close_is_not_hers_to_reopen() { + for closed_by in [json!({ "act": "put", "event": null, "words": null }), Value::Null] { + let mut kept = f2_after_r8("kept"); + kept["commitments"][0]["closedBy"] = closed_by.clone(); + let (state, applied) = f2_r9(&kept, json!([reopening(F2_R9_WORDS, None, true)])); + assert_eq!((state["commitments"][0]["status"].as_str(), reasons(&applied)), (Some("kept"), vec![json!("not_her_close")]), "{closed_by}"); + } + // Her own addition's close is hers. + let mut amended = f2_after_r8("kept"); + amended["commitments"][0]["closedBy"]["act"] = json!("amended"); + assert_eq!(f2_r9(&amended, json!([reopening(F2_R9_WORDS, None, true)])).0["commitments"][0]["status"], "open"); +}