diff --git a/lanes/av1pinauditfix.report.md b/lanes/av1pinauditfix.report.md new file mode 100644 index 00000000..e259f585 --- /dev/null +++ b/lanes/av1pinauditfix.report.md @@ -0,0 +1,187 @@ +# lanes/av1pinauditfix — the pin-gate audit reads its own test data + +Branch `lane-av1pinauditfix`, base main `79b2a73f`, worktree +`/home/user/.cache/wt/av1pinauditfix`. Scripts only; no decoder and no +`gate_coverage.rs` text changed. + +## Was the RED pre-existing? YES — introduced 2026-09-29, not tonight + +``` +$ git log --oneline -S'/../../fixtures' -- crates/ec-av1/src/gate_coverage.rs +35deab68 test(av1): commit the 14 warp/ii/rect pins — recovered originals, not re-encodes +$ git log --oneline -S'a_gate_using_the_old_shape' -- crates/ec-av1/src/gate_coverage.rs +35deab68 test(av1): commit the 14 warp/ii/rect pins — recovered originals, not re-encodes +$ git log --oneline -S'BARDIR' -- scripts/pin-gate-audit.py +116445f5 preflight rework: path-free generated header, reproducible artifact, split exit status +``` + +Bisected on real checkouts of both commits: + +``` +$ git worktree add /tmp/wt-pre35 35deab68 && cd /tmp/wt-pre35 +$ bash scripts/verify-fixture-library.sh +FAIL [invariant 1]: a committed pin is reached through the gitignored root + crates/ec-av1/src/gate_coverage.rs:1919:let c = std::fs::read(concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/x.obu")); +FAIL [invariant 4]: pin-reading gates whose pins are not committed + crates/ec-av1/src/gate_coverage.rs:1916:shapes concat! 1/1 pin(s) not committed+tracked, e.g. x.obu + +$ git checkout 35deab68~1 # ec4e9528 +$ bash scripts/verify-fixture-library.sh >/dev/null 2>&1; echo $? +0 +``` + +`35deab68` (2026-09-29 05:17 +0300) is the commit that added the synthetic +capability-test gate; its parent `ec4e9528` is green. So the pin audit has been +RED for every tree since that commit, and the blocker noticed tonight is +pre-existing, not introduced tonight. + +## The defect + +`pin_inventory_tests` holds a scanner's own input: a `r#"..."#` whose body is a +synthetic gate reproducing the forbidden root literal, handed to `pins_read` as +DATA so the capability survives the tree being fixed. Two scanners read it as +CODE: + +- `verify-fixture-library.sh` invariant 1 — a line regex over the whole file; +- `scripts/pin-gate-audit.py` invariant 4 — worse, `fn_bodies` finds `fn` lines + BY REGEX, so `fn a_gate_using_the_old_shape()` inside the raw string is + attributed as a real gate and its body is classified. + +This is the mirror of the class the same script already fixed for prose +("a doc comment reproducing a root literal invented a gate"). Comments are +stripped; embedded SOURCE was not. + +## The rule + +**A match inside a string literal that SPANS LINES is not a gate.** Rust has no +line-spanning non-raw string, so a literal containing a newline is embedded +source — a scanner test's input or a doc blob. A real pin read names its path in +a single-line literal. + +Implemented once, in `pin-gate-audit.py`: + +- `mask_embedded_source(text)` — blanks the interior of every line-spanning + literal, preserving newlines so line numbers survive; +- `read_source(path)` — read + mask, applied at FILE level, because + `fn_bodies`'s regex `fn` scan is what resurrects the raw string as a gate; +- `code_of(body)` — the existing comment-strip plus the mask. + +`verify-fixture-library.sh` invariant 1 now IMPORTS `mask_embedded_source` from +`pin-gate-audit.py` (importlib, by path) instead of carrying its own copy: the +two checks must not disagree about what counts as a gate, or fixing one leaves +the other red. + +Why a general rule and not a path allowlist: an allowlist is a second list of +places to remember and the next scanner test lands somewhere else. The property +that actually separates the cases is structural and checkable — a real pin read +names a path in a one-line literal; only test data wraps Rust source across +lines. + +Why it cannot hide a real violation: a non-raw literal aborts at the first +newline, so it can only blank within one line, and a one-line literal holds no +Rust source. A char literal is only recognised when it really closes within +three characters, so a LIFETIME (`&'a str`) is not mistaken for a string start +and cannot swallow the rest of a line. + +## Control 1 (positive) — a REAL violation still reds, and is NAMED + +`crates/ec-av1/src/zz_control_probe.rs` (scratch, removed after): + +```rust +#[test] +fn a_real_gate_reading_through_the_gitignored_root() { + let p = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/control-obu.obu"); + let _ = std::fs::read(p); +} +``` + +``` +$ bash scripts/av1-suite-preflight.sh + FAIL [invariant 1]: a committed pin is reached through the gitignored root + crates/ec-av1/src/zz_control_probe.rs:3:let p = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/control-obu.obu"); + FAIL [invariant 4]: pin-reading gates whose pins are not committed + crates/ec-av1/src/zz_control_probe.rs:2:a_real_gate_reading_through_the_gitignored_root concat! 1/1 pin(s) not committed+tracked, e.g. control-obu.obu +pin_audit_exit=1 state=FAIL +VERDICT=BLOCKED +``` + +### Control 1b — the rustfmt-SPLIT real violation, the case the rule must not hide + +```rust +#[test] +fn a_real_gate_reading_through_the_gitignored_root_split_over_lines() { + let p = concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../fixtures/control-obu.obu" + ); + let _ = std::fs::read(p); +} +``` + +``` + FAIL [invariant 4]: pin-reading gates whose pins are not committed + crates/ec-av1/src/zz_control_probe.rs:2:a_real_gate_reading_through_the_gitignored_root_split_over_lines concat! 1/1 pin(s) not committed+tracked, e.g. control-obu.obu +pin_audit_exit=1 state=FAIL +``` + +Invariant 4 still catches it (its `ROOT_RE` spans newlines). Invariant 1 does +NOT, because that scan is per-line — pre-existing behaviour, unchanged here and +out of scope for this fix. + +## Control 2 (negative) — the scanner's own test data does not red + +Restored tree, no probe file: + +``` +$ bash scripts/av1-suite-preflight.sh +=== PIN-GATE PREFLIGHT (EC_REQUIRE_FIXTURES=0) + pin gates: total=9 committed=22 uncommitted=0 ignored=0 assertless=0 +pin_audit_exit=0 state=GREEN +=== VERDICT +VERDICT=GREEN +``` + +Before the fix the same command read `total=11 … uncommitted=4` with four BADROW / +BARDIR lines naming `gate_coverage.rs:1927 a_gate_using_the_old_shape` and +`gate_coverage.rs:1966 shapes`. After it, the two invented gates are gone and +`uncommitted` is 0 — the census now counts only real gates. + +## `--self-test` green (it is invariant 4's own control) + +``` +$ python3 scripts/pin-gate-audit.py --self-test +SELFTEST selftest_a_reads_a_pin crate_pin +SELFTEST selftest_b_reads_a_pin crate_pin +SELFTEST PASS a doc comment between two gates left both counted as crate_pin +selftest_exit=0 +``` + +Unchanged before and after, and the preflight runs it (it is the check at +`verify-fixture-library.sh:332`). + +## The run required for acceptance + +``` +$ bash scripts/av1-suite-preflight.sh +pin_audit_exit=0 state=GREEN +VERDICT=GREEN +rungs_exit=0 ok_count=14 state=GREEN +``` + +`rung_check` is GREEN here because the oracle source is present on this box; on a +box without it the state is `not-run`, which is the separate expected state +Main named and is unaffected by this change. + +## Not done + +1. The audit's own `--self-test` still plants only the PROSE shape (a comment + between two gates). The new rule's own positive control — a scanner test whose + `r#"..."#` input must NOT be counted — is proven here by the live tree + (`total=11 → 9`, `uncommitted=4 → 0`), not by a committed self-test case. A + committed case would need the self-test to build a raw string inside its + synthetic crate; worth adding, not added here. +2. Invariant 1 remains a per-LINE regex and so misses a rustfmt-split real + violation (Control 1b). Pre-existing, not introduced or widened by this change. +3. `crates/ec-av1/src/gate_coverage.rs` was NOT modified — the charter allowed it + "only if strictly needed", and the general rule made it unnecessary. The + synthetic gate is left exactly as the capability test wants it. diff --git a/scripts/pin-gate-audit.py b/scripts/pin-gate-audit.py index b6cc64fd..1450eed4 100755 --- a/scripts/pin-gate-audit.py +++ b/scripts/pin-gate-audit.py @@ -86,6 +86,101 @@ def fn_bodies(text): yield i + 1, name, "\n".join(lines[i:end]), attrs +RAW_STR_OPEN_RE = re.compile(r'(?:b?r|rb)(#*)"') +CHAR_RE = re.compile(r"'(?:\\.|[^\\'])'") + + +def _blank(out, lo, hi): + """Blank [lo, hi) in place, preserving newlines so line numbers survive.""" + for k in range(lo, hi): + if out[k] != "\n": + out[k] = " " + + +def mask_embedded_source(text): + """Blank the INTERIOR of every string literal that SPANS LINES. + + THE RULE: a match inside a string literal that spans lines is not a gate. + Rust has no line-spanning non-raw string, so a literal containing a newline + is EMBEDDED SOURCE -- the input to a scanner's own capability test, or a + doc blob. `pin_inventory_tests` holds exactly that: a `r#"..."#` whose body + is a synthetic gate reproducing the forbidden `/../../fixtures` root, fed + to `pins_read` as DATA. Read as code it is a live violation, and it made + this audit red on a tree with no real violation in it -- the audit reading + its own test data, the mirror of the class the same script already fixed + for prose ("a doc comment reproducing a root literal invented a gate"). + + Why this rule and not a path allowlist: a path allowlist is a second list + of places to remember, and the next scanner test lands somewhere else. + The property that actually separates the two cases is structural -- a real + pin read names a path in a single-line literal; only test data wraps Rust + source across lines -- and that property is checkable, not a location. + + Why it cannot hide a real violation: a non-raw literal aborts on the first + newline, so it can only ever blank within one line, and a one-line literal + holds no Rust source. A char literal is matched only when it really closes + within three characters, so a LIFETIME (`&'a str`) is not mistaken for the + start of a string and cannot swallow the rest of a line. + """ + out = list(text) + i, n = 0, len(text) + while i < n: + m = RAW_STR_OPEN_RE.match(text, i) + if m: + close = '"' + m.group(1) + end = text.find(close, m.end()) + if end == -1: + i = m.end() + continue + if "\n" in text[m.end():end]: + _blank(out, m.end(), end) + i = end + len(close) + continue + if text[i] == '"': + j = i + 1 + closed = None + while j < n: + c = text[j] + if c == "\\": + j += 2 + continue + if c == '"': + closed = j + break + if c == "\n": + break + j += 1 + if closed is not None: + i = closed + 1 + else: + i += 1 + continue + c = CHAR_RE.match(text, i) + i = c.end() if c else i + 1 + return "".join(out) + + +def code_of(body): + """Comment-stripped, embedded-source-masked body -- the thing the shapes + are matched against. Comment stripping removes PROSE reproducing a shape; + this removes SOURCE reproducing a shape.""" + code = re.sub(r"/\*.*?\*/", "", body, flags=re.S) + code = "\n".join(l.split("//", 1)[0] for l in code.splitlines()) + return mask_embedded_source(code) + + +def read_source(path): + """Read a Rust source with every line-spanning string literal's interior + blanked. The mask has to happen at FILE level, not per body: `fn_bodies` + finds `fn` lines by regex, so a synthetic gate inside a test's `r#"..."#` + input is picked up as if it were a real fn, and its body -- the raw + string's own text -- is then scanned as CODE. Masking first means that + region is blank before any gate attribution happens, which is the only + place the distinction can be made.""" + with open(path, encoding="utf-8", errors="replace") as fh: + return mask_embedded_source(fh.read()) + + ROOT_RE = re.compile( r'concat!\(\s*env!\("CARGO_MANIFEST_DIR"\)\s*,\s*"([^"]*)"\s*\)' ) @@ -162,15 +257,14 @@ fn selftest_b_reads_a_pin() { fh.write(body) rows = [] for c, p in sources(): - text = open(p, encoding="utf-8", errors="replace").read() + text = read_source(p) rel = os.path.relpath(p, ROOT) for line, name, b, attrs in fn_bodies(text): if not any(a.startswith("#[test") for a in attrs): continue if not name.startswith("selftest_"): continue - code = re.sub(r"/\*.*?\*/", "", b, flags=re.S) - code = "\n".join(x.split("//", 1)[0] for x in code.splitlines()) + code = code_of(b) kind = "root-literal" if (ROOT_RE.search(code) or JOIN_RE.search(code)) else "crate_pin" rows.append((name, kind)) bad = [r for r in rows if r[1] != "crate_pin"] @@ -193,7 +287,7 @@ fn selftest_b_reads_a_pin() { def main(): helpers = {} # fn name -> body (all fns in the tree) for crate, path in sources(): - text = open(path, encoding="utf-8", errors="replace").read() + text = read_source(path) for _line, name, body, _attrs in fn_bodies(text): helpers.setdefault(name, body) @@ -201,7 +295,7 @@ def main(): bad = [] for crate, path in sources(): - text = open(path, encoding="utf-8", errors="replace").read() + text = read_source(path) rel = os.path.relpath(path, ROOT) for line, name, body, attrs in fn_bodies(text): if not any(a.startswith("#[test") for a in attrs): @@ -209,8 +303,7 @@ def main(): # Match every shape on a COMMENT-STRIPPED body. A doc comment that # reproduces a root literal to explain the shape it removed used to # invent a gate here, the same blindness invariant 1 had. - code = re.sub(r"/\*.*?\*/", "", body, flags=re.S) - code = "\n".join(l.split("//", 1)[0] for l in code.splitlines()) + code = code_of(body) root_lit = None root_kind = "none" var = None @@ -283,8 +376,12 @@ def main(): # The name list is bracketed, but comments sit between its # items ("lane-rect r2: HORP strip ..."), so strip line # comments before parsing the list and anchor on the format! - # that consumes it. - body_nc = re.sub(r"//[^\n]*", "", body) + # that consumes it. It is `code` and not `body` that feeds + # this: `code` is the comment-stripped, embedded-source-masked + # text, and reading the RAW body here re-imported the shape + # out of a scanner test's own `r#"..."#` input -- the same + # gate resurrected through a different match. + body_nc = code for lit in LIST_RE.finditer(body_nc): items = re.findall(r'"([A-Za-z0-9._-]+)"', lit.group(1)) if len(items) < 3: diff --git a/scripts/verify-fixture-library.sh b/scripts/verify-fixture-library.sh index e2021b29..48ef9944 100755 --- a/scripts/verify-fixture-library.sh +++ b/scripts/verify-fixture-library.sh @@ -195,8 +195,17 @@ fi # the difference. One such comment in crates/ec-av1 read as a live violation for # a whole round (found by the lane that fixed the real ones). forbidden=$(python3 - "$ROOT" <<'PYEOF' -import os, re, sys +import importlib.util, os, re, sys root = sys.argv[1] +# SINGLE-SOURCE the rule: this scan (invariant 1) and the census (invariant 4, +# scripts/pin-gate-audit.py) must not disagree about what counts as a gate, or +# fixing one leaves the other red. Both strip comments AND mask line-spanning +# string literals -- prose reproducing a shape and SOURCE reproducing a shape +# are both data, not a gate. +spec = importlib.util.spec_from_file_location( + "pin_gate_audit", os.path.join(root, "scripts", "pin-gate-audit.py")) +audit = importlib.util.module_from_spec(spec) +spec.loader.exec_module(audit) pat = re.compile(r'concat!\(\s*env!\("CARGO_MANIFEST_DIR"\)\s*,\s*"/\.\./\.\./fixtures/[^/"]*\.') for crate in sorted(os.listdir(os.path.join(root, "crates"))): for sub in ("src", "tests"): @@ -213,7 +222,7 @@ for crate in sorted(os.listdir(os.path.join(root, "crates"))): except OSError: continue text = re.sub(r"/\*.*?\*/", "", text, flags=re.S) - for i, line in enumerate(text.splitlines(), 1): + for i, line in enumerate(audit.mask_embedded_source(text).splitlines(), 1): code = line.split("//", 1)[0] if pat.search(code): print("{}:{}:{}".format(os.path.relpath(p, root), i, line.strip()))