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/recovery_verdicts.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 / recovery_verdicts.rs` 139 lines ยท 4928 bytes Raw Blame History 1 //! Recovery outcomes through the verifier (VAC M4d). An effect the daemon's ledger does not show 2 //! as landed must never verify as the DONE run does, and each of the three cases has its own 3 //! named refusal. The fixtures are the committed real and synthetic ones, mutated and restamped, 4 //! so the only difference from the passing bundle is the ack state (or the ack's absence). 5 //! The mutations are SYNTHETIC: the ack texts are the DONE ack with `state` changed, not an ack 6 //! the daemon wrote after a real interruption. Specification: provenance/BINDING.md. 7 8 mod common; 9 10 use common::*; 11 use interplane_provenance::verify; 12 use serde_json::{json, Value}; 13 use std::path::Path; 14 15 const REAL: &str = "fixtures/real-waldo-aien-chain"; 16 const FIX: &str = "fixtures/synthetic-fix-the-test"; 17 const SYN: &str = "fixtures/synthetic-full-chain"; 18 19 fn set_state(d: &Path, state: &str) { 20 let p = path_of(d, "ledger_ack"); 21 let mut v: Value = serde_json::from_slice(&std::fs::read(&p).unwrap()).unwrap(); 22 let mut t: Value = serde_json::from_str(v["text"].as_str().unwrap()).unwrap(); 23 t["state"] = json!(state); 24 v["text"] = json!(t.to_string()); 25 std::fs::write(&p, serde_json::to_vec_pretty(&v).unwrap()).unwrap(); 26 restamp(d, "ledger_ack"); 27 } 28 29 /// Intent with no ack: the ack is neither in the manifest nor on disk. 30 fn drop_ack(d: &Path) { 31 let p = path_of(d, "ledger_ack"); 32 let mut c = companion(d); 33 c["records"].as_object_mut().unwrap().remove("ledger_ack"); 34 write_companion(d, &c); 35 std::fs::remove_file(p).unwrap(); 36 } 37 38 fn starts(d: &Path, want: &str) -> String { 39 let v = verify(d); 40 assert!(v.starts_with(want), "wanted {want}, got {v}"); 41 v 42 } 43 44 #[test] 45 fn real_slice_done_is_pass_complete_and_the_three_unlanded_cases_are_not() { 46 let done = verify(&scratch(REAL, "m4d-real-done")); 47 assert!(done.starts_with("PASS complete"), "{done}"); 48 49 let d = scratch(REAL, "m4d-real-notdone"); 50 set_state(&d, "NOT_DONE"); 51 let nd = starts(&d, "FAIL effect_not_done:"); 52 53 let d = scratch(REAL, "m4d-real-unresolved"); 54 set_state(&d, "UNRESOLVED"); 55 let un = starts(&d, "FAIL effect_unresolved:"); 56 57 let d = scratch(REAL, "m4d-real-noack"); 58 drop_ack(&d); 59 let ni = starts(&d, "FAIL effect_interrupted:"); 60 61 // Four different verdicts, none of them a PASS. 62 let all = [done, nd, un, ni]; 63 for i in 0..all.len() { 64 for j in 0..i { 65 assert_ne!(all[i], all[j]); 66 } 67 } 68 } 69 70 #[test] 71 fn synthetic_slice_has_the_same_three_refusals() { 72 let d = scratch(SYN, "m4d-syn-notdone"); 73 set_state(&d, "NOT_DONE"); 74 starts(&d, "FAIL effect_not_done:"); 75 let d = scratch(SYN, "m4d-syn-unresolved"); 76 set_state(&d, "UNRESOLVED"); 77 starts(&d, "FAIL effect_unresolved:"); 78 let d = scratch(SYN, "m4d-syn-noack"); 79 drop_ack(&d); 80 starts(&d, "FAIL effect_interrupted:"); 81 } 82 83 #[test] 84 fn a_test_run_on_top_of_an_unlanded_effect_is_refused() { 85 let ok = verify(&scratch(FIX, "m4d-fix-done")); 86 assert!(ok.starts_with("PASS_LABELLED_INCOMPLETE"), "{ok}"); 87 for (name, state) in [ 88 ("nd", Some("NOT_DONE")), 89 ("un", Some("UNRESOLVED")), 90 ("ni", None), 91 ] { 92 let d = scratch(FIX, &format!("m4d-fix-{name}")); 93 match state { 94 Some(s) => set_state(&d, s), 95 None => drop_ack(&d), 96 } 97 let v = verify(&d); 98 assert!(v.starts_with("FAIL test_run_on_unlanded_effect:"), "{v}"); 99 let inner = match state { 100 Some("NOT_DONE") => "effect_not_done", 101 Some(_) => "effect_unresolved", 102 None => "effect_interrupted", 103 }; 104 assert!(v.contains(inner), "{v}"); 105 } 106 } 107 108 #[test] 109 fn test_records_without_a_section_on_an_unlanded_effect_are_still_refused_as_such() { 110 let d = scratch(FIX, "m4d-fix-nosection"); 111 set_state(&d, "NOT_DONE"); 112 let mut c = companion(&d); 113 c.as_object_mut().unwrap().remove("test_run"); 114 write_companion(&d, &c); 115 starts(&d, "FAIL test_run_on_unlanded_effect:"); 116 } 117 118 #[test] 119 fn an_unknown_ack_state_is_still_a_generic_mismatch() { 120 for s in ["OPEN", "done", "WRITTEN"] { 121 let d = scratch(REAL, &format!("m4d-real-unknown-{s}")); 122 set_state(&d, s); 123 let v = verify(&d); 124 assert_eq!(v, format!("FAIL binding_mismatch: ledger_ack.state={s}")); 125 } 126 } 127 128 #[test] 129 fn an_interrupted_bundle_still_needs_its_earlier_records_to_agree() { 130 // A forged claim next to a missing ack is reported as the forgery, not as an interruption. 131 let d = scratch(REAL, "m4d-real-noack-badintent"); 132 drop_ack(&d); 133 let p = path_of(&d, "ledger_intent"); 134 let mut v: Value = serde_json::from_slice(&std::fs::read(&p).unwrap()).unwrap(); 135 v["verified"] = json!(false); 136 std::fs::write(&p, serde_json::to_vec_pretty(&v).unwrap()).unwrap(); 137 restamp(&d, "ledger_intent"); 138 starts(&d, "FAIL binding_mismatch: ledger_intent.verified"); 139 }