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
aien-sovereign-core-mv / crates / aien-runtime / tests / requirements_words_test.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | //! sc#333: required-word wordings were either refused as uncertain before any |
| 17 | //! model call ("Make sure the words whetstone and angle both appear") or, worse, |
| 18 | //! silently not read ("use the exact words greens and browns", "must name |
| 19 | //! Priya, Tomas and Wen"): the product would approve a document without them. |
| 20 | //! They are now `RequiredWords`; near misses stay UNCERTAIN, never silent. A |
| 21 | //! hyphenated required word ("first-aid") is matched as a whole word. |
| 22 | use aien_runtime::requirements::{analyze, refusal_reason, Requirement}; |
| 23 | |
| 24 | use Requirement::*; |
| 25 | |
| 26 | fn words(w: &[&str]) -> Requirement { |
| 27 | RequiredWords(w.iter().map(|x| x.to_string()).collect()) |
| 28 | } |
| 29 | |
| 30 | fn reqs(goal: &str) -> Vec<Requirement> { |
| 31 | let ex = analyze(goal); |
| 32 | assert!( |
| 33 | ex.uncertain.is_empty(), |
| 34 | "{goal:?} should be read, uncertain: {:?}", |
| 35 | ex.uncertain |
| 36 | ); |
| 37 | ex.requirements |
| 38 | } |
| 39 | |
| 40 | #[test] |
| 41 | fn the_exact_words_are_read_not_dropped() { |
| 42 | // tasks-oq3-v4 W1, last sentence, verbatim. |
| 43 | assert_eq!( |
| 44 | reqs("Somewhere in the guide use the exact words greens and browns."), |
| 45 | [words(&["greens", "browns"])] |
| 46 | ); |
| 47 | // tasks-oq3-v4 W5, last sentence, verbatim. |
| 48 | 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."); |
| 49 | assert!(r.contains(&words(&["headlamp", "first-aid"])), "{r:?}"); |
| 50 | } |
| 51 | |
| 52 | #[test] |
| 53 | fn named_people_are_read_not_dropped() { |
| 54 | // tasks-oq3-v4 W4, verbatim. |
| 55 | 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."; |
| 56 | assert!(reqs(w4).contains(&words(&["Priya", "Tomas", "Wen"]))); |
| 57 | // v5 D4 (sc#339), verbatim. |
| 58 | 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."; |
| 59 | assert!(reqs(d4).contains(&words(&["Marta", "Owen", "Priya"]))); |
| 60 | } |
| 61 | |
| 62 | #[test] |
| 63 | fn the_words_that_must_appear_are_read() { |
| 64 | // v5 D1, last sentence, verbatim. |
| 65 | assert_eq!( |
| 66 | reqs("Make sure the words whetstone and angle both appear somewhere in it."), |
| 67 | [words(&["whetstone", "angle"])] |
| 68 | ); |
| 69 | // v5 D5, the word clause (the rest of D5 is sc#331 and sc#334). |
| 70 | assert_eq!( |
| 71 | reqs("Make me a checklist, and be sure the words passport and charger show up."), |
| 72 | [words(&["passport", "charger"])] |
| 73 | ); |
| 74 | for (goal, w) in [ |
| 75 | ( |
| 76 | "Ensure the words red and blue are used.", |
| 77 | vec!["red", "blue"], |
| 78 | ), |
| 79 | ( |
| 80 | "Check that the terms alpha, beta and gamma all appear in the file.", |
| 81 | vec!["alpha", "beta", "gamma"], |
| 82 | ), |
| 83 | ("Make sure the word kettle appears.", vec!["kettle"]), |
| 84 | ] { |
| 85 | assert_eq!(reqs(goal), [words(&w)], "{goal}"); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | #[test] |
| 90 | fn a_hyphenated_word_is_matched_whole() { |
| 91 | let r = [words(&["first-aid", "headlamp"])]; |
| 92 | assert!(refusal_reason(&r, "Pack the First-Aid kit and a headlamp.").is_none()); |
| 93 | for bad in [ |
| 94 | "Pack the first aid kit and a headlamp.", |
| 95 | "Ask a first-aider; bring a headlamp.", |
| 96 | "Pack a headlamp.", |
| 97 | ] { |
| 98 | let why = refusal_reason(&r, bad).expect("unmet"); |
| 99 | assert!(why.contains("first-aid"), "{bad}: {why}"); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | #[test] |
| 104 | fn a_hyphenated_word_has_punctuation_boundaries() { |
| 105 | let r = [words(&["first-aid"])]; |
| 106 | for good in [ |
| 107 | "Bring the first-aid-kit.", |
| 108 | "Bring (first-aid).", |
| 109 | "FIRST-AID.", |
| 110 | ] { |
| 111 | assert!(refusal_reason(&r, good).is_none(), "{good}"); |
| 112 | } |
| 113 | let x = [words(&["x-ray"])]; |
| 114 | assert!(refusal_reason(&x, "A box-ray is not one.").is_some()); |
| 115 | assert!(refusal_reason(&x, "Get an x-ray.").is_none()); |
| 116 | } |
| 117 | |
| 118 | #[test] |
| 119 | fn a_list_followed_by_a_new_clause_is_still_read() { |
| 120 | for (goal, w) in [ |
| 121 | ( |
| 122 | "It must name Priya, Tomas and Wen, and the file needs at least 14 lines.", |
| 123 | vec!["Priya", "Tomas", "Wen"], |
| 124 | ), |
| 125 | ( |
| 126 | "Make sure the words whetstone and angle appear, and keep it short.", |
| 127 | vec!["whetstone", "angle"], |
| 128 | ), |
| 129 | ( |
| 130 | "It must name Priya, Tomas and Wen, and I want it short.", |
| 131 | vec!["Priya", "Tomas", "Wen"], |
| 132 | ), |
| 133 | ( |
| 134 | "Make sure the words whetstone and angle appear, and then be at least 5 lines long.", |
| 135 | vec!["whetstone", "angle"], |
| 136 | ), |
| 137 | ( |
| 138 | "Use the exact words greens and browns somewhere in the file.", |
| 139 | vec!["greens", "browns"], |
| 140 | ), |
| 141 | ] { |
| 142 | let r = reqs(goal); |
| 143 | assert!(r.contains(&words(&w)), "{goal}: {r:?}"); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | #[test] |
| 148 | fn near_misses_stay_uncertain() { |
| 149 | for goal in [ |
| 150 | // negated |
| 151 | "Make sure the words whetstone and angle never appear.", |
| 152 | "Make sure the words whetstone and angle do not appear.", |
| 153 | // a scope the check cannot measure |
| 154 | "Make sure the words whetstone and angle appear in every section.", |
| 155 | "Use the exact words greens and browns somewhere in each section.", |
| 156 | // a count on the words |
| 157 | "Use the exact words greens and browns twice.", |
| 158 | // not single words |
| 159 | "Make sure the words sharp knife and angle appear.", |
| 160 | // a partly named list |
| 161 | "It must name Priya, Tomas and the dog.", |
| 162 | // sc#345 review: a title with a period, a list cut by ";" |
| 163 | "It must mention Dr. Smith.", |
| 164 | "It must mention Mr. Smith and Priya.", |
| 165 | "It must name Priya; and Tomas.", |
| 166 | "It must name Priya. And Tomas.", |
| 167 | // sc#345 review: a count or narrowing after the list |
| 168 | "It must mention Priya at least twice.", |
| 169 | "It must mention Priya, Tomas and Wen at least once each.", |
| 170 | "Use the exact words greens and browns somewhere in the list at least twice.", |
| 171 | "Use the exact words greens and browns somewhere in the list, but only in the summary.", |
| 172 | "Make sure the words whetstone and angle appear somewhere, but only in the summary.", |
| 173 | "Make sure the words whetstone and angle appear, and only in the summary.", |
| 174 | // sc#345 review: a place that may be a section |
| 175 | "Ensure the words red and blue appear in the summary.", |
| 176 | "Ensure the words red and blue appear in the body.", |
| 177 | "Use the exact words greens and browns somewhere in the notes.", |
| 178 | // sc#345 review: a choice is not "all of them" |
| 179 | "It must mention Priya or Tomas.", |
| 180 | "Make sure the words red or blue appear.", |
| 181 | "Use the exact words greens or browns.", |
| 182 | // round 2: a second requirement after ", and" |
| 183 | "It must name Priya and Tomas, and also Wen.", |
| 184 | "Make sure the words whetstone and angle appear, and kettle appears twice.", |
| 185 | "It must name Priya, Tomas and Wen, and nothing else.", |
| 186 | "It must name Priya, Tomas and Wen, and they must each appear in a different section.", |
| 187 | "It must name Priya and Tomas, and the dog.", |
| 188 | // round 3: a name or word hidden in the new clause |
| 189 | "It must name Priya and Tomas, and I want Wen too.", |
| 190 | "It must name Priya and Tomas, and I need Wen to appear.", |
| 191 | "It must name Priya and Tomas, and the one called Wen must appear twice.", |
| 192 | "It must name Priya and Tomas, and the Wen section needs a heading.", |
| 193 | "It must name Priya and Tomas, and write about Wen.", |
| 194 | "It must name Priya and Tomas, and add Wen.", |
| 195 | "It must name Priya and Tomas, and put Wen first.", |
| 196 | "It must name Priya and Tomas, and give Wen a section.", |
| 197 | "It must name Priya and Tomas, and end with Wen.", |
| 198 | "It must name Priya and Tomas, and keep Wen in the intro.", |
| 199 | "It must name Priya and Tomas, and then Wen.", |
| 200 | "Make sure the words whetstone and angle appear, and add kettle too.", |
| 201 | // negated forms |
| 202 | "Make sure none of the words whetstone and angle appear.", |
| 203 | "Make sure the words whetstone and angle don't appear.", |
| 204 | ] { |
| 205 | let ex = analyze(goal); |
| 206 | assert!( |
| 207 | !ex.uncertain.is_empty(), |
| 208 | "{goal:?} should stay uncertain, got {:?}", |
| 209 | ex.requirements |
| 210 | ); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | #[test] |
| 215 | fn wordings_without_a_word_list_stay_silent() { |
| 216 | for goal in [ |
| 217 | "Name the file notes.md.", |
| 218 | "It should mention safety and comfort.", |
| 219 | "Please name it after the river.", |
| 220 | ] { |
| 221 | let ex = analyze(goal); |
| 222 | assert!( |
| 223 | ex.uncertain.is_empty() && ex.requirements.is_empty(), |
| 224 | "{goal:?}: {ex:?}" |
| 225 | ); |
| 226 | } |
| 227 | } |