open-standards/wai/wai-rs/tests/dred_exact.rs
Transaction Science 3ad5e8b0cf
Some checks failed
wai-web wasm32 / does this change touch it (pull_request) Has been cancelled
wai-web wasm32 / wai-web wasm32 build · corpus, menu and writers (pull_request) Has been cancelled
wai-web reach builds / wai-web reach · does this change touch it (pull_request) Has been cancelled
wai-web reach builds / wai-web reach builds · the package of record, every output as recorded (pull_request) Has been cancelled
wai-web reach builds / wai-web reach builds · this tree's wai-web, every rung on its engine line (pull_request) Has been cancelled
wai-quantum studio and desktop / does this change touch it (pull_request) Has been cancelled
wai-quantum studio and desktop / studio · browser (pull_request) Has been cancelled
wai-quantum studio and desktop / desktop app · macos (pull_request) Has been cancelled
wai-pack / wai-pack · does this change touch it (pull_request) Has been cancelled
wai-pack / wai-pack · linux (pull_request) Has been cancelled
wai-pack / wai-pack · linux-arm64 (pull_request) Has been cancelled
wai-pack / wai-pack · macos (pull_request) Has been cancelled
wai-pack / wai-pack · independent verifier (Python) (pull_request) Has been cancelled
wai-pack / wai-pack · the floor through a media prober (pull_request) Has been cancelled
wai-pack / wai-pack · dependency licences (pull_request) Has been cancelled
wai-ops-gpu integer operators on GPUs / does this change touch it (pull_request) Has been cancelled
wai-ops-gpu integer operators on GPUs / builds · no adapter is not a pass (linux) (pull_request) Has been cancelled
wai-ops-gpu integer operators on GPUs / Metal GPU and browser WebGPU (macos) (pull_request) Has been cancelled
WAI neural sink gates / does this change touch it (pull_request) Has been cancelled
WAI neural sink gates / model-free refusals of the neural sink (pull_request) Has been cancelled
WAI energy receipts / does this change touch it (pull_request) Has been cancelled
WAI energy receipts / energy receipts · linux (pull_request) Has been cancelled
WAI energy receipts / energy receipts · linux-arm64 (pull_request) Has been cancelled
WAI energy receipts / energy receipts · macos (pull_request) Has been cancelled
WAI conformance / does this change touch it (pull_request) Has been cancelled
WAI conformance / cargo-class corpora · linux (pull_request) Has been cancelled
WAI conformance / cargo-class corpora · linux-arm64 (pull_request) Has been cancelled
WAI conformance / cargo-class corpora · macos (pull_request) Has been cancelled
WAI conformance / quantum core and corpus under wasm32-wasip2 (wasmtime) (pull_request) Has been cancelled
WAI conformance / v2 vocabulary · manifests validate as stated (pull_request) Has been cancelled
WAI conformance / independent verifiers · claims, JWP, key discovery and integer payloads (Python) (pull_request) Has been cancelled
WAI conformance / delivery telemetry · CMCD and CMSD against an independent library (pull_request) Has been cancelled
WAI conformance / cross-arch byte-equality · linux (pull_request) Has been cancelled
WAI conformance / cross-arch byte-equality · linux-arm64 (pull_request) Has been cancelled
WAI conformance / cross-arch byte-equality · macos (pull_request) Has been cancelled
WAI conformance / codec wrappers · fuzz smoke, text decode limits, C entry points, provenance, the semantic path (pull_request) Has been cancelled
WAI conformance / C2PA manifest emission · signed, read back, validated (pull_request) Has been cancelled
standards workspaces build + test / which workspaces this change touches (pull_request) Has been cancelled
standards workspaces build + test / macOS energy backends (pull_request) Has been cancelled
repository checks / lockfiles, tests in CI, workflow hygiene, spec and section references, public text (pull_request) Has been cancelled
joule-moq-web browser client / joule-moq-web · does this change touch it (pull_request) Has been cancelled
joule-moq-web browser client / joule-moq-web · browser end-to-end (macos) (pull_request) Has been cancelled
joule-moq-room room service / joule-moq-room · does this change touch it (pull_request) Has been cancelled
joule-moq-room room service / joule-moq-room, every target (pull_request) Has been cancelled
wai-rs: tests/dred_exact.rs holds §4.8: both graphs load under acc64, are refused under acc32, and use wai-ops/1-i32 only
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-22 04:59:28 -04:00

72 lines
3.3 KiB
Rust

//! `live-conformance/dred/` (extensions/opus-dred.md §9) against the reference module: every file
//! regenerates byte for byte from its fixed seeds and the pinned weights, no other file is there
//! but README.md, and every payload vector and case reaches the outcome it states. And the
//! extension's text against the module: §8 lists exactly the codes the module reports, and §4.2
//! and §4.5 state the digests the module computes.
//!
//! The weights file is not in the repository: `WAI_DRED_WEIGHTS` names it
//! (`live-conformance/dred/fetch.sh` fetches it and checks its digest). Without it the corpus
//! cannot be checked, and the test fails rather than pass without checking it.
use std::path::PathBuf;
use wai::dred_exact::{corpus, hex32, lower, payload, weights, Reason};
fn wai() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..")
}
fn extension() -> String {
std::fs::read_to_string(wai().join("extensions/opus-dred.md")).unwrap()
}
fn weights() -> Vec<u8> {
let p = std::env::var("WAI_DRED_WEIGHTS").expect(
"WAI_DRED_WEIGHTS must name the draft's weights file: bash wai/live-conformance/dred/fetch.sh <dir>, then WAI_DRED_WEIGHTS=<dir>/dred_unquantized_weights.bin",
);
std::fs::read(&p).unwrap_or_else(|e| panic!("{p}: {e}"))
}
#[test]
fn the_corpus_regenerates_and_every_vector_reaches_its_outcome() {
corpus::verify(&weights(), &wai().join("live-conformance/dred")).unwrap();
}
/// §8's table lists exactly the codes the module reports, in its order.
#[test]
fn the_refusals_table_is_the_modules() {
let text = extension();
let sec = text.split("\n## 8.").nth(1).expect("§8").split("\n## ").next().unwrap();
let listed: Vec<&str> = sec.lines().filter_map(|l| l.strip_prefix("| `")).filter_map(|l| l.split('`').next()).collect();
let want: Vec<&str> = Reason::LISTED.iter().map(|r| r.code()).collect();
assert_eq!(listed, want);
}
/// The digests the extension states are the module's: the draft's tables (§4.2), the tables'
/// constant and the two activation tables (§4.5).
#[test]
fn the_extension_states_the_modules_digests() {
let text = extension();
let tb = |t: &[i16]| {
use sha2::{Digest, Sha256};
let d: [u8; 32] = Sha256::digest(t.iter().flat_map(|x| x.to_le_bytes()).collect::<Vec<u8>>()).into();
hex32(&d)
};
for want in [hex32(&payload::tables_digest()), tb(&lower::tanh_table()), tb(&lower::sigmoid_table()), lower::EXP_C0.to_string()] {
assert!(text.contains(&want), "extensions/opus-dred.md states {want}");
}
}
/// §4.8: both graphs of the pinned set load under `acc64` and are refused under `acc32`, and
/// every operator they use is in `wai-ops/1-i32`.
#[test]
fn the_graphs_meet_acc64_and_not_acc32() {
let g = lower::lower(&weights::pinned(&weights()).unwrap()).unwrap();
for (name, graph) in [("init", &g.init), ("step", &g.step)] {
let b = graph.to_bytes();
assert!(wai_ops::graph::load(&b, wai_ops::Profile::Acc64).is_ok(), "{name} loads under acc64");
assert!(wai_ops::graph::load(&b, wai_ops::Profile::Acc32).is_err(), "{name} is refused under acc32");
use wai_ops::graph::opcode::*;
assert!(graph.ops.iter().all(|o| [CONV, LUT16, SPLIT, CONCAT, MUL, ADD, RESCALE].contains(&o.code)), "{name}: wai-ops/1-i32 operators");
}
}