forge
Explore
Log in

Don't you dare go Hollow

Merge lane-av1oracleskip r3 @ 7a865ee7 — the oracle-presence scan that closes the class structurally

Browse files at this commit

b4cb053e0335efb6badde7e4eb65f5f2535ac54aAhmet Kaan GümüşParent: f94e32d693b415
# Conflicts:
#	crates/ec-av1/src/gate_coverage.rs
crates/ec-av1/src/gate_coverage.rsmodified+167 -0
@@ -1531,4 +1531,171 @@ mod tests {
15311531 "expected the literal `=1` gates to still be there, found {pinned}"
15321532 );
15331533 }
1534+
1535+ /// lane-av1oracleskip: the ORACLE-PRESENCE SCAN — the mechanical
1536+ /// anti-regression for the skip class this lane closed.
1537+ ///
1538+ /// Why a scan and not a review rule: the r2 sweep found FIVE gates that
1539+ /// had been added with the bare `if aomdec_path().is_file() { …compare… }`
1540+ /// shape AFTER the first fix had already routed thirteen sites — every one
1541+ /// of them compiled, passed review and reported green with the oracle
1542+ /// compare silently skipped, under `EC_AV1_REQUIRE_AOMENC=1`. A guard
1543+ /// written the old way re-opens the class the moment it merges, so the
1544+ /// only thing that holds is a check that reads the source itself.
1545+ ///
1546+ /// The rule: a TOOL PRESENCE CHECK (`aomenc_path().is_file()`,
1547+ /// `aomdec_path().is_file()`, `affine_aomenc_path().is_file()`, plain or
1548+ /// `!…` inverted) may appear ONLY
1549+ /// 1. inside the body of the probe that owns that path
1550+ /// (`have_aomenc`, `aomdec_available`, `have_affine_aomenc`) — that
1551+ /// is where the assert-last and the env escape live, and
1552+ /// 2. inside an `assert!` (the deliberate hard-failure form), or
1553+ /// 3. in a comment, which cannot execute.
1554+ /// Anything else is a skip with no env escape, and the test fails naming
1555+ /// the exact `file:line`.
1556+ ///
1557+ /// THE FLOOR. A source scan that matches nothing is the false-pass shape
1558+ /// this crate has been bitten by twice (a `format!` brace escape, and
1559+ /// `args.find(')')` stopping at the wrong paren), so the scan refuses to
1560+ /// pass unless it actually inspected a plausible number of sites: the
1561+ /// count is printed and asserted against `MIN_SITES`. A probe that moved
1562+ /// out of the scan's reach, or a matcher broken by a rename, reds here
1563+ /// instead of reporting a clean bill of health.
1564+ #[test]
1565+ fn no_tool_presence_check_outside_its_probe() {
1566+ /// Below this, the scan is not looking at the tree it thinks it is.
1567+ /// Five is the STRUCTURAL floor: three probes (whose existence the span
1568+ /// assert below already pins) plus the two hard `assert!` sites. Doc
1569+ /// comments mentioning the old shape come and go with the prose, so
1570+ /// they are counted but never load-bearing here.
1571+ const MIN_SITES: usize = 5;
1572+ /// (file, the line that opens the probe owning that path)
1573+ const PROBES: &[(&str, &str)] = &[
1574+ ("stream.rs", "fn have_aomenc()"),
1575+ ("stream.rs", "fn aomdec_available("),
1576+ ("stream.rs", "fn have_affine_aomenc()"),
1577+ ];
1578+ const PATHS: &[&str] = &[
1579+ "aomenc_path().is_file()",
1580+ "aomdec_path().is_file()",
1581+ "affine_aomenc_path().is_file()",
1582+ ];
1583+ let files: [(&str, &str); 3] = [
1584+ ("stream.rs", include_str!("stream.rs")),
1585+ ("decode.rs", include_str!("decode.rs")),
1586+ ("encode.rs", include_str!("encode.rs")),
1587+ ];
1588+
1589+ // The line range each probe body owns: from its opener to the first
1590+ // following line that closes it at column 0.
1591+ let mut probe_spans: Vec<(usize, usize)> = Vec::new();
1592+ for (name, src) in files {
1593+ let lines: Vec<&str> = src.lines().collect();
1594+ for (probe_file, opener) in PROBES {
1595+ if *probe_file != name {
1596+ continue;
1597+ }
1598+ let Some(start) = lines.iter().position(|l| l.contains(opener)).map(|i| i + 1)
1599+ else {
1600+ continue;
1601+ };
1602+ let end = lines
1603+ .iter()
1604+ .skip(start)
1605+ .position(|l| l.trim_end() == "}")
1606+ .map(|off| start + off)
1607+ .unwrap_or(lines.len());
1608+ probe_spans.push((start, end));
1609+ }
1610+ }
1611+ assert!(
1612+ probe_spans.len() == PROBES.len(),
1613+ "the oracle-presence scan recognised {} of the {} probe bodies it is meant to \
1614+ exempt ({probe_spans:?}); a renamed or moved probe would silently exempt every \
1615+ site in the crate, so it reds here",
1616+ probe_spans.len(),
1617+ PROBES.len()
1618+ );
1619+
1620+ let mut sites = 0usize;
1621+ let mut allowed = 0usize;
1622+ let mut per_pattern: BTreeMap<&str, usize> = PATHS.iter().map(|p| (*p, 0)).collect();
1623+ let mut offenders: Vec<String> = Vec::new();
1624+ for (name, src) in files {
1625+ for (i, line) in src.lines().enumerate() {
1626+ // LONGEST match wins: `affine_aomenc_path().is_file()` CONTAINS
1627+ // `aomenc_path().is_file()`, so a first-match scan credits the
1628+ // affine probe's line to the aomenc pattern and the per-pattern
1629+ // floor below reds on a pattern that is very much present. (It
1630+ // did, on the first run of this test — which is the floor
1631+ // earning its place.)
1632+ let Some(path) = PATHS
1633+ .iter()
1634+ .filter(|p| line.contains(**p))
1635+ .max_by_key(|p| p.len())
1636+ else {
1637+ continue;
1638+ };
1639+ sites += 1;
1640+ *per_pattern.get_mut(path).expect("pattern came from PATHS") += 1;
1641+ let lineno = i + 1;
1642+ let trimmed = line.trim_start();
1643+ let in_probe = probe_spans
1644+ .iter()
1645+ .any(|(start, end)| lineno >= *start && lineno <= *end);
1646+ let in_assert = trimmed.starts_with("assert!")
1647+ || trimmed.starts_with("aomdec_path().is_file(),")
1648+ || trimmed.starts_with("aomenc_path().is_file(),")
1649+ || trimmed.starts_with("affine_aomenc_path().is_file(),");
1650+ let in_comment = trimmed.starts_with("//");
1651+ if in_probe || in_assert || in_comment {
1652+ allowed += 1;
1653+ } else {
1654+ offenders.push(format!(
1655+ "{name}:{lineno}: {}\n a tool presence check outside its probe — \
1656+ route it through the probe that owns this path (`have_aomenc`, \
1657+ `aomdec_available`, `have_affine_aomenc`): a bare `{path}` skips the \
1658+ gate with NO env escape, so under EC_AV1_REQUIRE_AOMENC=1 the gate still \
1659+ reports green with the oracle compare never run.",
1660+ line.trim()
1661+ ));
1662+ }
1663+ }
1664+ }
1665+ println!(
1666+ "oracle-presence scan: {sites} site(s) inspected, {allowed} in a probe / assert / \
1667+ comment, {} offender(s); per pattern {per_pattern:?}",
1668+ offenders.len()
1669+ );
1670+ // PER-PATTERN floor: a total count can hide one broken matcher (mutate
1671+ // ONE pattern and the other two still add up), so each of the three
1672+ // path patterns must be found at least once -- which the probe bodies
1673+ // guarantee, since each probe contains its own path's presence check.
1674+ let never_matched: Vec<&str> = per_pattern
1675+ .iter()
1676+ .filter(|(_, n)| **n == 0)
1677+ .map(|(p, _)| *p)
1678+ .collect();
1679+ assert!(
1680+ never_matched.is_empty(),
1681+ "the oracle-presence scan matched NOTHING for {never_matched:?}: that pattern is \
1682+ stale (renamed helper, `exists()` instead of `is_file()`, a `format!` escape) and \
1683+ the gates it was meant to police would pass unreviewed. Matched per pattern: \
1684+ {per_pattern:?}"
1685+ );
1686+ assert!(
1687+ sites >= MIN_SITES,
1688+ "the oracle-presence scan inspected only {sites} site(s), below its floor of \
1689+ {MIN_SITES}: the matcher has stopped matching this tree (renamed path helper, a \
1690+ `format!` escape, a moved probe), and with no floor this would pass while scanning \
1691+ nothing — the false-pass shape this crate has been bitten by twice"
1692+ );
1693+ assert!(
1694+ offenders.is_empty(),
1695+ "{} bare tool presence check(s) outside a probe — each one is a gate that can report \
1696+ green without running the oracle compare:\n {}",
1697+ offenders.len(),
1698+ offenders.join("\n ")
1699+ );
1700+ }
15341701 }
lanes/av1oracleSkip.report.mdmodified+83 -0
@@ -264,3 +264,86 @@ r1 reported is gone — lane-av1toolgates' entries were retired upstream).
264264 because the source-scan pattern for a whole-file assertion is itself a new
265265 piece of machinery, and this lane's charter is the probe. It is the obvious
266266 next step and it is small.
267+
268+---
269+
270+# r3 — the mechanical anti-regression: the class can no longer be reopened silently
271+
272+r2 left the class closed *currently* and the anti-regression *procedural*: a
273+new guard written as `aomdec_path().is_file()` compiles, passes review, and
274+re-opens exactly the hole r2 closed — which is how the five r2 sites got there
275+in the first place. r3 replaces the review rule with a check that reads the
276+source.
277+
278+## 11. The scan
279+
280+`gate_coverage::tests::no_tool_presence_check_outside_its_probe`, in
281+`crates/ec-av1/src/gate_coverage.rs` — the crate's existing source-scan home
282+(it already `include_str!`s `stream.rs` to re-derive the gates' recipes from
283+their own text), extended to all three test-bearing files.
284+
285+**The rule.** A tool presence check — `aomenc_path().is_file()`,
286+`aomdec_path().is_file()`, `affine_aomenc_path().is_file()`, plain or `!…`
287+inverted — may appear only
288+
289+1. inside the body of the probe that owns that path (`have_aomenc`,
290+ `aomdec_available`, `have_affine_aomenc`), where the assert-last and the
291+ env escape live; the scan computes each probe's line span from its `fn`
292+ opener to the first column-0 `}` and asserts it found all three, so a moved
293+ or renamed probe reds rather than silently exempting the whole crate;
294+2. inside an `assert!` (the deliberate hard-failure form); or
295+3. in a comment, which cannot execute.
296+
297+Anything else fails the test naming the exact `file:line`, the line's text, and
298+what to do about it. Current state:
299+
300+```
301+oracle-presence scan: 7 site(s) inspected, 7 in a probe / assert / comment,
302+0 offender(s); per pattern {"affine_aomenc_path().is_file()": 1,
303+"aomdec_path().is_file()": 5, "aomenc_path().is_file()": 1}
304+```
305+
306+**The floors.** A source scan that matches nothing is the false-pass shape
307+this batch has been bitten by twice (a `format!` brace escape, and
308+`args.find(')')` stopping at the wrong paren), so there are two, not one:
309+
310+* a total floor, `MIN_SITES = 5` — the STRUCTURAL count (three probes + two
311+ hard asserts), so prose that comes and goes with the doc comments is counted
312+ but never load-bearing;
313+* a **per-pattern** floor — each of the three path patterns must match at
314+ least once. A total alone hides a single broken matcher: mutating ONE
315+ pattern still leaves the other two adding up (measured: with
316+ `aomdec_path().exists()` substituted, the scan still reported 6 sites and
317+ passed). The per-pattern floor is what catches that.
318+
319+The per-pattern floor earned its place on its FIRST run, by catching a real
320+bug in the matcher written one line above it: `affine_aomenc_path().is_file()`
321+CONTAINS `aomenc_path().is_file()`, so a first-match scan credited the affine
322+probe's line to the aomenc pattern and the affine pattern matched nothing. The
323+matcher now takes the LONGEST match, and the floor is what noticed.
324+
325+## 12. Mutation proofs, both directions
326+
327+Both mutations were made, run, and reverted; `git diff crates/ec-av1/src/stream.rs`
328+is empty afterwards and the scan is green.
329+
330+| mutation | result |
331+|---|---|
332+| 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() {` |
333+| 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` |
334+| both reverted | **GREEN**, 7 sites inspected, 0 offenders |
335+
336+`touch` ran on every scanned source before every one of those runs — these
337+scans read compile-time sources, and a stale build would otherwise have read
338+the pre-mutation text.
339+
340+## 13. Status
341+
342+* `cargo test -p ec-av1 --lib -- gate_coverage refusal_inventory` -> **27
343+ passed, 0 failed** (26 in r2, plus this scan).
344+* The six gates the review named still pass with the oracle present (5 run in
345+ the final check: `5 passed, 0 failed`).
346+* Shape A is unchanged and still not a hole: the ~445
347+ `if !have_aomenc()` / `if !have_ffmpeg()` early returns call probes that
348+ assert last with the env escape, and the affine probe is now covered by this
349+ scan as well. What is gone is the only shape that had no probe at all.