aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / aien-replay / tests / trn1_conformance.rs
| 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 | //! TRN1 shared corpus through the Rust reader (spec section 9). |
| 17 | //! |
| 18 | //! TRN1_VECTORS points at aien-protocols `specs/execution-transcript/vectors` |
| 19 | //! (default: the sibling checkout `../aien-protocols` next to this repo). |
| 20 | //! With TRN1_REQUIRE=1 a missing corpus is a failure; otherwise the test |
| 21 | //! prints NOT_RUN and passes, so a plain local `cargo test` does not need the |
| 22 | //! sibling checkout. |
| 23 | |
| 24 | use aien_replay::{compare_line, verdict_line, verify, Verdict}; |
| 25 | use std::path::{Path, PathBuf}; |
| 26 | |
| 27 | fn vectors_dir() -> PathBuf { |
| 28 | std::env::var_os("TRN1_VECTORS") |
| 29 | .map(PathBuf::from) |
| 30 | .unwrap_or_else(|| { |
| 31 | Path::new(env!("CARGO_MANIFEST_DIR")) |
| 32 | .join("../../../aien-protocols/specs/execution-transcript/vectors") |
| 33 | }) |
| 34 | } |
| 35 | |
| 36 | fn load(dir: &Path, name: &str) -> Verdict { |
| 37 | let bytes = std::fs::read(dir.join(name)).unwrap_or_else(|e| panic!("read {name}: {e}")); |
| 38 | verify(&bytes) |
| 39 | } |
| 40 | |
| 41 | fn lines(dir: &Path, manifest: &str) -> Vec<String> { |
| 42 | std::fs::read_to_string(dir.join(manifest)) |
| 43 | .unwrap_or_else(|e| panic!("read {manifest}: {e}")) |
| 44 | .lines() |
| 45 | .filter(|l| !l.is_empty() && !l.starts_with('#')) |
| 46 | .map(str::to_owned) |
| 47 | .collect() |
| 48 | } |
| 49 | |
| 50 | #[test] |
| 51 | fn trn1_shared_corpus() { |
| 52 | let dir = vectors_dir(); |
| 53 | if !dir.join("expected.txt").exists() { |
| 54 | assert!( |
| 55 | std::env::var("TRN1_REQUIRE").as_deref() != Ok("1"), |
| 56 | "TRN1_REQUIRE=1 but no corpus at {}", |
| 57 | dir.display() |
| 58 | ); |
| 59 | println!( |
| 60 | "TRN1_CONFORMANCE impl=rust NOT_RUN (no corpus at {})", |
| 61 | dir.display() |
| 62 | ); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | let (mut pass, mut fail) = (0u32, 0u32); |
| 67 | for line in lines(&dir, "expected.txt") { |
| 68 | let (file, want) = line.split_once(' ').expect("<file> <verdict>"); |
| 69 | let got = verdict_line(&load(&dir, file)); |
| 70 | if got == want { |
| 71 | pass += 1; |
| 72 | } else { |
| 73 | fail += 1; |
| 74 | println!("MISMATCH {file}\n expected: {want}\n got: {got}"); |
| 75 | } |
| 76 | } |
| 77 | for line in lines(&dir, "compare.txt") { |
| 78 | let mut parts = line.splitn(3, ' '); |
| 79 | let (e, a, want) = ( |
| 80 | parts.next().expect("expected file"), |
| 81 | parts.next().expect("actual file"), |
| 82 | parts.next().expect("compare line"), |
| 83 | ); |
| 84 | let got = compare_line(&load(&dir, e), &load(&dir, a)); |
| 85 | if got == want { |
| 86 | pass += 1; |
| 87 | } else { |
| 88 | fail += 1; |
| 89 | println!("MISMATCH {e} {a}\n expected: {want}\n got: {got}"); |
| 90 | } |
| 91 | } |
| 92 | println!("TRN1_CONFORMANCE impl=rust pass={pass} fail={fail}"); |
| 93 | assert!(pass > 0 && fail == 0, "pass={pass} fail={fail}"); |
| 94 | } |