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_paragraphs_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#335: a paragraph count ("at least twelve paragraphs") was refused as |
| 17 | //! uncertain before any model call: there was no paragraph requirement. It is |
| 18 | //! now read as `MinParagraphs` for a minimum bound; an upper bound, an exact or |
| 19 | //! approximate count and a bare count stay UNCERTAIN. |
| 20 | use aien_runtime::requirements::{analyze, count_paragraphs, refusal_reason, Requirement}; |
| 21 | |
| 22 | use Requirement::*; |
| 23 | |
| 24 | /// tasks-oq3-v4 N2, verbatim. |
| 25 | const V4_N2: &str = "Create the file docs/HISTORY.md with a long account of the project history that has at least twelve paragraphs."; |
| 26 | /// tasks-oq3-v3 N2, verbatim. |
| 27 | const V3_N2: &str = "Create the file docs/OVERVIEW.md with a detailed overview of the project that has at least ten paragraphs."; |
| 28 | /// v5 N2 (sc#339), verbatim. |
| 29 | const V5_N2: &str = "I would like a long, detailed history of the marathon as a race, from the legend of ancient Greece to modern city events, saved as docs/marathon-story.md. Please make it at least twelve paragraphs long."; |
| 30 | /// v5 D6 (sc#339), the sentence under test up to its comma (the section clause is sc#331). |
| 31 | const V5_D6: &str = "Please write a warm, longer essay about adopting a rescue cat and save it as docs/rescue-cat-essay.md. It should run to at least 7 paragraphs."; |
| 32 | |
| 33 | fn reqs(goal: &str) -> Vec<Requirement> { |
| 34 | let ex = analyze(goal); |
| 35 | assert!( |
| 36 | ex.uncertain.is_empty(), |
| 37 | "{goal:?} should be read, uncertain: {:?}", |
| 38 | ex.uncertain |
| 39 | ); |
| 40 | ex.requirements |
| 41 | } |
| 42 | |
| 43 | #[test] |
| 44 | fn the_campaign_paragraph_goals_are_read() { |
| 45 | assert_eq!(reqs(V4_N2), [MinParagraphs(12)]); |
| 46 | assert_eq!(reqs(V3_N2), [MinParagraphs(10)]); |
| 47 | assert_eq!(reqs(V5_N2), [MinParagraphs(12)]); |
| 48 | assert_eq!(reqs(V5_D6), [MinParagraphs(7)]); |
| 49 | } |
| 50 | |
| 51 | #[test] |
| 52 | fn the_usual_minimum_wordings_are_read() { |
| 53 | for (goal, n) in [ |
| 54 | ("Write at least 3 paragraphs about bees.", 3), |
| 55 | ("Write 4 or more paragraphs about bees.", 4), |
| 56 | ("Write 5+ paragraphs about bees.", 5), |
| 57 | ("Use a minimum of six paragraphs.", 6), |
| 58 | ("Use no fewer than 2 paragraphs.", 2), |
| 59 | ("Write more than 3 paragraphs.", 4), |
| 60 | ("It must be 8 paragraphs or more.", 8), |
| 61 | ] { |
| 62 | assert_eq!(reqs(goal), [MinParagraphs(n)], "{goal}"); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | #[test] |
| 67 | fn other_paragraph_wordings_stay_uncertain() { |
| 68 | for goal in [ |
| 69 | "Write at most 3 paragraphs.", |
| 70 | "Write no more than 3 paragraphs.", |
| 71 | "Write exactly 3 paragraphs.", |
| 72 | "Write about 5 paragraphs.", |
| 73 | "Write between 3 and 5 paragraphs.", |
| 74 | "Write three paragraphs.", |
| 75 | "Write at least 3 paragraphs per section.", |
| 76 | "Write at least 3 paragraphs of code.", |
| 77 | "Do not write at least 3 paragraphs.", |
| 78 | "Write 2-3 paragraphs.", |
| 79 | ] { |
| 80 | let ex = analyze(goal); |
| 81 | assert!( |
| 82 | !ex.uncertain.is_empty(), |
| 83 | "{goal:?} should stay uncertain, got {:?}", |
| 84 | ex.requirements |
| 85 | ); |
| 86 | assert!( |
| 87 | !ex.requirements |
| 88 | .iter() |
| 89 | .any(|r| matches!(r, MinParagraphs(_))), |
| 90 | "{goal:?}: {ex:?}" |
| 91 | ); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | #[test] |
| 96 | fn paragraphs_are_counted_by_the_documented_rule() { |
| 97 | for (doc, n) in [ |
| 98 | ("", 0), |
| 99 | ("one line\n", 1), |
| 100 | ("one\ntwo lines, still one paragraph\n", 1), |
| 101 | ("first\n\nsecond\n\n\nthird\n", 3), |
| 102 | // a heading ends a paragraph and is not one |
| 103 | ("# Title\nfirst\n## Next\nsecond\n", 2), |
| 104 | // list items, table rows and breaks are not prose and end a paragraph |
| 105 | ("intro\n- a\n- b\n\nafter the list\n", 2), |
| 106 | // a line right after an item continues the item (sc#341 review) |
| 107 | ("intro\n- a\n- b\nafter the list\n", 1), |
| 108 | ("- a\n more\n- b\n more\n- c\n more\n", 0), |
| 109 | // indented code never starts a paragraph, but an indented line continues one |
| 110 | (" code1\n code2\n\n code3\n", 0), |
| 111 | ("text\n still the same paragraph\n", 1), |
| 112 | // HTML, setext underlines and lines without letters or digits |
| 113 | ("<div>\n\n<div>\n", 0), |
| 114 | ("Title\n=====\nbody\n", 1), |
| 115 | // round 2: a `---` underline is a setext heading too |
| 116 | ("Title\n---\n\nTitle2\n---\n\nTitle3\n---\n", 0), |
| 117 | ("Title\n-\nbody\n", 1), |
| 118 | ("above\n\n---\n\nbelow\n", 2), |
| 119 | // round 2: text indented under an item after a blank line belongs to it |
| 120 | ("- item\n\n indented para\n\n another\n", 0), |
| 121 | ("1. a\n\n para under item\n", 0), |
| 122 | ("- item\n\nnot indented, a paragraph\n", 1), |
| 123 | // round 2: HTML or a pipe inside a run does not split it |
| 124 | ("one\n<span>x</span>\ntwo\n", 1), |
| 125 | ("one\n|two\nthree\n", 1), |
| 126 | ("-\n\n1.\n\n***\n\n* * *\n\n...\n", 0), |
| 127 | // blockquotes are prose; CRLF and non-ASCII text are fine |
| 128 | ("> q1\n\n> q2\n", 2), |
| 129 | ("a\r\n\r\nb\r\n", 2), |
| 130 | ("# h\u{e9}llo\n\n\u{fc}\u{fc}\n", 1), |
| 131 | // an unclosed fence hides the rest of the file |
| 132 | ("before\n\n```\nafter\n\nmore\n", 1), |
| 133 | ("1. step\n2. step\n", 0), |
| 134 | ("| a | b |\n|---|---|\n| 1 | 2 |\n", 0), |
| 135 | ("above\n***\nbelow\n", 2), |
| 136 | // fenced code is not prose and ends a paragraph |
| 137 | ("before\n```\ncode\n\nmore code\n```\nafter\n", 2), |
| 138 | ("~~~\nonly code\n~~~\n", 0), |
| 139 | // "#tag" without a space is text, not a heading |
| 140 | ("#tag line\n", 1), |
| 141 | ] { |
| 142 | assert_eq!(count_paragraphs(doc), n, "{doc:?}"); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | #[test] |
| 147 | fn the_check_reports_what_it_found() { |
| 148 | let r = [MinParagraphs(3)]; |
| 149 | assert!(refusal_reason(&r, "a\n\nb\n\nc\n").is_none()); |
| 150 | let why = refusal_reason(&r, "a\nb\nc\n").expect("one paragraph only"); |
| 151 | assert!(why.contains("at least 3 paragraphs, found 1"), "{why}"); |
| 152 | } |