scripts: the pin-gate audit must not read its own test data
Browse files at this commit4c07cbc2ca9466907a3cbb5ccc7dab0eebf15b7eParent: b918b393 changed files +304 -11
- lanes/av1pinauditfix.report.md +187 -0
- scripts/pin-gate-audit.py +106 -9
- scripts/verify-fixture-library.sh +11 -2
lanes/av1pinauditfix.report.mdadded+187 -0
| @@ -0,0 +1,187 @@ | |||
| 1 | +# lanes/av1pinauditfix — the pin-gate audit reads its own test data | ||
| 2 | + | ||
| 3 | +Branch `lane-av1pinauditfix`, base main `79b2a73f`, worktree | ||
| 4 | +`/home/user/.cache/wt/av1pinauditfix`. Scripts only; no decoder and no | ||
| 5 | +`gate_coverage.rs` text changed. | ||
| 6 | + | ||
| 7 | +## Was the RED pre-existing? YES — introduced 2026-09-29, not tonight | ||
| 8 | + | ||
| 9 | +``` | ||
| 10 | +$ git log --oneline -S'/../../fixtures' -- crates/ec-av1/src/gate_coverage.rs | ||
| 11 | +35deab68 test(av1): commit the 14 warp/ii/rect pins — recovered originals, not re-encodes | ||
| 12 | +$ git log --oneline -S'a_gate_using_the_old_shape' -- crates/ec-av1/src/gate_coverage.rs | ||
| 13 | +35deab68 test(av1): commit the 14 warp/ii/rect pins — recovered originals, not re-encodes | ||
| 14 | +$ git log --oneline -S'BARDIR' -- scripts/pin-gate-audit.py | ||
| 15 | +116445f5 preflight rework: path-free generated header, reproducible artifact, split exit status | ||
| 16 | +``` | ||
| 17 | + | ||
| 18 | +Bisected on real checkouts of both commits: | ||
| 19 | + | ||
| 20 | +``` | ||
| 21 | +$ git worktree add /tmp/wt-pre35 35deab68 && cd /tmp/wt-pre35 | ||
| 22 | +$ bash scripts/verify-fixture-library.sh | ||
| 23 | +FAIL [invariant 1]: a committed pin is reached through the gitignored root | ||
| 24 | + crates/ec-av1/src/gate_coverage.rs:1919:let c = std::fs::read(concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/x.obu")); | ||
| 25 | +FAIL [invariant 4]: pin-reading gates whose pins are not committed | ||
| 26 | + crates/ec-av1/src/gate_coverage.rs:1916:shapes concat! 1/1 pin(s) not committed+tracked, e.g. x.obu | ||
| 27 | + | ||
| 28 | +$ git checkout 35deab68~1 # ec4e9528 | ||
| 29 | +$ bash scripts/verify-fixture-library.sh >/dev/null 2>&1; echo $? | ||
| 30 | +0 | ||
| 31 | +``` | ||
| 32 | + | ||
| 33 | +`35deab68` (2026-09-29 05:17 +0300) is the commit that added the synthetic | ||
| 34 | +capability-test gate; its parent `ec4e9528` is green. So the pin audit has been | ||
| 35 | +RED for every tree since that commit, and the blocker noticed tonight is | ||
| 36 | +pre-existing, not introduced tonight. | ||
| 37 | + | ||
| 38 | +## The defect | ||
| 39 | + | ||
| 40 | +`pin_inventory_tests` holds a scanner's own input: a `r#"..."#` whose body is a | ||
| 41 | +synthetic gate reproducing the forbidden root literal, handed to `pins_read` as | ||
| 42 | +DATA so the capability survives the tree being fixed. Two scanners read it as | ||
| 43 | +CODE: | ||
| 44 | + | ||
| 45 | +- `verify-fixture-library.sh` invariant 1 — a line regex over the whole file; | ||
| 46 | +- `scripts/pin-gate-audit.py` invariant 4 — worse, `fn_bodies` finds `fn` lines | ||
| 47 | + BY REGEX, so `fn a_gate_using_the_old_shape()` inside the raw string is | ||
| 48 | + attributed as a real gate and its body is classified. | ||
| 49 | + | ||
| 50 | +This is the mirror of the class the same script already fixed for prose | ||
| 51 | +("a doc comment reproducing a root literal invented a gate"). Comments are | ||
| 52 | +stripped; embedded SOURCE was not. | ||
| 53 | + | ||
| 54 | +## The rule | ||
| 55 | + | ||
| 56 | +**A match inside a string literal that SPANS LINES is not a gate.** Rust has no | ||
| 57 | +line-spanning non-raw string, so a literal containing a newline is embedded | ||
| 58 | +source — a scanner test's input or a doc blob. A real pin read names its path in | ||
| 59 | +a single-line literal. | ||
| 60 | + | ||
| 61 | +Implemented once, in `pin-gate-audit.py`: | ||
| 62 | + | ||
| 63 | +- `mask_embedded_source(text)` — blanks the interior of every line-spanning | ||
| 64 | + literal, preserving newlines so line numbers survive; | ||
| 65 | +- `read_source(path)` — read + mask, applied at FILE level, because | ||
| 66 | + `fn_bodies`'s regex `fn` scan is what resurrects the raw string as a gate; | ||
| 67 | +- `code_of(body)` — the existing comment-strip plus the mask. | ||
| 68 | + | ||
| 69 | +`verify-fixture-library.sh` invariant 1 now IMPORTS `mask_embedded_source` from | ||
| 70 | +`pin-gate-audit.py` (importlib, by path) instead of carrying its own copy: the | ||
| 71 | +two checks must not disagree about what counts as a gate, or fixing one leaves | ||
| 72 | +the other red. | ||
| 73 | + | ||
| 74 | +Why a general rule and not a path allowlist: an allowlist is a second list of | ||
| 75 | +places to remember and the next scanner test lands somewhere else. The property | ||
| 76 | +that actually separates the cases is structural and checkable — a real pin read | ||
| 77 | +names a path in a one-line literal; only test data wraps Rust source across | ||
| 78 | +lines. | ||
| 79 | + | ||
| 80 | +Why it cannot hide a real violation: a non-raw literal aborts at the first | ||
| 81 | +newline, so it can only blank within one line, and a one-line literal holds no | ||
| 82 | +Rust source. A char literal is only recognised when it really closes within | ||
| 83 | +three characters, so a LIFETIME (`&'a str`) is not mistaken for a string start | ||
| 84 | +and cannot swallow the rest of a line. | ||
| 85 | + | ||
| 86 | +## Control 1 (positive) — a REAL violation still reds, and is NAMED | ||
| 87 | + | ||
| 88 | +`crates/ec-av1/src/zz_control_probe.rs` (scratch, removed after): | ||
| 89 | + | ||
| 90 | +```rust | ||
| 91 | +#[test] | ||
| 92 | +fn a_real_gate_reading_through_the_gitignored_root() { | ||
| 93 | + let p = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/control-obu.obu"); | ||
| 94 | + let _ = std::fs::read(p); | ||
| 95 | +} | ||
| 96 | +``` | ||
| 97 | + | ||
| 98 | +``` | ||
| 99 | +$ bash scripts/av1-suite-preflight.sh | ||
| 100 | + FAIL [invariant 1]: a committed pin is reached through the gitignored root | ||
| 101 | + crates/ec-av1/src/zz_control_probe.rs:3:let p = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/control-obu.obu"); | ||
| 102 | + FAIL [invariant 4]: pin-reading gates whose pins are not committed | ||
| 103 | + 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 | ||
| 104 | +pin_audit_exit=1 state=FAIL | ||
| 105 | +VERDICT=BLOCKED | ||
| 106 | +``` | ||
| 107 | + | ||
| 108 | +### Control 1b — the rustfmt-SPLIT real violation, the case the rule must not hide | ||
| 109 | + | ||
| 110 | +```rust | ||
| 111 | +#[test] | ||
| 112 | +fn a_real_gate_reading_through_the_gitignored_root_split_over_lines() { | ||
| 113 | + let p = concat!( | ||
| 114 | + env!("CARGO_MANIFEST_DIR"), | ||
| 115 | + "/../../fixtures/control-obu.obu" | ||
| 116 | + ); | ||
| 117 | + let _ = std::fs::read(p); | ||
| 118 | +} | ||
| 119 | +``` | ||
| 120 | + | ||
| 121 | +``` | ||
| 122 | + FAIL [invariant 4]: pin-reading gates whose pins are not committed | ||
| 123 | + 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 | ||
| 124 | +pin_audit_exit=1 state=FAIL | ||
| 125 | +``` | ||
| 126 | + | ||
| 127 | +Invariant 4 still catches it (its `ROOT_RE` spans newlines). Invariant 1 does | ||
| 128 | +NOT, because that scan is per-line — pre-existing behaviour, unchanged here and | ||
| 129 | +out of scope for this fix. | ||
| 130 | + | ||
| 131 | +## Control 2 (negative) — the scanner's own test data does not red | ||
| 132 | + | ||
| 133 | +Restored tree, no probe file: | ||
| 134 | + | ||
| 135 | +``` | ||
| 136 | +$ bash scripts/av1-suite-preflight.sh | ||
| 137 | +=== PIN-GATE PREFLIGHT (EC_REQUIRE_FIXTURES=0) | ||
| 138 | + pin gates: total=9 committed=22 uncommitted=0 ignored=0 assertless=0 | ||
| 139 | +pin_audit_exit=0 state=GREEN | ||
| 140 | +=== VERDICT | ||
| 141 | +VERDICT=GREEN | ||
| 142 | +``` | ||
| 143 | + | ||
| 144 | +Before the fix the same command read `total=11 … uncommitted=4` with four BADROW / | ||
| 145 | +BARDIR lines naming `gate_coverage.rs:1927 a_gate_using_the_old_shape` and | ||
| 146 | +`gate_coverage.rs:1966 shapes`. After it, the two invented gates are gone and | ||
| 147 | +`uncommitted` is 0 — the census now counts only real gates. | ||
| 148 | + | ||
| 149 | +## `--self-test` green (it is invariant 4's own control) | ||
| 150 | + | ||
| 151 | +``` | ||
| 152 | +$ python3 scripts/pin-gate-audit.py --self-test | ||
| 153 | +SELFTEST selftest_a_reads_a_pin crate_pin | ||
| 154 | +SELFTEST selftest_b_reads_a_pin crate_pin | ||
| 155 | +SELFTEST PASS a doc comment between two gates left both counted as crate_pin | ||
| 156 | +selftest_exit=0 | ||
| 157 | +``` | ||
| 158 | + | ||
| 159 | +Unchanged before and after, and the preflight runs it (it is the check at | ||
| 160 | +`verify-fixture-library.sh:332`). | ||
| 161 | + | ||
| 162 | +## The run required for acceptance | ||
| 163 | + | ||
| 164 | +``` | ||
| 165 | +$ bash scripts/av1-suite-preflight.sh | ||
| 166 | +pin_audit_exit=0 state=GREEN | ||
| 167 | +VERDICT=GREEN | ||
| 168 | +rungs_exit=0 ok_count=14 state=GREEN | ||
| 169 | +``` | ||
| 170 | + | ||
| 171 | +`rung_check` is GREEN here because the oracle source is present on this box; on a | ||
| 172 | +box without it the state is `not-run`, which is the separate expected state | ||
| 173 | +Main named and is unaffected by this change. | ||
| 174 | + | ||
| 175 | +## Not done | ||
| 176 | + | ||
| 177 | +1. The audit's own `--self-test` still plants only the PROSE shape (a comment | ||
| 178 | + between two gates). The new rule's own positive control — a scanner test whose | ||
| 179 | + `r#"..."#` input must NOT be counted — is proven here by the live tree | ||
| 180 | + (`total=11 → 9`, `uncommitted=4 → 0`), not by a committed self-test case. A | ||
| 181 | + committed case would need the self-test to build a raw string inside its | ||
| 182 | + synthetic crate; worth adding, not added here. | ||
| 183 | +2. Invariant 1 remains a per-LINE regex and so misses a rustfmt-split real | ||
| 184 | + violation (Control 1b). Pre-existing, not introduced or widened by this change. | ||
| 185 | +3. `crates/ec-av1/src/gate_coverage.rs` was NOT modified — the charter allowed it | ||
| 186 | + "only if strictly needed", and the general rule made it unnecessary. The | ||
| 187 | + synthetic gate is left exactly as the capability test wants it. | ||
scripts/pin-gate-audit.pymodified+106 -9
| @@ -86,6 +86,101 @@ def fn_bodies(text): | |||
| 86 | yield i + 1, name, "\n".join(lines[i:end]), attrs | 86 | yield i + 1, name, "\n".join(lines[i:end]), attrs |
| 87 | 87 | ||
| 88 | 88 | ||
| 89 | +RAW_STR_OPEN_RE = re.compile(r'(?:b?r|rb)(#*)"') | ||
| 90 | +CHAR_RE = re.compile(r"'(?:\\.|[^\\'])'") | ||
| 91 | + | ||
| 92 | + | ||
| 93 | +def _blank(out, lo, hi): | ||
| 94 | + """Blank [lo, hi) in place, preserving newlines so line numbers survive.""" | ||
| 95 | + for k in range(lo, hi): | ||
| 96 | + if out[k] != "\n": | ||
| 97 | + out[k] = " " | ||
| 98 | + | ||
| 99 | + | ||
| 100 | +def mask_embedded_source(text): | ||
| 101 | + """Blank the INTERIOR of every string literal that SPANS LINES. | ||
| 102 | + | ||
| 103 | + THE RULE: a match inside a string literal that spans lines is not a gate. | ||
| 104 | + Rust has no line-spanning non-raw string, so a literal containing a newline | ||
| 105 | + is EMBEDDED SOURCE -- the input to a scanner's own capability test, or a | ||
| 106 | + doc blob. `pin_inventory_tests` holds exactly that: a `r#"..."#` whose body | ||
| 107 | + is a synthetic gate reproducing the forbidden `/../../fixtures` root, fed | ||
| 108 | + to `pins_read` as DATA. Read as code it is a live violation, and it made | ||
| 109 | + this audit red on a tree with no real violation in it -- the audit reading | ||
| 110 | + its own test data, the mirror of the class the same script already fixed | ||
| 111 | + for prose ("a doc comment reproducing a root literal invented a gate"). | ||
| 112 | + | ||
| 113 | + Why this rule and not a path allowlist: a path allowlist is a second list | ||
| 114 | + of places to remember, and the next scanner test lands somewhere else. | ||
| 115 | + The property that actually separates the two cases is structural -- a real | ||
| 116 | + pin read names a path in a single-line literal; only test data wraps Rust | ||
| 117 | + source across lines -- and that property is checkable, not a location. | ||
| 118 | + | ||
| 119 | + Why it cannot hide a real violation: a non-raw literal aborts on the first | ||
| 120 | + newline, so it can only ever blank within one line, and a one-line literal | ||
| 121 | + holds no Rust source. A char literal is matched only when it really closes | ||
| 122 | + within three characters, so a LIFETIME (`&'a str`) is not mistaken for the | ||
| 123 | + start of a string and cannot swallow the rest of a line. | ||
| 124 | + """ | ||
| 125 | + out = list(text) | ||
| 126 | + i, n = 0, len(text) | ||
| 127 | + while i < n: | ||
| 128 | + m = RAW_STR_OPEN_RE.match(text, i) | ||
| 129 | + if m: | ||
| 130 | + close = '"' + m.group(1) | ||
| 131 | + end = text.find(close, m.end()) | ||
| 132 | + if end == -1: | ||
| 133 | + i = m.end() | ||
| 134 | + continue | ||
| 135 | + if "\n" in text[m.end():end]: | ||
| 136 | + _blank(out, m.end(), end) | ||
| 137 | + i = end + len(close) | ||
| 138 | + continue | ||
| 139 | + if text[i] == '"': | ||
| 140 | + j = i + 1 | ||
| 141 | + closed = None | ||
| 142 | + while j < n: | ||
| 143 | + c = text[j] | ||
| 144 | + if c == "\\": | ||
| 145 | + j += 2 | ||
| 146 | + continue | ||
| 147 | + if c == '"': | ||
| 148 | + closed = j | ||
| 149 | + break | ||
| 150 | + if c == "\n": | ||
| 151 | + break | ||
| 152 | + j += 1 | ||
| 153 | + if closed is not None: | ||
| 154 | + i = closed + 1 | ||
| 155 | + else: | ||
| 156 | + i += 1 | ||
| 157 | + continue | ||
| 158 | + c = CHAR_RE.match(text, i) | ||
| 159 | + i = c.end() if c else i + 1 | ||
| 160 | + return "".join(out) | ||
| 161 | + | ||
| 162 | + | ||
| 163 | +def code_of(body): | ||
| 164 | + """Comment-stripped, embedded-source-masked body -- the thing the shapes | ||
| 165 | + are matched against. Comment stripping removes PROSE reproducing a shape; | ||
| 166 | + this removes SOURCE reproducing a shape.""" | ||
| 167 | + code = re.sub(r"/\*.*?\*/", "", body, flags=re.S) | ||
| 168 | + code = "\n".join(l.split("//", 1)[0] for l in code.splitlines()) | ||
| 169 | + return mask_embedded_source(code) | ||
| 170 | + | ||
| 171 | + | ||
| 172 | +def read_source(path): | ||
| 173 | + """Read a Rust source with every line-spanning string literal's interior | ||
| 174 | + blanked. The mask has to happen at FILE level, not per body: `fn_bodies` | ||
| 175 | + finds `fn` lines by regex, so a synthetic gate inside a test's `r#"..."#` | ||
| 176 | + input is picked up as if it were a real fn, and its body -- the raw | ||
| 177 | + string's own text -- is then scanned as CODE. Masking first means that | ||
| 178 | + region is blank before any gate attribution happens, which is the only | ||
| 179 | + place the distinction can be made.""" | ||
| 180 | + with open(path, encoding="utf-8", errors="replace") as fh: | ||
| 181 | + return mask_embedded_source(fh.read()) | ||
| 182 | + | ||
| 183 | + | ||
| 89 | ROOT_RE = re.compile( | 184 | ROOT_RE = re.compile( |
| 90 | r'concat!\(\s*env!\("CARGO_MANIFEST_DIR"\)\s*,\s*"([^"]*)"\s*\)' | 185 | r'concat!\(\s*env!\("CARGO_MANIFEST_DIR"\)\s*,\s*"([^"]*)"\s*\)' |
| 91 | ) | 186 | ) |
| @@ -162,15 +257,14 @@ fn selftest_b_reads_a_pin() { | |||
| 162 | fh.write(body) | 257 | fh.write(body) |
| 163 | rows = [] | 258 | rows = [] |
| 164 | for c, p in sources(): | 259 | for c, p in sources(): |
| 165 | - text = open(p, encoding="utf-8", errors="replace").read() | 260 | + text = read_source(p) |
| 166 | rel = os.path.relpath(p, ROOT) | 261 | rel = os.path.relpath(p, ROOT) |
| 167 | for line, name, b, attrs in fn_bodies(text): | 262 | for line, name, b, attrs in fn_bodies(text): |
| 168 | if not any(a.startswith("#[test") for a in attrs): | 263 | if not any(a.startswith("#[test") for a in attrs): |
| 169 | continue | 264 | continue |
| 170 | if not name.startswith("selftest_"): | 265 | if not name.startswith("selftest_"): |
| 171 | continue | 266 | continue |
| 172 | - code = re.sub(r"/\*.*?\*/", "", b, flags=re.S) | 267 | + code = code_of(b) |
| 173 | - code = "\n".join(x.split("//", 1)[0] for x in code.splitlines()) | ||
| 174 | kind = "root-literal" if (ROOT_RE.search(code) or JOIN_RE.search(code)) else "crate_pin" | 268 | kind = "root-literal" if (ROOT_RE.search(code) or JOIN_RE.search(code)) else "crate_pin" |
| 175 | rows.append((name, kind)) | 269 | rows.append((name, kind)) |
| 176 | bad = [r for r in rows if r[1] != "crate_pin"] | 270 | bad = [r for r in rows if r[1] != "crate_pin"] |
| @@ -193,7 +287,7 @@ fn selftest_b_reads_a_pin() { | |||
| 193 | def main(): | 287 | def main(): |
| 194 | helpers = {} # fn name -> body (all fns in the tree) | 288 | helpers = {} # fn name -> body (all fns in the tree) |
| 195 | for crate, path in sources(): | 289 | for crate, path in sources(): |
| 196 | - text = open(path, encoding="utf-8", errors="replace").read() | 290 | + text = read_source(path) |
| 197 | for _line, name, body, _attrs in fn_bodies(text): | 291 | for _line, name, body, _attrs in fn_bodies(text): |
| 198 | helpers.setdefault(name, body) | 292 | helpers.setdefault(name, body) |
| 199 | 293 | ||
| @@ -201,7 +295,7 @@ def main(): | |||
| 201 | bad = [] | 295 | bad = [] |
| 202 | 296 | ||
| 203 | for crate, path in sources(): | 297 | for crate, path in sources(): |
| 204 | - text = open(path, encoding="utf-8", errors="replace").read() | 298 | + text = read_source(path) |
| 205 | rel = os.path.relpath(path, ROOT) | 299 | rel = os.path.relpath(path, ROOT) |
| 206 | for line, name, body, attrs in fn_bodies(text): | 300 | for line, name, body, attrs in fn_bodies(text): |
| 207 | if not any(a.startswith("#[test") for a in attrs): | 301 | if not any(a.startswith("#[test") for a in attrs): |
| @@ -209,8 +303,7 @@ def main(): | |||
| 209 | # Match every shape on a COMMENT-STRIPPED body. A doc comment that | 303 | # Match every shape on a COMMENT-STRIPPED body. A doc comment that |
| 210 | # reproduces a root literal to explain the shape it removed used to | 304 | # reproduces a root literal to explain the shape it removed used to |
| 211 | # invent a gate here, the same blindness invariant 1 had. | 305 | # invent a gate here, the same blindness invariant 1 had. |
| 212 | - code = re.sub(r"/\*.*?\*/", "", body, flags=re.S) | 306 | + code = code_of(body) |
| 213 | - code = "\n".join(l.split("//", 1)[0] for l in code.splitlines()) | ||
| 214 | root_lit = None | 307 | root_lit = None |
| 215 | root_kind = "none" | 308 | root_kind = "none" |
| 216 | var = None | 309 | var = None |
| @@ -283,8 +376,12 @@ def main(): | |||
| 283 | # The name list is bracketed, but comments sit between its | 376 | # The name list is bracketed, but comments sit between its |
| 284 | # items ("lane-rect r2: HORP strip ..."), so strip line | 377 | # items ("lane-rect r2: HORP strip ..."), so strip line |
| 285 | # comments before parsing the list and anchor on the format! | 378 | # comments before parsing the list and anchor on the format! |
| 286 | - # that consumes it. | 379 | + # that consumes it. It is `code` and not `body` that feeds |
| 287 | - body_nc = re.sub(r"//[^\n]*", "", body) | 380 | + # this: `code` is the comment-stripped, embedded-source-masked |
| 381 | + # text, and reading the RAW body here re-imported the shape | ||
| 382 | + # out of a scanner test's own `r#"..."#` input -- the same | ||
| 383 | + # gate resurrected through a different match. | ||
| 384 | + body_nc = code | ||
| 288 | for lit in LIST_RE.finditer(body_nc): | 385 | for lit in LIST_RE.finditer(body_nc): |
| 289 | items = re.findall(r'"([A-Za-z0-9._-]+)"', lit.group(1)) | 386 | items = re.findall(r'"([A-Za-z0-9._-]+)"', lit.group(1)) |
| 290 | if len(items) < 3: | 387 | if len(items) < 3: |
scripts/verify-fixture-library.shmodified+11 -2
| @@ -195,8 +195,17 @@ fi | |||
| 195 | # the difference. One such comment in crates/ec-av1 read as a live violation for | 195 | # the difference. One such comment in crates/ec-av1 read as a live violation for |
| 196 | # a whole round (found by the lane that fixed the real ones). | 196 | # a whole round (found by the lane that fixed the real ones). |
| 197 | forbidden=$(python3 - "$ROOT" <<'PYEOF' | 197 | forbidden=$(python3 - "$ROOT" <<'PYEOF' |
| 198 | -import os, re, sys | 198 | +import importlib.util, os, re, sys |
| 199 | root = sys.argv[1] | 199 | root = sys.argv[1] |
| 200 | +# SINGLE-SOURCE the rule: this scan (invariant 1) and the census (invariant 4, | ||
| 201 | +# scripts/pin-gate-audit.py) must not disagree about what counts as a gate, or | ||
| 202 | +# fixing one leaves the other red. Both strip comments AND mask line-spanning | ||
| 203 | +# string literals -- prose reproducing a shape and SOURCE reproducing a shape | ||
| 204 | +# are both data, not a gate. | ||
| 205 | +spec = importlib.util.spec_from_file_location( | ||
| 206 | + "pin_gate_audit", os.path.join(root, "scripts", "pin-gate-audit.py")) | ||
| 207 | +audit = importlib.util.module_from_spec(spec) | ||
| 208 | +spec.loader.exec_module(audit) | ||
| 200 | pat = re.compile(r'concat!\(\s*env!\("CARGO_MANIFEST_DIR"\)\s*,\s*"/\.\./\.\./fixtures/[^/"]*\.') | 209 | pat = re.compile(r'concat!\(\s*env!\("CARGO_MANIFEST_DIR"\)\s*,\s*"/\.\./\.\./fixtures/[^/"]*\.') |
| 201 | for crate in sorted(os.listdir(os.path.join(root, "crates"))): | 210 | for crate in sorted(os.listdir(os.path.join(root, "crates"))): |
| 202 | for sub in ("src", "tests"): | 211 | for sub in ("src", "tests"): |
| @@ -213,7 +222,7 @@ for crate in sorted(os.listdir(os.path.join(root, "crates"))): | |||
| 213 | except OSError: | 222 | except OSError: |
| 214 | continue | 223 | continue |
| 215 | text = re.sub(r"/\*.*?\*/", "", text, flags=re.S) | 224 | text = re.sub(r"/\*.*?\*/", "", text, flags=re.S) |
| 216 | - for i, line in enumerate(text.splitlines(), 1): | 225 | + for i, line in enumerate(audit.mask_embedded_source(text).splitlines(), 1): |
| 217 | code = line.split("//", 1)[0] | 226 | code = line.split("//", 1)[0] |
| 218 | if pat.search(code): | 227 | if pat.search(code): |
| 219 | print("{}:{}:{}".format(os.path.relpath(p, root), i, line.strip())) | 228 | print("{}:{}:{}".format(os.path.relpath(p, root), i, line.strip())) |