open-standards/wai/wai-rs/tests/jpegai_scope_ort.rs
Transaction Science 48426dd890
Some checks failed
standards workspaces build + test / jouleclaw-rs (pull_request) Successful in 2m18s
standards workspaces build + test / aac-rs (pull_request) Successful in 47s
standards workspaces build + test / joule-code-rs (pull_request) Successful in 47s
standards workspaces build + test / joulecontract-rs (pull_request) Successful in 29s
standards workspaces build + test / map-rs (pull_request) Successful in 28s
standards workspaces build + test / mesh-rs (pull_request) Successful in 26s
no-vanity-metrics / Scan committed Markdown for vanity metrics (pull_request) Successful in 3s
standards workspaces build + test / openpay (pull_request) Successful in 1m18s
wai cross-architecture byte-equality / linux-aarch64 (pull_request) Successful in 16s
standards workspaces build + test / eoc-rs (pull_request) Successful in 1m48s
WAI conformance / cargo-class corpora · linux-arm64 (pull_request) Successful in 49s
WAI conformance / cross-arch byte-equality · linux-arm64 (pull_request) Successful in 15s
standards workspaces build + test / jcp-rs (pull_request) Successful in 1m17s
standards workspaces build + test / proof-rs (pull_request) Successful in 1m10s
standards workspaces build + test / sandbox-rs (pull_request) Successful in 2m6s
standards workspaces build + test / smart-byte-rs (pull_request) Successful in 2m28s
wai cross-architecture byte-equality / linux-x86_64 (pull_request) Successful in 15s
WAI conformance / cargo-class corpora · linux (pull_request) Successful in 1m9s
WAI conformance / cross-arch byte-equality · linux (pull_request) Successful in 14s
WAI conformance / C2PA manifest emission · signed, read back, validated (pull_request) Successful in 40s
wai formal verification (integer core) / kani (pull_request) Successful in 3m51s
WAI neural decoders end-to-end / synthetic fixtures → Rust decode → reference (±4) (pull_request) Failing after 1m11s
WAI neural sink gates / model-free refusals of the neural sink (pull_request) Successful in 26s
standards workspaces build + test / arl-rs (pull_request) Successful in 3m55s
standards workspaces build + test / joule-ui-rs (pull_request) Successful in 2m26s
standards workspaces build + test / jouledesk-rs (pull_request) Successful in 2m43s
standards workspaces build + test / joulehook-rs (pull_request) Successful in 2m46s
standards workspaces build + test / sense-rs (pull_request) Successful in 2m36s
standards workspaces build + test / macOS energy backend (jcp-energy) (pull_request) Failing after 2m29s
wai cross-architecture byte-equality / macos-arm64 (reference) (pull_request) Successful in 13s
WAI conformance / cargo-class corpora · macos (pull_request) Successful in 56s
WAI conformance / cross-arch byte-equality · macos (pull_request) Successful in 13s
wai cross-architecture byte-equality / windows-x86_64 (pull_request) Has been cancelled
WAI conformance / cargo-class corpora · windows (pull_request) Has been cancelled
WAI conformance / cross-arch byte-equality · windows (pull_request) Has been cancelled
wai: state what each determinism tier guarantees, and make replicate mean it
SPEC §7 required an integer decode for `intent = replicate` in one paragraph
and accepted entropy-consistency in another. Resolved in one direction:

- Over a neural capability, `replicate` promises `decode-equivalence` — the
  whole decode to the final medium reproduces on every conforming sink.
  `entropy-consistency` (the decoded symbols reproduce; later stages may not)
  no longer backs it. The tier is a property of the capability as registered,
  not of one implementation.
- Over a standard codec, `replicate` promises that standard's decoder
  conformance, stated per registry class. `StandardTolerance` covers codecs
  whose standard holds decoders to a criterion around a reference;
  `StandardUnclassified` covers codecs not yet classified.
- `wai.image.jpegai` moves to the new `NeuralEntropyExact` class: its
  entropy decode is integer and exact, its later stages are float. It no longer
  backs `replicate`. This is recorded as a conservative choice pending a
  reading of ISO/IEC 6048-4, not as a finding about that standard.
- The JPEG AI decoders now refuse codestreams outside the configuration they
  implement (other β, model_id, colour transform or LSBS settings) instead of
  decoding them incorrectly, and detect flush-to-zero and round-toward-zero
  float environments.
- `wai wrap` writes `replicate` only over capabilities, and fallbacks, whose
  class a sink accepts unpinned.
- extensions/determinism-tiers.md gains an evidence table stating which
  platforms and CI jobs have exercised each guarantee, including what has not
  run.
- CI: a neural-gates workflow runs the model-free gates, including
  decode_envelope_strict, in an Ubuntu 24.04 image where the `neural` build
  links.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-28 18:25:52 -04:00

49 lines
2.3 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! The float ONNX path (`wai::neural::jpegai`) accepts exactly the codestreams the
//! exact decoder accepts: both hard-code one configuration (tools_0, β = 0, the
//! high-operation-point synthesis, one eICCI model pair, 256×256 4:4:4), and a
//! codestream outside it is refused with `Unsupported` rather than decoded to the
//! wrong image.
//!
//! env: WAI_JPEGAI_ASSETS = the jpegai-vm-assets root (the ONNX model bundle).
//! Skips without it; no CI job provides it.
#![cfg(feature = "neural")]
use wai::neural::jpegai::{decode, JpegAiError, JpegAiModel};
const TEST256: &[u8] = include_bytes!("vectors/jpegai/test256.bin");
/// Overwrite `n` bits (MSB-first) at absolute bit `pos` with `value`.
fn set_bits(data: &mut [u8], pos: usize, n: usize, value: u64) {
for i in 0..n {
let bit = (value >> (n - 1 - i)) & 1;
let (byte, sh) = ((pos + i) / 8, 7 - (pos + i) % 8);
data[byte] = (data[byte] & !(1 << sh)) | ((bit as u8) << sh);
}
}
#[test]
fn ort_path_refuses_what_the_exact_decoder_refuses() {
let Ok(dir) = std::env::var("WAI_JPEGAI_ASSETS") else {
eprintln!("skip: set WAI_JPEGAI_ASSETS to the jpegai-vm-assets root");
return;
};
let model = JpegAiModel::load(&dir).expect("load the ONNX model bundle");
use wai::jpegai_bitstream::{find_segment, parse_container, parse_picture_header, Marker};
let pih = find_segment(&parse_container(TEST256), Marker::Pih).unwrap().start_bit();
// (field offset inside the PIH payload, width, new value, word the refusal names)
for (at, width, value, word) in [(90, 12, 2048 + 7, "beta"), (85, 4, 1, "model_id")] {
let mut d = TEST256.to_vec();
set_bits(&mut d, pih + at, width, value);
let ph = parse_picture_header(&d, pih);
assert!(ph.beta_displacement_log != [0, 0] || ph.model_id != 0, "the edit hit a field");
match decode(&d, &model) {
Err(JpegAiError::Unsupported(why)) => assert!(why.contains(word), "{why}"),
Err(e) => panic!("expected Unsupported naming {word}, got {e}"),
Ok(_) => panic!("an out-of-scope codestream ({word}) was decoded"),
}
}
let img = decode(TEST256, &model).expect("the in-scope codestream decodes");
assert_eq!((img.width, img.height), (256, 256));
}