interplane-mv
INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.
Brought by drakestapleton
interplane-mv / provenance / tests / verdicts.rs
| 1 | //! One test per verdict. Every expected verdict is a literal: the verifier must print exactly |
| 2 | //! these bytes. Mutations happen on copies under CARGO_TARGET_TMPDIR; committed fixtures are |
| 3 | //! never rewritten. |
| 4 | |
| 5 | mod common; |
| 6 | |
| 7 | use common::*; |
| 8 | use interplane_provenance::gojson::sha256_hex; |
| 9 | use interplane_provenance::synth::{self, Opts}; |
| 10 | use interplane_provenance::verify; |
| 11 | use serde_json::{json, Value}; |
| 12 | use std::path::Path; |
| 13 | |
| 14 | const SYN: &str = "fixtures/synthetic-full-chain"; |
| 15 | const REAL: &str = "fixtures/real-waldo-smoke"; |
| 16 | const REAL_TJ: &str = "fixtures/real-waldo-tokenizer-json"; |
| 17 | const WEAK: &str = "fixtures/synthetic-weak-receipt"; |
| 18 | |
| 19 | #[test] |
| 20 | fn valid_self_contained_archive() { |
| 21 | assert_eq!( |
| 22 | verify(Path::new(SYN)), |
| 23 | "PASS_LABELLED_INCOMPLETE missing=link:model_turn effect=aien-ledger-slice/1:strong proposal=scripted_turn" |
| 24 | ); |
| 25 | assert_eq!( |
| 26 | verify(Path::new(WEAK)), |
| 27 | "PASS_LABELLED_INCOMPLETE missing=link:model_turn effect=record_effect_receipt/1:weak" |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | #[test] |
| 32 | fn synthetic_fixtures_are_reproducible_byte_for_byte() { |
| 33 | for (fixture, weak) in [(SYN, false), (WEAK, true)] { |
| 34 | let d = Path::new(env!("CARGO_TARGET_TMPDIR")).join(format!("regen-{weak}")); |
| 35 | let _ = std::fs::remove_dir_all(&d); |
| 36 | synth::write_synthetic( |
| 37 | &d, |
| 38 | &Opts { |
| 39 | weak, |
| 40 | ..Opts::default() |
| 41 | }, |
| 42 | ) |
| 43 | .unwrap(); |
| 44 | let c = companion(&d); |
| 45 | for (_, r) in c["records"].as_object().unwrap() { |
| 46 | let p = r["path"].as_str().unwrap(); |
| 47 | assert_eq!( |
| 48 | std::fs::read(d.join(p)).unwrap(), |
| 49 | std::fs::read(Path::new(fixture).join(p)).unwrap(), |
| 50 | "{p}" |
| 51 | ); |
| 52 | } |
| 53 | assert_eq!( |
| 54 | std::fs::read(d.join("COMPANION.json")).unwrap(), |
| 55 | std::fs::read(Path::new(fixture).join("COMPANION.json")).unwrap() |
| 56 | ); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | #[test] |
| 61 | fn real_waldo_export_is_labelled_incomplete() { |
| 62 | assert_eq!( |
| 63 | verify(Path::new(REAL)), |
| 64 | "PASS_LABELLED_INCOMPLETE missing=link:aien,link:effect,link:interplane" |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | #[test] |
| 69 | fn changed_weight_bytes() { |
| 70 | let d = scratch(SYN, "changed_weight_bytes"); |
| 71 | let p = path_of(&d, "export_weights"); |
| 72 | let mut b = std::fs::read(&p).unwrap(); |
| 73 | let last = b.len() - 1; |
| 74 | b[last] ^= 0x01; |
| 75 | std::fs::write(&p, b).unwrap(); |
| 76 | assert_eq!(verify(&d), "FAIL digest_mismatch: export_weights"); |
| 77 | } |
| 78 | |
| 79 | #[test] |
| 80 | fn changed_weight_bytes_with_restamped_manifest() { |
| 81 | let d = scratch(SYN, "changed_weight_bytes_restamped"); |
| 82 | let p = path_of(&d, "export_weights"); |
| 83 | let mut b = std::fs::read(&p).unwrap(); |
| 84 | let last = b.len() - 1; |
| 85 | b[last] ^= 0x01; |
| 86 | std::fs::write(&p, b).unwrap(); |
| 87 | restamp(&d, "export_weights"); |
| 88 | assert_eq!( |
| 89 | verify(&d), |
| 90 | "FAIL binding_mismatch: release_bom.artifacts[model.safetensors]" |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | #[test] |
| 95 | fn tokenizer_swapped_and_restamped() { |
| 96 | let d = scratch(SYN, "tokenizer_swapped"); |
| 97 | let p = path_of(&d, "export_tokenizer"); |
| 98 | let mut t: Value = serde_json::from_slice(&std::fs::read(&p).unwrap()).unwrap(); |
| 99 | t["model"]["vocab"]["world"] = json!(5); |
| 100 | t["model"]["vocab"]["note"] = json!(4); |
| 101 | std::fs::write(&p, serde_json::to_vec_pretty(&t).unwrap()).unwrap(); |
| 102 | restamp(&d, "export_tokenizer"); |
| 103 | assert_eq!( |
| 104 | verify(&d), |
| 105 | "FAIL binding_mismatch: release_bom.artifacts[tokenizer.json]" |
| 106 | ); |
| 107 | } |
| 108 | |
| 109 | #[test] |
| 110 | fn config_vocab_disagrees_with_tokenizer() { |
| 111 | // A fully consistent chain (every digest recomputed) whose config cannot serve its tokenizer. |
| 112 | let d = Path::new(env!("CARGO_TARGET_TMPDIR")) |
| 113 | .join("verdicts") |
| 114 | .join("config_vocab"); |
| 115 | let _ = std::fs::remove_dir_all(&d); |
| 116 | synth::write_synthetic( |
| 117 | &d, |
| 118 | &Opts { |
| 119 | config_vocab: Some(9), |
| 120 | ..Opts::default() |
| 121 | }, |
| 122 | ) |
| 123 | .unwrap(); |
| 124 | assert_eq!( |
| 125 | verify(&d), |
| 126 | "FAIL incompatible: config.vocab_size=9 tokenizer_vocab=8" |
| 127 | ); |
| 128 | } |
| 129 | |
| 130 | #[test] |
| 131 | fn missing_bom_in_archive_declared_complete() { |
| 132 | let d = scratch(SYN, "missing_bom_unlabelled"); |
| 133 | std::fs::remove_file(path_of(&d, "waldo_model_bom")).unwrap(); |
| 134 | assert_eq!(verify(&d), "FAIL missing_record: waldo_model_bom"); |
| 135 | } |
| 136 | |
| 137 | #[test] |
| 138 | fn missing_bom_correctly_labelled_incomplete() { |
| 139 | // The derived-export situation: only the hash of the managed model BOM survives. |
| 140 | let d = scratch(SYN, "missing_bom_labelled"); |
| 141 | std::fs::remove_file(path_of(&d, "waldo_model_bom")).unwrap(); |
| 142 | let mut c = companion(&d); |
| 143 | c["records"]["waldo_model_bom"]["retained"] = json!(false); |
| 144 | c["completeness"] = |
| 145 | json!({"state": "incomplete", "missing": ["link:model_turn", "record:waldo_model_bom"]}); |
| 146 | write_companion(&d, &c); |
| 147 | assert_eq!( |
| 148 | verify(&d), |
| 149 | "PASS_LABELLED_INCOMPLETE missing=link:model_turn,record:waldo_model_bom effect=aien-ledger-slice/1:strong proposal=scripted_turn" |
| 150 | ); |
| 151 | } |
| 152 | |
| 153 | #[test] |
| 154 | fn missing_bom_labelled_record_but_archive_claims_complete() { |
| 155 | let d = scratch(SYN, "missing_bom_mislabelled"); |
| 156 | std::fs::remove_file(path_of(&d, "waldo_model_bom")).unwrap(); |
| 157 | let mut c = companion(&d); |
| 158 | c["records"]["waldo_model_bom"]["retained"] = json!(false); |
| 159 | write_companion(&d, &c); |
| 160 | assert_eq!( |
| 161 | verify(&d), |
| 162 | "FAIL completeness_mismatch: record:waldo_model_bom" |
| 163 | ); |
| 164 | } |
| 165 | |
| 166 | #[test] |
| 167 | fn missing_bom_labelled_with_wrong_hash() { |
| 168 | let d = scratch(SYN, "missing_bom_wrong_hash"); |
| 169 | std::fs::remove_file(path_of(&d, "waldo_model_bom")).unwrap(); |
| 170 | let mut c = companion(&d); |
| 171 | c["records"]["waldo_model_bom"]["retained"] = json!(false); |
| 172 | c["records"]["waldo_model_bom"]["waldo_sha256"] = json!("0".repeat(64)); |
| 173 | c["completeness"] = |
| 174 | json!({"state": "incomplete", "missing": ["link:model_turn", "record:waldo_model_bom"]}); |
| 175 | write_companion(&d, &c); |
| 176 | assert_eq!( |
| 177 | verify(&d), |
| 178 | "FAIL binding_mismatch: release_bom.source_bom_sha256" |
| 179 | ); |
| 180 | } |
| 181 | |
| 182 | #[test] |
| 183 | fn changed_license_metadata_with_restamped_manifest() { |
| 184 | let d = scratch(SYN, "changed_license"); |
| 185 | let p = path_of(&d, "waldo_run_bom"); |
| 186 | let text = std::fs::read_to_string(&p) |
| 187 | .unwrap() |
| 188 | .replace("\"CC0-1.0\"", "\"MIT\""); |
| 189 | std::fs::write(&p, text).unwrap(); |
| 190 | restamp(&d, "waldo_run_bom"); |
| 191 | assert_eq!( |
| 192 | verify(&d), |
| 193 | "FAIL binding_mismatch: run_bom.corpus_bom_sha256" |
| 194 | ); |
| 195 | } |
| 196 | |
| 197 | #[test] |
| 198 | fn changed_manifest_metadata() { |
| 199 | let d = scratch(SYN, "changed_manifest_metadata"); |
| 200 | let mut c = companion(&d); |
| 201 | c["aien"]["candidate_id"] = json!("CAND-3"); |
| 202 | write_companion(&d, &c); |
| 203 | assert_eq!(verify(&d), "FAIL binding_mismatch: candidate.id"); |
| 204 | } |
| 205 | |
| 206 | #[test] |
| 207 | fn truncated_record_write() { |
| 208 | let d = scratch(SYN, "truncated_record"); |
| 209 | let p = path_of(&d, "export_weights"); |
| 210 | let b = std::fs::read(&p).unwrap(); |
| 211 | std::fs::write(&p, &b[..b.len() / 2]).unwrap(); |
| 212 | assert_eq!( |
| 213 | verify(&d), |
| 214 | "FAIL size_mismatch: export_weights declared=160 actual=80" |
| 215 | ); |
| 216 | } |
| 217 | |
| 218 | #[test] |
| 219 | fn truncated_manifest_write() { |
| 220 | let d = scratch(SYN, "truncated_manifest"); |
| 221 | let b = std::fs::read(d.join("COMPANION.json")).unwrap(); |
| 222 | std::fs::write(d.join("COMPANION.json"), &b[..b.len() / 2]).unwrap(); |
| 223 | assert_eq!(verify(&d), "FAIL unparseable_companion: COMPANION.json"); |
| 224 | } |
| 225 | |
| 226 | #[test] |
| 227 | fn receipt_for_another_request_substituted() { |
| 228 | let d = scratch(WEAK, "receipt_other_request"); |
| 229 | let other = synth::receipt_bytes( |
| 230 | "write_file", |
| 231 | &synth::request_args(synth::OTHER_REQUEST_ID), |
| 232 | &synth::result_data(synth::OTHER_REQUEST_ID), |
| 233 | true, |
| 234 | ); |
| 235 | std::fs::write(path_of(&d, "effect_receipt"), other).unwrap(); |
| 236 | restamp(&d, "effect_receipt"); |
| 237 | assert_eq!( |
| 238 | verify(&d), |
| 239 | "FAIL binding_mismatch: effect_receipt.arguments_digest request=call-prov-01" |
| 240 | ); |
| 241 | } |
| 242 | |
| 243 | #[test] |
| 244 | fn receipt_claimed_for_another_trace() { |
| 245 | let d = scratch(WEAK, "receipt_other_trace"); |
| 246 | let mut c = companion(&d); |
| 247 | c["interplane"]["trace_id"] = json!("trace-prov-99"); |
| 248 | write_companion(&d, &c); |
| 249 | assert_eq!( |
| 250 | verify(&d), |
| 251 | "FAIL binding_mismatch: interplane_trace[0].trace_id" |
| 252 | ); |
| 253 | } |
| 254 | |
| 255 | #[test] |
| 256 | fn load_claim_on_export_aien_cannot_load() { |
| 257 | let d = scratch(REAL, "real_load_claim"); |
| 258 | let mut c = companion(&d); |
| 259 | c["aien"] = json!({"candidate_id": "CAND-3", "executable": "aien-cli-native-release", |
| 260 | "executable_sha256": "3a17ee79a238ad223fd59f4436d98906a0144b8d5ac47809da194a9ac1d493db"}); |
| 261 | c["completeness"]["missing"] = json!(["link:effect", "link:interplane"]); |
| 262 | write_companion(&d, &c); |
| 263 | assert_eq!( |
| 264 | verify(&d), |
| 265 | "FAIL load_unsupported: unsupported_tokenizer:OpenWALDOByteTokenizer" |
| 266 | ); |
| 267 | } |
| 268 | |
| 269 | #[test] |
| 270 | fn unknown_lineage_cannot_carry_training_records() { |
| 271 | let d = scratch(REAL, "real_lineage_conflict"); |
| 272 | let mut c = companion(&d); |
| 273 | c["lineage"] = |
| 274 | json!({"kind": "unknown_pretraining", "origin": {"model_id": "x", "revision": "unknown"}}); |
| 275 | write_companion(&d, &c); |
| 276 | assert_eq!( |
| 277 | verify(&d), |
| 278 | "FAIL lineage_conflict: unknown_pretraining with record waldo_model_bom" |
| 279 | ); |
| 280 | } |
| 281 | |
| 282 | #[test] |
| 283 | fn sealed_manifest_is_never_rewritten() { |
| 284 | let d = scratch(SYN, "no_rewrite"); |
| 285 | let before = std::fs::read(d.join("COMPANION.json")).unwrap(); |
| 286 | assert!(synth::seal(&d, companion(&d)).is_err()); |
| 287 | assert_eq!(std::fs::read(d.join("COMPANION.json")).unwrap(), before); |
| 288 | } |
| 289 | |
| 290 | #[test] |
| 291 | fn export_weights_not_derived_from_trained_run() { |
| 292 | // Weights changed, and both the manifest and the release BOM re-pinned to them: only the |
| 293 | // conversion check (tensor data section equals the run's pinned weights) still refuses. |
| 294 | let d = scratch(SYN, "conversion_mismatch"); |
| 295 | let p = path_of(&d, "export_weights"); |
| 296 | let mut b = std::fs::read(&p).unwrap(); |
| 297 | let last = b.len() - 1; |
| 298 | b[last] ^= 0x01; |
| 299 | std::fs::write(&p, &b).unwrap(); |
| 300 | restamp(&d, "export_weights"); |
| 301 | let rp = path_of(&d, "release_bom"); |
| 302 | let mut rel: Value = serde_json::from_slice(&std::fs::read(&rp).unwrap()).unwrap(); |
| 303 | for a in rel["artifacts"].as_array_mut().unwrap() { |
| 304 | if a["path"] == "model.safetensors" { |
| 305 | a["sha256"] = json!(sha256_hex(&b)); |
| 306 | } |
| 307 | } |
| 308 | std::fs::write(&rp, serde_json::to_vec_pretty(&rel).unwrap()).unwrap(); |
| 309 | restamp(&d, "release_bom"); |
| 310 | assert_eq!( |
| 311 | verify(&d), |
| 312 | "FAIL conversion_mismatch: safetensors data section run_weights != export_weights" |
| 313 | ); |
| 314 | } |
| 315 | |
| 316 | #[test] |
| 317 | fn real_waldo_tokenizer_json_loaded_by_aien_is_labelled_incomplete() { |
| 318 | assert_eq!( |
| 319 | verify(Path::new(REAL_TJ)), |
| 320 | "PASS_LABELLED_INCOMPLETE missing=link:effect,link:interplane" |
| 321 | ); |
| 322 | } |
| 323 | |
| 324 | #[test] |
| 325 | fn real_load_log_for_other_model_bytes_is_refused() { |
| 326 | let d = scratch(REAL_TJ, "real_tj_load_log_swapped"); |
| 327 | let p = path_of(&d, "aien_load_log"); |
| 328 | let text = std::fs::read_to_string(&p).unwrap(); |
| 329 | let c = companion(&d); |
| 330 | let sha = c["records"]["export_weights"]["sha256"].as_str().unwrap(); |
| 331 | std::fs::write(&p, text.replace(sha, &"0".repeat(64))).unwrap(); |
| 332 | restamp(&d, "aien_load_log"); |
| 333 | assert_eq!(verify(&d), "FAIL binding_mismatch: aien_load.model_sha256"); |
| 334 | } |
| 335 | |
| 336 | #[test] |
| 337 | fn candidate_claim_without_manifest_is_refused() { |
| 338 | let d = scratch(REAL_TJ, "real_tj_candidate_claim_no_manifest"); |
| 339 | let mut c = companion(&d); |
| 340 | c["aien"]["candidate_id"] = Value::from("CAND-4"); |
| 341 | write_companion(&d, &c); |
| 342 | assert_eq!( |
| 343 | verify(&d), |
| 344 | "FAIL binding_mismatch: candidate_id without candidate_manifest" |
| 345 | ); |
| 346 | } |