open-standards/wai/wai-vector/tests/held_sets.rs
Transaction Science 2f147d2a30
Some checks failed
standards workspaces build + test / jouleclaw-rs (pull_request) Successful in 2m13s
standards workspaces build + test / aac-rs (pull_request) Successful in 1m58s
standards workspaces build + test / joule-code-rs (pull_request) Successful in 50s
standards workspaces build + test / joulecontract-rs (pull_request) Successful in 34s
standards workspaces build + test / map-rs (pull_request) Successful in 31s
standards workspaces build + test / mesh-rs (pull_request) Successful in 31s
no-vanity-metrics / Scan committed Markdown for vanity metrics (pull_request) Has been cancelled
no-vanity-metrics / WAI public text names no comparison (pull_request) Has been cancelled
no-vanity-metrics / WAI public text names no company or product (pull_request) Has been cancelled
standards workspaces build + test / arl-rs (pull_request) Has been cancelled
standards workspaces build + test / eoc-rs (pull_request) Has been cancelled
standards workspaces build + test / jcp-rs (pull_request) Has been cancelled
standards workspaces build + test / joule-ui-rs (pull_request) Has been cancelled
standards workspaces build + test / jouledesk-rs (pull_request) Has been cancelled
standards workspaces build + test / joulehook-rs (pull_request) Has been cancelled
standards workspaces build + test / proof-rs (pull_request) Has been cancelled
standards workspaces build + test / sandbox-rs (pull_request) Has been cancelled
standards workspaces build + test / sense-rs (pull_request) Has been cancelled
standards workspaces build + test / smart-byte-rs (pull_request) Has been cancelled
standards workspaces build + test / macOS energy backends (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 / C2PA manifest emission · signed, read back, validated (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 section references / cited sections exist (pull_request) Has been cancelled
wai-vector vector graphics / linux-aarch64 (pull_request) Has been cancelled
wai-vector vector graphics / linux-x86_64 (pull_request) Has been cancelled
wai-vector vector graphics / macos-arm64 (pull_request) Has been cancelled
wai-vector vector graphics / wasm32-wasip2 (wasmtime) (pull_request) Has been cancelled
wai-vector vector graphics / wasm32 under Node (pull_request) Has been cancelled
wai-vector vector graphics / fuzz, peak allocation, comparison count (pull_request) Has been cancelled
workflow hygiene / every workflow supersedes its own queue (pull_request) Has been cancelled
standards workspaces build + test / openpay (pull_request) Has been cancelled
wai-vector: WOS1 and WVG1 with the refusal order of §2.7, the clock, tracks, the interval check and the cost (D7-2)
The reference crate of wai.graphics.vector (no_std + alloc, no
dependencies; SHA-256 is wai-ops's, by #[path]):
- WOS1 parsed with §2.1's load checks in order, and written;
- WVG1 split (steps 1-3, nothing allocated before the exact length),
  the record pass (step 4), the cross-record checks (step 5(a)-(h)),
  the sets by digest with at most length + 1 bytes read (step 6), the
  glyphs (7), the interval check (8) and the per-frame cost (9);
- the clock with the frame range by division, track evaluation, and
  placement;
- the JSON authoring form, one member per field, packing back to the
  same bytes;
- the CLI: check, cost, pack, unpack, vectors gen and verify;
- a wasm32 module and verify.mjs for Node.

The corpus wai/vector-conformance/ (arith, canonical, refusals,
geometry, cost) with its README's provenance line and a sha256.json
sidecar naming the div255 table; wai-vector.yml with native, wasip2,
node and fuzz jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-11 03:59:47 -04:00

58 lines
2.1 KiB
Rust

//! §2.7 step 6: a held set is read by digest, at most `length + 1` bytes of it, and
//! hashed before it is parsed.
use wai_vector::refuse::Code;
use wai_vector::sha256::sha256;
use wai_vector::vectors::{corpus_store, find, sets};
use wai_vector::wvg1::{self, Resolver};
/// A resolver that serves one stream for one digest and counts the bytes it hands out.
struct Counting {
sha: [u8; 32],
data: Vec<u8>,
at: usize,
served: usize,
}
impl Resolver for Counting {
fn open(&mut self, sha: &[u8; 32]) -> bool {
self.at = 0;
*sha == self.sha
}
fn read(&mut self, buf: &mut [u8]) -> usize {
let n = buf.len().min(self.data.len() - self.at);
buf[..n].copy_from_slice(&self.data[self.at..self.at + n]);
self.at += n;
self.served += n;
n
}
}
#[test]
fn held_set_one_byte_longer_is_a_mismatch() {
let v = find("refusals", "s6-held-one-byte-longer").unwrap();
let e = wvg1::load(&v.bytes, &mut corpus_store()).unwrap_err();
assert_eq!((e.code, e.step), (Code::OutlineMismatch, "6"));
let v = find("canonical", "held").unwrap();
assert!(wvg1::load(&v.bytes, &mut corpus_store()).is_ok());
}
/// A stream far longer than its record's length: the sink reads `length + 1` bytes and
/// stops.
#[test]
fn a_counting_resolver_sees_at_most_length_plus_one_bytes() {
let b = sets::set_b().write();
let v = find("canonical", "held").unwrap();
let d = wvg1::parse(&v.bytes).unwrap();
assert_eq!(d.sets[0].length as usize, b.len());
let mut long = b.clone();
long.extend(std::iter::repeat_n(0xAB, 1 << 20));
let mut r = Counting { sha: sha256(&b), data: long, at: 0, served: 0 };
let e = wvg1::load(&v.bytes, &mut r).unwrap_err();
assert_eq!(e.code, Code::OutlineMismatch);
assert!(r.served <= b.len() + 1, "the sink read {} bytes of a set of length {}", r.served, b.len());
// The exact stream: read to its end and accepted.
let mut r = Counting { sha: sha256(&b), data: b.clone(), at: 0, served: 0 };
assert!(wvg1::load(&v.bytes, &mut r).is_ok());
assert_eq!(r.served, b.len());
}