interplane.Get Omega
Read in your language

interplane-mv

INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.

Brought by drakestapleton

branch main Branches Tags History

interplane-mv / provenance / tests / review_hardening.rs

173 lines · 5890 bytes Raw Blame History
1//! #76 independent review findings, each as a refusal on a copy of a committed fixture:
2//! duplicate JSON keys (manifest, record, and the JSON inside a ledger note), test material that
3//! claims a complete chain, symlinked records, a second final result in the trace, a malformed
4//! `retained` flag, a repeated candidate-manifest key, and the candidate on the verdict line.
5mod common;
6use common::*;
7use interplane_provenance::verify;
8use serde_json::json;
9use std::path::Path;
10
11const REAL: &str = "fixtures/real-waldo-aien-chain";
12const SYN: &str = "fixtures/synthetic-full-chain";
13
14/// Replace the first `from` in the record's raw bytes, then restamp its size and digest.
15fn edit_raw(d: &Path, rec: &str, from: &str, to: &str) {
16 let p = path_of(d, rec);
17 let t = std::fs::read_to_string(&p).unwrap();
18 assert!(t.contains(from), "{rec} lacks {from:?}");
19 std::fs::write(&p, t.replacen(from, to, 1)).unwrap();
20 restamp(d, rec);
21}
22
23#[test]
24fn the_real_chain_names_its_missing_candidate_on_the_verdict_line() {
25 assert_eq!(
26 verify(Path::new(env!("CARGO_MANIFEST_DIR")).join(REAL).as_path()),
27 "PASS complete effect=aien-ledger-slice/1:strong proposal=model_generation/2 candidate=none"
28 );
29}
30
31#[test]
32fn a_duplicate_key_in_the_manifest_is_refused() {
33 let d = scratch(REAL, "dup_manifest");
34 let p = d.join("COMPANION.json");
35 let t = std::fs::read_to_string(&p).unwrap();
36 let t = t.replacen(
37 "\"completeness\": {",
38 "\"completeness\": {\"state\": \"incomplete\",",
39 1,
40 );
41 std::fs::write(&p, t).unwrap();
42 assert_eq!(verify(&d), "FAIL unparseable_companion: COMPANION.json");
43}
44
45#[test]
46fn a_duplicate_key_in_a_record_is_refused() {
47 let d = scratch(REAL, "dup_trace");
48 edit_raw(
49 &d,
50 "interplane_trace",
51 "\"message_id\": \"m-1\",",
52 "\"message_id\": \"m-9\", \"message_id\": \"m-1\",",
53 );
54 assert_eq!(verify(&d), "FAIL unparseable_record: interplane_trace");
55}
56
57#[test]
58fn a_duplicate_key_inside_a_ledger_note_is_refused() {
59 let d = scratch(REAL, "dup_note");
60 edit_raw(
61 &d,
62 "ledger_generation",
63 "{\\\"daemon\\\":",
64 "{\\\"generation\\\":0,\\\"daemon\\\":",
65 );
66 let v = verify(&d);
67 assert!(v.starts_with("FAIL ") && v.contains("text"), "{v}");
68}
69
70#[test]
71fn test_material_never_verifies_as_complete() {
72 for (i, (class, want)) in [
73 (
74 json!("synthetic"),
75 "FAIL synthetic_complete: fixture.class=synthetic",
76 ),
77 (
78 json!("staged"),
79 "FAIL synthetic_complete: fixture.class=staged",
80 ),
81 (json!(null), "FAIL malformed_companion: fixture.class"),
82 ]
83 .into_iter()
84 .enumerate()
85 {
86 let d = scratch(REAL, &format!("fixture_class_{i}"));
87 let mut c = companion(&d);
88 c["fixture"]["class"] = class;
89 write_companion(&d, &c);
90 assert_eq!(verify(&d), want);
91 }
92}
93
94#[test]
95fn a_symlinked_record_or_directory_is_refused() {
96 let d = scratch(REAL, "symlink_file");
97 let p = path_of(&d, "export_config");
98 let outside = d.with_extension("outside-config.json");
99 std::fs::rename(&p, &outside).unwrap();
100 std::os::unix::fs::symlink(&outside, &p).unwrap();
101 assert_eq!(
102 verify(&d),
103 "FAIL malformed_companion: records.export_config.path (symlink)"
104 );
105
106 let d = scratch(REAL, "symlink_dir");
107 let dir = d.join("records/export");
108 let outside = d.with_extension("outside-export");
109 let _ = std::fs::remove_dir_all(&outside);
110 std::fs::rename(&dir, &outside).unwrap();
111 std::os::unix::fs::symlink(&outside, &dir).unwrap();
112 let v = verify(&d);
113 assert!(
114 v.starts_with("FAIL malformed_companion: records.export_") && v.ends_with("(symlink)"),
115 "{v}"
116 );
117}
118
119#[test]
120fn a_result_after_the_final_one_is_refused() {
121 let d = scratch(REAL, "second_final");
122 let p = path_of(&d, "interplane_trace");
123 let mut t: serde_json::Value = serde_json::from_slice(&std::fs::read(&p).unwrap()).unwrap();
124 let last = t[2].clone();
125 assert_eq!(last["payload"]["status"], "ok");
126 t.as_array_mut().unwrap().push(last);
127 std::fs::write(&p, serde_json::to_vec_pretty(&t).unwrap()).unwrap();
128 restamp(&d, "interplane_trace");
129 assert_eq!(
130 verify(&d),
131 "FAIL binding_mismatch: interplane_trace[3] result after the final one for real-run-04:t0:c0"
132 );
133
134 let d = scratch(REAL, "second_request");
135 let p = path_of(&d, "interplane_trace");
136 let mut t: serde_json::Value = serde_json::from_slice(&std::fs::read(&p).unwrap()).unwrap();
137 let req = t[0].clone();
138 t.as_array_mut().unwrap().insert(1, req);
139 std::fs::write(&p, serde_json::to_vec_pretty(&t).unwrap()).unwrap();
140 restamp(&d, "interplane_trace");
141 let v = verify(&d);
142 assert!(
143 v.starts_with("FAIL binding_mismatch: interplane_trace[1] second tool_request"),
144 "{v}"
145 );
146}
147
148#[test]
149fn a_non_boolean_retained_flag_is_refused() {
150 let d = scratch(REAL, "retained_str");
151 let mut c = companion(&d);
152 c["records"]["export_config"]["retained"] = json!("yes");
153 write_companion(&d, &c);
154 assert_eq!(
155 verify(&d),
156 "FAIL malformed_companion: records.export_config.retained"
157 );
158}
159
160#[test]
161fn a_repeated_candidate_manifest_key_is_refused() {
162 let d = scratch(SYN, "cand_dup");
163 let p = path_of(&d, "candidate_manifest");
164 let t = std::fs::read_to_string(&p).unwrap();
165 // A second root `schema` before the real one: a first-wins and a last-wins reader agree on the
166 // value here, so only the repeat itself can be refused.
167 std::fs::write(&p, format!("schema = \"CandidateManifestV1\"\n{t}")).unwrap();
168 restamp(&d, "candidate_manifest");
169 assert_eq!(
170 verify(&d),
171 "FAIL binding_mismatch: candidate manifest repeats a key"
172 );
173}