Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/patches/151e1b2f619ee78f # aien-sovereign-core-mv AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/aien-sovereign-core-mv#345 (code only) closed derived `151e1b2f619ee78f` #345 Imported from GitHub aien-dev/aien-sovereign-core-mv#345 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `c4179f7d9c6d42d2a051d5a7858aaf9f5729d8bb` · Head `60924fb0c8b7c87d98a2aad1d0a4ecdd26f8eeb5` ### Fetch it A git bundle of the pull request's head, 18943 bytes. ``` curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/151e1b2f619ee78f.bundle -o 151e1b2f619ee78f.bundle git fetch 151e1b2f619ee78f.bundle refs/pull/345/head ``` Raw bundle · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/aien-sovereign-core-mv 345 60924fb0c8b7c87d98a2aad1d0a4ecdd26f8eeb5 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":345,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/345","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:52Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.crumb b/.crumb index 66674ebb..9c215f76 100644 --- a/.crumb +++ b/.crumb @@ -77,14 +77,14 @@ } ], "children_root": "sha256:285ca7eafbe46d808ebe5e4fb533e464bfdf0fedaf3eef486ac2e2c8826baf6f", - "compiled_at": "2026-10-08T18:19:04Z", + "compiled_at": "2026-10-08T18:38:52Z", "compiler": "crumb-compile/1", - "digest": "sha256:e8119ca26a0edd4a6516befc79d82edf5ec931e496780c76b442959779cca769", + "digest": "sha256:d7d8e1cf3dd77ae6a53627aac4ed52c58c25317ec9cebc392f20a285f3db745d", "evidence_files": 187, "evidence_root": "sha256:27ee0353cb4d4aae2b7dbce2bfe0d9f4ef2a94cd7a4555b84684d59372503280", - "files": 1610, - "generated_at_commit": "ba22d4198a1169241a200f867f9eab0bc8ac8336", - "source_tree": "sha256:5993f464e2a6b8acbfcf4c38cd8527ec115ec5dcb49ce865d5d8801799cebb3d" + "files": 1611, + "generated_at_commit": "bdda4408e4b41ff453846c71e4c2dc1b207f7cc2", + "source_tree": "sha256:eea94d1ed80695bb0752311ba2d5cf507cbc09a0e5c869366397c811c4d21f02" } }, "history": [], diff --git a/crates/aien-runtime/src/requirements.rs b/crates/aien-runtime/src/requirements.rs index 9710a61e..83503fb7 100644 --- a/crates/aien-runtime/src/requirements.rs +++ b/crates/aien-runtime/src/requirements.rs @@ -116,7 +116,9 @@ pub enum Requirement { }, /// Case-insensitive substrings of the document. RequiredPhrases(Vec), - /// Whole words, case-insensitive. + /// Whole words, case-insensitive. A word holding a mark other than an + /// apostrophe ("first-aid") must occur whole: no letter or digit right + /// before or after it. RequiredWords(Vec), /// Section titles that must each appear as a heading. RequiredHeadings(Vec), @@ -252,9 +254,19 @@ impl Requirement { } Requirement::RequiredWords(p) => { let have: HashSet = words_of(content).into_iter().collect(); + let low = content.to_lowercase(); let missing: Vec = p .iter() - .filter(|x| !have.contains(&x.to_lowercase())) + .filter(|x| { + let x = x.to_lowercase(); + // A word with a hyphen or other mark ("first-aid") is + // matched whole in the text, not as split word parts. + if x.chars().all(|c| c.is_alphanumeric() || c == '\'') { + !have.contains(&x) + } else { + !has_whole(&low, &x) + } + }) .cloned() .collect(); (!missing.is_empty()).then(|| format!("{label}, missing {}", quoted(&missing))) @@ -390,6 +402,18 @@ fn non_empty_lines(s: &str) -> usize { } /// Lowercase alphanumeric words (apostrophes kept inside a word). +/// `needle` occurs in `hay` with no letter or digit right before or after it. +/// Punctuation is a boundary: "first-aid" is found in "first-aid-kit" and +/// "(first-aid)", not in "first-aider"; "x-ray" is not found in "box-ray". +fn has_whole(hay: &str, needle: &str) -> bool { + !needle.is_empty() + && hay.match_indices(needle).any(|(i, _)| { + let before = hay[..i].chars().next_back(); + let after = hay[i + needle.len()..].chars().next(); + !before.is_some_and(char::is_alphanumeric) && !after.is_some_and(char::is_alphanumeric) + }) +} + fn words_of(s: &str) -> Vec { s.split(|c: char| !(c.is_alphanumeric() || c == '\'')) .map(|w| w.trim_matches('\'').to_lowercase()) diff --git a/crates/aien-runtime/src/requirements_extract.rs b/crates/aien-runtime/src/requirements_extract.rs index a3fce2fe..d4f0caac 100644 --- a/crates/aien-runtime/src/requirements_extract.rs +++ b/crates/aien-runtime/src/requirements_extract.rs @@ -19,7 +19,9 @@ //! | `sections|headings titled|named|called A, B and C`, `sections: A, B and C`; with quoted titles also `section(s) is|are titled "A"` and `[one] section(s) must|should|will|shall|can be titled "A"` | `RequiredHeadings` (a count before the noun must equal the number of titles; `organise it under three sections titled ...` is read the same). The is/are/be forms stay UNCERTAIN after `each every all any` or with `if unless optionally optional may might when whenever perhaps maybe` in the clause | //! | `between N and M lines|words` (N <= M) | `MinX(N)` and `MaxX(M)`, inclusive. Other nouns, `from N to M`, ranges like `2-3`, `... or so`, and a range on a part of the document (a countable noun or `gap space distance` right before `between`, or `each every per` within three words) stay UNCERTAIN | //! | `covers|covering A, B and C` (and `to|should|must|will|can cover ...`) | `RequiredTopics` | -//! | `include|contain|use|mention the word(s)|term(s) X, Y` or `"X", "Y"` | `RequiredWords` | +//! | `include|contain|use|mention the [exact|following|specific|same] word(s)|term(s) X, Y` or `"X", "Y"`, optionally followed by `somewhere|anywhere in it|in the text|file|document|list` (a place that is the whole document; any other place, a choice (`or`), or a count or scope after the list is UNCERTAIN) | `RequiredWords` | +//! | `make sure|be sure|ensure|check that the word(s)|term(s) X and Y [both|all|each] appear|occur|show up|are used|are included|are present [somewhere in it]` | `RequiredWords`; a negator, another verb, a narrower place, a choice (`or`) or a count after it is UNCERTAIN | +//! | `must|should|will|shall|to|also name|mention A, B and C [by name]` where every item is one capitalised word | `RequiredWords` (names); a list mixing names and other words, a choice (`or`), a count or scope after it, or a title with a period (`Dr. Smith`) is UNCERTAIN; a list without names (`the file README.md`, `2024`, `the Smith family`) stays silent | //! | `include|contain|use|mention the phrase "X"` / `the phrases "X", "Y"` | `RequiredPhrases` | //! | `add|append|insert|with N line(s)`, `exactly N lines` after such a verb, `a N-line ` after a verb | `AddedLines` exactly N | //! | `write|put|create|draft|compose|produce|generate N line(s)` | `AddedLines` at least N | @@ -976,6 +978,214 @@ fn split_list(region: &str) -> Vec { segs } +/// Words that may name the whole document as the place a word must appear: +/// "somewhere", "anywhere", "in it", "in the text|file|document|list". A part +/// that may be a section ("the summary", "the body", "the notes") is not one. +const PLACE_WORDS: [&str; 9] = [ + "somewhere", + "anywhere", + "in", + "it", + "the", + "text", + "file", + "document", + "list", +]; + +/// Titles written with a period, so the name continues after it ("Dr. Smith"). +const NAME_TITLES: [&str; 10] = [ + "dr", "mr", "mrs", "ms", "prof", "st", "jr", "sr", "mt", "rev", +]; + +/// Words after ", and" that open a new instruction ("..., and write 5 lines"). +const CLAUSE_VERBS: [&str; 13] = [ + "then", "write", "add", "be", "keep", "make", "save", "put", "please", "give", "end", "start", + "finish", +]; + +/// Words after ", and" that open a new clause when a verb soon follows ("..., +/// and the file needs at least 14 lines", "..., and it must be short"). +const CLAUSE_SUBJECTS: [&str; 8] = ["the", "it", "its", "this", "that", "there", "i", "we"]; + +/// Verbs that make a `CLAUSE_SUBJECTS` opener a clause rather than one more item. +const CLAUSE_AUX: [&str; 18] = [ + "must", "should", "needs", "need", "is", "are", "has", "have", "will", "can", "shall", "would", + "want", "wants", "stays", "stay", "gets", "get", +]; + +/// Words in the clause after ", and" that may add to the list or bind it. +const CLAUSE_MENTIONS: [&str; 19] = [ + "name", "names", "named", "mention", "mentions", "appear", "appears", "include", "includes", + "contain", "contains", "use", "uses", "twice", "once", "thrice", "too", "also", "each", +]; + +/// The text after a word or name list ends it cleanly: nothing, a sentence end +/// (not after a title such as "Dr", and not a next sentence that starts with +/// "and" or "or"), or ", and" opening a new instruction or clause. Anything +/// else after the list ("at least twice", ", but only in the summary", "; and +/// Tomas", ", and also Wen", ", and nothing else") may bind to it, and the +/// list is then uncertain (sc#345 review). +fn list_ends_cleanly(after: &str, last_item: &str) -> bool { + let t = after.trim_start_matches([' ', '\t']); + if t.is_empty() || t.starts_with(['\n', '\r']) { + return true; + } + if t.starts_with(['.', '!', '?']) { + let next = t[1..].split_whitespace().next().map(clean).unwrap_or(""); + return !(t.starts_with('.') + && NAME_TITLES.contains(&last_item.to_ascii_lowercase().as_str())) + && !matches!(next.to_ascii_lowercase().as_str(), "and" | "or"); + } + let t = t.strip_prefix(',').unwrap_or(t); + // The new clause runs to the end of its sentence; it must not carry a name + // or word requirement of its own ("..., and I want Wen too", "..., and add Z"). + let end = t + .char_indices() + .find(|&(i, c)| { + c == '\n' + || (matches!(c, '.' | '!' | '?') + && t[i + 1..].chars().next().is_none_or(char::is_whitespace)) + }) + .map_or(t.len(), |(i, _)| i); + let raw: Vec<&str> = t[..end].split_whitespace().collect(); + let names_more = raw.iter().skip(2).any(|x| { + let x = plain(x); + let low = x.to_ascii_lowercase(); + (x.starts_with(|c: char| c.is_uppercase()) && x != "I") + || CLAUSE_MENTIONS.contains(&low.as_str()) + }); + if names_more { + return false; + } + let ws: Vec = raw + .iter() + .take(7) + .map(|x| clean(x).to_ascii_lowercase()) + .collect(); + if ws.first().map(String::as_str) != Some("and") { + return false; + } + match ws.get(1).map(String::as_str) { + Some(x) if CLAUSE_VERBS.contains(&x) => true, + Some(x) if CLAUSE_SUBJECTS.contains(&x) => { + ws[2..].iter().any(|x| CLAUSE_AUX.contains(&x.as_str())) + } + _ => false, + } +} + +/// The list offers a choice ("Priya or Tomas"): a required-words list is all of them. +fn is_choice(list: &str) -> bool { + // Only the words outside quotes: a quoted phrase may itself hold "or". + let mut outside = String::new(); + let mut quoted = false; + for c in list.chars() { + match c { + '"' => quoted = !quoted, + '\u{201C}' => quoted = true, + '\u{201D}' => quoted = false, + _ if !quoted => outside.push(c), + _ => {} + } + } + outside + .split_whitespace() + .any(|x| matches!(clean(x).to_ascii_lowercase().as_str(), "or" | "either")) +} + +/// "somewhere in the list", "anywhere in it": a place that is the whole document. +fn whole_document_place(t: &str) -> bool { + t.split_whitespace() + .all(|x| PLACE_WORDS.contains(&plain(&x.to_ascii_lowercase()))) +} + +/// The word list and the last token of `the words X and Y [both|all] appear| +/// appears|occur|occurs|show up|shows up|are used|is used|are included|are +/// present [somewhere in it]` (`k` is `the`, `q` the noun). None when anything +/// else follows, a negator sits in the clause, or an item is not one word. +fn words_must_appear(goal: &str, toks: &[Tok], k: usize, q: usize) -> Option<(Vec, usize)> { + let w = |i: usize| toks.get(i).map(|t| t.word.as_str()); + if negated_before(toks, k - 1) { + return None; + } + // The verb, in the same clause as the noun. + let mut v = q + 1; + loop { + let x = w(v)?; + if NEGATORS.contains(&x) { + return None; + } + if matches!( + x, + "appear" | "appears" | "occur" | "occurs" | "show" | "shows" | "are" | "is" + ) { + break; + } + // Commas separate the list items; a sentence or clause mark ends the search. + if toks[v].raw.ends_with(['.', ';', ':', '!', '?', ')']) { + return None; + } + v += 1; + } + let mut items_end = v; + if matches!(w(v - 1), Some("both" | "all" | "each")) { + items_end = v - 1; + } + if items_end <= q + 1 { + return None; + } + let items: Vec = split_list(&goal[toks[q].end..toks[items_end].start]) + .iter() + .map(|t| trim_title(t)) + .collect(); + if items.is_empty() + || items.len() > 20 + || !items + .iter() + .all(|t| !t.is_empty() && t.split_whitespace().count() == 1) + { + return None; + } + let mut last = v; + match w(v)? { + "show" | "shows" => { + if w(v + 1) != Some("up") { + return None; + } + last = v + 1; + } + "are" | "is" => { + if !matches!(w(v + 1), Some("used" | "included" | "present")) { + return None; + } + last = v + 1; + } + _ => {} + } + // The rest of the clause names the whole document, or nothing. + while !ends_clause(&toks[last].raw) { + match w(last + 1) { + None => break, + Some(x) if CLAUSE_JOINERS.contains(&x) => break, + Some(x) if PLACE_WORDS.contains(&x) => last += 1, + Some(_) => return None, + } + } + // The clause must end there, not carry a count or a narrowing on. + let raw = &toks[last].raw; + let punct = raw.len() + - raw + .trim_end_matches([',', '.', ';', ':', '!', '?', ')']) + .len(); + if !list_ends_cleanly(&goal[toks[last].end - punct..], "") + || is_choice(&goal[toks[q].end..toks[items_end].start]) + { + return None; + } + Some((items, last)) +} + fn trim_title(t: &str) -> String { t.trim() .trim_matches(|c: char| matches!(c, '"' | '\'' | '\u{201C}' | '\u{201D}' | '*' | '_' | '`')) @@ -1577,7 +1787,16 @@ pub fn analyze(goal: &str) -> Extraction { { continue; } - let Some(kind) = toks.get(k + 2).map(|t| t.word.as_str()) else { + // "use the exact words X and Y" (sc#333): an adjective may sit before the noun. + let q = if toks + .get(k + 2) + .is_some_and(|t| matches!(t.word.as_str(), "exact" | "following" | "specific" | "same")) + { + k + 3 + } else { + k + 2 + }; + let Some(kind) = toks.get(q).map(|t| t.word.as_str()) else { continue; }; if !matches!( @@ -1594,7 +1813,17 @@ pub fn analyze(goal: &str) -> Extraction { bad(&mut unsure, k, false); continue; } - let region = list_region(goal, toks[k + 2].end); + let full = list_region(goal, toks[q].end); + // "... headlamp and first-aid somewhere in the list": a place that is the + // whole document is not part of the list; any other place is uncertain. + let (region, place_ok) = match ["somewhere", "anywhere"] + .iter() + .filter_map(|p| full.to_ascii_lowercase().find(&format!(" {p}"))) + .min() + { + Some(at) => (&full[..at], whole_document_place(&full[at..])), + None => (full, true), + }; let quotes = quoted_items(region); let (items, tail_ok) = if quotes.is_empty() { let items: Vec = split_list(region).iter().map(|t| trim_title(t)).collect(); @@ -1611,7 +1840,15 @@ pub fn analyze(goal: &str) -> Extraction { tail.is_empty() || CLAUSE_JOINERS.contains(&tail_word), ) }; - if !negated_before(&toks, k) && tail_ok && !items.is_empty() && items.len() <= 20 { + let ends_ok = list_ends_cleanly(&goal[toks[q].end + full.len()..], ""); + if !negated_before(&toks, k) + && tail_ok + && place_ok + && ends_ok + && !is_choice(region) + && !items.is_empty() + && items.len() <= 20 + { let dst = if kind == "phrases" { &mut phrases } else { @@ -1622,17 +1859,95 @@ pub fn analyze(goal: &str) -> Extraction { dst.push(t); } } - handled.extend(k..=k + 2); - mark_bytes( - &mut handled, - &toks, - toks[k + 2].end, - toks[k + 2].end + region.len(), - ); + handled.extend(k..=q); + mark_bytes(&mut handled, &toks, toks[q].end, toks[q].end + full.len()); } else { bad(&mut unsure, k, false); } } + // "make sure|be sure|ensure|check that the words X and Y [both|all] appear| + // show up|are used [somewhere in it]" (sc#333). + for k in 1..n { + let w = |i: usize| toks.get(i).map(|t| t.word.as_str()); + if w(k) != Some("the") + || !matches!(w(k - 1), Some("sure" | "ensure" | "that")) + || handled.contains(&k) + { + continue; + } + let q = if matches!(w(k + 1), Some("exact" | "following" | "specific")) { + k + 2 + } else { + k + 1 + }; + if !matches!(w(q), Some("word" | "words" | "term" | "terms")) { + continue; + } + match words_must_appear(goal, &toks, k, q) { + Some((items, last)) => { + for t in items { + if !words.contains(&t) { + words.push(t); + } + } + handled.extend(k - 1..=last); + } + None => bad(&mut unsure, k - 1, false), + } + } + // "must|should|will|to name|mention Priya, Tomas and Wen [by name]": a list + // of single capitalised words (names) is RequiredWords; a list that mixes + // names and other words, offers a choice ("Priya or Tomas"), or carries a + // count or scope on ("at least twice", "Dr. Smith") is uncertain; a list + // without names ("the file README.md", "2024") stays silent (sc#333). + for k in 1..n { + if !matches!( + toks[k].word.as_str(), + "name" | "names" | "mention" | "mentions" + ) || !matches!( + toks[k - 1].word.as_str(), + "must" | "should" | "will" | "shall" | "to" | "also" + ) || handled.contains(&k) + || ends_clause(&toks[k].raw) + { + continue; + } + let full = list_region(goal, toks[k].end); + // ", and the file needs ..." or ", and I want ..." starts a new clause; + // ", and Wen" is the last name. + let region = match full.match_indices(", and ").find(|(i, m)| { + let rest = &full[i + m.len()..]; + rest.starts_with(|c: char| c.is_lowercase()) || rest.starts_with("I ") + }) { + Some((i, _)) => &full[..i], + None => full, + }; + let trimmed = region.trim_end(); + let list = trimmed + .strip_suffix(" by name") + .or_else(|| trimmed.strip_suffix(" by name,")) + .unwrap_or(trimmed); + let items: Vec = split_list(list).iter().map(|t| trim_title(t)).collect(); + let capital = |t: &String| t.starts_with(|c: char| c.is_ascii_uppercase()); + let names = !items.is_empty() + && items.len() <= 20 + && items + .iter() + .all(|t| capital(t) && t.split_whitespace().count() == 1); + let last_item = items.last().map_or("", String::as_str); + let ends_ok = list_ends_cleanly(&goal[toks[k].end + region.len()..], last_item); + if names && ends_ok && !is_choice(list) && !negated_before(&toks, k) { + for t in items { + if !words.contains(&t) { + words.push(t); + } + } + handled.insert(k); + mark_bytes(&mut handled, &toks, toks[k].end, toks[k].end + region.len()); + } else if items.iter().any(capital) { + bad(&mut unsure, k - 1, false); + } + } // The singular phrase key that matched no quoted text at all. for k in 0..n { if toks[k].word.starts_with("includ") || toks[k].word.starts_with("contain") { @@ -1924,7 +2239,16 @@ pub fn analyze(goal: &str) -> Extraction { || (i >= 1 && matches!( nm(i - 1), - Some("these" | "following" | "those" | "the" | "key") + Some( + "these" + | "following" + | "those" + | "the" + | "key" + | "exact" + | "specific" + | "same" + ) ))); if (heading_list || word_list) && !handled.contains(&i) { bad(&mut unsure, i.saturating_sub(2), false); diff --git a/crates/aien-runtime/tests/requirements_words_test.rs b/crates/aien-runtime/tests/requirements_words_test.rs new file mode 100644 index 00000000..4a55273b --- /dev/null +++ b/crates/aien-runtime/tests/requirements_words_test.rs @@ -0,0 +1,212 @@ +//! sc#333: required-word wordings were either refused as uncertain before any +//! model call ("Make sure the words whetstone and angle both appear") or, worse, +//! silently not read ("use the exact words greens and browns", "must name +//! Priya, Tomas and Wen"): the product would approve a document without them. +//! They are now `RequiredWords`; near misses stay UNCERTAIN, never silent. A +//! hyphenated required word ("first-aid") is matched as a whole word. +use aien_runtime::requirements::{analyze, refusal_reason, Requirement}; + +use Requirement::*; + +fn words(w: &[&str]) -> Requirement { + RequiredWords(w.iter().map(|x| x.to_string()).collect()) +} + +fn reqs(goal: &str) -> Vec { + let ex = analyze(goal); + assert!( + ex.uncertain.is_empty(), + "{goal:?} should be read, uncertain: {:?}", + ex.uncertain + ); + ex.requirements +} + +#[test] +fn the_exact_words_are_read_not_dropped() { + // tasks-oq3-v4 W1, last sentence, verbatim. + assert_eq!( + reqs("Somewhere in the guide use the exact words greens and browns."), + [words(&["greens", "browns"])] + ); + // tasks-oq3-v4 W5, last sentence, verbatim. + let r = reqs("Use sections titled \"Shelter\", \"Food and water\" and \"Safety\", and use the exact words headlamp and first-aid somewhere in the list."); + assert!(r.contains(&words(&["headlamp", "first-aid"])), "{r:?}"); +} + +#[test] +fn named_people_are_read_not_dropped() { + // tasks-oq3-v4 W4, verbatim. + let w4 = "Create the file docs/WEEK-SUMMARY.md summarising notes/standup-log.txt in at least 14 lines. It needs a section titled \"Highlights\" and a section titled \"Open questions\", and it must name Priya, Tomas and Wen."; + assert!(reqs(w4).contains(&words(&["Priya", "Tomas", "Wen"]))); + // v5 D4 (sc#339), verbatim. + let d4 = "There is a file at notes/choir-rehearsal.txt with my rough notes from choir practice. Please create a new file called docs/choir-summary.md that summarises it, and leave the original alone. The summary needs at least 13 lines, two sections titled \"Key Points\" and \"Next Steps\", and must mention Marta, Owen and Priya by name."; + assert!(reqs(d4).contains(&words(&["Marta", "Owen", "Priya"]))); +} + +#[test] +fn the_words_that_must_appear_are_read() { + // v5 D1, last sentence, verbatim. + assert_eq!( + reqs("Make sure the words whetstone and angle both appear somewhere in it."), + [words(&["whetstone", "angle"])] + ); + // v5 D5, the word clause (the rest of D5 is sc#331 and sc#334). + assert_eq!( + reqs("Make me a checklist, and be sure the words passport and charger show up."), + [words(&["passport", "charger"])] + ); + for (goal, w) in [ + ( + "Ensure the words red and blue are used.", + vec!["red", "blue"], + ), + ( + "Check that the terms alpha, beta and gamma all appear in the file.", + vec!["alpha", "beta", "gamma"], + ), + ("Make sure the word kettle appears.", vec!["kettle"]), + ] { + assert_eq!(reqs(goal), [words(&w)], "{goal}"); + } +} + +#[test] +fn a_hyphenated_word_is_matched_whole() { + let r = [words(&["first-aid", "headlamp"])]; + assert!(refusal_reason(&r, "Pack the First-Aid kit and a headlamp.").is_none()); + for bad in [ + "Pack the first aid kit and a headlamp.", + "Ask a first-aider; bring a headlamp.", + "Pack a headlamp.", + ] { + let why = refusal_reason(&r, bad).expect("unmet"); + assert!(why.contains("first-aid"), "{bad}: {why}"); + } +} + +#[test] +fn a_hyphenated_word_has_punctuation_boundaries() { + let r = [words(&["first-aid"])]; + for good in [ + "Bring the first-aid-kit.", + "Bring (first-aid).", + "FIRST-AID.", + ] { + assert!(refusal_reason(&r, good).is_none(), "{good}"); + } + let x = [words(&["x-ray"])]; + assert!(refusal_reason(&x, "A box-ray is not one.").is_some()); + assert!(refusal_reason(&x, "Get an x-ray.").is_none()); +} + +#[test] +fn a_list_followed_by_a_new_clause_is_still_read() { + for (goal, w) in [ + ( + "It must name Priya, Tomas and Wen, and the file needs at least 14 lines.", + vec!["Priya", "Tomas", "Wen"], + ), + ( + "Make sure the words whetstone and angle appear, and keep it short.", + vec!["whetstone", "angle"], + ), + ( + "It must name Priya, Tomas and Wen, and I want it short.", + vec!["Priya", "Tomas", "Wen"], + ), + ( + "Make sure the words whetstone and angle appear, and then be at least 5 lines long.", + vec!["whetstone", "angle"], + ), + ( + "Use the exact words greens and browns somewhere in the file.", + vec!["greens", "browns"], + ), + ] { + let r = reqs(goal); + assert!(r.contains(&words(&w)), "{goal}: {r:?}"); + } +} + +#[test] +fn near_misses_stay_uncertain() { + for goal in [ + // negated + "Make sure the words whetstone and angle never appear.", + "Make sure the words whetstone and angle do not appear.", + // a scope the check cannot measure + "Make sure the words whetstone and angle appear in every section.", + "Use the exact words greens and browns somewhere in each section.", + // a count on the words + "Use the exact words greens and browns twice.", + // not single words + "Make sure the words sharp knife and angle appear.", + // a partly named list + "It must name Priya, Tomas and the dog.", + // sc#345 review: a title with a period, a list cut by ";" + "It must mention Dr. Smith.", + "It must mention Mr. Smith and Priya.", + "It must name Priya; and Tomas.", + "It must name Priya. And Tomas.", + // sc#345 review: a count or narrowing after the list + "It must mention Priya at least twice.", + "It must mention Priya, Tomas and Wen at least once each.", + "Use the exact words greens and browns somewhere in the list at least twice.", + "Use the exact words greens and browns somewhere in the list, but only in the summary.", + "Make sure the words whetstone and angle appear somewhere, but only in the summary.", + "Make sure the words whetstone and angle appear, and only in the summary.", + // sc#345 review: a place that may be a section + "Ensure the words red and blue appear in the summary.", + "Ensure the words red and blue appear in the body.", + "Use the exact words greens and browns somewhere in the notes.", + // sc#345 review: a choice is not "all of them" + "It must mention Priya or Tomas.", + "Make sure the words red or blue appear.", + "Use the exact words greens or browns.", + // round 2: a second requirement after ", and" + "It must name Priya and Tomas, and also Wen.", + "Make sure the words whetstone and angle appear, and kettle appears twice.", + "It must name Priya, Tomas and Wen, and nothing else.", + "It must name Priya, Tomas and Wen, and they must each appear in a different section.", + "It must name Priya and Tomas, and the dog.", + // round 3: a name or word hidden in the new clause + "It must name Priya and Tomas, and I want Wen too.", + "It must name Priya and Tomas, and I need Wen to appear.", + "It must name Priya and Tomas, and the one called Wen must appear twice.", + "It must name Priya and Tomas, and the Wen section needs a heading.", + "It must name Priya and Tomas, and write about Wen.", + "It must name Priya and Tomas, and add Wen.", + "It must name Priya and Tomas, and put Wen first.", + "It must name Priya and Tomas, and give Wen a section.", + "It must name Priya and Tomas, and end with Wen.", + "It must name Priya and Tomas, and keep Wen in the intro.", + "It must name Priya and Tomas, and then Wen.", + "Make sure the words whetstone and angle appear, and add kettle too.", + // negated forms + "Make sure none of the words whetstone and angle appear.", + "Make sure the words whetstone and angle don't appear.", + ] { + let ex = analyze(goal); + assert!( + !ex.uncertain.is_empty(), + "{goal:?} should stay uncertain, got {:?}", + ex.requirements + ); + } +} + +#[test] +fn wordings_without_a_word_list_stay_silent() { + for goal in [ + "Name the file notes.md.", + "It should mention safety and comfort.", + "Please name it after the river.", + ] { + let ex = analyze(goal); + assert!( + ex.uncertain.is_empty() && ex.requirements.is_empty(), + "{goal:?}: {ex:?}" + ); + } +} ```