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 / compose_wait_test.rs

186 lines · 7369 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//! The omega settle wait really set before each run, and the target-kind
17//! decision (existing path => Edit/refused, missing path => Document).
18//! One test binary, one wait test: `LAST_WAIT_MS` is process-global.
19//!
20//! Every test drives `ComposeBridge::run_task` (tests/support/compose_harness.rs)
21//! and reads which proposer was asked, the prompt and limit it was handed, and
22//! the run's report. A goal refused before any model call comes back as `Err`.
23#[path = "support/compose_harness.rs"]
24mod compose_harness;
25#[path = "support/home_guard.rs"]
26mod home_guard;
27
28use compose_harness::{first_call, reply, Asked, Harness};
29use std::sync::atomic::Ordering;
30use std::sync::{Arc, Mutex};
31use std::time::Duration;
32
33/// Linked build only: run_task_inner tells omega budget + 1000 ms for each
34/// kind before compose.run (observed inside the proposer, i.e. during the run).
35#[test]
36#[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")]
37fn run_task_sets_omega_wait_to_budget_plus_margin_for_both_kinds() {
38 let _home = home_guard::home_slot();
39 let seen: Arc<Mutex<Vec<u32>>> = Arc::default();
40 let s = seen.clone();
41 let h = Harness::new(Arc::new(move |_, _: &str, _: Duration| {
42 s.lock()
43 .unwrap()
44 .push(aien_omega_compose::LAST_WAIT_MS.load(Ordering::SeqCst));
45 reply("filename: faq.md\nconstraint: x\n")
46 }));
47 h.write("notes.md", "# notes\n");
48 for goal in ["add a line to notes.md", "write a new file faq.md"] {
49 h.run(goal).unwrap();
50 }
51 let seen = seen.lock().unwrap().clone();
52 assert_eq!(
53 seen,
54 vec![30_000, 121_000],
55 "wait seen during each run: edit 30000, document 121000"
56 );
57 let asked: Vec<Asked> = h.calls().iter().map(|c| c.asked).collect();
58 assert_eq!(asked, [Asked::Edit, Asked::Document]);
59}
60
61/// One deadline across attempts: each retry is given only what is left of
62/// the document budget, never a fresh budget.
63#[test]
64#[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")]
65fn one_deadline_is_shared_across_attempts() {
66 let _home = home_guard::home_slot();
67 let h = Harness::new(Arc::new(|_, _: &str, _: Duration| {
68 std::thread::sleep(Duration::from_millis(60));
69 reply("not a proposal")
70 }));
71 let r = h.run("write a new file faq.md").unwrap();
72 assert!(r.proposal.is_none() && r.proposer_error.is_some(), "{r:?}");
73 let c = h.calls();
74 assert!(c.iter().all(|c| c.asked == Asked::Document));
75 let l: Vec<Duration> = c.iter().map(|c| c.limit).collect();
76 assert!(l.len() >= 2, "{l:?}");
77 // the default document budget, 120 s
78 assert!(l[0] <= Duration::from_secs(120));
79 for w in l.windows(2) {
80 assert!(w[1] + Duration::from_millis(55) <= w[0], "{l:?}");
81 }
82 assert_eq!(r.proposal_attempts.len(), l.len());
83}
84
85fn ws_with(files: &[(&str, &[u8])]) -> (tempfile::TempDir, std::path::PathBuf) {
86 let d = tempfile::tempdir().unwrap();
87 let ws = d.path().join("ws");
88 std::fs::create_dir_all(&ws).unwrap();
89 for (n, c) in files {
90 std::fs::write(ws.join(n), c).unwrap();
91 }
92 let ws = std::fs::canonicalize(ws).unwrap();
93 (d, ws)
94}
95
96#[test]
97#[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")]
98fn missing_file_is_document() {
99 let _home = home_guard::home_slot();
100 let (_d, ws) = ws_with(&[]);
101 let (c, _) = first_call("write faq.md", &ws).unwrap();
102 // a new document: the document proposer, no edit block, the new-file block
103 assert_eq!(c.asked, Asked::Document);
104 assert!(!c.prompt.contains("already exists"), "{}", c.prompt);
105 assert!(
106 c.prompt
107 .contains("Write the new file faq.md. The filename line of your answer must be exactly: filename: faq.md"),
108 "{}",
109 c.prompt
110 );
111}
112
113#[test]
114#[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")]
115fn small_existing_file_is_edit() {
116 let _home = home_guard::home_slot();
117 let h = Harness::new(Arc::new(|_, _: &str, _: Duration| {
118 reply("filename: notes.md\n# notes\nnew line\n")
119 }));
120 h.write("notes.md", "# notes\n");
121 let r = h.run("add a line to notes.md").unwrap();
122 let c = h.calls();
123 assert_eq!(c[0].asked, Asked::Edit);
124 assert!(c[0].prompt.contains("already exists"), "{}", c[0].prompt);
125 // the edit target: notes.md with exactly its content, shown and merged into
126 assert!(
127 c[0].prompt
128 .contains("The file notes.md already exists. Its current content is:\n# notes\nWrite"),
129 "{}",
130 c[0].prompt
131 );
132 assert_eq!(
133 r.proposal.as_deref(),
134 Some("filename: notes.md\n# notes\nnew line\n"),
135 "{r:?}"
136 );
137}
138
139#[test]
140fn large_existing_file_is_refused_not_document() {
141 let _home = home_guard::home_slot();
142 let big = vec![b'a'; 11 * 1024];
143 let h = Harness::new(Arc::new(|_, _: &str, _: Duration| {
144 reply("filename: big.md\nx\n")
145 }));
146 std::fs::write(h.ws().join("big.md"), &big).unwrap();
147 let e = h.run("rewrite big.md").unwrap_err();
148 assert!(e.contains("big.md") && e.contains("already exists"), "{e}");
149 // refused, never a new document: no proposer was asked
150 assert!(h.calls().is_empty());
151 assert_eq!(std::fs::read(h.ws().join("big.md")).unwrap(), big);
152}
153
154#[test]
155fn non_utf8_existing_file_is_refused() {
156 let _home = home_guard::home_slot();
157 let h = Harness::new(Arc::new(|_, _: &str, _: Duration| {
158 reply("filename: bin.md\nx\n")
159 }));
160 std::fs::write(h.ws().join("bin.md"), [0xff, 0xfe, 0x00, 0x80]).unwrap();
161 let e = h.run("rewrite bin.md").unwrap_err();
162 assert!(e.contains("not UTF-8"), "{e}");
163 assert!(h.calls().is_empty());
164}
165
166#[test]
167#[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")]
168fn outward_symlink_is_refused_and_directory_is_skipped() {
169 let _home = home_guard::home_slot();
170 let h = Harness::new(Arc::new(|_, _: &str, _: Duration| {
171 reply("filename: docs/faq.md\nq and a\n")
172 }));
173 let outside = h.tmp.path().join("secret.txt");
174 std::fs::write(&outside, "s\n").unwrap();
175 std::fs::create_dir_all(h.ws().join("docs")).unwrap();
176 std::os::unix::fs::symlink(&outside, h.ws().join("link.md")).unwrap();
177 assert!(h.run("rewrite link.md").is_err());
178 assert!(h.calls().is_empty());
179 // the directory `docs` is not the destination: a new document
180 h.run("put it in docs faq.md").unwrap();
181 let c = h.calls();
182 assert!(!c.is_empty());
183 assert_eq!(c[0].asked, Asked::Document);
184 assert!(!c[0].prompt.contains("already exists"), "{}", c[0].prompt);
185 assert_eq!(std::fs::read_to_string(&outside).unwrap(), "s\n");
186}