diff --git a/crates/mind-body/src/projection/read.rs b/crates/mind-body/src/projection/read.rs index a21c4d6..5b6137c 100644 --- a/crates/mind-body/src/projection/read.rs +++ b/crates/mind-body/src/projection/read.rs @@ -264,10 +264,11 @@ pub(crate) fn content(word: &str) -> bool { } /// Whether a search's words find `text`: every word of the query that carries content stands in it as a whole word, case -/// blind (Soul's R7). One matcher for the live forge and the fixture, so the harness and the live path agree. +/// blind, each lightly stemmed as `ReadRequest::normal` stems it (Soul's R7, R9), so "consent receipts" finds "receipt". +/// One matcher for the live forge and the fixture, so the harness and the live path agree. fn search_finds(query: &str, text: &str) -> bool { - let wanted: Vec = word_tokens(query).into_iter().filter(|word| content(word)).collect(); - let held = word_tokens(text); + let wanted: Vec = word_tokens(query).into_iter().filter(|word| content(word)).map(|word| stem(&word)).collect(); + let held: Vec = word_tokens(text).into_iter().map(|word| stem(&word)).collect(); !wanted.is_empty() && wanted.iter().all(|word| held.contains(word)) } @@ -384,11 +385,15 @@ impl ReadSource for ReadFixture { fn read(&self, request: &ReadRequest, _since: DateTime) -> Result { let key = request.normal(); let request_of = |entry: &ReadEntry| serde_json::from_value::(serde_json::json!({ "kind": entry.kind, "target": entry.target })).ok(); + // A search always goes through the matcher over the recorded changes, never a lookup of a recorded search (Soul's + // R9): the live path has no such lookup either. + if matches!(request, ReadRequest::Repo(target) if target.contains("?q=")) { + return fixture_search(&self.0, request).ok_or(ReadFailure::NotFound); + } 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()), - Some(_) => Err(ReadFailure::NotFound), - None => fixture_search(&self.0, request).ok_or(ReadFailure::NotFound), + _ => Err(ReadFailure::NotFound), } } } diff --git a/crates/mind-body/src/projection/read/tests.rs b/crates/mind-body/src/projection/read/tests.rs index ab5948a..77e5c45 100644 --- a/crates/mind-body/src/projection/read/tests.rs +++ b/crates/mind-body/src/projection/read/tests.rs @@ -157,3 +157,28 @@ fn r8_a_search_and_a_number_have_one_normal_form() { assert_eq!(normal("GameCult/Bifrost#0"), "repo:gamecult/bifrost#0"); assert_eq!(normal("GameCult/Bifrost?q=queries class"), "repo:gamecult/bifrost?q=class query"); } + +/// Soul's R9: one matcher, stemmed as the normal form is, in the fixture and the live path alike: "merge pages" and "page +/// merge" find the same, and "consent receipts" finds what "consent receipt" finds, live as in the fixture. +#[test] +fn r9_one_matcher_stems_for_the_fixture_and_the_live_forge() { + let fixture: ReadFixture = serde_json::from_value(serde_json::json!([ + { "kind": "repo", "target": "GameCult/Bifrost#87", "text": "Merge pages and notices\nProve both." }, + { "kind": "repo", "target": "GameCult/Bifrost#59", "text": "Chat sign-in needs a live consent receipt" }, + ])) + .unwrap(); + let since = Utc::now(); + let search = |target: &str| fixture.read(&ReadRequest::Repo(target.into()), since); + assert_eq!(search("GameCult/Bifrost?q=merge pages"), search("GameCult/Bifrost?q=page merge")); + assert!(search("GameCult/Bifrost?q=merge pages").is_ok_and(|found| found.contains("#87"))); + assert_eq!(search("GameCult/Bifrost?q=consent receipts"), search("GameCult/Bifrost?q=consent receipt")); + assert!(search("GameCult/Bifrost?q=consent receipts").is_ok_and(|found| found.contains("#59"))); + struct Recorded; + impl ForgeGet for Recorded { + fn get(&self, _path: &str) -> anyhow::Result<(u16, String)> { + Ok((200, include_str!("../fixtures/forge-bifrost-q-consent.json").to_owned())) + } + } + assert_eq!(repo_read(&Recorded, "GameCult/Bifrost?q=consent receipts"), repo_read(&Recorded, "GameCult/Bifrost?q=consent receipt")); + assert!(repo_read(&Recorded, "GameCult/Bifrost?q=consent receipts").unwrap().starts_with("- #71 ")); +}