From 693b4153b166f152c11b8dd43b0ad6168d2e4d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 29 Sep 2026 05:33:18 +0300 Subject: [PATCH] =?UTF-8?q?gate=5Fcoverage:=20the=20oracle-presence=20scan?= =?UTF-8?q?=20=E2=80=94=20the=20class=20can=20no=20longer=20reopen=20silen?= =?UTF-8?q?tly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit r2 closed the bare `aomdec_path().is_file()` class on the current tree but left the anti-regression procedural, and that is how the five r2 sites got there in the first place: a guard written the old way compiles, passes review and re-opens the hole. This adds the mechanical check, in the crate's existing source-scan shape (include_str! over stream.rs/decode.rs/encode.rs, next to the recipe re-derivation that already scans stream.rs). The rule: a tool presence check (aomenc/aomdec/affine `_path().is_file()`, plain or inverted) may appear only inside the probe that owns that path (have_aomenc, aomdec_available, have_affine_aomenc), inside an assert!, or in a comment. The scan derives each probe's line span from its fn opener to the first column-0 brace and asserts it found all three, so a moved probe reds instead of silently exempting the crate. Anything else fails naming file:line, the line text, and the fix. Current state: 7 sites inspected, 7 allowed, 0 offenders. Two floors, because a total alone hides a single broken matcher: a structural total (MIN_SITES = 5 = three probes + two asserts, so prose churn is not load-bearing) and a PER-PATTERN floor requiring each of the three path patterns to match at least once. The per-pattern floor earned its place on its first run by catching a real bug in the matcher one line above it — `affine_aomenc_path().is_file()` CONTAINS `aomenc_path().is_file()`, so a first-match scan credited the affine probe's line to the aomenc pattern; the matcher now takes the longest match. Mutations, both reverted (git diff on stream.rs empty, scan green): - a bare `if aomdec_path().is_file()` injected into gate_444_lossy_live_exact -> RED naming `stream.rs:7634`; - one pattern replaced by a non-matching `aomdec_path().exists()` -> RED on the per-pattern floor ("matched NOTHING … the gates it was meant to police would pass unreviewed"). With only a total floor this one PASSES: the other two patterns still add up to 6 sites. `touch` on every scanned source before every run — these scans read compile-time text. Acceptance: gate_coverage + refusal_inventory 27 passed, 0 failed; the gates the review named still pass with the oracle present (5 passed). --- crates/ec-av1/src/gate_coverage.rs | 211 +++++++++++++++++++++++++---- lanes/av1oracleSkip.report.md | 83 ++++++++++++ 2 files changed, 271 insertions(+), 23 deletions(-) diff --git a/crates/ec-av1/src/gate_coverage.rs b/crates/ec-av1/src/gate_coverage.rs index fa614b24..9e2dcbc8 100644 --- a/crates/ec-av1/src/gate_coverage.rs +++ b/crates/ec-av1/src/gate_coverage.rs @@ -140,24 +140,24 @@ enum On { /// "defaulted means unknown" rule of [`NEVER_EXERCISED`] applies unchanged: a /// default of `1` does not prove the encoder picked the tool for any stream, so /// only a gate that spells an on-value at that bit depth retires an entry. - // lane-av1distwtd r3: `enable-tx-size-search` is the one DEFAULT_ON_TOOLS - // entry the r2 audit could NOT settle, and the reason is a THIRD detector - // limit rather than a coverage fact. After the r3 call-resolving fix, 113 - // of the 230 selected gates name it: 88 pass `=0`, 15 pass `=1`, and 9 - // build the value into a `format!`/`String` variable that neither - // `flags_in` nor `settings_in` can see, because both scan for a literal - // `"--flag=value"` inside one segment. - // - // WHAT WOULD SETTLE IT, for whoever takes it next -- the method, not a - // guess: extend `flags_in`/`settings_in` to resolve a local binding, the - // same way `gate_bodies` now resolves calls. Concretely, when a segment - // contains `let = format!("--enable-tx-size-search={tx_search}")` - // (or a `String::from`/`to_string` of the same shape), record the - // TEMPLATE and bind the variable's value at each use site. Re-count, and - // only then decide whether the tool is a live hole. Until that exists the - // count above is a floor, not a measurement: 9 gates are unclassified in - // an unknown direction, and an unknown direction is exactly the failure - // mode this file exists to prevent. +// lane-av1distwtd r3: `enable-tx-size-search` is the one DEFAULT_ON_TOOLS +// entry the r2 audit could NOT settle, and the reason is a THIRD detector +// limit rather than a coverage fact. After the r3 call-resolving fix, 113 +// of the 230 selected gates name it: 88 pass `=0`, 15 pass `=1`, and 9 +// build the value into a `format!`/`String` variable that neither +// `flags_in` nor `settings_in` can see, because both scan for a literal +// `"--flag=value"` inside one segment. +// +// WHAT WOULD SETTLE IT, for whoever takes it next -- the method, not a +// guess: extend `flags_in`/`settings_in` to resolve a local binding, the +// same way `gate_bodies` now resolves calls. Concretely, when a segment +// contains `let = format!("--enable-tx-size-search={tx_search}")` +// (or a `String::from`/`to_string` of the same shape), record the +// TEMPLATE and bind the variable's value at each use site. Re-count, and +// only then decide whether the tool is a live hole. Until that exists the +// count above is a floor, not a measurement: 9 gates are unclassified in +// an unknown direction, and an unknown direction is exactly the failure +// mode this file exists to prevent. #[cfg(test)] const DEFAULT_ON_TOOLS: &[(&str, &[&str], &str, On)] = &[ ( @@ -434,8 +434,8 @@ const NEVER_ON_10BIT: &[(&str, &str)] = &[]; #[cfg(test)] mod tests { use super::{ - On, ALIASES, DEFAULT_ON_TOOLS, NEVER_EXERCISED, NEVER_EXERCISED_10BIT, - NEVER_EXERCISED_8BIT, NEVER_ON_10BIT, NEVER_ON_8BIT, TOOL_UNIVERSE, + ALIASES, DEFAULT_ON_TOOLS, NEVER_EXERCISED, NEVER_EXERCISED_8BIT, NEVER_EXERCISED_10BIT, + NEVER_ON_8BIT, NEVER_ON_10BIT, On, TOOL_UNIVERSE, }; use std::collections::{BTreeMap, BTreeSet}; @@ -770,9 +770,7 @@ mod tests { // it to the 8-bit bucket, not just the 10-bit one. let flip = gates .iter() - .find(|b| { - b.contains("a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform") - }) + .find(|b| b.contains("a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform")) .expect("the flip-idtx gate must be seen"); assert!( covers_both_depths(flip), @@ -1022,4 +1020,171 @@ mod tests { } } } + + /// lane-av1oracleskip: the ORACLE-PRESENCE SCAN — the mechanical + /// anti-regression for the skip class this lane closed. + /// + /// Why a scan and not a review rule: the r2 sweep found FIVE gates that + /// had been added with the bare `if aomdec_path().is_file() { …compare… }` + /// shape AFTER the first fix had already routed thirteen sites — every one + /// of them compiled, passed review and reported green with the oracle + /// compare silently skipped, under `EC_AV1_REQUIRE_AOMENC=1`. A guard + /// written the old way re-opens the class the moment it merges, so the + /// only thing that holds is a check that reads the source itself. + /// + /// The rule: a TOOL PRESENCE CHECK (`aomenc_path().is_file()`, + /// `aomdec_path().is_file()`, `affine_aomenc_path().is_file()`, plain or + /// `!…` inverted) may appear ONLY + /// 1. inside the body of the probe that owns that path + /// (`have_aomenc`, `aomdec_available`, `have_affine_aomenc`) — that + /// is where the assert-last and the env escape live, and + /// 2. inside an `assert!` (the deliberate hard-failure form), or + /// 3. in a comment, which cannot execute. + /// Anything else is a skip with no env escape, and the test fails naming + /// the exact `file:line`. + /// + /// THE FLOOR. A source scan that matches nothing is the false-pass shape + /// this crate has been bitten by twice (a `format!` brace escape, and + /// `args.find(')')` stopping at the wrong paren), so the scan refuses to + /// pass unless it actually inspected a plausible number of sites: the + /// count is printed and asserted against `MIN_SITES`. A probe that moved + /// out of the scan's reach, or a matcher broken by a rename, reds here + /// instead of reporting a clean bill of health. + #[test] + fn no_tool_presence_check_outside_its_probe() { + /// Below this, the scan is not looking at the tree it thinks it is. + /// Five is the STRUCTURAL floor: three probes (whose existence the span + /// assert below already pins) plus the two hard `assert!` sites. Doc + /// comments mentioning the old shape come and go with the prose, so + /// they are counted but never load-bearing here. + const MIN_SITES: usize = 5; + /// (file, the line that opens the probe owning that path) + const PROBES: &[(&str, &str)] = &[ + ("stream.rs", "fn have_aomenc()"), + ("stream.rs", "fn aomdec_available("), + ("stream.rs", "fn have_affine_aomenc()"), + ]; + const PATHS: &[&str] = &[ + "aomenc_path().is_file()", + "aomdec_path().is_file()", + "affine_aomenc_path().is_file()", + ]; + let files: [(&str, &str); 3] = [ + ("stream.rs", include_str!("stream.rs")), + ("decode.rs", include_str!("decode.rs")), + ("encode.rs", include_str!("encode.rs")), + ]; + + // The line range each probe body owns: from its opener to the first + // following line that closes it at column 0. + let mut probe_spans: Vec<(usize, usize)> = Vec::new(); + for (name, src) in files { + let lines: Vec<&str> = src.lines().collect(); + for (probe_file, opener) in PROBES { + if *probe_file != name { + continue; + } + let Some(start) = lines.iter().position(|l| l.contains(opener)).map(|i| i + 1) + else { + continue; + }; + let end = lines + .iter() + .skip(start) + .position(|l| l.trim_end() == "}") + .map(|off| start + off) + .unwrap_or(lines.len()); + probe_spans.push((start, end)); + } + } + assert!( + probe_spans.len() == PROBES.len(), + "the oracle-presence scan recognised {} of the {} probe bodies it is meant to \ + exempt ({probe_spans:?}); a renamed or moved probe would silently exempt every \ + site in the crate, so it reds here", + probe_spans.len(), + PROBES.len() + ); + + let mut sites = 0usize; + let mut allowed = 0usize; + let mut per_pattern: BTreeMap<&str, usize> = PATHS.iter().map(|p| (*p, 0)).collect(); + let mut offenders: Vec = Vec::new(); + for (name, src) in files { + for (i, line) in src.lines().enumerate() { + // LONGEST match wins: `affine_aomenc_path().is_file()` CONTAINS + // `aomenc_path().is_file()`, so a first-match scan credits the + // affine probe's line to the aomenc pattern and the per-pattern + // floor below reds on a pattern that is very much present. (It + // did, on the first run of this test — which is the floor + // earning its place.) + let Some(path) = PATHS + .iter() + .filter(|p| line.contains(**p)) + .max_by_key(|p| p.len()) + else { + continue; + }; + sites += 1; + *per_pattern.get_mut(path).expect("pattern came from PATHS") += 1; + let lineno = i + 1; + let trimmed = line.trim_start(); + let in_probe = probe_spans + .iter() + .any(|(start, end)| lineno >= *start && lineno <= *end); + let in_assert = trimmed.starts_with("assert!") + || trimmed.starts_with("aomdec_path().is_file(),") + || trimmed.starts_with("aomenc_path().is_file(),") + || trimmed.starts_with("affine_aomenc_path().is_file(),"); + let in_comment = trimmed.starts_with("//"); + if in_probe || in_assert || in_comment { + allowed += 1; + } else { + offenders.push(format!( + "{name}:{lineno}: {}\n a tool presence check outside its probe — \ + route it through the probe that owns this path (`have_aomenc`, \ + `aomdec_available`, `have_affine_aomenc`): a bare `{path}` skips the \ + gate with NO env escape, so under EC_AV1_REQUIRE_AOMENC=1 the gate still \ + reports green with the oracle compare never run.", + line.trim() + )); + } + } + } + println!( + "oracle-presence scan: {sites} site(s) inspected, {allowed} in a probe / assert / \ + comment, {} offender(s); per pattern {per_pattern:?}", + offenders.len() + ); + // PER-PATTERN floor: a total count can hide one broken matcher (mutate + // ONE pattern and the other two still add up), so each of the three + // path patterns must be found at least once -- which the probe bodies + // guarantee, since each probe contains its own path's presence check. + let never_matched: Vec<&str> = per_pattern + .iter() + .filter(|(_, n)| **n == 0) + .map(|(p, _)| *p) + .collect(); + assert!( + never_matched.is_empty(), + "the oracle-presence scan matched NOTHING for {never_matched:?}: that pattern is \ + stale (renamed helper, `exists()` instead of `is_file()`, a `format!` escape) and \ + the gates it was meant to police would pass unreviewed. Matched per pattern: \ + {per_pattern:?}" + ); + assert!( + sites >= MIN_SITES, + "the oracle-presence scan inspected only {sites} site(s), below its floor of \ + {MIN_SITES}: the matcher has stopped matching this tree (renamed path helper, a \ + `format!` escape, a moved probe), and with no floor this would pass while scanning \ + nothing — the false-pass shape this crate has been bitten by twice" + ); + assert!( + offenders.is_empty(), + "{} bare tool presence check(s) outside a probe — each one is a gate that can report \ + green without running the oracle compare:\n {}", + offenders.len(), + offenders.join("\n ") + ); + } } diff --git a/lanes/av1oracleSkip.report.md b/lanes/av1oracleSkip.report.md index 676b04df..c6d932c5 100644 --- a/lanes/av1oracleSkip.report.md +++ b/lanes/av1oracleSkip.report.md @@ -264,3 +264,86 @@ r1 reported is gone — lane-av1toolgates' entries were retired upstream). because the source-scan pattern for a whole-file assertion is itself a new piece of machinery, and this lane's charter is the probe. It is the obvious next step and it is small. + +--- + +# r3 — the mechanical anti-regression: the class can no longer be reopened silently + +r2 left the class closed *currently* and the anti-regression *procedural*: a +new guard written as `aomdec_path().is_file()` compiles, passes review, and +re-opens exactly the hole r2 closed — which is how the five r2 sites got there +in the first place. r3 replaces the review rule with a check that reads the +source. + +## 11. The scan + +`gate_coverage::tests::no_tool_presence_check_outside_its_probe`, in +`crates/ec-av1/src/gate_coverage.rs` — the crate's existing source-scan home +(it already `include_str!`s `stream.rs` to re-derive the gates' recipes from +their own text), extended to all three test-bearing files. + +**The rule.** A tool presence check — `aomenc_path().is_file()`, +`aomdec_path().is_file()`, `affine_aomenc_path().is_file()`, plain or `!…` +inverted — may appear only + +1. inside the body of the probe that owns that path (`have_aomenc`, + `aomdec_available`, `have_affine_aomenc`), where the assert-last and the + env escape live; the scan computes each probe's line span from its `fn` + opener to the first column-0 `}` and asserts it found all three, so a moved + or renamed probe reds rather than silently exempting the whole crate; +2. inside an `assert!` (the deliberate hard-failure form); or +3. in a comment, which cannot execute. + +Anything else fails the test naming the exact `file:line`, the line's text, and +what to do about it. Current state: + +``` +oracle-presence scan: 7 site(s) inspected, 7 in a probe / assert / comment, +0 offender(s); per pattern {"affine_aomenc_path().is_file()": 1, +"aomdec_path().is_file()": 5, "aomenc_path().is_file()": 1} +``` + +**The floors.** A source scan that matches nothing is the false-pass shape +this batch has been bitten by twice (a `format!` brace escape, and +`args.find(')')` stopping at the wrong paren), so there are two, not one: + +* a total floor, `MIN_SITES = 5` — the STRUCTURAL count (three probes + two + hard asserts), so prose that comes and goes with the doc comments is counted + but never load-bearing; +* a **per-pattern** floor — each of the three path patterns must match at + least once. A total alone hides a single broken matcher: mutating ONE + pattern still leaves the other two adding up (measured: with + `aomdec_path().exists()` substituted, the scan still reported 6 sites and + passed). The per-pattern floor is what catches that. + +The per-pattern floor earned its place on its FIRST run, by catching a real +bug in the matcher written one line above it: `affine_aomenc_path().is_file()` +CONTAINS `aomenc_path().is_file()`, so a first-match scan credited the affine +probe's line to the aomenc pattern and the affine pattern matched nothing. The +matcher now takes the LONGEST match, and the floor is what noticed. + +## 12. Mutation proofs, both directions + +Both mutations were made, run, and reverted; `git diff crates/ec-av1/src/stream.rs` +is empty afterwards and the scan is green. + +| mutation | result | +|---|---| +| a bare `if aomdec_path().is_file() { let _ = 1; }` injected into `gate_444_lossy_live_exact` | **RED**, naming the site: `1 bare tool presence check(s) outside a probe … stream.rs:7634: if aomdec_path().is_file() {` | +| one pattern replaced by a non-matching `aomdec_path().exists()` | **RED** on the per-pattern floor: `the oracle-presence scan matched NOTHING for ["aomdec_path().exists()"] … that pattern is stale (renamed helper, exists() instead of is_file(), a format! escape) and the gates it was meant to police would pass unreviewed` | +| both reverted | **GREEN**, 7 sites inspected, 0 offenders | + +`touch` ran on every scanned source before every one of those runs — these +scans read compile-time sources, and a stale build would otherwise have read +the pre-mutation text. + +## 13. Status + +* `cargo test -p ec-av1 --lib -- gate_coverage refusal_inventory` -> **27 + passed, 0 failed** (26 in r2, plus this scan). +* The six gates the review named still pass with the oracle present (5 run in + the final check: `5 passed, 0 failed`). +* Shape A is unchanged and still not a hole: the ~445 + `if !have_aomenc()` / `if !have_ffmpeg()` early returns call probes that + assert last with the env escape, and the affine probe is now covered by this + scan as well. What is gone is the only shape that had no probe at all.