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/benchmarks-mv/blob/main/tests/evidence_records.rs # benchmarks-mv Measurement harnesses and evidence bundles for AIEN on the NVIDIA DGX Spark GB10. Speed is reported against the machine's physical limit and my own previous run. Attachment of AienOS. 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 `benchmarks-mv / tests / evidence_records.rs` 360 lines ยท 12446 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 //! Runs `bench_verify_records` on the committed fixtures and bundles and checks its exact defect lines. 17 18 use std::fs; 19 use std::path::{Path, PathBuf}; 20 use std::process::Command; 21 22 const ROOT: &str = env!("CARGO_MANIFEST_DIR"); 23 const BUNDLE: &str = "artifacts/gb10_canonical_`1789907893`_4d762"; 24 25 fn verify(root: &Path, args: &[&str]) -> (i32, Vec) { 26 let out = Command::new(env!("CARGO_BIN_EXE_bench_verify_records")) 27 .arg("--root") 28 .arg(root) 29 .args(args) 30 .output() 31 .expect("run bench_verify_records"); 32 let lines = String::from_utf8(out.stdout) 33 .expect("utf-8 output") 34 .lines() 35 .map(str::to_string) 36 .collect(); 37 (out.status.code().expect("exit code"), lines) 38 } 39 40 fn bad(name: &str, expected: &[&str]) { 41 let path = format!("tests/fixtures/records/bad/{name}.json"); 42 let (code, lines) = verify(Path::new(ROOT), &[&path]); 43 let want: Vec = expected.iter().map(|l| format!("{path}: {l}")).collect(); 44 assert_eq!(lines, want, "defect lines for {name}"); 45 assert_eq!(code, 1, "{name} must fail"); 46 } 47 48 #[test] 49 fn good_fixture_and_committed_evidence_pass() { 50 let (code, lines) = verify(Path::new(ROOT), &["--tracked", "records", "artifacts"]); 51 assert_eq!(lines, Vec::::new()); 52 assert_eq!(code, 0); 53 } 54 55 /// --tracked finds a record by its schema wherever git tracks it, and leaves the bad fixtures out. 56 #[test] 57 fn tracked_finds_records_outside_the_usual_directories() { 58 let scratch = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("evidence_tracked_walk"); 59 let _ = fs::remove_dir_all(&scratch); 60 let unbound = Path::new(ROOT).join("tests/fixtures/records/bad/unbound_claim.json"); 61 for dst in [ 62 "evidence/elsewhere/claim.json", 63 "tests/fixtures/records/bad/unbound_claim.json", 64 ] { 65 fs::create_dir_all(scratch.join(dst).parent().unwrap()).unwrap(); 66 fs::copy(&unbound, scratch.join(dst)).unwrap(); 67 } 68 let git = |args: &[&str]| { 69 let ok = Command::new("git") 70 .arg("-C") 71 .arg(&scratch) 72 .args(args) 73 .output() 74 .expect("run git") 75 .status 76 .success(); 77 assert!(ok, "git {args:?}"); 78 }; 79 git(&["init", "-q"]); 80 git(&["add", "-A"]); 81 // Control: the default directories do not reach evidence/elsewhere. 82 assert_eq!(verify(&scratch, &[]), (0, Vec::new())); 83 let (code, lines) = verify(&scratch, &["--tracked"]); 84 assert_eq!(code, 1); 85 assert!(!lines.is_empty()); 86 assert!( 87 lines 88 .iter() 89 .all(|l| l.starts_with("evidence/elsewhere/claim.json: ")), 90 "{lines:?}" 91 ); 92 let _ = fs::remove_dir_all(&scratch); 93 } 94 95 /// --tracked reports a tracked JSON it cannot parse and a record whose schema is a near miss, 96 /// instead of skipping them; another `aien-bench-` schema (a preregistration) is not a record. 97 #[test] 98 fn tracked_reports_broken_and_misspelled_records() { 99 let scratch = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("evidence_tracked_broken"); 100 let _ = fs::remove_dir_all(&scratch); 101 let good = fs::read_to_string( 102 Path::new(ROOT).join("tests/fixtures/records/good/experimental_bound.json"), 103 ) 104 .unwrap(); 105 let dir = scratch.join("evidence"); 106 fs::create_dir_all(&dir).unwrap(); 107 fs::write(dir.join("broken.json"), &good[..good.len() / 2]).unwrap(); 108 let mut typo: serde_json::Value = serde_json::from_str(&good).unwrap(); 109 typo["schema"] = serde_json::json!("aien-bench-record/1 "); 110 fs::write(dir.join("typo.json"), typo.to_string()).unwrap(); 111 fs::write( 112 dir.join("prereg.json"), 113 r#"{"schema":"aien-bench-prereg/1"}"#, 114 ) 115 .unwrap(); 116 let git = |args: &[&str]| { 117 let ok = Command::new("git") 118 .arg("-C") 119 .arg(&scratch) 120 .args(args) 121 .output() 122 .expect("run git") 123 .status 124 .success(); 125 assert!(ok, "git {args:?}"); 126 }; 127 git(&["init", "-q"]); 128 git(&["add", "-A"]); 129 let (code, lines) = verify(&scratch, &["--tracked"]); 130 assert_eq!(code, 1, "{lines:?}"); 131 for f in ["evidence/broken.json: ", "evidence/typo.json: "] { 132 assert!(lines.iter().any(|l| l.starts_with(f)), "{f} in {lines:?}"); 133 } 134 assert!( 135 lines.iter().any(|l| l.contains("invalid JSON")), 136 "{lines:?}" 137 ); 138 assert!( 139 !lines.iter().any(|l| l.starts_with("evidence/prereg.json")), 140 "{lines:?}" 141 ); 142 let _ = fs::remove_dir_all(&scratch); 143 } 144 145 #[test] 146 fn bad_commit() { 147 bad( 148 "bad_commit", 149 &["source.commit: \"`dfd5ea9`\" is not a 40-character lowercase hex commit id"], 150 ); 151 } 152 153 #[test] 154 fn missing_field() { 155 bad("missing_field", &["backend.model: missing"]); 156 } 157 158 #[test] 159 fn placeholder() { 160 bad( 161 "placeholder", 162 &["backend.precision: placeholder value \"TBD\""], 163 ); 164 } 165 166 #[test] 167 fn status_outside_the_vocabulary() { 168 bad( 169 "bad_status", 170 &["status: \"PASSED\" is not one of VERIFIED, EXPERIMENTAL, HISTORICAL, NOT_RUN, FAIL, SUPERSEDED"], 171 ); 172 } 173 174 #[test] 175 fn evidence_path_missing() { 176 bad( 177 "missing_evidence", 178 &["evidence[0]: path does not exist: artifacts/gb10_canonical_`1789907893`_4d762/does_not_exist.json"], 179 ); 180 } 181 182 #[test] 183 fn verified_needs_clean_tree_and_full_provenance() { 184 let nr = "not_recorded is only allowed in HISTORICAL or SUPERSEDED records"; 185 bad( 186 "verified_dirty", 187 &[ 188 "backend.binary_sha256: missing (a claimed result names the sha256 of what was measured)", 189 &format!("backend.endpoint: {nr}"), 190 "backend.model_sha256: missing (a claimed result names the sha256 of what was measured)", 191 &format!("build.profile: {nr}"), 192 &format!("build.rustc: {nr}"), 193 &format!("methodology.clock: {nr}"), 194 &format!("methodology.samples: {nr}"), 195 &format!("methodology.token_accounting: {nr}"), 196 "methodology.tolerance: missing (the numerical tolerance outputs are compared with)", 197 "methodology.warmup: missing (iterations run and discarded before measuring)", 198 "parity: missing (output parity against a reference: reference, verdict, evidence)", 199 "source.dirty: VERIFIED requires dirty == false", 200 ], 201 ); 202 } 203 204 // DRA-166: a claimed result binds the measured binary and model, warmup, tolerance and parity. 205 #[test] 206 fn claimed_result_without_binding() { 207 bad( 208 "unbound_claim", 209 &[ 210 "backend.binary_sha256: missing (a claimed result names the sha256 of what was measured)", 211 "backend.model_sha256: missing (a claimed result names the sha256 of what was measured)", 212 "methodology.tolerance: missing (the numerical tolerance outputs are compared with)", 213 "methodology.warmup: missing (iterations run and discarded before measuring)", 214 "parity: missing (output parity against a reference: reference, verdict, evidence)", 215 ], 216 ); 217 } 218 219 // A FAIL record is a claimed result too: it binds what was measured like VERIFIED and EXPERIMENTAL. 220 #[test] 221 fn failed_result_without_binding() { 222 bad( 223 "unbound_fail", 224 &[ 225 "backend.binary_sha256: missing (a claimed result names the sha256 of what was measured)", 226 "backend.model_sha256: missing (a claimed result names the sha256 of what was measured)", 227 "methodology.tolerance: missing (the numerical tolerance outputs are compared with)", 228 "methodology.warmup: missing (iterations run and discarded before measuring)", 229 "parity: missing (output parity against a reference: reference, verdict, evidence)", 230 ], 231 ); 232 } 233 234 #[test] 235 fn binary_digest_must_be_sha256() { 236 bad( 237 "bad_binary_digest", 238 &["backend.binary_sha256: \"abc123\" is not a 64-character lowercase hex sha256"], 239 ); 240 } 241 242 #[test] 243 fn corrupted_parity_evidence_is_caught() { 244 bad( 245 "parity_corrupt", 246 &["parity.evidence_sha256: does not match the bytes of tests/fixtures/records/good/evidence/parity_tokens.txt"], 247 ); 248 } 249 250 #[test] 251 fn verified_needs_parity_pass() { 252 bad( 253 "verified_parity_not_run", 254 &["parity.verdict: VERIFIED requires parity PASS"], 255 ); 256 } 257 258 #[test] 259 fn parity_fail_is_not_an_experimental_claim() { 260 bad( 261 "parity_fail_experimental", 262 &["parity.verdict: a parity FAIL makes the record FAIL, not EXPERIMENTAL"], 263 ); 264 } 265 266 /// Negative control on the good fixture: one byte appended to its parity evidence file in a 267 /// scratch root turns the bound record into a defect. 268 #[test] 269 fn parity_evidence_byte_flip_in_scratch_copy() { 270 let scratch = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("evidence_parity_tamper"); 271 let _ = fs::remove_dir_all(&scratch); 272 let rec = "tests/fixtures/records/good/experimental_bound.json"; 273 let ev = "tests/fixtures/records/good/evidence/parity_tokens.txt"; 274 for f in [rec, ev] { 275 let dst = scratch.join(f); 276 fs::create_dir_all(dst.parent().unwrap()).unwrap(); 277 fs::copy(Path::new(ROOT).join(f), &dst).unwrap(); 278 } 279 assert_eq!(verify(&scratch, &[rec]), (0, Vec::new())); 280 let mut bytes = fs::read(scratch.join(ev)).unwrap(); 281 bytes.push(b'\n'); 282 fs::write(scratch.join(ev), bytes).unwrap(); 283 assert_eq!( 284 verify(&scratch, &[rec]), 285 ( 286 1, 287 vec![format!( 288 "{rec}: parity.evidence_sha256: does not match the bytes of {ev}" 289 )] 290 ) 291 ); 292 let _ = fs::remove_dir_all(&scratch); 293 } 294 295 #[test] 296 fn p95_from_one_sample() { 297 bad( 298 "p95_one_sample", 299 &["metrics.cold_fork_to_first_token_ms_p95: p95 needs at least 20 samples, record has 1"], 300 ); 301 } 302 303 #[test] 304 fn stream_events_are_not_tokens() { 305 bad( 306 "events_as_tokens", 307 &["metrics.decode_throughput_tok_per_sec: token metric with token_accounting events_not_tokens (stream events are not tokens)"], 308 ); 309 } 310 311 #[test] 312 fn llm_workload_runs_a_model() { 313 bad( 314 "nomodel_llm", 315 &["backend.model_sha256: \"none\" with workload llm_streaming (an LLM workload runs a model)"], 316 ); 317 } 318 319 #[test] 320 fn non_numeric_values() { 321 bad( 322 "non_numeric", 323 &[ 324 "metrics.physical_cow_pages_allocated: must be a finite number", 325 "workload.prefix_tokens: must be a finite number", 326 ], 327 ); 328 } 329 330 /// Copy the committed bundle to a scratch root and break it three ways. 331 #[test] 332 fn tampered_bundle_is_reported() { 333 let scratch = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("evidence_bundle_tamper"); 334 let _ = fs::remove_dir_all(&scratch); 335 let dst = scratch.join(BUNDLE); 336 fs::create_dir_all(&dst).unwrap(); 337 for e in fs::read_dir(Path::new(ROOT).join(BUNDLE)).unwrap() { 338 let e = e.unwrap(); 339 fs::copy(e.path(), dst.join(e.file_name())).unwrap(); 340 } 341 // Clean copy passes (control). 342 assert_eq!(verify(&scratch, &["artifacts"]), (0, Vec::new())); 343 344 let mut cold = fs::read(dst.join("branch_cold.json")).unwrap(); 345 cold.push(b'\n'); 346 fs::write(dst.join("branch_cold.json"), cold).unwrap(); 347 fs::remove_file(dst.join("branch_steady.json")).unwrap(); 348 fs::write(dst.join("extra.txt"), b"not listed\n").unwrap(); 349 let (code, lines) = verify(&scratch, &["artifacts"]); 350 assert_eq!( 351 lines, 352 vec![ 353 format!("{BUNDLE}/branch_steady.json: SHA256SUMS: listed file is missing"), 354 format!("{BUNDLE}/branch_cold.json: sha256: does not match SHA256SUMS"), 355 format!("{BUNDLE}/extra.txt: SHA256SUMS: file is not listed"), 356 ] 357 ); 358 assert_eq!(code, 1); 359 let _ = fs::remove_dir_all(&scratch); 360 }