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-cli / tests / objective_record_test.rs

206 lines · 6592 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//! sovereign-core #380 (lane L6, acceptance step E2 and CTRL-E2): the
17//! installation records the operator's objective before any work, refuses a
18//! declared forbidden effect class, and ties `compose propose` to the record.
19//! These tests drive the real CLI binary; none needs a daemon or a model.
20use serde_json::Value;
21use sha2::{Digest, Sha256};
22use std::path::{Path, PathBuf};
23use std::process::{Command, Output};
24
25const TEXT: &str = "Summarise the three files in inbox/ into outbox/report.md";
26
27fn expected_id(text: &str) -> String {
28 hex::encode(Sha256::digest(
29 format!("AIEN_E2E_OBJECTIVE_V1\n{text}").as_bytes(),
30 ))
31}
32
33fn run(prov: &Path, args: &[&str]) -> Output {
34 Command::new(env!("CARGO_BIN_EXE_aien-cli"))
35 .args(args)
36 .env("AIEN_PROVENANCE_DIR", prov)
37 // No daemon exists: anything that reaches the daemon fails differently.
38 .env("AIEN_RUNTIME_SOCK", prov.join("no-such.sock"))
39 .output()
40 .expect("run aien-cli")
41}
42
43fn json_of(o: &Output) -> Value {
44 String::from_utf8_lossy(&o.stdout)
45 .lines()
46 .rev()
47 .find_map(|l| serde_json::from_str::<Value>(l).ok())
48 .unwrap_or_else(|| panic!("no JSON on stdout: {:?}", o))
49}
50
51fn stderr_of(o: &Output) -> String {
52 String::from_utf8_lossy(&o.stderr).to_string()
53}
54
55fn prov() -> (tempfile::TempDir, PathBuf) {
56 let t = tempfile::tempdir().unwrap();
57 let p = t.path().join("prov");
58 (t, p)
59}
60
61#[test]
62fn record_writes_file_and_id_is_reproducible() {
63 let (_t, p) = prov();
64 let o = run(&p, &["objective", "record", "--text", TEXT]);
65 assert!(o.status.success(), "{:?}", o);
66 let v = json_of(&o);
67 assert_eq!(v["ok"], true);
68 let id = v["objective_id"].as_str().unwrap().to_string();
69 assert_eq!(id, expected_id(TEXT));
70 assert_eq!(
71 v["objective_text_sha256"],
72 hex::encode(Sha256::digest(TEXT))
73 );
74 assert_eq!(v["recorded_before_work"], true);
75 assert_eq!(v["operator_surface"], "aien-cli");
76 assert!(v["utc"].as_str().unwrap().ends_with('Z'));
77 let path = PathBuf::from(v["path"].as_str().unwrap());
78 assert!(path.starts_with(&p) && path.is_file());
79 assert_eq!(
80 path.file_name().unwrap().to_str().unwrap(),
81 format!("{id}.json")
82 );
83 let rec: Value = serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();
84 assert_eq!(rec["objective_id"], id);
85 assert_eq!(rec["objective_text"], TEXT);
86 assert_eq!(rec["effect_class"], "WORKSPACE_WRITE");
87 // Same text again gives the same identity.
88 let again = json_of(&run(&p, &["objective", "record", "--text", TEXT]));
89 assert_eq!(again["objective_id"], id);
90}
91
92#[test]
93fn record_refuses_over_length_text() {
94 let (_t, p) = prov();
95 let ok = "a".repeat(2000);
96 assert!(run(&p, &["objective", "record", "--text", &ok])
97 .status
98 .success());
99 let long = "a".repeat(2001);
100 let o = run(&p, &["objective", "record", "--text", &long]);
101 assert!(!o.status.success());
102 assert_eq!(json_of(&o)["ok"], false);
103 assert!(
104 stderr_of(&o).contains("OBJECTIVE_REFUSED TooLong"),
105 "{}",
106 stderr_of(&o)
107 );
108}
109
110#[test]
111fn record_refuses_forbidden_effect_class_before_any_work() {
112 let (_t, p) = prov();
113 let o = run(
114 &p,
115 &[
116 "objective",
117 "record",
118 "--text",
119 "Email the report",
120 "--effect-class",
121 "EXTERNAL_IRREVERSIBLE",
122 ],
123 );
124 assert!(!o.status.success());
125 let v = json_of(&o);
126 assert_eq!(v["ok"], false);
127 assert_eq!(v["refusal"], "ForbiddenEffectClass");
128 assert!(
129 stderr_of(&o).contains("OBJECTIVE_REFUSED ForbiddenEffectClass"),
130 "{}",
131 stderr_of(&o)
132 );
133 // Nothing was recorded and no effect receipt exists.
134 assert!(!p
135 .join("objectives")
136 .join(format!("{}.json", expected_id("Email the report")))
137 .exists());
138 let leftovers = std::fs::read_dir(&p).map(|d| d.count()).unwrap_or(0);
139 assert_eq!(leftovers, 0);
140}
141
142#[test]
143fn show_prints_the_record() {
144 let (_t, p) = prov();
145 let id = json_of(&run(&p, &["objective", "record", "--text", TEXT]))["objective_id"]
146 .as_str()
147 .unwrap()
148 .to_string();
149 let o = run(&p, &["objective", "show", &id]);
150 assert!(o.status.success(), "{:?}", o);
151 let v = json_of(&o);
152 assert_eq!(v["ok"], true);
153 assert_eq!(v["objective_id"], id);
154 assert_eq!(v["objective_text"], TEXT);
155 let missing = run(&p, &["objective", "show", &"0".repeat(64)]);
156 assert!(!missing.status.success());
157 assert!(stderr_of(&missing).contains("OBJECTIVE_REFUSED ObjectiveMissing"));
158}
159
160fn propose(p: &Path, ws: &Path, goal: &str, id: &str) -> Output {
161 run(
162 p,
163 &[
164 "compose",
165 "propose",
166 "--workspace",
167 ws.to_str().unwrap(),
168 "--goal",
169 goal,
170 "--objective-id",
171 id,
172 ],
173 )
174}
175
176#[test]
177fn propose_with_mismatched_objective_id_is_refused() {
178 let (t, p) = prov();
179 let id = json_of(&run(&p, &["objective", "record", "--text", TEXT]))["objective_id"]
180 .as_str()
181 .unwrap()
182 .to_string();
183 let ws = t.path().join("ws");
184 std::fs::create_dir_all(&ws).unwrap();
185 let o = propose(&p, &ws, "Summarise something else", &id);
186 assert!(!o.status.success());
187 let v = json_of(&o);
188 assert_eq!(v["ok"], false);
189 assert!(
190 v["error"].as_str().unwrap().contains("ObjectiveMismatch"),
191 "{v}"
192 );
193}
194
195#[test]
196fn propose_with_missing_objective_id_is_refused() {
197 let (t, p) = prov();
198 let ws = t.path().join("ws");
199 std::fs::create_dir_all(&ws).unwrap();
200 let o = propose(&p, &ws, TEXT, &"f".repeat(64));
201 assert!(!o.status.success());
202 assert!(json_of(&o)["error"]
203 .as_str()
204 .unwrap()
205 .contains("ObjectiveMissing"));
206}