interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-runtime / tests / requirements_usability_test.rs

487 lines · 17568 bytes Raw Blame History
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//! Ordinary counted requests and the wider wordings (crate::requirements_extract),
17//! PR round 2: "Add 2 lines to README.md" is read, not refused; every goal of the
18//! campaign task files is classified (recognized, silent or uncertain) and the
19//! refused ones are listed with their reason.
20#[path = "support/compose_harness.rs"]
21mod compose_harness;
22#[path = "support/home_guard.rs"]
23mod home_guard;
24
25use aien_runtime::requirements::{analyze, refusal_reason, unmet, ItemKind, Requirement};
26use compose_harness::{always, Asked, Harness};
27
28use Requirement::*;
29
30fn added(n: usize, exact: bool) -> Requirement {
31 AddedLines {
32 n,
33 exact,
34 prior: None,
35 }
36}
37
38fn reqs(goal: &str) -> Vec<Requirement> {
39 let ex = analyze(goal);
40 assert!(
41 ex.uncertain.is_empty(),
42 "{goal:?} should be read, uncertain: {:?}",
43 ex.uncertain
44 );
45 ex.requirements
46}
47
48fn uncertain(goal: &str) -> Vec<String> {
49 let ex = analyze(goal);
50 assert!(
51 !ex.uncertain.is_empty(),
52 "{goal:?} should be refused as uncertain, got {:?}",
53 ex.requirements
54 );
55 ex.uncertain
56}
57
58#[test]
59fn counted_requests_are_read_by_the_documented_rule() {
60 // add|append|insert|with N lines (and "N-line"): exactly N added lines.
61 for (goal, n) in [
62 ("Add 2 lines to README.md", 2),
63 ("Append 3 lines to LOG.md", 3),
64 ("Add a one-line note to README.md", 1),
65 ("Insert two lines under the intro in docs/a.md", 2),
66 ("Add exactly 4 lines to docs/a.md.", 4),
67 ("Write a two-line poem", 2),
68 (
69 "Create the file docs/CONTACT.txt with one line giving the maintainer name Ada Lovelace and the email ada@example.org.",
70 1,
71 ),
72 ] {
73 assert_eq!(reqs(goal), [added(n, true)], "{goal}");
74 }
75 // sc#349: the plain phrase after "saying" is required as well
76 assert_eq!(
77 reqs("Add one line to notes/TODO.md saying buy milk"),
78 [
79 added(1, true),
80 RequiredPhrases(vec!["buy milk".to_string()])
81 ]
82 );
83 // write|put|create|... N lines: at least N added lines.
84 for (goal, n) in [
85 ("Write 20 lines about X to docs/x.md", 20),
86 ("Please write five lines on composting in docs/c.md", 5),
87 ("Draft 12 lines for the changelog", 12),
88 ] {
89 assert_eq!(reqs(goal), [added(n, false)], "{goal}");
90 }
91}
92
93#[test]
94fn bare_counts_with_a_qualifier_or_no_verb_stay_uncertain() {
95 for goal in [
96 "Add 3 lines of context to README.md",
97 "Write 10 lines per section in docs/a.md",
98 "Keep it to 10 lines",
99 "Do not add 2 lines to README.md",
100 "The note should be 5 lines",
101 // sc#336: an addition may sit in a longer file; a new one-sentence
102 // file ("with a one-sentence greeting") is read as SingleSentence.
103 "Add a one-sentence summary to README.md",
104 ] {
105 uncertain(goal);
106 }
107}
108
109#[test]
110fn wider_wordings_are_read() {
111 assert_eq!(
112 reqs("Write a new file docs/B.md. A minimum of 20 lines is needed."),
113 [MinLines(20)]
114 );
115 assert_eq!(reqs("At least 20 lines are required."), [MinLines(20)]);
116 assert_eq!(reqs("It needs 20 lines minimum."), [MinLines(20)]);
117 assert_eq!(
118 reqs("Finish with a section titled \"Restore notes\" that holds at least 15 words of plain text."),
119 [
120 SectionMinWords {
121 title: Some("Restore notes".into()),
122 n: 15
123 },
124 RequiredHeadings(vec!["Restore notes".into()]),
125 ]
126 );
127 assert_eq!(
128 reqs("The last section needs at least 15 words of plain text."),
129 [SectionMinWords { title: None, n: 15 }]
130 );
131 assert_eq!(
132 reqs("Use three level-two sections titled \"Building\", \"Testing\" and \"Packaging\", then add notes."),
133 [LevelHeadings {
134 level: 2,
135 titles: vec!["Building".into(), "Testing".into(), "Packaging".into()]
136 }]
137 );
138 assert_eq!(
139 reqs("Include three separate fenced code examples."),
140 [MinItems(ItemKind::CodeBlocks, 3)]
141 );
142}
143
144#[test]
145fn unscoped_word_counts_and_topic_lists_stay_uncertain() {
146 uncertain("Write it with at least 15 words of plain text.");
147 // sc#332: a counted topic list is read when the count matches the list.
148 uncertain("Cover two topics: drying, labelling and storage.");
149 uncertain("Put one fenced shell code example in each of them.");
150 uncertain("Each section has two sentences.");
151}
152
153#[test]
154fn the_new_checks_measure_the_right_thing() {
155 let doc = "# A\nprose\n\n## Building\none two three\n## Testing\nx\n## Packaging\ny\n";
156 let lv = LevelHeadings {
157 level: 2,
158 titles: vec!["Building".into(), "Testing".into(), "Packaging".into()],
159 };
160 assert!(lv.check(doc).is_none());
161 // Wrong level is missing; extra ## sections are fine.
162 let deep = doc.replace("## Testing", "### Testing");
163 assert!(lv.check(&deep).unwrap().contains("\"Testing\""));
164 assert!(lv.check(&format!("{doc}## Summary\nz\n")).is_none());
165 let last = SectionMinWords { title: None, n: 3 };
166 assert!(last.check("# T\n## End\nonly two\n").is_some());
167 assert!(last.check("# T\n## End\nnow three words\n").is_none());
168 // Code lines and headings are not plain text.
169 let named = SectionMinWords {
170 title: Some("Restore notes".into()),
171 n: 4,
172 };
173 assert!(named
174 .check("## Restore notes\n```sh\none two three four five\n```\nshort\n")
175 .is_some());
176 assert!(named
177 .check("## Restore notes\nfour plain words here\n")
178 .is_none());
179 assert!(named.check("## Other\nfour plain words here\n").is_some());
180 let blocks = MinItems(ItemKind::CodeBlocks, 2);
181 assert!(blocks.check("```sh\na\n```\ntext\n~~~\nb\n~~~\n").is_none());
182 assert!(blocks.check("```sh\na\n```\n").is_some());
183}
184
185/// One compose task through `ComposeBridge::run_task` with `prior` as the
186/// content of `path` (None: `path` does not exist, a new document). The model
187/// always answers `reply`. Ok = the approved proposal, Err = the refusal.
188fn run_edit(goal: &str, path: &str, prior: Option<&str>, reply: &str) -> Result<String, String> {
189 let ex = analyze(goal);
190 assert!(ex.uncertain.is_empty(), "{:?}", ex.uncertain);
191 let h = Harness::new(always(reply));
192 if let Some(p) = prior {
193 h.write(path, p);
194 }
195 let r = h.run(goal).unwrap();
196 let want = if prior.is_some() {
197 Asked::Edit
198 } else {
199 Asked::Document
200 };
201 assert!(h.calls().iter().all(|c| c.asked == want), "{goal}");
202 r.proposal
203 .ok_or_else(|| r.proposer_error.unwrap_or_default())
204}
205
206const PRIOR: &str = "# Notes\n\nfirst\nsecond\n";
207
208#[test]
209#[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")]
210fn counted_edits_are_judged_on_the_diff_of_the_exact_proposed_bytes() {
211 let _home = home_guard::home_slot();
212 let g = "Add 2 lines to README.md";
213 let two = "filename: README.md\n# Notes\n\nfirst\nnew a\nnew b\nsecond\n";
214 let one = "filename: README.md\n# Notes\n\nfirst\nnew a\nsecond\n";
215 let three = "filename: README.md\n# Notes\n\nfirst\nnew a\nnew b\nnew c\nsecond\n";
216 assert!(run_edit(g, "README.md", Some(PRIOR), two).is_ok());
217 let e = run_edit(g, "README.md", Some(PRIOR), one).unwrap_err();
218 assert!(
219 e.contains("exactly 2 added non-empty lines, found 1"),
220 "{e}"
221 );
222 let e = run_edit(g, "README.md", Some(PRIOR), three).unwrap_err();
223 assert!(e.contains("found 3"), "{e}");
224 // Blank lines are not lines.
225 let blanks = "filename: README.md\n# Notes\n\nfirst\n\nnew a\n\nnew b\nsecond\n";
226 assert!(run_edit(g, "README.md", Some(PRIOR), blanks).is_ok());
227 // "write N lines": at least N added; a new file has no prior lines.
228 let w = "Write 3 lines about bread to README.md";
229 let four = "filename: README.md\n# Notes\n\nfirst\na\nb\nc\nd\nsecond\n";
230 assert!(run_edit(w, "README.md", Some(PRIOR), four).is_ok());
231 assert!(run_edit(w, "README.md", Some(PRIOR), two).is_err());
232 let fresh = "filename: NEW.md\nl1\nl2\n";
233 assert!(run_edit("Add 2 lines to NEW.md", "NEW.md", None, fresh).is_ok());
234 assert!(run_edit("Add 3 lines to NEW.md", "NEW.md", None, fresh).is_err());
235 // Whole-file bytes that rewrite prior lines count the rewritten ones as added.
236 let rewritten = "filename: README.md\n# Notes\n\nfirst CHANGED\nsecond\nnew\n";
237 let e = run_edit(g, "README.md", Some(PRIOR), rewritten);
238 assert!(e.is_ok(), "{e:?}");
239}
240
241#[test]
242fn an_unresolved_added_line_count_fails_closed() {
243 let ex = analyze("Add 2 lines to README.md");
244 let u = unmet(&ex.requirements, "a\nb\n");
245 assert_eq!(u.len(), 1);
246 assert!(u[0].contains("cannot be measured"), "{u:?}");
247 assert!(refusal_reason(&ex.requirements, "a\nb\n").is_some());
248 // Resolved against the file the bytes replace, the same bytes pass.
249 let ok = ex.resolved("");
250 assert!(unmet(&ok.requirements, "a\nb\n").is_empty());
251}
252
253#[test]
254fn a_machine_goal_for_an_approved_proposal_states_no_requirement() {
255 // The goal the hook builds is "apply approved proposal for <path> (request <id>)".
256 for path in [
257 "docs/10 lines.md",
258 "docs/add 2 lines.md",
259 "notes/at least 5 lines.md",
260 "write 20 lines.txt",
261 ] {
262 let goal = format!("apply approved proposal for {path} (request req-1)");
263 let ex = analyze(&goal);
264 assert!(
265 ex.requirements.is_empty() && ex.uncertain.is_empty(),
266 "{goal}: {ex:?}"
267 );
268 }
269}
270
271// ---- the campaign goals: recognized, silent or uncertain ----
272
273const CORPUS: &str = include_str!("fixtures/goal_corpus.tsv");
274
275/// Goals that state no measurable requirement: nothing to enforce, nothing refused.
276const SILENT: [&str; 12] = [
277 "dryrun-tasks-v2/N2",
278 "dryrun-tasks-v2/R1",
279 "dryrun-tasks-v2/T5",
280 "dryrun-tasks-v2/T7",
281 "tasks-oq3-v3/E1",
282 "tasks-oq3-v3/E2",
283 "tasks-oq3-v4/U1",
284 "tasks-oq3-v4/U2",
285 "tasks-v5/T1",
286 "tasks-v5/T3",
287 "tasks-v6/T5",
288 "tasks-v8/T7",
289];
290
291/// Goals whose explicit requirements are all read and enforced.
292const RECOGNIZED: [&str; 21] = [
293 "dryrun-tasks-v2/N1",
294 "tasks-oq3-v3/N1",
295 "tasks-oq3-v4/N1",
296 "tasks-v6/N1",
297 "dryrun-tasks-v2/T4",
298 "tasks-oq3-v3/G2",
299 "tasks-oq3-v3/G3",
300 // sc#336: a file of one sentence.
301 "tasks-oq3-v3/R1",
302 "tasks-oq3-v4/R1",
303 // sc#335: "at least ten|twelve paragraphs" is MinParagraphs.
304 "tasks-oq3-v3/N2",
305 "tasks-oq3-v4/N2",
306 "tasks-oq3-v4/RT4",
307 "tasks-oq3-v4/RT6",
308 "tasks-oq3-v4/W1",
309 "tasks-oq3-v4/W2",
310 "tasks-oq3-v4/W3",
311 "tasks-oq3-v4/W4",
312 // sc#334: "at least twelve of them" after `a line starting with "- [ ]"`.
313 "tasks-oq3-v4/W5",
314 "tasks-v5/T2",
315 "tasks-v8/D3",
316 "tasks-v8/D4",
317];
318
319/// Goals still refused as uncertain, each with the span that is reported and why.
320const REFUSED: [(&str, &str, &str); 3] = [
321 (
322 "dryrun-tasks-v2/T6",
323 "one section per symptom",
324 "a section count that depends on the content",
325 ),
326 (
327 "tasks-oq3-v3/G1",
328 "one fenced shell code example in each of them",
329 "a per-section code example count",
330 ),
331 (
332 "tasks-v8/D5",
333 "10 frequently asked questions and answers",
334 "a count with a long adjective phrase",
335 ),
336];
337
338#[test]
339fn every_campaign_goal_is_recognized_silent_or_refused_for_a_listed_reason() {
340 let mut seen = 0;
341 for line in CORPUS.lines() {
342 let (id, goal) = line.split_once('\t').expect("id TAB goal");
343 let ex = analyze(goal);
344 seen += 1;
345 if SILENT.contains(&id) {
346 assert!(
347 ex.requirements.is_empty() && ex.uncertain.is_empty(),
348 "{id} should be silent: {ex:?}"
349 );
350 } else if RECOGNIZED.contains(&id) {
351 assert!(
352 !ex.requirements.is_empty() && ex.uncertain.is_empty(),
353 "{id} should be recognized: {ex:?}"
354 );
355 } else if let Some((_, span, _why)) = REFUSED.iter().find(|r| r.0 == id) {
356 assert!(
357 ex.uncertain.iter().any(|u| u.contains(span)),
358 "{id} should be refused on {span:?}: {:?}",
359 ex.uncertain
360 );
361 } else {
362 panic!("{id} is in no list: {ex:?}");
363 }
364 }
365 // Every listed id exists in the corpus.
366 assert_eq!(seen, SILENT.len() + RECOGNIZED.len() + REFUSED.len());
367}
368
369#[test]
370fn the_w2_goal_is_fully_enforced() {
371 let goal = CORPUS
372 .lines()
373 .find(|l| l.starts_with("tasks-oq3-v4/W2\t"))
374 .and_then(|l| l.split_once('\t'))
375 .map(|x| x.1)
376 .unwrap();
377 let ex = analyze(goal);
378 assert!(ex.uncertain.is_empty());
379 assert!(ex.requirements.contains(&MinLines(20)));
380 assert!(ex.requirements.contains(&MinItems(ItemKind::CodeBlocks, 3)));
381 assert!(ex.requirements.contains(&SectionMinWords {
382 title: Some("Restore notes".into()),
383 n: 15
384 }));
385 let mut good = String::new();
386 for t in ["Create the archive", "Copy it offsite", "Verify the copy"] {
387 good.push_str(&format!(
388 "## {t}\n```sh\necho {}\n```\nsome words about it\n\n",
389 t.len()
390 ));
391 }
392 good.push_str("## Restore notes\nrestore the newest archive first then check the files one by one afterwards carefully\n");
393 for i in 0..10 {
394 good.push_str(&format!("closing line {i}\n"));
395 }
396 // The long closing lines sit in the last section; keep the heading text rule honest.
397 let good = good.replace("closing line 0\n", "");
398 assert!(
399 refusal_reason(&ex.requirements, &good).is_none(),
400 "{:?}",
401 refusal_reason(&ex.requirements, &good)
402 );
403 let short = good.replace(
404 "restore the newest archive first then check the files one by one afterwards carefully\n",
405 "restore it\n",
406 );
407 let short = short
408 .lines()
409 .filter(|l| !l.starts_with("closing line"))
410 .collect::<Vec<_>>()
411 .join("\n");
412 assert!(refusal_reason(&ex.requirements, &short)
413 .unwrap()
414 .contains("words of plain text in the section \"Restore notes\""));
415}
416
417// ---- round 3 ----
418
419fn added_check(goal: &str, prior: &str, content: &str) -> Option<String> {
420 let ex = analyze(goal).resolved(prior);
421 assert!(ex.uncertain.is_empty(), "{:?}", ex.uncertain);
422 refusal_reason(&ex.requirements, content)
423}
424
425#[test]
426fn an_add_request_may_not_delete_or_rewrite_existing_lines() {
427 let prior = "a\nb\nc\nd\n";
428 let g = "Add 2 lines to README.md";
429 for bad in ["x\ny\n", "a\nb\nx\ny\n", "a\nb\nC\nD\n", "a\nb\nc\nd\nx\n"] {
430 assert!(
431 added_check(g, prior, bad).is_some(),
432 "{bad:?} must be refused"
433 );
434 }
435 let e = added_check(g, prior, "a\nb\nC\nD\n").unwrap();
436 assert!(e.contains("changed or removed"), "{e}");
437 // Inserts in the middle or at the end, blank lines, and trailing-space-only
438 // edits to existing lines are allowed (trailing whitespace is not content).
439 for ok in [
440 "a\nb\nx\nc\ny\nd\n",
441 "a\nb\nc\nd\nx\ny\n",
442 "x\ny\na\nb\nc\nd\n",
443 "a \nb\nc\t\nd\n\nx\n\ny\n",
444 ] {
445 assert!(added_check(g, prior, ok).is_none(), "{ok:?} must pass");
446 }
447 // The same holds for "write N lines" (at least N).
448 let w = "Write 2 lines about bread to README.md";
449 assert!(added_check(w, prior, "x\ny\nz\n").is_some());
450 assert!(added_check(w, prior, "a\nb\nc\nd\nx\ny\nz\n").is_none());
451}
452
453#[test]
454fn vague_or_odd_counts_are_uncertain_not_silent() {
455 for goal in [
456 "Add 2-3 lines to README.md",
457 "Write a dozen lines about bread",
458 "The line count should be at least 40.",
459 "Write a script with 2 shell commands.",
460 "Use \"A\", \"B\" and \"C\" as level-two headings.",
461 "Use level-two headings \"A\", \"B\" and \"C\".",
462 "Write three-plus sections about bread.",
463 "Use a section titled Intro has 80 words of plain text.",
464 "Add 2 lines at most to README.md",
465 ] {
466 uncertain(goal);
467 }
468}
469
470#[test]
471fn lower_bound_after_the_noun_and_single_line() {
472 assert_eq!(
473 reqs("Write forty lines at least to docs/a.md"),
474 [added(40, false)]
475 );
476 assert_eq!(
477 reqs("Add a single line saying hello to a.md"),
478 [added(1, true), RequiredPhrases(vec!["hello".to_string()])]
479 );
480 // No explicit count: nothing is measured (documented): "a line" is not a number word.
481 // sc#349: no count is measured, but what the line says is still required
482 assert_eq!(
483 reqs("Add a line saying hello to a.md"),
484 [RequiredPhrases(vec!["hello".to_string()])]
485 );
486 assert!(reqs("Add a couple of lines or a few to a.md").is_empty());
487}