From 093155e1233df104c1a0f60030d3dec4f2ebaa88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 15:56:09 +0300 Subject: [PATCH] test(av1): pin the decode path's refusals, and the claims they make Two things this decoder keeps relearning. A refusal string is a claim: 'this encoder never writes one' asserts something about the world, and one such string was disproved by the very gate that carried it. And refusals accumulate silently -- each one is the right call for the lane that adds it (refuse by name rather than desync), but the total is the distance to decoding a default-settings stream, and nothing printed the total. refusal_inventory derives every unsupported(...) reason reachable on the decode path -- decode.rs and stream.rs, both call shapes -- and pins it: 39 distinct refusals, of which 7 are phrased as claims about what an encoder emits and are now declared in their own list rather than scattered. Adding, renaming or removing a refusal fails until the inventory is updated, so the diff of this file is the decoder's capability delta in English. A new claim-shaped refusal fails separately, with the reason it needs evidence. Negative-checked: dropping one entry fails both tests naming that exact string. Suite 236 passed / 0 failed. --- crates/ec-av1/src/lib.rs | 1 + crates/ec-av1/src/refusal_inventory.rs | 189 +++++++++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 crates/ec-av1/src/refusal_inventory.rs diff --git a/crates/ec-av1/src/lib.rs b/crates/ec-av1/src/lib.rs index 1c78afb5..c346e506 100644 --- a/crates/ec-av1/src/lib.rs +++ b/crates/ec-av1/src/lib.rs @@ -30,6 +30,7 @@ pub mod msac; pub mod mvstack; pub mod obu; pub mod quant; +mod refusal_inventory; pub mod sequence; pub mod stream; pub mod tile; diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs new file mode 100644 index 00000000..7fd24f9f --- /dev/null +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -0,0 +1,189 @@ +//! An inventory of what this decoder refuses, and a check on the claims those +//! refusals make. +//! +//! Two rules this repository keeps learning the hard way: +//! +//! 1. A refusal string is a **claim**. "This encoder never writes one" asserts +//! that a real encoder cannot emit the case -- and one such string was +//! disproved by the very gate that carried it (the wedge-interintra hang, +//! 2026-08-30): the refusal was written from a mismatching frame's header +//! state, so it named a correlate rather than the defect. Any refusal +//! phrased as a capability claim about the ENCODER, rather than about this +//! decoder, needs evidence, and this module makes the set of such strings +//! explicit instead of letting it grow quietly. +//! 2. Refusals accumulate silently. A lane that adds one to unblock itself is +//! doing the right thing (refuse by name rather than desync), but the total +//! is the distance to a decoder that handles a default-settings stream, and +//! nobody sees a total that nothing prints. +//! +//! So the test below re-derives every `unsupported(...)` reason reachable on +//! the decode path -- `decode.rs` and `stream.rs` -- and pins it. Adding or +//! removing a refusal fails until the list is updated, which is the point: the +//! diff of this file is the decoder's capability delta, in one place, in +//! English. + +#[cfg(test)] +const CAPABILITY_CLAIMS: &[&str] = &[ + "a non-2D tx class on a rectangular transform (never expected at this size)", + "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", + "a nonzero angle delta (this encoder never writes one)", + "a partition below 16x16 other than a clean split (this encoder never writes one)", + "a partition below 8x8 (this encoder never writes one)", + "a partition type this encoder never writes", + "a tx_type symbol on a rectangular transform (never expected at this size)", +]; + +#[cfg(test)] +const REFUSALS: &[&str] = &[ + "GLOBALMV (round 3)", + "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", + "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", + "a Golomb tail longer than this decoder reads", + "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", + "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)", + "a block that actually uses a palette (UV) -- reconstruction is out of scope", + "a block that actually uses a palette (Y) -- reconstruction is out of scope", + "a block that actually uses intrabc (this decoder never reconstructs one)", + "a directional chroma mode (round 2)", + "a frame OBU with no tile group", + "a frame naming primary_ref_frame at a reference slot with no saved CDF state", + "a frame with cdef_bits > 0 (this decoder never reads the per-64x64 cdef_idx symbol)", + "a frame with delta_q_present or delta_lf_present set (this decoder never reads the per-superblock delta symbols)", + "a frame with loop restoration enabled (this decoder never reads the per-unit lr symbols)", + "a frame with more than one tile (this decoder only ever decodes tile 0)", + "a frame with no mode-info grid", + "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)", + "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", + "a reference frame other than LAST_FRAME (round 2)", + "a reference frame selected with no picture at this frame's own ref_frame_idx slot for it", + "a reference picture that is not this frame's own true size", + "a show_existing_frame header naming an empty reference slot", + "a smooth or paeth chroma mode (round 2)", + "an 8x8 leaf that coded WARPED_CAUSAL (motion_mode == 2): av1_find_projection/the affine warp filter are not ported, only motion_mode_allowed's alphabet choice is", + "an inter frame using TxMode::Select (this decoder's inter path never reads a tx_depth symbol, so it desyncs after the first block's mode)", + "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)", + "an inter frame with no key frame before it", + "an inter partition below 16x16 (8x8 and smaller inter blocks are not coded yet)", + "an intra mode this decoder does not code (round 2)", + "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet", + "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", +]; + +#[cfg(test)] +mod tests { + use super::{CAPABILITY_CLAIMS, REFUSALS}; + use std::collections::BTreeSet; + + /// Every distinct `unsupported(...)` reason on the decode path. + /// + /// Both sources use the same shape -- `stream.rs` calls + /// `Error::unsupported(context, reason)` and `decode.rs` a local + /// `unsupported(reason)` helper -- so the reason is always the LAST string + /// literal of the call, and Rust's `\` line continuations inside it are + /// joined the way rustc joins them. + fn decode_path_refusals() -> BTreeSet { + let mut found = BTreeSet::new(); + for src in [include_str!("decode.rs"), include_str!("stream.rs")] { + let bytes = src.as_bytes(); + for (start, _) in src.match_indices("unsupported(") { + // `Error::unsupported(` and the bare helper both end here. + let mut i = start + "unsupported(".len(); + let mut last: Option = None; + loop { + while i < bytes.len() && (bytes[i] as char).is_whitespace() { + i += 1; + } + if i >= bytes.len() || bytes[i] != b'"' { + break; + } + i += 1; + let mut lit = String::new(); + while i < bytes.len() && bytes[i] != b'"' { + if bytes[i] == b'\\' { + // A backslash-newline continuation drops the newline + // and the indentation that follows it. + if bytes.get(i + 1) == Some(&b'\n') { + i += 2; + while i < bytes.len() && matches!(bytes[i], b' ' | b'\t') { + i += 1; + } + continue; + } + lit.push(bytes[i] as char); + lit.push(bytes[i + 1] as char); + i += 2; + continue; + } + lit.push(bytes[i] as char); + i += 1; + } + i += 1; + last = Some(lit); + while i < bytes.len() && (bytes[i] as char).is_whitespace() { + i += 1; + } + if i < bytes.len() && bytes[i] == b',' { + i += 1; + continue; + } + break; + } + if let Some(reason) = last { + // `Error::unsupported`'s first argument is the context + // ("AV1 tile"), which is not a reason. + if reason != "AV1 tile" { + found.insert(reason); + } + } + } + } + found + } + + #[test] + fn the_decode_path_refuses_exactly_the_listed_cases() { + let found = decode_path_refusals(); + let listed: BTreeSet = CAPABILITY_CLAIMS + .iter() + .chain(REFUSALS) + .map(|&s| s.to_owned()) + .collect(); + assert!(found.len() >= 30, "the refusal scan found only {} reasons -- it is broken, not the decoder", found.len()); + + let added: Vec<&String> = found.difference(&listed).collect(); + assert!( + added.is_empty(), + "new decode-path refusals are not in the inventory: {added:#?}\n\ + Add each to REFUSALS -- or, if it claims something about what an ENCODER can \ + emit, to CAPABILITY_CLAIMS, which requires evidence that the case is genuinely \ + unreachable rather than merely unseen." + ); + let removed: Vec<&String> = listed.difference(&found).collect(); + assert!( + removed.is_empty(), + "these refusals are listed but no longer in the decode path: {removed:#?}\n\ + Delete them from the inventory -- the capability landed, which is the good case." + ); + } + + /// A refusal may say what THIS DECODER does not do. Saying what an encoder + /// never emits is a claim about the world, and this repository has already + /// shipped one that was false. + #[test] + fn capability_claims_are_declared_not_scattered() { + let claimy: Vec = decode_path_refusals() + .into_iter() + .filter(|r| r.contains("never writes") || r.contains("never expected")) + .collect(); + let declared: BTreeSet<&str> = CAPABILITY_CLAIMS.iter().copied().collect(); + for reason in &claimy { + assert!( + declared.contains(reason.as_str()), + "{reason:?} claims an encoder never emits this case but is not in \ + CAPABILITY_CLAIMS. Such a claim needs a gate that proves the case is \ + unreachable; until it has one, phrase the refusal as what this decoder \ + does not decode." + ); + } + } +}