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_enforce_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 | //! Explicit document requirements survive from the goal to the commit |
| 17 | //! (crate::requirements, crate::requirements_extract). Covers the two |
| 18 | //! open-model-qwen3 v3 gaps (G3 "with" after a count, G2 "covers" topics), |
| 19 | //! the uncertain-span refusal and the missing-record refusal (#289). |
| 20 | #[path = "support/compose_harness.rs"] |
| 21 | mod compose_harness; |
| 22 | #[path = "support/home_guard.rs"] |
| 23 | mod home_guard; |
| 24 | |
| 25 | use aien_runtime::control::{ComposeTaskReport, ControlResponse}; |
| 26 | use aien_runtime::requirements::{analyze, extract, refusal_reason, ItemKind, Requirement}; |
| 27 | use aien_runtime::{check_file_proposal, ComposeBridge, ComposeProposer, Generation}; |
| 28 | use compose_harness::Harness; |
| 29 | use std::sync::{Arc, Mutex}; |
| 30 | use std::time::Duration; |
| 31 | |
| 32 | use Requirement::*; |
| 33 | |
| 34 | const G3_GOAL: &str = "Create the file docs/ONBOARDING.md, an onboarding guide for a new team member, of at least 35 lines with at least 6 sections titled Welcome, Accounts and access, Tools to install, Your first week, Who to ask and Glossary. Write at least two sentences in every section."; |
| 35 | const G2_GOAL: &str = "Create the file docs/RELEASE-CHECKLIST.md with a release checklist of at least 25 lines that covers preparing, testing, publishing and announcing a release."; |
| 36 | // The recorded v3 replies (campaign receipts 35f00c9f and 10b9db39), with |
| 37 | // the dash characters replaced because the repo style check bans them. |
| 38 | const G3_V3_REPLY: &str = include_str!("fixtures/v3_replies/g3_onboarding_v3.txt"); |
| 39 | const G2_V3_REPLY: &str = include_str!("fixtures/v3_replies/g2_release_checklist_v3.txt"); |
| 40 | |
| 41 | fn gen(text: &str) -> Result<Generation, String> { |
| 42 | Ok(Generation { |
| 43 | text: text.to_string(), |
| 44 | tokens: 5, |
| 45 | finish_reason: Some("eos".into()), |
| 46 | ..Default::default() |
| 47 | }) |
| 48 | } |
| 49 | |
| 50 | fn content_of(reply: &str) -> String { |
| 51 | check_file_proposal(reply).unwrap().content |
| 52 | } |
| 53 | |
| 54 | /// One compose task through `ComposeBridge::run_task`: the model answers call |
| 55 | /// k with `replies[k - 1]` (the last one repeats). Returns the report and the |
| 56 | /// prompts the model was handed. |
| 57 | fn run(goal: &str, replies: Vec<String>) -> (ComposeTaskReport, Vec<String>) { |
| 58 | let ex = analyze(goal); |
| 59 | assert!(ex.uncertain.is_empty(), "{:?}", ex.uncertain); |
| 60 | let texts: Vec<&str> = replies.iter().map(String::as_str).collect(); |
| 61 | let h = Harness::new(compose_harness::replies(&texts)); |
| 62 | let r = h.run(goal).unwrap(); |
| 63 | let p = h.calls().into_iter().map(|c| c.prompt).collect(); |
| 64 | (r, p) |
| 65 | } |
| 66 | |
| 67 | /// A reply that meets every requirement of the G3 goal. |
| 68 | fn g3_good() -> String { |
| 69 | let mut s = String::from("filename: docs/ONBOARDING.md\n"); |
| 70 | for t in [ |
| 71 | "Welcome", |
| 72 | "Accounts and access", |
| 73 | "Tools to install", |
| 74 | "Your first week", |
| 75 | "Who to ask", |
| 76 | "Glossary", |
| 77 | ] { |
| 78 | s.push_str(&format!("# {t}\n\n")); |
| 79 | s.push_str("This section has a first sentence. It also has a second sentence.\n"); |
| 80 | s.push_str("- one more line about it\n- and another line about it\n- a third line about it\n- a fourth line about it\n\n"); |
| 81 | } |
| 82 | s |
| 83 | } |
| 84 | |
| 85 | /// A reply that meets every requirement of the G2 goal. |
| 86 | fn g2_good() -> String { |
| 87 | let mut s = String::from("filename: docs/RELEASE-CHECKLIST.md\n# Release checklist\n"); |
| 88 | for i in 0..8 { |
| 89 | s.push_str(&format!("- [ ] Prepare step {i}: confirm the version\n")); |
| 90 | } |
| 91 | for i in 0..6 { |
| 92 | s.push_str(&format!("- [ ] Testing step {i}: run the suite\n")); |
| 93 | } |
| 94 | for i in 0..6 { |
| 95 | s.push_str(&format!( |
| 96 | "- [ ] Publish step {i}: publishing the packages\n" |
| 97 | )); |
| 98 | } |
| 99 | for i in 0..6 { |
| 100 | s.push_str(&format!( |
| 101 | "- [ ] Announce step {i}: announcing the release\n" |
| 102 | )); |
| 103 | } |
| 104 | s |
| 105 | } |
| 106 | |
| 107 | // ---- extraction ---- |
| 108 | |
| 109 | #[test] |
| 110 | fn g3_goal_is_fully_recognized() { |
| 111 | let ex = analyze(G3_GOAL); |
| 112 | assert!(ex.uncertain.is_empty(), "{:?}", ex.uncertain); |
| 113 | assert_eq!( |
| 114 | ex.requirements, |
| 115 | [ |
| 116 | MinLines(35), |
| 117 | MinItems(ItemKind::Sections, 6), |
| 118 | MinSentencesPerSection(2), |
| 119 | RequiredHeadings( |
| 120 | [ |
| 121 | "Welcome", |
| 122 | "Accounts and access", |
| 123 | "Tools to install", |
| 124 | "Your first week", |
| 125 | "Who to ask", |
| 126 | "Glossary" |
| 127 | ] |
| 128 | .map(String::from) |
| 129 | .to_vec() |
| 130 | ), |
| 131 | ] |
| 132 | ); |
| 133 | } |
| 134 | |
| 135 | #[test] |
| 136 | fn g2_goal_is_fully_recognized() { |
| 137 | let ex = analyze(G2_GOAL); |
| 138 | assert!(ex.uncertain.is_empty(), "{:?}", ex.uncertain); |
| 139 | assert_eq!( |
| 140 | ex.requirements, |
| 141 | [ |
| 142 | MinLines(25), |
| 143 | RequiredTopics( |
| 144 | ["preparing", "testing", "publishing", "announcing a release"] |
| 145 | .map(String::from) |
| 146 | .to_vec() |
| 147 | ) |
| 148 | ] |
| 149 | ); |
| 150 | } |
| 151 | |
| 152 | #[test] |
| 153 | fn line_count_phrasings() { |
| 154 | for (g, want) in [ |
| 155 | ("at least 20 lines", MinLines(20)), |
| 156 | ("at least twenty lines", MinLines(20)), |
| 157 | ("a document of at least 20 lines with a title", MinLines(20)), |
| 158 | ("a note of at least 35 lines long", MinLines(35)), |
| 159 | ("no fewer than 20 lines", MinLines(20)), |
| 160 | ("not fewer than 20 lines.", MinLines(20)), |
| 161 | ("20 or more lines", MinLines(20)), |
| 162 | ("20+ lines", MinLines(20)), |
| 163 | ("a minimum of 12 lines", MinLines(12)), |
| 164 | ("more than 20 lines", MinLines(21)), |
| 165 | ("at most 8 lines", MaxLines(8)), |
| 166 | ("no more than eight lines", MaxLines(8)), |
| 167 | ("8 or fewer lines", MaxLines(8)), |
| 168 | ("up to 8 lines", MaxLines(8)), |
| 169 | ("fewer than 9 lines", MaxLines(8)), |
| 170 | ("at least twenty-five lines", MinLines(25)), |
| 171 | ("at least 200 words", MinWords(200)), |
| 172 | ("at most 50 words.", MaxWords(50)), |
| 173 | ("at least 3 headings", MinItems(ItemKind::Sections, 3)), |
| 174 | ] { |
| 175 | let ex = analyze(g); |
| 176 | assert!(ex.uncertain.is_empty(), "{g}: {:?}", ex.uncertain); |
| 177 | assert_eq!(ex.requirements, [want], "{g}"); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | #[test] |
| 182 | fn uncertain_spans_are_reported_not_dropped() { |
| 183 | for (g, span) in [ |
| 184 | ( |
| 185 | "show at least 3 lines of context", |
| 186 | "at least 3 lines of context", |
| 187 | ), |
| 188 | ( |
| 189 | "at least 5 items per category", |
| 190 | "at least 5 items per category", |
| 191 | ), |
| 192 | ("at most 5 items", "at most 5 items"), |
| 193 | ("at most 3 paragraphs", "at most 3 paragraphs"), |
| 194 | ("exactly 20 lines", "exactly 20 lines"), |
| 195 | ("about 30 lines", "about 30 lines"), |
| 196 | ("between 10 and 20 items", "between 10 and 20 items"), |
| 197 | ("write **at least 20 lines**", "at least 20 lines"), |
| 198 | ("at least 20 long lines", "at least 20 long lines"), |
| 199 | ("do not write at least 20 lines", "at least 20 lines"), |
| 200 | ("a 35-line document", "35-line document"), |
| 201 | ("write at least 2 sentences", "at least 2 sentences"), |
| 202 | ( |
| 203 | "do not include the phrase \"X\"", |
| 204 | "include the phrase \"X\"", |
| 205 | ), |
| 206 | ( |
| 207 | "include the phrase \"X\" in the title", |
| 208 | "include the phrase", |
| 209 | ), |
| 210 | ("with 5 sections titled A, B", "sections titled A, B"), |
| 211 | ( |
| 212 | "include the words alpha beta gamma", |
| 213 | "include the words alpha", |
| 214 | ), |
| 215 | ] { |
| 216 | let ex = analyze(g); |
| 217 | assert!( |
| 218 | ex.uncertain.iter().any(|u| u.contains(span)), |
| 219 | "{g}: {:?}", |
| 220 | ex.uncertain |
| 221 | ); |
| 222 | let why = ex.refusal().unwrap(); |
| 223 | assert!(why.starts_with("uncertain requirement"), "{why}"); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | #[test] |
| 228 | fn clean_goals_have_no_uncertain_spans() { |
| 229 | for g in [ |
| 230 | "write a long document", |
| 231 | "do not use tables. Write at least 20 lines.", |
| 232 | "Add the line \"- add dark mode\" under the \"## Planned\" heading in ROADMAP.md.", |
| 233 | "list three reasons", |
| 234 | ] { |
| 235 | assert!(analyze(g).uncertain.is_empty(), "{g}: {:?}", analyze(g)); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | #[test] |
| 240 | fn headings_words_phrases_and_topics_extract() { |
| 241 | assert_eq!( |
| 242 | extract("a guide with sections named Intro, Usage and FAQ."), |
| 243 | [RequiredHeadings(vec![ |
| 244 | "Intro".into(), |
| 245 | "Usage".into(), |
| 246 | "FAQ".into() |
| 247 | ])] |
| 248 | ); |
| 249 | assert_eq!( |
| 250 | extract("3 sections called \"Alpha beta\", \"Gamma\" and \"Delta\""), |
| 251 | [RequiredHeadings(vec![ |
| 252 | "Alpha beta".into(), |
| 253 | "Gamma".into(), |
| 254 | "Delta".into() |
| 255 | ])] |
| 256 | ); |
| 257 | assert_eq!( |
| 258 | extract("The text must include the words alpha, beta and gamma."), |
| 259 | [RequiredWords(vec![ |
| 260 | "alpha".into(), |
| 261 | "beta".into(), |
| 262 | "gamma".into() |
| 263 | ])] |
| 264 | ); |
| 265 | assert_eq!( |
| 266 | extract("use the words \"red\" and \"blue\""), |
| 267 | [RequiredWords(vec!["red".into(), "blue".into()])] |
| 268 | ); |
| 269 | assert_eq!( |
| 270 | extract("include the phrases \"good day\", \"all clear\""), |
| 271 | [RequiredPhrases(vec!["good day".into(), "all clear".into()])] |
| 272 | ); |
| 273 | assert_eq!( |
| 274 | extract("a guide that should cover setup, usage and cleanup in at least 30 lines"), |
| 275 | [ |
| 276 | MinLines(30), |
| 277 | RequiredTopics(vec!["setup".into(), "usage".into(), "cleanup".into()]) |
| 278 | ] |
| 279 | ); |
| 280 | assert_eq!( |
| 281 | extract("In every section, write at least three sentences."), |
| 282 | [MinSentencesPerSection(3)] |
| 283 | ); |
| 284 | // "a cover letter" is not a topic list |
| 285 | assert!(analyze("write a cover letter").requirements.is_empty()); |
| 286 | } |
| 287 | |
| 288 | // ---- checks ---- |
| 289 | |
| 290 | #[test] |
| 291 | fn headings_must_be_heading_lines_and_ignore_numbering_case_and_punctuation() { |
| 292 | let r = RequiredHeadings(vec!["Your first week".into(), "Glossary".into()]); |
| 293 | let ok = "# 1. Your First Week:\ntext\n## **glossary**\nx\n"; |
| 294 | assert!(r.check(ok).is_none()); |
| 295 | // a plain line, or a heading inside a code fence, is not a heading |
| 296 | let bad = "Your first week\n```\n# Glossary\n```\n"; |
| 297 | let why = r.check(bad).unwrap(); |
| 298 | assert!( |
| 299 | why.contains("missing \"Your first week\", \"Glossary\""), |
| 300 | "{why}" |
| 301 | ); |
| 302 | } |
| 303 | |
| 304 | #[test] |
| 305 | fn required_words_are_whole_words_case_insensitive() { |
| 306 | let r = RequiredWords(vec!["Blue".into(), "red".into()]); |
| 307 | assert!(r.check("A RED car, a blue one.").is_none()); |
| 308 | let why = r.check("bluebird and reddish").unwrap(); |
| 309 | assert!(why.contains("missing \"Blue\", \"red\""), "{why}"); |
| 310 | } |
| 311 | |
| 312 | #[test] |
| 313 | fn topic_word_forms_are_conservative() { |
| 314 | let r = RequiredTopics(vec![ |
| 315 | "preparing".into(), |
| 316 | "publishing".into(), |
| 317 | "announcing a release".into(), |
| 318 | ]); |
| 319 | // different suffixes agree |
| 320 | assert!(r |
| 321 | .check("Prepare it. Publish it. We announce this release.") |
| 322 | .is_none()); |
| 323 | // nearby words that do not share the stem do not |
| 324 | let why = r.check("Prepare it. Make it public. The announcement of a release."); |
| 325 | let why = why.unwrap(); |
| 326 | assert!(why.contains("not covered: publishing"), "{why}"); |
| 327 | // code blocks are not prose |
| 328 | let why = RequiredTopics(vec!["testing".into()]) |
| 329 | .check("```\ntesting\n```\nnothing here\n") |
| 330 | .unwrap(); |
| 331 | assert!(why.contains("testing"), "{why}"); |
| 332 | } |
| 333 | |
| 334 | #[test] |
| 335 | fn sentences_per_section_counts_prose_under_each_heading() { |
| 336 | let r = MinSentencesPerSection(2); |
| 337 | let ok = |
| 338 | "# Title\n## A\nOne sentence here. Two sentences here.\n## B\nFirst one! Second one?\n"; |
| 339 | assert!(r.check(ok).is_none(), "{:?}", r.check(ok)); |
| 340 | let bad = |
| 341 | "## A\nOne sentence here. Two sentences here.\n## B\nOnly one sentence here.\n## C\n\n"; |
| 342 | let why = r.check(bad).unwrap(); |
| 343 | assert!( |
| 344 | why.contains("B (1)") && why.contains("C (0)") && !why.contains("A ("), |
| 345 | "{why}" |
| 346 | ); |
| 347 | assert!(r |
| 348 | .check("no headings at all. really.\n") |
| 349 | .unwrap() |
| 350 | .contains("no headings")); |
| 351 | // decimals and version numbers do not end a sentence |
| 352 | assert!(MinSentencesPerSection(2) |
| 353 | .check("## A\nUse python 3.10 now. Then 2.5 more.\n") |
| 354 | .is_none()); |
| 355 | } |
| 356 | |
| 357 | #[test] |
| 358 | fn word_counts_and_multiple_code_blocks() { |
| 359 | assert!(MinWords(5).check("a b c d e").is_none()); |
| 360 | assert!(MinWords(6).check("a b c d e").unwrap().contains("found 5")); |
| 361 | // headings after code blocks, and text after several code blocks, still count |
| 362 | let doc = "# One\n```rust\n# not a heading\n```\ntext\n```\n## also not\n```\n## Real\ntail text here. And more.\n"; |
| 363 | assert!(RequiredHeadings(vec!["One".into(), "Real".into()]) |
| 364 | .check(doc) |
| 365 | .is_none()); |
| 366 | assert!(RequiredHeadings(vec!["not a heading".into()]) |
| 367 | .check(doc) |
| 368 | .is_some()); |
| 369 | assert!(MinItems(ItemKind::Sections, 2).check(doc).is_none()); |
| 370 | assert!(MinItems(ItemKind::Sections, 3) |
| 371 | .check(doc) |
| 372 | .unwrap() |
| 373 | .contains("found 2")); |
| 374 | assert!(RequiredTopics(vec!["tail".into()]).check(doc).is_none()); |
| 375 | } |
| 376 | |
| 377 | // ---- the recorded v3 replies ---- |
| 378 | |
| 379 | #[test] |
| 380 | #[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")] |
| 381 | fn recorded_g3_reply_is_refused_and_a_good_reply_passes() { |
| 382 | let _home = home_guard::home_slot(); |
| 383 | let ex = analyze(G3_GOAL); |
| 384 | let why = refusal_reason(&ex.requirements, &content_of(G3_V3_REPLY)).unwrap(); |
| 385 | assert!( |
| 386 | why.contains("at least 35 non-empty lines, found 13"), |
| 387 | "{why}" |
| 388 | ); |
| 389 | let (r, prompts) = run(G3_GOAL, vec![G3_V3_REPLY.into(), g3_good()]); |
| 390 | assert_eq!(r.proposal.as_deref(), Some(g3_good().as_str()), "{r:?}"); |
| 391 | let a = &r.proposal_attempts; |
| 392 | assert_eq!(a[0].outcome, "refused"); |
| 393 | assert!(a[0].unmet_requirements[0].contains("found 13")); |
| 394 | assert_eq!(a[1].outcome, "parsed"); |
| 395 | // the retry prompt names what was missed |
| 396 | assert!( |
| 397 | prompts[1].contains("at least 35 non-empty lines, found 13"), |
| 398 | "{}", |
| 399 | prompts[1] |
| 400 | ); |
| 401 | } |
| 402 | |
| 403 | #[test] |
| 404 | #[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")] |
| 405 | fn recorded_g3_reply_exhausts_with_nothing_approved() { |
| 406 | let _home = home_guard::home_slot(); |
| 407 | let (r, _) = run(G3_GOAL, vec![G3_V3_REPLY.into()]); |
| 408 | assert!( |
| 409 | r.proposal.is_none() && r.uncommitted_proposal.is_none(), |
| 410 | "{r:?}" |
| 411 | ); |
| 412 | let why = r.proposer_error.unwrap(); |
| 413 | assert!(why.contains("found 13"), "{why}"); |
| 414 | let a = &r.proposal_attempts; |
| 415 | assert_eq!(a.len(), 3); |
| 416 | assert!(a |
| 417 | .iter() |
| 418 | .all(|x| x.outcome == "refused" && x.aegis.is_none())); |
| 419 | } |
| 420 | |
| 421 | #[test] |
| 422 | fn g3_wrong_headings_and_short_sections_are_named() { |
| 423 | let mut s = String::from("filename: docs/ONBOARDING.md\n"); |
| 424 | for t in ["Welcome", "Setup", "Glossary"] { |
| 425 | s.push_str(&format!("# {t}\n\nOnly one sentence here.\n")); |
| 426 | } |
| 427 | for i in 0..30 { |
| 428 | s.push_str(&format!("filler line {i}\n")); |
| 429 | } |
| 430 | let why = refusal_reason(&analyze(G3_GOAL).requirements, &content_of(&s)).unwrap(); |
| 431 | assert!(why.contains("at least 6 headings, found 3"), "{why}"); |
| 432 | assert!(why.contains("missing \"Accounts and access\""), "{why}"); |
| 433 | assert!(why.contains("too few in: Welcome (1)"), "{why}"); |
| 434 | } |
| 435 | |
| 436 | #[test] |
| 437 | #[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")] |
| 438 | fn recorded_g2_reply_is_refused_and_a_good_reply_passes() { |
| 439 | let _home = home_guard::home_slot(); |
| 440 | let ex = analyze(G2_GOAL); |
| 441 | let why = refusal_reason(&ex.requirements, &content_of(G2_V3_REPLY)).unwrap(); |
| 442 | assert!(why.contains("not covered: publishing"), "{why}"); |
| 443 | let (r, prompts) = run(G2_GOAL, vec![G2_V3_REPLY.into(), g2_good()]); |
| 444 | assert_eq!(r.proposal.as_deref(), Some(g2_good().as_str()), "{r:?}"); |
| 445 | assert_eq!(r.proposal_attempts[0].outcome, "refused"); |
| 446 | assert!( |
| 447 | prompts[1].contains("not covered: publishing"), |
| 448 | "{}", |
| 449 | prompts[1] |
| 450 | ); |
| 451 | // the recorded reply is exhausted when the model keeps repeating it |
| 452 | let (r, _) = run(G2_GOAL, vec![G2_V3_REPLY.into()]); |
| 453 | assert!(r.proposal.is_none() && r.proposer_error.is_some(), "{r:?}"); |
| 454 | assert_eq!(r.proposal_attempts.len(), 3); |
| 455 | } |
| 456 | |
| 457 | // ---- through the real compose run (linked build only) ---- |
| 458 | |
| 459 | fn bridge_with( |
| 460 | tmp: &std::path::Path, |
| 461 | f: impl Fn(&str) -> Result<Generation, String> + Send + Sync + 'static, |
| 462 | ) -> ComposeBridge { |
| 463 | let proposer: ComposeProposer = Arc::new(move |p: &str, _: Duration| f(p)); |
| 464 | ComposeBridge::new(tmp.join("compose"), proposer, "test:enforce") |
| 465 | } |
| 466 | |
| 467 | fn result(resp: ControlResponse) -> Option<aien_runtime::control::ComposeTaskReport> { |
| 468 | if !aien_omega_compose::LINKED { |
| 469 | assert!(matches!(resp, ControlResponse::Error(_))); |
| 470 | return None; |
| 471 | } |
| 472 | let ControlResponse::ComposeTaskResult(r) = resp else { |
| 473 | panic!("{resp:?}") |
| 474 | }; |
| 475 | Some(*r) |
| 476 | } |
| 477 | |
| 478 | #[test] |
| 479 | fn linked_uncertain_goal_is_refused_before_any_model_call() { |
| 480 | let _home = home_guard::home_slot(); |
| 481 | let tmp = tempfile::tempdir().unwrap(); |
| 482 | let ws = tmp.path().join("ws"); |
| 483 | std::fs::create_dir_all(&ws).unwrap(); |
| 484 | let calls = Arc::new(Mutex::new(0usize)); |
| 485 | let c = calls.clone(); |
| 486 | let bridge = bridge_with(tmp.path(), move |_| { |
| 487 | *c.lock().unwrap() += 1; |
| 488 | gen("filename: DOC.md\nhello\n") |
| 489 | }); |
| 490 | let resp = bridge.run_task( |
| 491 | "write DOC.md with at least 3 lines of context", |
| 492 | ws.to_str().unwrap(), |
| 493 | ); |
| 494 | let Some(r) = result(resp) else { return }; |
| 495 | assert_eq!(*calls.lock().unwrap(), 0); |
| 496 | assert!(!r.committed, "{r:?}"); |
| 497 | assert!(r.proposal.is_none()); |
| 498 | assert_eq!(r.requirements_uncertain, ["at least 3 lines of context"]); |
| 499 | assert!(r |
| 500 | .proposer_error |
| 501 | .unwrap() |
| 502 | .starts_with("uncertain requirement")); |
| 503 | assert_eq!(std::fs::read_dir(&ws).unwrap().count(), 0); |
| 504 | } |
| 505 | |
| 506 | #[test] |
| 507 | fn linked_g3_original_reply_is_refused_then_a_good_reply_commits_exact_bytes() { |
| 508 | let _home = home_guard::home_slot(); |
| 509 | let tmp = tempfile::tempdir().unwrap(); |
| 510 | let ws = tmp.path().join("ws"); |
| 511 | std::fs::create_dir_all(&ws).unwrap(); |
| 512 | let calls = Arc::new(Mutex::new(0usize)); |
| 513 | let c = calls.clone(); |
| 514 | let bridge = bridge_with(tmp.path(), move |_| { |
| 515 | let mut n = c.lock().unwrap(); |
| 516 | *n += 1; |
| 517 | let good = g3_good(); |
| 518 | gen(if *n == 1 { G3_V3_REPLY } else { &good }) |
| 519 | }); |
| 520 | let resp = bridge.run_task(G3_GOAL, ws.to_str().unwrap()); |
| 521 | let Some(r) = result(resp) else { return }; |
| 522 | assert!(r.requirements_uncertain.is_empty()); |
| 523 | assert_eq!(r.proposal_attempts.len(), 2, "{r:?}"); |
| 524 | assert_eq!(r.proposal_attempts[0].outcome, "refused"); |
| 525 | assert!(r.committed, "{r:?}"); |
| 526 | let p = check_file_proposal(r.proposal.as_deref().unwrap()).unwrap(); |
| 527 | assert_eq!(p.content, content_of(&g3_good())); |
| 528 | assert!(refusal_reason(&analyze(G3_GOAL).requirements, &p.content).is_none()); |
| 529 | } |
| 530 | |
| 531 | #[test] |
| 532 | fn linked_g2_original_reply_exhausts_and_nothing_is_written() { |
| 533 | let _home = home_guard::home_slot(); |
| 534 | let tmp = tempfile::tempdir().unwrap(); |
| 535 | let ws = tmp.path().join("ws"); |
| 536 | std::fs::create_dir_all(&ws).unwrap(); |
| 537 | let bridge = bridge_with(tmp.path(), |_| gen(G2_V3_REPLY)); |
| 538 | let resp = bridge.run_task(G2_GOAL, ws.to_str().unwrap()); |
| 539 | let Some(r) = result(resp) else { return }; |
| 540 | assert!(!r.committed, "{r:?}"); |
| 541 | assert!(r.proposal.is_none()); |
| 542 | assert_eq!(r.proposal_attempts.len(), 3); |
| 543 | assert!(r |
| 544 | .proposer_error |
| 545 | .unwrap() |
| 546 | .contains("not covered: publishing")); |
| 547 | assert_eq!(std::fs::read_dir(&ws).unwrap().count(), 0); |
| 548 | } |
| 549 | |
| 550 | // ---- review round: nothing that looks like a requirement passes silently ---- |
| 551 | |
| 552 | #[test] |
| 553 | fn sixteen_review_goals_are_recognized_or_uncertain_never_silent() { |
| 554 | for g in [ |
| 555 | "run to 30 lines or more", |
| 556 | "25 lines minimum", |
| 557 | "Keep it to 10 lines", |
| 558 | "no longer than 40 lines", |
| 559 | "Limit it to 80 words", |
| 560 | "Use each of these words: alpha, beta", |
| 561 | "Include headings for A and B", |
| 562 | "needs a Summary heading and a Risks heading", |
| 563 | "three sections", |
| 564 | "ten bullet points", |
| 565 | "Give it two code blocks", |
| 566 | "One code block only", |
| 567 | "Three paragraphs", |
| 568 | "Cover at least 4 topics: a, b, c, d", |
| 569 | "Each section needs 2 sentences", |
| 570 | "say the word 'canary' at least twice", |
| 571 | ] { |
| 572 | let ex = analyze(g); |
| 573 | assert!( |
| 574 | !ex.requirements.is_empty() || !ex.uncertain.is_empty(), |
| 575 | "silent: {g}" |
| 576 | ); |
| 577 | } |
| 578 | // the common ones are recognized properly |
| 579 | assert_eq!(extract("run to 30 lines or more"), [MinLines(30)]); |
| 580 | assert_eq!(extract("25 lines minimum"), [MinLines(25)]); |
| 581 | assert_eq!(extract("no longer than 40 lines"), [MaxLines(40)]); |
| 582 | } |
| 583 | |
| 584 | #[test] |
| 585 | fn false_positive_guards_stay_silent() { |
| 586 | for g in [ |
| 587 | "Fix the 2 typos", |
| 588 | "version 3.2 notes", |
| 589 | "10 minute setup guide", |
| 590 | "5 tests", |
| 591 | "Add the line \"- x\" under the \"## Planned\" heading in ROADMAP.md.", |
| 592 | "Update section 2 of the README", |
| 593 | "Create 2024-report.md with a short summary", |
| 594 | ] { |
| 595 | let ex = analyze(g); |
| 596 | assert!( |
| 597 | ex.requirements.is_empty() && ex.uncertain.is_empty(), |
| 598 | "{g}: {ex:?}" |
| 599 | ); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | #[test] |
| 604 | fn a_count_after_covering_is_a_count_or_uncertain_never_a_topic() { |
| 605 | let ex = analyze("Write GUIDE.md covering 5 steps."); |
| 606 | assert!(ex.requirements.is_empty(), "{ex:?}"); |
| 607 | assert!(!ex.uncertain.is_empty()); |
| 608 | } |
| 609 | |
| 610 | #[test] |
| 611 | fn trailing_courtesy_words_are_tolerated() { |
| 612 | assert_eq!(extract("At most 15 lines please."), [MaxLines(15)]); |
| 613 | assert!(analyze("At most 15 lines please.").uncertain.is_empty()); |
| 614 | assert_eq!(extract("at least 12 lines, thanks"), [MinLines(12)]); |
| 615 | } |