gate_coverage: the oracle-presence scan — the class can no longer reopen silently
Browse files at this commit693b4153b166f152c11b8dd43b0ad6168d2e4d3eParent: 1f8005c2 changed files +271 -23
- crates/ec-av1/src/gate_coverage.rs +188 -23
- lanes/av1oracleSkip.report.md +83 -0
crates/ec-av1/src/gate_coverage.rsmodified+188 -23
| @@ -140,24 +140,24 @@ enum On { | ||
| 140 | 140 | /// "defaulted means unknown" rule of [`NEVER_EXERCISED`] applies unchanged: a |
| 141 | 141 | /// default of `1` does not prove the encoder picked the tool for any stream, so |
| 142 | 142 | /// only a gate that spells an on-value at that bit depth retires an entry. |
| 143 | - // lane-av1distwtd r3: `enable-tx-size-search` is the one DEFAULT_ON_TOOLS | |
| 144 | - // entry the r2 audit could NOT settle, and the reason is a THIRD detector | |
| 145 | - // limit rather than a coverage fact. After the r3 call-resolving fix, 113 | |
| 146 | - // of the 230 selected gates name it: 88 pass `=0`, 15 pass `=1`, and 9 | |
| 147 | - // build the value into a `format!`/`String` variable that neither | |
| 148 | - // `flags_in` nor `settings_in` can see, because both scan for a literal | |
| 149 | - // `"--flag=value"` inside one segment. | |
| 150 | - // | |
| 151 | - // WHAT WOULD SETTLE IT, for whoever takes it next -- the method, not a | |
| 152 | - // guess: extend `flags_in`/`settings_in` to resolve a local binding, the | |
| 153 | - // same way `gate_bodies` now resolves calls. Concretely, when a segment | |
| 154 | - // contains `let <name> = format!("--enable-tx-size-search={tx_search}")` | |
| 155 | - // (or a `String::from`/`to_string` of the same shape), record the | |
| 156 | - // TEMPLATE and bind the variable's value at each use site. Re-count, and | |
| 157 | - // only then decide whether the tool is a live hole. Until that exists the | |
| 158 | - // count above is a floor, not a measurement: 9 gates are unclassified in | |
| 159 | - // an unknown direction, and an unknown direction is exactly the failure | |
| 160 | - // mode this file exists to prevent. | |
| 143 | +// lane-av1distwtd r3: `enable-tx-size-search` is the one DEFAULT_ON_TOOLS | |
| 144 | +// entry the r2 audit could NOT settle, and the reason is a THIRD detector | |
| 145 | +// limit rather than a coverage fact. After the r3 call-resolving fix, 113 | |
| 146 | +// of the 230 selected gates name it: 88 pass `=0`, 15 pass `=1`, and 9 | |
| 147 | +// build the value into a `format!`/`String` variable that neither | |
| 148 | +// `flags_in` nor `settings_in` can see, because both scan for a literal | |
| 149 | +// `"--flag=value"` inside one segment. | |
| 150 | +// | |
| 151 | +// WHAT WOULD SETTLE IT, for whoever takes it next -- the method, not a | |
| 152 | +// guess: extend `flags_in`/`settings_in` to resolve a local binding, the | |
| 153 | +// same way `gate_bodies` now resolves calls. Concretely, when a segment | |
| 154 | +// contains `let <name> = format!("--enable-tx-size-search={tx_search}")` | |
| 155 | +// (or a `String::from`/`to_string` of the same shape), record the | |
| 156 | +// TEMPLATE and bind the variable's value at each use site. Re-count, and | |
| 157 | +// only then decide whether the tool is a live hole. Until that exists the | |
| 158 | +// count above is a floor, not a measurement: 9 gates are unclassified in | |
| 159 | +// an unknown direction, and an unknown direction is exactly the failure | |
| 160 | +// mode this file exists to prevent. | |
| 161 | 161 | #[cfg(test)] |
| 162 | 162 | const DEFAULT_ON_TOOLS: &[(&str, &[&str], &str, On)] = &[ |
| 163 | 163 | ( |
| @@ -434,8 +434,8 @@ const NEVER_ON_10BIT: &[(&str, &str)] = &[]; | ||
| 434 | 434 | #[cfg(test)] |
| 435 | 435 | mod tests { |
| 436 | 436 | use super::{ |
| 437 | - On, ALIASES, DEFAULT_ON_TOOLS, NEVER_EXERCISED, NEVER_EXERCISED_10BIT, | |
| 438 | - NEVER_EXERCISED_8BIT, NEVER_ON_10BIT, NEVER_ON_8BIT, TOOL_UNIVERSE, | |
| 437 | + ALIASES, DEFAULT_ON_TOOLS, NEVER_EXERCISED, NEVER_EXERCISED_8BIT, NEVER_EXERCISED_10BIT, | |
| 438 | + NEVER_ON_8BIT, NEVER_ON_10BIT, On, TOOL_UNIVERSE, | |
| 439 | 439 | }; |
| 440 | 440 | use std::collections::{BTreeMap, BTreeSet}; |
| 441 | 441 | |
| @@ -770,9 +770,7 @@ mod tests { | ||
| 770 | 770 | // it to the 8-bit bucket, not just the 10-bit one. |
| 771 | 771 | let flip = gates |
| 772 | 772 | .iter() |
| 773 | - .find(|b| { | |
| 774 | - b.contains("a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform") | |
| 775 | - }) | |
| 773 | + .find(|b| b.contains("a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform")) | |
| 776 | 774 | .expect("the flip-idtx gate must be seen"); |
| 777 | 775 | assert!( |
| 778 | 776 | covers_both_depths(flip), |
| @@ -1022,4 +1020,171 @@ mod tests { | ||
| 1022 | 1020 | } |
| 1023 | 1021 | } |
| 1024 | 1022 | } |
| 1023 | + | |
| 1024 | + /// lane-av1oracleskip: the ORACLE-PRESENCE SCAN — the mechanical | |
| 1025 | + /// anti-regression for the skip class this lane closed. | |
| 1026 | + /// | |
| 1027 | + /// Why a scan and not a review rule: the r2 sweep found FIVE gates that | |
| 1028 | + /// had been added with the bare `if aomdec_path().is_file() { …compare… }` | |
| 1029 | + /// shape AFTER the first fix had already routed thirteen sites — every one | |
| 1030 | + /// of them compiled, passed review and reported green with the oracle | |
| 1031 | + /// compare silently skipped, under `EC_AV1_REQUIRE_AOMENC=1`. A guard | |
| 1032 | + /// written the old way re-opens the class the moment it merges, so the | |
| 1033 | + /// only thing that holds is a check that reads the source itself. | |
| 1034 | + /// | |
| 1035 | + /// The rule: a TOOL PRESENCE CHECK (`aomenc_path().is_file()`, | |
| 1036 | + /// `aomdec_path().is_file()`, `affine_aomenc_path().is_file()`, plain or | |
| 1037 | + /// `!…` inverted) may appear ONLY | |
| 1038 | + /// 1. inside the body of the probe that owns that path | |
| 1039 | + /// (`have_aomenc`, `aomdec_available`, `have_affine_aomenc`) — that | |
| 1040 | + /// is where the assert-last and the env escape live, and | |
| 1041 | + /// 2. inside an `assert!` (the deliberate hard-failure form), or | |
| 1042 | + /// 3. in a comment, which cannot execute. | |
| 1043 | + /// Anything else is a skip with no env escape, and the test fails naming | |
| 1044 | + /// the exact `file:line`. | |
| 1045 | + /// | |
| 1046 | + /// THE FLOOR. A source scan that matches nothing is the false-pass shape | |
| 1047 | + /// this crate has been bitten by twice (a `format!` brace escape, and | |
| 1048 | + /// `args.find(')')` stopping at the wrong paren), so the scan refuses to | |
| 1049 | + /// pass unless it actually inspected a plausible number of sites: the | |
| 1050 | + /// count is printed and asserted against `MIN_SITES`. A probe that moved | |
| 1051 | + /// out of the scan's reach, or a matcher broken by a rename, reds here | |
| 1052 | + /// instead of reporting a clean bill of health. | |
| 1053 | + #[test] | |
| 1054 | + fn no_tool_presence_check_outside_its_probe() { | |
| 1055 | + /// Below this, the scan is not looking at the tree it thinks it is. | |
| 1056 | + /// Five is the STRUCTURAL floor: three probes (whose existence the span | |
| 1057 | + /// assert below already pins) plus the two hard `assert!` sites. Doc | |
| 1058 | + /// comments mentioning the old shape come and go with the prose, so | |
| 1059 | + /// they are counted but never load-bearing here. | |
| 1060 | + const MIN_SITES: usize = 5; | |
| 1061 | + /// (file, the line that opens the probe owning that path) | |
| 1062 | + const PROBES: &[(&str, &str)] = &[ | |
| 1063 | + ("stream.rs", "fn have_aomenc()"), | |
| 1064 | + ("stream.rs", "fn aomdec_available("), | |
| 1065 | + ("stream.rs", "fn have_affine_aomenc()"), | |
| 1066 | + ]; | |
| 1067 | + const PATHS: &[&str] = &[ | |
| 1068 | + "aomenc_path().is_file()", | |
| 1069 | + "aomdec_path().is_file()", | |
| 1070 | + "affine_aomenc_path().is_file()", | |
| 1071 | + ]; | |
| 1072 | + let files: [(&str, &str); 3] = [ | |
| 1073 | + ("stream.rs", include_str!("stream.rs")), | |
| 1074 | + ("decode.rs", include_str!("decode.rs")), | |
| 1075 | + ("encode.rs", include_str!("encode.rs")), | |
| 1076 | + ]; | |
| 1077 | + | |
| 1078 | + // The line range each probe body owns: from its opener to the first | |
| 1079 | + // following line that closes it at column 0. | |
| 1080 | + let mut probe_spans: Vec<(usize, usize)> = Vec::new(); | |
| 1081 | + for (name, src) in files { | |
| 1082 | + let lines: Vec<&str> = src.lines().collect(); | |
| 1083 | + for (probe_file, opener) in PROBES { | |
| 1084 | + if *probe_file != name { | |
| 1085 | + continue; | |
| 1086 | + } | |
| 1087 | + let Some(start) = lines.iter().position(|l| l.contains(opener)).map(|i| i + 1) | |
| 1088 | + else { | |
| 1089 | + continue; | |
| 1090 | + }; | |
| 1091 | + let end = lines | |
| 1092 | + .iter() | |
| 1093 | + .skip(start) | |
| 1094 | + .position(|l| l.trim_end() == "}") | |
| 1095 | + .map(|off| start + off) | |
| 1096 | + .unwrap_or(lines.len()); | |
| 1097 | + probe_spans.push((start, end)); | |
| 1098 | + } | |
| 1099 | + } | |
| 1100 | + assert!( | |
| 1101 | + probe_spans.len() == PROBES.len(), | |
| 1102 | + "the oracle-presence scan recognised {} of the {} probe bodies it is meant to \ | |
| 1103 | + exempt ({probe_spans:?}); a renamed or moved probe would silently exempt every \ | |
| 1104 | + site in the crate, so it reds here", | |
| 1105 | + probe_spans.len(), | |
| 1106 | + PROBES.len() | |
| 1107 | + ); | |
| 1108 | + | |
| 1109 | + let mut sites = 0usize; | |
| 1110 | + let mut allowed = 0usize; | |
| 1111 | + let mut per_pattern: BTreeMap<&str, usize> = PATHS.iter().map(|p| (*p, 0)).collect(); | |
| 1112 | + let mut offenders: Vec<String> = Vec::new(); | |
| 1113 | + for (name, src) in files { | |
| 1114 | + for (i, line) in src.lines().enumerate() { | |
| 1115 | + // LONGEST match wins: `affine_aomenc_path().is_file()` CONTAINS | |
| 1116 | + // `aomenc_path().is_file()`, so a first-match scan credits the | |
| 1117 | + // affine probe's line to the aomenc pattern and the per-pattern | |
| 1118 | + // floor below reds on a pattern that is very much present. (It | |
| 1119 | + // did, on the first run of this test — which is the floor | |
| 1120 | + // earning its place.) | |
| 1121 | + let Some(path) = PATHS | |
| 1122 | + .iter() | |
| 1123 | + .filter(|p| line.contains(**p)) | |
| 1124 | + .max_by_key(|p| p.len()) | |
| 1125 | + else { | |
| 1126 | + continue; | |
| 1127 | + }; | |
| 1128 | + sites += 1; | |
| 1129 | + *per_pattern.get_mut(path).expect("pattern came from PATHS") += 1; | |
| 1130 | + let lineno = i + 1; | |
| 1131 | + let trimmed = line.trim_start(); | |
| 1132 | + let in_probe = probe_spans | |
| 1133 | + .iter() | |
| 1134 | + .any(|(start, end)| lineno >= *start && lineno <= *end); | |
| 1135 | + let in_assert = trimmed.starts_with("assert!") | |
| 1136 | + || trimmed.starts_with("aomdec_path().is_file(),") | |
| 1137 | + || trimmed.starts_with("aomenc_path().is_file(),") | |
| 1138 | + || trimmed.starts_with("affine_aomenc_path().is_file(),"); | |
| 1139 | + let in_comment = trimmed.starts_with("//"); | |
| 1140 | + if in_probe || in_assert || in_comment { | |
| 1141 | + allowed += 1; | |
| 1142 | + } else { | |
| 1143 | + offenders.push(format!( | |
| 1144 | + "{name}:{lineno}: {}\n a tool presence check outside its probe — \ | |
| 1145 | + route it through the probe that owns this path (`have_aomenc`, \ | |
| 1146 | + `aomdec_available`, `have_affine_aomenc`): a bare `{path}` skips the \ | |
| 1147 | + gate with NO env escape, so under EC_AV1_REQUIRE_AOMENC=1 the gate still \ | |
| 1148 | + reports green with the oracle compare never run.", | |
| 1149 | + line.trim() | |
| 1150 | + )); | |
| 1151 | + } | |
| 1152 | + } | |
| 1153 | + } | |
| 1154 | + println!( | |
| 1155 | + "oracle-presence scan: {sites} site(s) inspected, {allowed} in a probe / assert / \ | |
| 1156 | + comment, {} offender(s); per pattern {per_pattern:?}", | |
| 1157 | + offenders.len() | |
| 1158 | + ); | |
| 1159 | + // PER-PATTERN floor: a total count can hide one broken matcher (mutate | |
| 1160 | + // ONE pattern and the other two still add up), so each of the three | |
| 1161 | + // path patterns must be found at least once -- which the probe bodies | |
| 1162 | + // guarantee, since each probe contains its own path's presence check. | |
| 1163 | + let never_matched: Vec<&str> = per_pattern | |
| 1164 | + .iter() | |
| 1165 | + .filter(|(_, n)| **n == 0) | |
| 1166 | + .map(|(p, _)| *p) | |
| 1167 | + .collect(); | |
| 1168 | + assert!( | |
| 1169 | + never_matched.is_empty(), | |
| 1170 | + "the oracle-presence scan matched NOTHING for {never_matched:?}: that pattern is \ | |
| 1171 | + stale (renamed helper, `exists()` instead of `is_file()`, a `format!` escape) and \ | |
| 1172 | + the gates it was meant to police would pass unreviewed. Matched per pattern: \ | |
| 1173 | + {per_pattern:?}" | |
| 1174 | + ); | |
| 1175 | + assert!( | |
| 1176 | + sites >= MIN_SITES, | |
| 1177 | + "the oracle-presence scan inspected only {sites} site(s), below its floor of \ | |
| 1178 | + {MIN_SITES}: the matcher has stopped matching this tree (renamed path helper, a \ | |
| 1179 | + `format!` escape, a moved probe), and with no floor this would pass while scanning \ | |
| 1180 | + nothing — the false-pass shape this crate has been bitten by twice" | |
| 1181 | + ); | |
| 1182 | + assert!( | |
| 1183 | + offenders.is_empty(), | |
| 1184 | + "{} bare tool presence check(s) outside a probe — each one is a gate that can report \ | |
| 1185 | + green without running the oracle compare:\n {}", | |
| 1186 | + offenders.len(), | |
| 1187 | + offenders.join("\n ") | |
| 1188 | + ); | |
| 1189 | + } | |
| 1025 | 1190 | } |
lanes/av1oracleSkip.report.mdmodified+83 -0
| @@ -264,3 +264,86 @@ r1 reported is gone — lane-av1toolgates' entries were retired upstream). | ||
| 264 | 264 | because the source-scan pattern for a whole-file assertion is itself a new |
| 265 | 265 | piece of machinery, and this lane's charter is the probe. It is the obvious |
| 266 | 266 | 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. |