Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/crates/aien-runtime/tests/destination_test.rs # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / crates / aien-runtime / tests / destination_test.rs` 251 lines ยท 9214 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 //! Issue #288: the task kind, prompt and budget follow the DESTINATION the 17 //! goal names, not the first path that happens to exist. 18 //! 19 //! Every test drives `ComposeBridge::run_task` (tests/support/compose_harness.rs). 20 //! The task kind is which proposer the bridge asked (`Asked::Edit` = the goal 21 //! edits an existing file, `Asked::Document` = a new document), the edit target 22 //! and the destination are the blocks of the prompt the model was handed, and a 23 //! refused goal is the bridge's refusal text (no model call). 24 #[path = "support/compose_harness.rs"] 25 mod compose_harness; 26 #[path = "support/home_guard.rs"] 27 mod home_guard; 28 29 use compose_harness::{silent, Asked, Call, Harness}; 30 31 /// A harness whose workspace holds `files` and an empty `docs` folder. 32 fn ws_with(files: &[(&str, &str)]) -> Harness { 33 let h = Harness::new(silent()); 34 std::fs::create_dir_all(h.ws().join("docs")).unwrap(); 35 for (n, c) in files { 36 h.write(n, c); 37 } 38 h 39 } 40 41 /// The first model call of a run of `goal` (the run must not be refused). 42 fn first(h: &Harness, goal: &str) -> Call { 43 h.clear(); 44 let r = h 45 .run(goal) 46 .unwrap_or_else(|e| panic!("{goal}: refused: {e}")); 47 h.calls() 48 .into_iter() 49 .next() 50 .unwrap_or_else(|| panic!("{goal}: no model call: {r:?}")) 51 } 52 53 /// The bridge's refusal of `goal`, without the `RunComposeTask: ` prefix; no 54 /// model call was made. 55 fn refused(h: &Harness, goal: &str) -> String { 56 h.clear(); 57 let e = h.run(goal).expect_err(goal); 58 assert!( 59 h.calls().is_empty(), 60 "{goal}: a refused goal reached the model" 61 ); 62 e.strip_prefix("RunComposeTask: ") 63 .unwrap_or_else(|| panic!("{goal}: not a task refusal: {e}")) 64 .to_string() 65 } 66 67 /// The new-document block the prompt ends with when the goal names a 68 /// destination that does not exist yet (the product's text, verbatim). 69 fn new_block(path: &str) -> String { 70 format!("\nWrite the new file {path}. The filename line of your answer must be exactly: filename: {path}") 71 } 72 73 /// The edit block the prompt ends with when the goal's destination is an 74 /// existing file (the product's text, verbatim). 75 fn edit_block(path: &str, content: &str) -> String { 76 let nl = if content.ends_with('\n') { "" } else { "\n" }; 77 format!( 78 "\nThe file {path} already exists. Its current content is:\n{content}{nl}\ 79 Write the complete new content of {path}: keep every existing line and make the requested change." 80 ) 81 } 82 83 #[test] 84 #[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")] 85 fn create_new_file_about_an_existing_one_is_a_new_document() { 86 let _home = home_guard::home_slot(); 87 let h = ws_with(&[("README.md", "# readme\n")]); 88 let goal = "Create docs/SUMMARY.md about README.md"; 89 let c = first(&h, goal); 90 // A new document (no edit target), destination docs/SUMMARY.md. 91 assert_eq!(c.asked, Asked::Document); 92 assert!( 93 c.prompt.ends_with(&new_block("docs/SUMMARY.md")), 94 "{}", 95 c.prompt 96 ); 97 assert!(!c.prompt.contains("already exists")); 98 } 99 100 #[test] 101 #[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")] 102 fn update_destination_using_a_source_is_an_edit_of_the_destination() { 103 let _home = home_guard::home_slot(); 104 let h = ws_with(&[("README.md", "# readme\n"), ("docs/NOTES.md", "n\n")]); 105 let c = first(&h, "Update README.md using docs/NOTES.md"); 106 assert_eq!(c.asked, Asked::Edit); 107 // The edit target: README.md with its exact content. 108 assert!( 109 c.prompt.ends_with(&edit_block("README.md", "# readme\n")), 110 "{}", 111 c.prompt 112 ); 113 assert!(c.prompt.contains("The file README.md already exists")); 114 } 115 116 #[test] 117 #[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")] 118 fn append_to_existing_guide_is_an_edit() { 119 let _home = home_guard::home_slot(); 120 let h = ws_with(&[("docs/GUIDE.md", "# guide\n")]); 121 let c = first(&h, "Append a section to docs/GUIDE.md"); 122 assert_eq!(c.asked, Asked::Edit); 123 assert!( 124 c.prompt 125 .ends_with(&edit_block("docs/GUIDE.md", "# guide\n")), 126 "{}", 127 c.prompt 128 ); 129 } 130 131 #[test] 132 #[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")] 133 fn missing_destination_with_existing_source_is_new() { 134 let _home = home_guard::home_slot(); 135 let h = ws_with(&[("src.txt", "s\n")]); 136 let c = first(&h, "Write out.md based on src.txt"); 137 assert_eq!(c.asked, Asked::Document); 138 assert!(!c.prompt.contains("already exists"), "{}", c.prompt); 139 } 140 141 // Refused before any model call: runs in the stub build too. 142 #[test] 143 fn unsafe_destinations_are_refused_with_a_reason() { 144 let _home = home_guard::home_slot(); 145 let h = Harness::new(silent()); 146 let outside = h.tmp.path().join("outside"); 147 std::fs::create_dir_all(&outside).unwrap(); 148 std::fs::write(outside.join("s.txt"), "s\n").unwrap(); 149 std::fs::create_dir_all(h.ws().join("docs")).unwrap(); 150 std::os::unix::fs::symlink(outside.join("s.txt"), h.ws().join("link.md")).unwrap(); 151 std::os::unix::fs::symlink(&outside, h.ws().join("linkdir")).unwrap(); 152 h.write("README.md", "r\n"); 153 let abs = format!("Create {} about README.md", outside.join("n.md").display()); 154 for goal in [ 155 "Create ../x.md about README.md", 156 abs.as_str(), 157 "Create ~/x.md about README.md", 158 "Update link.md using README.md", 159 "Create linkdir/new.md about README.md", 160 ] { 161 let why = refused(&h, goal); 162 assert!(why.contains("destination"), "{goal}: {why}"); 163 } 164 } 165 166 #[test] 167 fn two_destinations_are_an_ambiguous_refusal_naming_both() { 168 let _home = home_guard::home_slot(); 169 let h = ws_with(&[("a.md", "a\n")]); 170 for goal in ["Create a.md and b.md", "Update a.md. Then create b.md"] { 171 let e = refused(&h, goal); 172 assert!( 173 e.contains("ambiguous destination") && e.contains("a.md") && e.contains("b.md"), 174 "{e}" 175 ); 176 } 177 } 178 179 #[test] 180 #[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")] 181 fn source_only_goal_is_refused_with_candidates() { 182 let _home = home_guard::home_slot(); 183 let h = ws_with(&[("README.md", "# r\n")]); 184 let e = refused(&h, "Summarise README.md"); 185 assert!( 186 e.contains("no destination named") && e.contains("README.md"), 187 "{e}" 188 ); 189 let c = first(&h, "Edit the given README.md "); 190 assert_eq!(c.asked, Asked::Edit); 191 assert!( 192 c.prompt.ends_with(&edit_block("README.md", "# r\n")), 193 "{}", 194 c.prompt 195 ); 196 let c = first(&h, "Update the reference README.md"); 197 assert!( 198 c.prompt.ends_with(&edit_block("README.md", "# r\n")), 199 "{}", 200 c.prompt 201 ); 202 } 203 204 #[test] 205 #[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")] 206 fn new_document_prompt_states_the_destination() { 207 let _home = home_guard::home_slot(); 208 let h = ws_with(&[("README.md", "# r\n")]); 209 let p = first(&h, "Create docs/SUMMARY.md about README.md").prompt; 210 assert!(p.contains("filename: docs/SUMMARY.md"), "{p}"); 211 } 212 213 #[test] 214 fn rename_is_refused() { 215 let _home = home_guard::home_slot(); 216 let h = ws_with(&[("a.md", "a\n")]); 217 assert!(refused(&h, "Rename a.md to b.md").contains("rename is not supported")); 218 } 219 220 #[test] 221 #[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")] 222 fn u1_garage_goal_is_an_edit_of_the_named_file() { 223 let _home = home_guard::home_slot(); 224 let h = ws_with(&[]); 225 let garage = "# Garage\n\n## Before a trip\n- check oil\n"; 226 h.write("notes/GARAGE.md", garage); 227 let goal = r###"Please add "- check tyre pressure" to the "## Before a trip" section of notes/GARAGE.md."###; 228 let c = first(&h, goal); 229 assert_eq!(c.asked, Asked::Edit); 230 // The edit target, and so the destination, is notes/GARAGE.md. 231 assert!( 232 c.prompt.ends_with(&edit_block("notes/GARAGE.md", garage)), 233 "{}", 234 c.prompt 235 ); 236 } 237 238 #[test] 239 #[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")] 240 fn summary_of_source_into_destination_is_a_document() { 241 let _home = home_guard::home_slot(); 242 let h = ws_with(&[("README.md", "# r\n")]); 243 let c = first(&h, "Write a summary of README.md into docs/SUMMARY.md"); 244 assert_eq!(c.asked, Asked::Document); 245 assert!(!c.prompt.contains("already exists"), "{}", c.prompt); 246 assert!( 247 c.prompt.ends_with(&new_block("docs/SUMMARY.md")), 248 "{}", 249 c.prompt 250 ); 251 }