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/interplane-mv/blob/main/provenance/tests/fix_the_test.rs # interplane-mv INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority. 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 `interplane-mv / provenance / tests / fix_the_test.rs` 373 lines ยท 11367 bytes Raw Blame History 1 //! The fix-the-test slice: `vac-test-run/1` (test run), the source pin and the `aien.native` 2 //! claim. Every expected verdict is a literal. Mutated archives are restamped (record digests 3 //! recomputed), so only the new checks can refuse them. Specification: provenance/BINDING.md. 4 5 mod common; 6 7 use common::*; 8 use interplane_provenance::synth::{self, Opts}; 9 use interplane_provenance::verify; 10 use serde_json::{json, Value}; 11 use std::path::{Path, PathBuf}; 12 13 const FIX: &str = "fixtures/synthetic-fix-the-test"; 14 const STRONG: &str = "effect=aien-ledger-slice/1:strong proposal=scripted_turn"; 15 const BLOB_OTHER: &str = "`9999999999999999999999999999999999999999999999999999999999999999`"; 16 17 fn variant(name: &str, native: Option) -> PathBuf { 18 let d = Path::new(env!("CARGO_TARGET_TMPDIR")) 19 .join("fixthetest") 20 .join(name); 21 let _ = std::fs::remove_dir_all(&d); 22 synth::write_synthetic( 23 &d, 24 &Opts { 25 fix_the_test: true, 26 native, 27 ..Default::default() 28 }, 29 ) 30 .unwrap(); 31 d 32 } 33 34 fn edit(d: &Path, rec: &str, f: impl FnOnce(&mut Value)) { 35 let p = path_of(d, rec); 36 let mut v: Value = serde_json::from_slice(&std::fs::read(&p).unwrap()).unwrap(); 37 f(&mut v); 38 std::fs::write(&p, serde_json::to_vec_pretty(&v).unwrap()).unwrap(); 39 restamp(d, rec); 40 } 41 42 fn edit_companion(d: &Path, f: impl FnOnce(&mut Value)) { 43 let mut c = companion(d); 44 f(&mut c); 45 write_companion(d, &c); 46 } 47 48 fn declare_missing(c: &mut Value, items: &[&str]) { 49 c["completeness"]["missing"] = json!(items); 50 } 51 52 fn code(d: &Path) -> String { 53 verify(d) 54 } 55 56 fn refused(d: &Path, want: &str) { 57 let v = code(d); 58 assert!( 59 v.starts_with(&format!("FAIL {want}:")), 60 "wanted {want}, got {v}" 61 ); 62 } 63 64 #[test] 65 fn committed_fixture_is_labelled_incomplete_with_native_proven() { 66 let d = scratch(FIX, "ftt-committed"); 67 assert_eq!( 68 code(&d), 69 format!("PASS_LABELLED_INCOMPLETE missing=link:model_turn {STRONG}") 70 ); 71 } 72 73 #[test] 74 fn committed_fixture_matches_the_generator() { 75 let d = variant("regen", Some(true)); 76 let root = Path::new(env!("CARGO_MANIFEST_DIR")).join(FIX); 77 assert_eq!( 78 std::fs::read(d.join("COMPANION.json")).unwrap(), 79 std::fs::read(root.join("COMPANION.json")).unwrap() 80 ); 81 } 82 83 #[test] 84 fn absent_native_field_is_labelled_missing_never_complete() { 85 let d = variant("no-native", None); 86 assert_eq!( 87 code(&d), 88 format!("PASS_LABELLED_INCOMPLETE missing=link:model_turn,link:native {STRONG}") 89 ); 90 } 91 92 #[test] 93 fn native_claimed_false_is_labelled_missing() { 94 let d = variant("stub", Some(false)); 95 assert_eq!( 96 code(&d), 97 format!("PASS_LABELLED_INCOMPLETE missing=link:model_turn,link:native {STRONG}") 98 ); 99 } 100 101 #[test] 102 fn declaring_native_missing_is_required_to_match() { 103 // Dropping `link:native` from the declared list while no native proof exists is unlabelled. 104 let d = variant("undeclared", None); 105 edit_companion(&d, |c| { 106 c["completeness"]["missing"] = json!(["link:model_turn"]) 107 }); 108 refused(&d, "completeness_mismatch"); 109 } 110 111 // ---- tamper tests ------------------------------------------------------------------------- 112 113 #[test] 114 fn changed_exit_code_is_a_test_run_mismatch() { 115 let d = scratch(FIX, "ftt-exit"); 116 edit(&d, "test_run_record", |v| v["exit_code"] = json!(1)); 117 refused(&d, "test_run_mismatch"); 118 } 119 120 #[test] 121 fn test_that_already_passed_before_the_fix_is_refused() { 122 let d = scratch(FIX, "ftt-before"); 123 edit(&d, "test_run_record", |v| v["test_exit_before"] = json!(0)); 124 refused(&d, "test_run_mismatch"); 125 } 126 127 #[test] 128 fn swapped_stdout_digest_is_a_test_run_mismatch() { 129 let d = scratch(FIX, "ftt-stdout-digest"); 130 edit(&d, "test_run_record", |v| { 131 v["stdout_sha256"] = json!(BLOB_OTHER) 132 }); 133 refused(&d, "test_run_mismatch"); 134 } 135 136 #[test] 137 fn swapped_stdout_file_is_a_test_run_mismatch() { 138 let d = scratch(FIX, "ftt-stdout-file"); 139 let p = path_of(&d, "test_stdout"); 140 std::fs::remove_file(&p).unwrap(); 141 std::fs::write(&p, b"ok everything passed, trust me\n").unwrap(); 142 restamp(&d, "test_stdout"); 143 refused(&d, "test_run_mismatch"); 144 } 145 146 #[test] 147 fn wrong_target_blob_after_is_a_test_run_mismatch() { 148 let d = scratch(FIX, "ftt-blob"); 149 edit(&d, "test_run_record", |v| { 150 v["target_blob_sha256_after"] = json!(BLOB_OTHER) 151 }); 152 refused(&d, "test_run_mismatch"); 153 } 154 155 #[test] 156 fn argv_other_than_the_task_command_is_a_test_run_mismatch() { 157 let d = scratch(FIX, "ftt-argv"); 158 edit(&d, "test_run_record", |v| v["argv"] = json!(["true"])); 159 refused(&d, "test_run_mismatch"); 160 } 161 162 #[test] 163 fn task_id_disagreement_is_a_test_run_mismatch() { 164 let d = scratch(FIX, "ftt-taskid"); 165 edit_companion(&d, |c| c["test_run"]["task_id"] = json!("another-task")); 166 refused(&d, "test_run_mismatch"); 167 } 168 169 #[test] 170 fn dropped_test_run_section_is_test_run_missing() { 171 let d = scratch(FIX, "ftt-dropped"); 172 edit_companion(&d, |c| { 173 c.as_object_mut().unwrap().remove("test_run"); 174 }); 175 refused(&d, "test_run_missing"); 176 } 177 178 #[test] 179 fn dropped_test_run_record_is_test_run_missing() { 180 let d = scratch(FIX, "ftt-dropped-record"); 181 edit_companion(&d, |c| { 182 c["records"] 183 .as_object_mut() 184 .unwrap() 185 .remove("test_run_record"); 186 }); 187 refused(&d, "test_run_missing"); 188 } 189 190 #[test] 191 fn tampered_source_pin_blob_is_a_source_pin_mismatch() { 192 let d = scratch(FIX, "ftt-pin-blob"); 193 edit(&d, "source_pin", |v| { 194 v["target_blob_sha256"] = json!(BLOB_OTHER) 195 }); 196 refused(&d, "source_pin_mismatch"); 197 } 198 199 #[test] 200 fn tampered_source_pin_path_and_commit_are_source_pin_mismatches() { 201 let d = scratch(FIX, "ftt-pin-path"); 202 edit(&d, "source_pin", |v| { 203 v["target_path"] = json!("src/other.c") 204 }); 205 refused(&d, "source_pin_mismatch"); 206 let d = scratch(FIX, "ftt-pin-commit"); 207 edit(&d, "source_pin", |v| v["commit"] = json!("abc")); 208 refused(&d, "source_pin_mismatch"); 209 } 210 211 #[test] 212 fn unsupported_test_run_binding_or_version_is_refused() { 213 let d = scratch(FIX, "ftt-binding"); 214 edit_companion(&d, |c| c["test_run"]["binding"] = json!("vac-test-run/2")); 215 refused(&d, "unsupported_test_run"); 216 let d = scratch(FIX, "ftt-version"); 217 edit(&d, "test_run_record", |v| v["v"] = json!(2)); 218 refused(&d, "unsupported_test_run"); 219 } 220 221 // ---- native claim ------------------------------------------------------------------------- 222 223 #[test] 224 fn forged_native_true_against_a_stub_recall_is_contradicted() { 225 let d = variant("forged-stub", Some(false)); 226 edit_companion(&d, |c| { 227 c["aien"]["native"] = json!({"claimed": true, "omega_sha": synth::OMEGA_SHA}); 228 declare_missing(c, &["link:model_turn"]); 229 }); 230 refused(&d, "native_claim_contradicted"); 231 } 232 233 #[test] 234 fn forged_native_true_with_no_recall_report_is_contradicted() { 235 let d = variant("forged-absent", None); 236 edit_companion(&d, |c| { 237 c["aien"]["native"] = json!({"claimed": true, "omega_sha": synth::OMEGA_SHA}); 238 declare_missing(c, &["link:model_turn"]); 239 }); 240 refused(&d, "native_claim_contradicted"); 241 } 242 243 #[test] 244 fn forged_native_sha_differing_from_the_recall_is_contradicted() { 245 let d = scratch(FIX, "ftt-native-sha"); 246 edit_companion(&d, |c| { 247 c["aien"]["native"]["omega_sha"] = json!("`0000000000000000000000000000000000000000`"); 248 }); 249 refused(&d, "native_claim_contradicted"); 250 } 251 252 #[test] 253 fn native_false_while_the_recall_says_native_is_contradicted() { 254 let d = scratch(FIX, "ftt-native-under"); 255 edit_companion(&d, |c| { 256 c["aien"]["native"]["claimed"] = json!(false); 257 declare_missing(c, &["link:model_turn", "link:native"]); 258 }); 259 refused(&d, "native_claim_contradicted"); 260 } 261 262 #[test] 263 fn malformed_native_is_malformed() { 264 let d = scratch(FIX, "ftt-native-malformed"); 265 edit_companion(&d, |c| { 266 c["aien"]["native"] = json!({"claimed": "yes"}); 267 declare_missing(c, &["link:model_turn", "link:native"]); 268 }); 269 refused(&d, "malformed_companion"); 270 } 271 272 #[test] 273 fn test_run_needs_the_strong_ledger_binding() { 274 let d = variant("weak-ledger", Some(true)); 275 edit_companion(&d, |c| { 276 c["effect"]["binding"] = json!("record_effect_receipt/1") 277 }); 278 let v = code(&d); 279 assert!(v.starts_with("FAIL "), "{v}"); 280 } 281 282 #[test] 283 fn verifying_the_slice_changes_nothing() { 284 let d = scratch(FIX, "ftt-readonly"); 285 let before = std::fs::read(d.join("COMPANION.json")).unwrap(); 286 let _ = verify(&d); 287 assert_eq!(before, std::fs::read(d.join("COMPANION.json")).unwrap()); 288 } 289 290 #[test] 291 fn write_outside_the_task_target_is_a_task_scope_mismatch() { 292 // The task allows src/clamp.c; here it names the test file instead, so the grant's write 293 // (src/clamp.c) is not the file the task allows. The same check refuses a run whose grant 294 // writes the test file while the task names the code. 295 let d = scratch(FIX, "ftt-scope"); 296 edit(&d, "task", |v| { 297 v["target_path"] = json!("test/test_clamp.c") 298 }); 299 refused(&d, "task_scope_mismatch"); 300 } 301 302 #[test] 303 fn task_without_a_target_path_is_a_task_scope_mismatch() { 304 let d = scratch(FIX, "ftt-scope-absent"); 305 edit(&d, "task", |v| { 306 v.as_object_mut().unwrap().remove("target_path"); 307 }); 308 refused(&d, "task_scope_mismatch"); 309 } 310 311 #[test] 312 fn stderr_digest_claimed_but_stderr_file_missing_is_refused() { 313 let d = scratch(FIX, "ftt-stderr-missing"); 314 let p = path_of(&d, "test_stderr"); 315 std::fs::remove_file(&p).unwrap(); 316 // Drop the record entry too: the digest alone must not pass. 317 let mut c = companion(&d); 318 let recs = c["records"].as_object_mut().expect("records object"); 319 recs.remove("test_stderr"); 320 write_companion(&d, &c); 321 refused(&d, "test_run_mismatch"); 322 } 323 324 #[test] 325 fn stderr_digest_claimed_but_stderr_not_retained_is_refused() { 326 let d = scratch(FIX, "ftt-stderr-unretained"); 327 let mut c = companion(&d); 328 let r = &mut c["records"]["test_stderr"]; 329 r.as_object_mut().unwrap().remove("path"); 330 r["retained"] = json!(false); 331 c["completeness"]["missing"] 332 .as_array_mut() 333 .unwrap() 334 .push(json!("record:test_stderr")); 335 write_companion(&d, &c); 336 refused(&d, "test_run_mismatch"); 337 } 338 339 #[test] 340 fn stderr_altered_by_one_byte_is_refused() { 341 let d = scratch(FIX, "ftt-stderr-flip"); 342 let p = path_of(&d, "test_stderr"); 343 let mut b = std::fs::read(&p).unwrap(); 344 if b.is_empty() { 345 b.push(b'x'); 346 } else { 347 b[0] ^= 1; 348 } 349 std::fs::write(&p, b).unwrap(); 350 restamp(&d, "test_stderr"); 351 refused(&d, "test_run_mismatch"); 352 } 353 354 #[test] 355 fn intact_stderr_still_passes() { 356 let d = scratch(FIX, "ftt-stderr-ok"); 357 assert!(code(&d).starts_with("PASS_LABELLED_INCOMPLETE")); 358 } 359 360 #[test] 361 fn stdout_digest_claimed_but_stdout_not_retained_is_refused() { 362 let d = scratch(FIX, "ftt-stdout-unretained"); 363 let mut c = companion(&d); 364 let r = &mut c["records"]["test_stdout"]; 365 r.as_object_mut().unwrap().remove("path"); 366 r["retained"] = json!(false); 367 c["completeness"]["missing"] 368 .as_array_mut() 369 .unwrap() 370 .push(json!("record:test_stdout")); 371 write_companion(&d, &c); 372 refused(&d, "test_run_mismatch"); 373 }