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-allen/tests/deployment_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-allen / tests / deployment_test.rs` 240 lines ยท 8239 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 //! Model swap / rollback / KV discard / deployment record tamper rows. 17 //! 18 //! PLACEHOLDER rows use synthetic digests and do NOT establish real 19 //! model-swap continuity. REAL_DIGESTS rows hash two real, checked-in weight 20 //! files (crates/aien-inference-abi/fixtures) with the host hasher; no model 21 //! is run, so they prove the record binds real artifact bytes, not behaviour. 22 mod support; 23 use aien_allen::binding::{pin_path, Pin}; 24 use aien_allen::deployment::{ 25 append, check_artifact, deployments_path, sha256_file_hex, verify, DeployRefusal, Input, 26 }; 27 use aien_allen::hex; 28 use aien_allen::resolve::{resolve, Context, SubjectSource}; 29 use std::path::PathBuf; 30 use support::*; 31 32 const M1: [u8; 32] = [1; 32]; 33 34 fn input(model: &str, placeholder: bool) -> Input { 35 Input { 36 model_sha256: model.to_string(), 37 config_sha256: hex(&h32("config")), 38 candidate_id: "cand-test".into(), 39 executable_sha256: hex(&h32("exe")), 40 revision: "rev-test".into(), 41 placeholder, 42 } 43 } 44 45 struct Rig { 46 _t: tempfile::TempDir, 47 home: PathBuf, 48 subj: PathBuf, 49 kv: PathBuf, 50 f: Fx, 51 } 52 53 fn rig() -> Rig { 54 let t = tempfile::tempdir().unwrap(); 55 let f = fx("a"); 56 let c = chain(&f, 2); 57 let subj = write_head(&t.path().join("subject.bin"), c.last().unwrap()); 58 let kv = t.path().join("kv-standin"); 59 std::fs::create_dir_all(&kv).unwrap(); 60 std::fs::write(kv.join("block0"), b"reconstructible kv bytes").unwrap(); 61 let r = Rig { 62 home: t.path().join("compose"), 63 subj, 64 kv, 65 f, 66 _t: t, 67 }; 68 resolve( 69 &SubjectSource::Head(r.subj.clone()), 70 &pin_path(&r.home), 71 &Context { 72 machine_id: M1, 73 lineage: Some(r.f.cortex), 74 }, 75 Some(&hex(&r.f.agent)), 76 ) 77 .unwrap(); 78 r 79 } 80 81 fn state(r: &Rig) -> (Vec, Vec) { 82 ( 83 std::fs::read(&r.subj).unwrap(), 84 std::fs::read(pin_path(&r.home)).unwrap(), 85 ) 86 } 87 88 #[test] 89 fn placeholder_model_swap_and_rollback_leave_identity_untouched() { 90 let r = rig(); 91 let before = state(&r); 92 let dep = deployments_path(&r.home); 93 let (a, b) = (hex(&h32("PLACEHOLDER-A")), hex(&h32("PLACEHOLDER-B"))); 94 append(&dep, &r.f.agent, input(&a, true)).unwrap(); 95 append(&dep, &r.f.agent, input(&b, true)).unwrap(); 96 append(&dep, &r.f.agent, input(&a, true)).unwrap(); // rollback to A 97 // Subject object and pin: byte-identical (empty diff). 98 assert_eq!(before, state(&r)); 99 let h = verify(&dep, &r.f.agent).unwrap(); 100 assert_eq!(h.len(), 3, "history retained, never rewound"); 101 assert_eq!(h[0].model_sha256, h[2].model_sha256); 102 assert_ne!(h[0].model_sha256, h[1].model_sha256); 103 assert!(h.iter().all(|e| e.placeholder)); 104 // The pin has no model field: it is the same bytes, so it cannot name one. 105 let p = std::fs::read(pin_path(&r.home)).unwrap(); 106 assert!(!p.windows(32).any(|w| w == h32("PLACEHOLDER-A"))); 107 // Identity still resolves to the same logical agent. 108 let res = resolve( 109 &SubjectSource::Head(r.subj.clone()), 110 &pin_path(&r.home), 111 &Context { 112 machine_id: M1, 113 lineage: Some(r.f.cortex), 114 }, 115 None, 116 ) 117 .unwrap(); 118 assert_eq!(res.agent, r.f.agent); 119 } 120 121 #[test] 122 fn real_digests_of_two_checked_in_weight_files() { 123 let r = rig(); 124 let fx_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../aien-inference-abi/fixtures"); 125 let wa = fx_dir.join("openwaldo-byte/model.safetensors"); 126 let wb = fx_dir.join("llama32_1b_oracle.safetensors"); 127 let (da, db) = (sha256_file_hex(&wa).unwrap(), sha256_file_hex(&wb).unwrap()); 128 assert_ne!(da, db); 129 let before = state(&r); 130 let dep = deployments_path(&r.home); 131 append(&dep, &r.f.agent, input(&da, false)).unwrap(); 132 append(&dep, &r.f.agent, input(&db, false)).unwrap(); 133 let h = verify(&dep, &r.f.agent).unwrap(); 134 check_artifact(&h[0], &wa).unwrap(); 135 check_artifact(&h[1], &wb).unwrap(); 136 // Cross-check: model A's record does not match model B's bytes. 137 assert!(matches!( 138 check_artifact(&h[0], &wb), 139 Err(DeployRefusal::ArtifactChanged { .. }) 140 )); 141 assert_eq!( 142 before, 143 state(&r), 144 "subject and pin unchanged across the swap" 145 ); 146 } 147 148 #[test] 149 fn changed_artifact_bytes_are_refused() { 150 let r = rig(); 151 let art = r._t.path().join("model.bin"); 152 std::fs::write(&art, b"weights v1").unwrap(); 153 let dep = deployments_path(&r.home); 154 append( 155 &dep, 156 &r.f.agent, 157 input(&sha256_file_hex(&art).unwrap(), true), 158 ) 159 .unwrap(); 160 let h = verify(&dep, &r.f.agent).unwrap(); 161 check_artifact(&h[0], &art).unwrap(); 162 std::fs::write(&art, b"weights v2").unwrap(); 163 assert!(matches!( 164 check_artifact(&h[0], &art), 165 Err(DeployRefusal::ArtifactChanged { seq: 1, .. }) 166 )); 167 } 168 169 #[test] 170 fn kv_discard_does_not_change_identity() { 171 let r = rig(); 172 let before = state(&r); 173 std::fs::remove_dir_all(&r.kv).unwrap(); 174 assert_eq!(before, state(&r)); 175 let res = resolve( 176 &SubjectSource::Head(r.subj.clone()), 177 &pin_path(&r.home), 178 &Context { 179 machine_id: M1, 180 lineage: Some(r.f.cortex), 181 }, 182 None, 183 ) 184 .unwrap(); 185 assert_eq!(res.agent, r.f.agent); 186 // The pin type has no field in which KV could be named. 187 let p = Pin::decode(&before.1).unwrap(); 188 assert_eq!(p.agent, r.f.agent); 189 } 190 191 #[test] 192 fn tampered_deployment_records_are_refused() { 193 let r = rig(); 194 let dep = deployments_path(&r.home); 195 for n in 0..3 { 196 append(&dep, &r.f.agent, input(&hex(&h32(&format!("m{n}"))), true)).unwrap(); 197 } 198 let good = std::fs::read_to_string(&dep).unwrap(); 199 let lines: Vec<&str> = good.lines().collect(); 200 // Edited content (hash no longer matches). 201 std::fs::write(&dep, good.replace("rev-test", "rev-evil")).unwrap(); 202 assert!(matches!( 203 verify(&dep, &r.f.agent), 204 Err(DeployRefusal::ChainBroken(1)) 205 )); 206 // Deleted middle line. 207 std::fs::write(&dep, format!("{}\n{}\n", lines[0], lines[2])).unwrap(); 208 assert!(matches!( 209 verify(&dep, &r.f.agent), 210 Err(DeployRefusal::ChainBroken(2)) 211 )); 212 // Reordered lines. 213 std::fs::write(&dep, format!("{}\n{}\n{}\n", lines[1], lines[0], lines[2])).unwrap(); 214 assert!(verify(&dep, &r.f.agent).is_err()); 215 // Truncated final line. 216 std::fs::write(&dep, &good[..good.len() - 5]).unwrap(); 217 assert!(verify(&dep, &r.f.agent).is_err()); 218 // Appending onto a damaged record is refused, not repaired. 219 assert!(append(&dep, &r.f.agent, input("x", true)).is_err()); 220 // Forged identity: a record for another agent is refused for this one. 221 std::fs::write(&dep, &good).unwrap(); 222 let other = h32("other agent"); 223 assert!(matches!( 224 verify(&dep, &other), 225 Err(DeployRefusal::ForgedIdentity(1)) 226 )); 227 // Restored original verifies again. 228 assert_eq!(verify(&dep, &r.f.agent).unwrap().len(), 3); 229 } 230 231 #[test] 232 fn model_supplied_text_cannot_become_identity() { 233 // The record's agent field is the host-resolved agent; an attempt to pass 234 // a model-claimed identity has no API: append takes the agent from the 235 // resolved subject. A hand-forged line with another agent is refused above. 236 let r = rig(); 237 let dep = deployments_path(&r.home); 238 let e = append(&dep, &r.f.agent, input(&hex(&h32("m")), true)).unwrap(); 239 assert_eq!(e.agent, hex(&r.f.agent)); 240 }