From 11ebbdb4b1f52f2fe78d6d5ca6de104f0c91e7df Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 1 Oct 2026 09:37:27 -0500 Subject: [PATCH] test(crumbs): CRB1 shared conformance test + CI job (impl=rust) Runs every vector of the language-neutral CRB1 corpus (aien-protocols specs/crumb-visible, CRUMB_READER_CONTRACT.md 1.0.0) through VisibleCrumb::from_bytes, prints the contract outcome line and compares it byte for byte. VisibleError maps to the contract's numbered refusal codes at the edge (test only, no crate API change). Also checks that two decodes of the same bytes agree. New workflow crumb-visible-conformance.yml checks out the corpus pinned at aien-protocols b50c00d and requires it (CRB1_REQUIRE=1). Without a corpus and without CRB1_REQUIRE the test reports NOT_RUN. Local: CRUMB_VISIBLE_V1_CONFORMANCE impl=rust pass=171 fail=0. Co-Authored-By: Claude Fable 5.1 Co-authored-by: Drake Stapleton --- .../workflows/crumb-visible-conformance.yml | 51 +++++++++ crates/crumbs/tests/visible_conformance.rs | 106 ++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 .github/workflows/crumb-visible-conformance.yml create mode 100644 crates/crumbs/tests/visible_conformance.rs diff --git a/.github/workflows/crumb-visible-conformance.yml b/.github/workflows/crumb-visible-conformance.yml new file mode 100644 index 00000000..db87764b --- /dev/null +++ b/.github/workflows/crumb-visible-conformance.yml @@ -0,0 +1,51 @@ +name: CRB1 conformance + +# Migration seam 1: the Rust reference reader (crates/crumbs) must pass the +# shared CRB1 corpus in aien-protocols specs/crumb-visible with zero +# differences. The corpus is pinned by commit; bump the pin when the +# contract corpus changes. + +"on": + push: + branches: [main] + paths: + - "crates/crumbs/**" + - ".github/workflows/crumb-visible-conformance.yml" + pull_request: + branches: [main] + paths: + - "crates/crumbs/**" + - ".github/workflows/crumb-visible-conformance.yml" + workflow_dispatch: + +permissions: + contents: read + +jobs: + crb1-rust: + name: CRB1 conformance (impl=rust) + runs-on: ubuntu-latest + steps: + - name: Checkout Source + uses: actions/checkout@v4 + + - name: Checkout pinned CRB1 contract corpus + uses: actions/checkout@v4 + with: + repository: aien-dev/aien-protocols + ref: b50c00d737fa5c57ea7280e2aa4b0354ff166cf5 + path: crb1-protocols + + - name: Setup Sibling Dependencies + run: | + mkdir -p ../aien-protocols + cp -r crb1-protocols/* ../aien-protocols/ + + - name: Install Stable Rust Toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Run shared corpus through the Rust reader + env: + CRB1_VECTORS: ${{ github.workspace }}/crb1-protocols/specs/crumb-visible/vectors + CRB1_REQUIRE: "1" + run: cargo test -p crumbs --test visible_conformance -- --nocapture diff --git a/crates/crumbs/tests/visible_conformance.rs b/crates/crumbs/tests/visible_conformance.rs new file mode 100644 index 00000000..efd3079f --- /dev/null +++ b/crates/crumbs/tests/visible_conformance.rs @@ -0,0 +1,106 @@ +//! CRB1 shared conformance: the Rust reference reader against the +//! language-neutral corpus in aien-protocols (specs/crumb-visible). +//! +//! Every vector listed in `expected.txt` is decoded with +//! `VisibleCrumb::from_bytes`; the outcome is printed in the contract's line +//! format and compared byte for byte. Refusals are compared by the contract's +//! numbered code, mapped here at the edge so no Rust type crosses the contract. +//! +//! Corpus location: `$CRB1_VECTORS`, else the sibling checkout +//! `../aien-protocols/specs/crumb-visible/vectors` next to this repository. +//! When the corpus is absent the test reports NOT_RUN, unless +//! `CRB1_REQUIRE=1` (set by the dedicated CI job), in which case it fails. + +use crumbs::visible::{VisibleCrumb, VisibleError}; +use std::path::PathBuf; + +/// Contract refusal codes (CRUMB_READER_CONTRACT.md, section "Refusal codes"). +fn contract_code(e: VisibleError) -> i32 { + match e { + VisibleError::Magic => -1, + VisibleError::Version => -2, + VisibleError::Shape => -3, + VisibleError::Lane => -4, + VisibleError::Length => -5, + VisibleError::NonCanonical => -6, + } +} + +/// Contract outcome line (without the leading file name). +fn outcome(bytes: &[u8]) -> String { + let c = match VisibleCrumb::from_bytes(bytes) { + Ok(c) => c, + Err(e) => return format!("refuse {}", contract_code(e)), + }; + let mut line = format!( + "ok enc={} in={}x{} out={}x{} n={}", + c.encoding as u8, + c.in_arity, + c.in_lane_bytes, + c.out_arity, + c.out_lane_bytes, + c.examples.len() + ); + if let Some(b) = c.budget { + line.push_str(&format!( + " budget={},{},{},{}", + b.max_candidates, b.max_depth, b.max_oracle_queries, b.max_program_ops + )); + } + for (i, o) in c.values() { + line.push_str(" |"); + for v in i { + line.push_str(&format!(" {v}")); + } + line.push_str(" ->"); + for v in o { + line.push_str(&format!(" {v}")); + } + } + line +} + +fn corpus_dir() -> PathBuf { + match std::env::var_os("CRB1_VECTORS") { + Some(d) => PathBuf::from(d), + None => PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("../../../aien-protocols/specs/crumb-visible/vectors"), + } +} + +#[test] +fn crumb_visible_v1_conformance() { + let dir = corpus_dir(); + let manifest = dir.join("expected.txt"); + let Ok(text) = std::fs::read_to_string(&manifest) else { + let required = std::env::var("CRB1_REQUIRE").is_ok_and(|v| v == "1"); + println!( + "CRUMB_VISIBLE_V1_CONFORMANCE impl=rust NOT_RUN (no corpus at {})", + manifest.display() + ); + assert!(!required, "CRB1_REQUIRE=1 but the corpus is missing"); + return; + }; + let (mut pass, mut fail) = (0usize, 0usize); + for line in text.lines() { + if line.is_empty() || line.starts_with('#') { + continue; + } + let (name, want) = line + .split_once(' ') + .expect("manifest line: "); + let bytes = std::fs::read(dir.join(name)).expect("vector file listed in manifest"); + // Determinism: two decodes of the same bytes give the same line. + let got = outcome(&bytes); + assert_eq!(got, outcome(&bytes), "non-deterministic outcome for {name}"); + if got == want { + pass += 1; + } else { + fail += 1; + println!("MISMATCH {name}\n want: {want}\n got: {got}"); + } + } + println!("CRUMB_VISIBLE_V1_CONFORMANCE impl=rust pass={pass} fail={fail}"); + assert!(pass > 0, "empty corpus"); + assert_eq!(fail, 0); +}