Persona harness: fixture reads match by normal form, and a search reads the titles of the recorded changes
Soul's R7 item 4. ReadFixture finds a recorded read by ReadRequest::normal. A search (`GameCult/Name?q=words`) that no entry records is answered from the repo's recorded pull requests and issues (`GameCult/Name#n`): each whose title (first line) holds every word, as `- #n title`; none, and it is not found. Room fixtures and simulation plans get it through `[[read]]` / `[[cast.read]]` with no new schema. The unused ReadRequest::key goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
652ec1ec5b
commit
60edbb7be3
2 changed files with 48 additions and 13 deletions
|
|
@ -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<ReadEntry>);
|
||||
|
||||
impl ReadSource for ReadFixture {
|
||||
fn read(&self, request: &ReadRequest, _since: DateTime<Utc>) -> Result<String, ReadFailure> {
|
||||
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::<ReadRequest>(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<String> {
|
||||
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<String> = 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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue