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 / destination_corpus_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 | //! The destination parser over every campaign goal corpus in this repository |
| 17 | //! (v5 G6 finding: two independently authored v5 goals were refused before |
| 18 | //! the model). For each goal the probe records what `named_destination` reads |
| 19 | //! and what the compose bridge then decides, and compares the whole table |
| 20 | //! with the committed record |
| 21 | //! `docs/campaigns/open-model-qwen3/evidence-v5/destination-probe.tsv`. |
| 22 | //! Any change to how a real goal is read shows up here as a diff. |
| 23 | //! |
| 24 | //! The verdict is observed through `ComposeBridge::run_task` |
| 25 | //! (tests/support/compose_harness.rs) with a silent model: |
| 26 | //! - `Refused(why)`: the bridge refused the goal before any model call; its |
| 27 | //! refusal text is `RunComposeTask: ` followed by `why`. |
| 28 | //! - `Edit(path)`: the edit proposer was asked, and the prompt carries the |
| 29 | //! edit block of `path`. |
| 30 | //! - `New`: the document proposer was asked; or the run was refused before the |
| 31 | //! model for a goal requirement it could not read (no call to look at), and |
| 32 | //! the workspace is empty, so no file exists that could have been an edit. |
| 33 | //! |
| 34 | //! The workspace is empty, so an edit goal whose file a campaign seeds reads |
| 35 | //! as `New` here; the parse column is what matters. To rewrite the record: |
| 36 | //! `DEST_PROBE_WRITE=<path> cargo test -p aien-runtime --test |
| 37 | //! destination_corpus_test` (linked build), then review the diff. |
| 38 | #[path = "support/compose_harness.rs"] |
| 39 | mod compose_harness; |
| 40 | #[path = "support/home_guard.rs"] |
| 41 | mod home_guard; |
| 42 | |
| 43 | use aien_runtime::destination::named_destination; |
| 44 | use compose_harness::{silent, Asked, Harness}; |
| 45 | use std::path::{Path, PathBuf}; |
| 46 | |
| 47 | const CORPUS: &[&str] = &[ |
| 48 | "docs/campaigns/open-model-qwen3/tasks-oq3-v5.json", |
| 49 | "docs/campaigns/open-model-qwen3/tasks-oq3-v4.json", |
| 50 | "docs/campaigns/open-model-qwen3/tasks-oq3-v3.json", |
| 51 | "docs/campaigns/open-model-qwen3/dryrun-tasks-v2.json", |
| 52 | "docs/campaigns/open-model-qwen3/diagnostic-long-1-tasks.json", |
| 53 | "docs/campaigns/next-phase-1/tasks-v5.json", |
| 54 | "docs/campaigns/next-phase-1/tasks-v6.json", |
| 55 | "docs/campaigns/next-phase-1/tasks-v8.json", |
| 56 | ]; |
| 57 | const RECORD: &str = "docs/campaigns/open-model-qwen3/evidence-v5/destination-probe.tsv"; |
| 58 | |
| 59 | /// The prefix of a task refusal made before any model call. |
| 60 | const REFUSAL_PREFIX: &str = "RunComposeTask: "; |
| 61 | |
| 62 | fn repo() -> PathBuf { |
| 63 | Path::new(env!("CARGO_MANIFEST_DIR")).join("../..") |
| 64 | } |
| 65 | |
| 66 | /// (corpus, id, goal) for every task of every corpus file. |
| 67 | fn goals() -> Vec<(String, String, String)> { |
| 68 | let mut out = Vec::new(); |
| 69 | for f in CORPUS { |
| 70 | let text = std::fs::read_to_string(repo().join(f)).unwrap_or_else(|e| panic!("{f}: {e}")); |
| 71 | let v: serde_json::Value = serde_json::from_str(&text).unwrap(); |
| 72 | for t in v["tasks"] |
| 73 | .as_array() |
| 74 | .unwrap_or_else(|| panic!("{f}: no tasks")) |
| 75 | { |
| 76 | out.push(( |
| 77 | f.to_string(), |
| 78 | t["id"].as_str().unwrap().to_string(), |
| 79 | t["goal"].as_str().unwrap().to_string(), |
| 80 | )); |
| 81 | } |
| 82 | } |
| 83 | out |
| 84 | } |
| 85 | |
| 86 | /// The path of the edit block in `prompt`, if it carries one. |
| 87 | fn edit_path(prompt: &str) -> Option<String> { |
| 88 | const HEAD: &str = "\nThe file "; |
| 89 | const TAIL: &str = " already exists. Its current content is:\n"; |
| 90 | let end = prompt.rfind(TAIL)?; |
| 91 | let start = prompt[..end].rfind(HEAD)? + HEAD.len(); |
| 92 | Some(prompt[start..end].to_string()) |
| 93 | } |
| 94 | |
| 95 | /// What the bridge decides for `goal` in the harness workspace. |
| 96 | fn verdict(h: &Harness, goal: &str) -> String { |
| 97 | h.clear(); |
| 98 | let r = match h.run(goal) { |
| 99 | Err(e) => { |
| 100 | assert!( |
| 101 | h.calls().is_empty(), |
| 102 | "{goal}: a refused goal reached the model" |
| 103 | ); |
| 104 | let why = e |
| 105 | .strip_prefix(REFUSAL_PREFIX) |
| 106 | .unwrap_or_else(|| panic!("{goal}: not a task refusal: {e}")); |
| 107 | return format!("Refused({why})"); |
| 108 | } |
| 109 | Ok(r) => r, |
| 110 | }; |
| 111 | match h.calls().first() { |
| 112 | Some(c) if c.asked == Asked::Document => { |
| 113 | assert_eq!(edit_path(&c.prompt), None, "{goal}: {}", c.prompt); |
| 114 | "New".into() |
| 115 | } |
| 116 | Some(c) => format!( |
| 117 | "Edit({})", |
| 118 | edit_path(&c.prompt).unwrap_or_else(|| panic!("{goal}: no edit block: {}", c.prompt)) |
| 119 | ), |
| 120 | None => { |
| 121 | // Refused before the model for a requirement it could not read: |
| 122 | // one refused attempt, and nothing in the workspace to edit. |
| 123 | assert_eq!(r.proposal_attempts.len(), 1, "{goal}: {r:?}"); |
| 124 | assert_eq!(r.proposal_attempts[0].outcome, "refused", "{goal}: {r:?}"); |
| 125 | assert_eq!(std::fs::read_dir(h.ws()).unwrap().count(), 0, "{goal}"); |
| 126 | "New".into() |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | fn table(h: &Harness) -> String { |
| 132 | let mut s = String::from("corpus\tid\tparse\tverdict\n"); |
| 133 | for (f, id, goal) in goals() { |
| 134 | let parse = match named_destination(&goal, &|_| false) { |
| 135 | Ok(Some(p)) => format!("dest {p}"), |
| 136 | Ok(None) => "none".into(), |
| 137 | Err(e) => format!("error {e}"), |
| 138 | }; |
| 139 | s.push_str(&format!("{f}\t{id}\t{parse}\t{}\n", verdict(h, &goal))); |
| 140 | } |
| 141 | s |
| 142 | } |
| 143 | |
| 144 | #[test] |
| 145 | #[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")] |
| 146 | fn every_campaign_goal_reads_as_recorded() { |
| 147 | let _home = home_guard::home_slot(); |
| 148 | let h = Harness::new(silent()); |
| 149 | let now = table(&h); |
| 150 | assert!(goals().len() >= 60, "a corpus file went missing"); |
| 151 | if let Ok(p) = std::env::var("DEST_PROBE_WRITE") { |
| 152 | std::fs::write(&p, &now).unwrap(); |
| 153 | } |
| 154 | let record = std::fs::read_to_string(repo().join(RECORD)).unwrap_or_default(); |
| 155 | assert!( |
| 156 | now == record, |
| 157 | "the destination parser reads a campaign goal differently from {RECORD}:\n{}", |
| 158 | now.lines() |
| 159 | .zip(record.lines().chain(std::iter::repeat(""))) |
| 160 | .filter(|(a, b)| a != b) |
| 161 | .map(|(a, b)| format!(" now: {a}\n record: {b}")) |
| 162 | .collect::<Vec<_>>() |
| 163 | .join("\n") |
| 164 | ); |
| 165 | } |
| 166 | |
| 167 | /// The three v5 goals the G6 finding is about, by their declared destination. |
| 168 | #[test] |
| 169 | #[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")] |
| 170 | fn v5_goals_resolve_to_their_declared_destinations() { |
| 171 | let _home = home_guard::home_slot(); |
| 172 | let h = Harness::new(silent()); |
| 173 | let v5: Vec<_> = goals() |
| 174 | .into_iter() |
| 175 | .filter(|(f, _, _)| f.ends_with("tasks-oq3-v5.json")) |
| 176 | .collect(); |
| 177 | let goal = |id: &str| v5.iter().find(|(_, i, _)| i == id).unwrap().2.clone(); |
| 178 | for (id, want) in [ |
| 179 | ("D2", "docs/rename-photos.md"), |
| 180 | ("D4", "docs/choir-summary.md"), |
| 181 | ] { |
| 182 | assert_eq!( |
| 183 | named_destination(&goal(id), &|_| false), |
| 184 | Ok(Some(want.to_string())), |
| 185 | "{id}" |
| 186 | ); |
| 187 | assert_eq!(verdict(&h, &goal(id)), "New", "{id}"); |
| 188 | } |
| 189 | // N1 is read, then refused as unsafe (outside the workspace). |
| 190 | assert_eq!( |
| 191 | named_destination(&goal("N1"), &|_| false), |
| 192 | Ok(Some("../shared-stuff/reminder.txt".to_string())) |
| 193 | ); |
| 194 | let v = verdict(&h, &goal("N1")); |
| 195 | assert!( |
| 196 | v.starts_with("Refused(") && v.contains("cannot be written safely"), |
| 197 | "{v}" |
| 198 | ); |
| 199 | } |