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_said_line_test.rs

204 lines · 7557 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//! sc#349: `one line saying hello` / `one line that says hello` (no quotes).
17//! A short plain phrase that runs to the end of its sentence (or to a trailing
18//! destination file) is a required phrase; anything wider is UNCERTAIN, never
19//! dropped. The one-line count is kept in every case.
20#[path = "support/compose_harness.rs"]
21mod compose_harness;
22#[path = "support/home_guard.rs"]
23mod home_guard;
24
25use aien_runtime::control::ControlResponse;
26use aien_runtime::requirements::{analyze, refusal_reason, Requirement};
27use aien_runtime::{ComposeBridge, ComposeProposer, Generation};
28use compose_harness::{always, Harness};
29use std::sync::Arc;
30use std::time::Duration;
31
32use Requirement::*;
33
34fn read(goal: &str) -> Vec<Requirement> {
35 let ex = analyze(goal);
36 assert!(ex.uncertain.is_empty(), "{goal:?}: {:?}", ex.uncertain);
37 ex.requirements
38}
39
40fn one_line_with(goal: &str, phrase: &str) {
41 let r = read(goal);
42 assert!(
43 r.iter().any(|q| matches!(
44 q,
45 AddedLines {
46 n: 1,
47 exact: true,
48 ..
49 }
50 )),
51 "{goal}: {r:?}"
52 );
53 assert!(
54 r.contains(&RequiredPhrases(vec![phrase.to_string()])),
55 "{goal}: {r:?}"
56 );
57}
58
59#[test]
60fn a_plain_unquoted_phrase_is_required() {
61 one_line_with("Add a single line saying hello to a.md", "hello");
62 one_line_with("Create a.txt containing one line that says hello.", "hello");
63 one_line_with("Add one line to notes/TODO.md saying buy milk", "buy milk");
64 one_line_with("Add one line saying Good Morning.", "Good Morning");
65 one_line_with("Add one line to a.md that says hello world!", "hello world");
66}
67
68#[test]
69fn an_ambiguous_unquoted_phrase_is_uncertain_never_dropped() {
70 for goal in [
71 "Add a single line saying hello and then save it to a.md",
72 "Add a single line saying something nice to a.md",
73 "Add one line saying hello, then stop",
74 "Add one line saying it to a.md",
75 "Create a.txt containing one line that says the project keeps every change inside its workspace.",
76 "Add one line saying",
77 "Add one line saying save the file to a.md",
78 "Add one line saying hello to the end of a.md",
79 ] {
80 let ex = analyze(goal);
81 assert!(!ex.uncertain.is_empty(), "{goal:?} should be uncertain: {:?}", ex.requirements);
82 }
83}
84
85#[test]
86fn unrelated_numbers_and_words_are_unchanged() {
87 assert!(read("Fix 2 typos in README.md").is_empty());
88 assert!(read("Add a line to a.md").is_empty());
89}
90
91#[test]
92fn the_check_refuses_a_line_without_the_phrase() {
93 let reqs = analyze("Add a single line saying hello to a.md")
94 .resolved("")
95 .requirements;
96 assert!(refusal_reason(&reqs, "goodbye\n").is_some());
97 assert!(refusal_reason(&reqs, "hello\n").is_none());
98 assert!(refusal_reason(&reqs, "hello\nhello again\n").is_some());
99}
100
101#[test]
102fn linked_compose_does_not_commit_a_line_without_the_phrase() {
103 let _home = home_guard::home_slot();
104 let tmp = tempfile::tempdir().unwrap();
105 let ws = tmp.path().join("ws");
106 std::fs::create_dir_all(&ws).unwrap();
107 let run = |reply: &'static str, sub: &str| {
108 let proposer: ComposeProposer = Arc::new(move |_: &str, _: Duration| {
109 Ok(Generation {
110 text: reply.to_string(),
111 tokens: 5,
112 finish_reason: Some("eos".into()),
113 ..Default::default()
114 })
115 });
116 let bridge = ComposeBridge::new(tmp.path().join(sub), proposer, "test:said");
117 bridge.run_task(
118 "Create a.md containing one line saying hello.",
119 ws.to_str().unwrap(),
120 )
121 };
122 let resp = run("filename: a.md\ngoodbye\n", "c1");
123 if !aien_omega_compose::LINKED {
124 assert!(matches!(resp, ControlResponse::Error(_)));
125 return;
126 }
127 let ControlResponse::ComposeTaskResult(r) = resp else {
128 panic!("{resp:?}")
129 };
130 assert!(!r.committed, "{r:?}");
131 assert!(r.proposal.is_none());
132 assert!(
133 r.proposer_error
134 .as_deref()
135 .is_some_and(|e| e.contains("hello")),
136 "{r:?}"
137 );
138 assert_eq!(r.proposal_attempts.len(), 3, "{:?}", r.proposal_attempts);
139 assert!(!ws.join("a.md").exists());
140 let ControlResponse::ComposeTaskResult(ok) = run("filename: a.md\nhello\n", "c2") else {
141 panic!()
142 };
143 assert!(ok.committed, "{ok:?}");
144 // committed = the proposal is approved for write authorization with these exact bytes
145 assert_eq!(ok.proposal.as_deref(), Some("filename: a.md\nhello\n"));
146}
147
148/// The compose verification boundary through `ComposeBridge::run_task`: a
149/// reply whose one line lacks the phrase is never approved.
150#[test]
151#[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")]
152fn the_proposal_boundary_approves_only_the_line_with_the_phrase() {
153 let _home = home_guard::home_slot();
154 let goal = "Create a.md containing one line saying hello.";
155 let go = |text: &str| {
156 let h = Harness::new(always(text));
157 let r = h.run(goal).unwrap();
158 r.proposal
159 .ok_or_else(|| r.proposer_error.unwrap_or_default())
160 };
161 assert!(go("filename: a.md\ngoodbye\n").is_err());
162 assert!(go("filename: a.md\nhello\n").is_ok());
163}
164
165/// A saying clause on a line is never silently dropped, whatever the count
166/// wording: it is read (one line, short plain phrase) or uncertain.
167#[test]
168fn a_saying_clause_on_any_line_wording_is_read_or_uncertain() {
169 // not exact ("write" means at least) but a single line with a plain phrase: read
170 for (goal, phrase) in [
171 ("Write one line saying hello to a.md", "hello"),
172 ("Write a line saying hello to a.md", "hello"),
173 ("Add a line that says hello.", "hello"),
174 ("Write a line saying \"hello there\"", "hello there"),
175 ] {
176 let r = read(goal);
177 assert!(
178 r.contains(&RequiredPhrases(vec![phrase.to_string()])),
179 "{goal}: {r:?}"
180 );
181 }
182 // another count, or a bound, cannot say what each line holds: uncertain
183 for goal in [
184 "Add 2 lines saying hi to a.md",
185 "Write three lines saying hello",
186 "Add 2 lines that say hi",
187 "Add at least 3 lines saying hi to a.md",
188 "Add at least one line saying hi to a.md",
189 "Add one line at least saying hi to a.md",
190 "Write a line saying hello and then save it",
191 "Write a line saying something nice",
192 "Add one line saying",
193 ] {
194 let ex = analyze(goal);
195 assert!(
196 !ex.uncertain.is_empty(),
197 "{goal:?} must be uncertain, got {:?}",
198 ex.requirements
199 );
200 }
201 // unrelated numbers and words stay as they were
202 assert!(read("Fix 2 typos in README.md").is_empty());
203 assert!(read("Add a line to a.md").is_empty());
204}