diff --git a/crates/mind-body/src/projection/read.rs b/crates/mind-body/src/projection/read.rs index f6e706c..4fd4180 100644 --- a/crates/mind-body/src/projection/read.rs +++ b/crates/mind-body/src/projection/read.rs @@ -106,15 +106,6 @@ impl ReadRequest { Self::Web(url) => url.clone(), } } - - fn key(&self) -> (&'static str, &str) { - match self { - Self::Mind(words) => ("mind", words), - Self::Campaign(slug) => ("campaign", slug), - Self::Repo(target) => ("repo", target), - Self::Web(url) => ("web", url), - } - } } /// Why a read returned nothing, from code's table (map 16.22.3). @@ -341,22 +332,48 @@ pub(crate) struct ReadEntry { } /// Recorded reads for a harness run (`[[read]]` in a room fixture, `[[cast.read]]` in a simulation plan): a read nobody -/// recorded is not there. No forge and no mind is read. +/// recorded is not there. No forge and no mind is read. A read matches an entry by its normal form (`ReadRequest::normal`); +/// a search no entry records searches the titles (first lines) of the repo's recorded pull requests and issues +/// (`GameCult/Name#n`) for all its words, as the forge would. #[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize)] #[serde(transparent)] pub struct ReadFixture(Vec); impl ReadSource for ReadFixture { fn read(&self, request: &ReadRequest, _since: DateTime) -> Result { - let (kind, target) = request.key(); - match self.0.iter().find(|entry| entry.kind == kind && entry.target == target) { + let key = request.normal(); + let request_of = |entry: &ReadEntry| serde_json::from_value::(serde_json::json!({ "kind": entry.kind, "target": entry.target })).ok(); + match self.0.iter().find(|entry| request_of(entry).is_some_and(|recorded| recorded.normal() == key)) { Some(ReadEntry { refused: Some(why), .. }) => Err(*why), Some(ReadEntry { text: Some(text), .. }) => Ok(text.clone()), - _ => Err(ReadFailure::NotFound), + Some(_) => Err(ReadFailure::NotFound), + None => self.search(request).ok_or(ReadFailure::NotFound), } } } +impl ReadFixture { + /// A search of a repo by the titles of its recorded pull requests and issues: each whose title holds every word, as + /// `- #n title`; none, and nothing was found. + fn search(&self, request: &ReadRequest) -> Option { + let ReadRequest::Repo(target) = request else { return None }; + let (repo, words) = target.split_once("?q=")?; + let (repo, words) = (repo.to_lowercase(), word_tokens(words)); + let listed: Vec = self + .0 + .iter() + .filter(|entry| entry.kind == "repo") + .filter_map(|entry| { + let (of, number) = entry.target.split_once('#')?; + let title = entry.text.as_deref()?.lines().next()?.trim(); + let held = word_tokens(title); + (of.to_lowercase() == repo && words.iter().all(|word| held.contains(word))).then(|| format!("- #{number} {title}")) + }) + .collect(); + (!listed.is_empty()).then(|| listed.join("\n")) + } +} + // --------------------------------------------------------------------------------------------- // Live. diff --git a/crates/mind-body/src/projection/read/tests.rs b/crates/mind-body/src/projection/read/tests.rs index 6596689..ab8c557 100644 --- a/crates/mind-body/src/projection/read/tests.rs +++ b/crates/mind-body/src/projection/read/tests.rs @@ -107,3 +107,21 @@ fn k28_a_search_finds_an_older_change_by_her_words() { assert_eq!(repo_read(&Forge(std::cell::RefCell::default(), false), "GameCult/Bifrost?q=nothing here"), Err(ReadFailure::NotFound)); assert_eq!(ReadRequest::Repo("GameCult/Bifrost?q=consent receipt".into()).what(her()), "a search of GameCult/Bifrost for \"consent receipt\""); } + +/// Soul's R7: the fixture reads by normal form, and a search no entry records searches the titles of the repo's recorded +/// pull requests and issues for all its words. +#[test] +fn r7_a_fixture_search_matches_the_titles_of_its_recorded_changes() { + let fixture: ReadFixture = serde_json::from_value(serde_json::json!([ + { "kind": "repo", "target": "GameCult/Bifrost#89", "text": "Consent receipt for door grants\nThe body of it." }, + { "kind": "repo", "target": "GameCult/Bifrost#90", "text": "Sign-in gate" }, + { "kind": "repo", "target": "GameCult/Lodur#4", "text": "Consent for reflexes" }, + ])) + .unwrap(); + let since = Utc::now(); + let search = |target: &str| fixture.read(&ReadRequest::Repo(target.into()), since); + assert_eq!(search("GameCult/Bifrost?q=consent receipt"), Ok("- #89 Consent receipt for door grants".into())); + assert_eq!(search("gamecult/bifrost?q=Consent"), Ok("- #89 Consent receipt for door grants".into()), "the repo's own changes only, case-blind"); + assert_eq!(search("GameCult/Bifrost?q=consent signature"), Err(ReadFailure::NotFound)); + assert_eq!(search("gamecult/BIFROST#90"), Ok("Sign-in gate".into()), "a recorded read by its normal form"); +}