Merge lane-av1pinselftest: the audit self-test plants the shape that actually bit (a phantom gate inside a raw string)
Browse files at this commit2 changed files +133 -6
- lanes/av1pinselftest.report.md +101 -0
- scripts/pin-gate-audit.py +32 -6
lanes/av1pinselftest.report.mdadded+101 -0
| @@ -0,0 +1,101 @@ | |||
| 1 | +# lanes/av1pinselftest — the self-test now plants the shape that actually bit | ||
| 2 | + | ||
| 3 | +Branch `lane-av1pinselftest`, base main `5da8b247` (the merge of | ||
| 4 | +`lane-av1pinauditfix`). Scripts only. | ||
| 5 | + | ||
| 6 | +This closes the one item `lanes/av1pinauditfix.report.md` declared not-done: | ||
| 7 | +the audit's `--self-test` planted only the PROSE shape, so the new rule's | ||
| 8 | +negative control rested on the live tree's 11→9 / 4→0 count change rather than | ||
| 9 | +on a committed case. | ||
| 10 | + | ||
| 11 | +## What the control now plants | ||
| 12 | + | ||
| 13 | +A third synthetic gate whose body embeds a **raw string** containing a synthetic | ||
| 14 | +gate that reproduces the forbidden root literal — the exact shape | ||
| 15 | +`pin_inventory_tests` has in the real tree, and the shape that made the audit red: | ||
| 16 | + | ||
| 17 | +```rust | ||
| 18 | +#[test] | ||
| 19 | +fn selftest_c_embeds_a_raw_string_input() { | ||
| 20 | + let synthetic = r#" | ||
| 21 | + #[test] | ||
| 22 | + fn selftest_phantom_inside_a_raw_string() { | ||
| 23 | + let fixtures = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/phantom.obu"); | ||
| 24 | + check(&fixtures); | ||
| 25 | + } | ||
| 26 | +"#; | ||
| 27 | + let p = crate_pin("embedded-pin.obu"); | ||
| 28 | + helper(); | ||
| 29 | + assert!(!synthetic.is_empty() && !p.as_os_str().is_empty()); | ||
| 30 | +} | ||
| 31 | +``` | ||
| 32 | + | ||
| 33 | +**The phantom carries the `selftest_` prefix on purpose.** `self_test` skips any | ||
| 34 | +`fn` whose name does not start with `selftest_`, so a differently-named phantom | ||
| 35 | +would be filtered out and the control would pass for the wrong reason — the | ||
| 36 | +vacuity trap. With the prefix, a broken mask makes the phantom appear as a row | ||
| 37 | +and the control fails. | ||
| 38 | + | ||
| 39 | +Three assertions, all new: | ||
| 40 | + | ||
| 41 | +1. `selftest_c_embeds_a_raw_string_input` is present and classified `crate_pin` | ||
| 42 | + (it is a real gate and must not be lost); | ||
| 43 | +2. `selftest_phantom_inside_a_raw_string` is **absent** from the rows — `fn_bodies` | ||
| 44 | + must not resurrect it; | ||
| 45 | +3. no row's pin names contain `phantom` — the name must not leak either. | ||
| 46 | + | ||
| 47 | +## GREEN | ||
| 48 | + | ||
| 49 | +``` | ||
| 50 | +$ python3 scripts/pin-gate-audit.py --self-test | ||
| 51 | +SELFTEST selftest_a_reads_a_pin crate_pin golden3-pin.obu | ||
| 52 | +SELFTEST selftest_b_reads_a_pin crate_pin sbpart-pin.obu | ||
| 53 | +SELFTEST selftest_c_embeds_a_raw_string_input crate_pin embedded-pin.obu | ||
| 54 | +SELFTEST PASS a doc comment between two gates left both counted as crate_pin, and a raw-string input did not become a gate | ||
| 55 | +selftest_exit=0 | ||
| 56 | +``` | ||
| 57 | + | ||
| 58 | +## RED — mutation: the mask disabled in `read_source` | ||
| 59 | + | ||
| 60 | +```diff | ||
| 61 | +- return mask_embedded_source(fh.read()) | ||
| 62 | ++ return fh.read() # MUTATED: mask disabled | ||
| 63 | +``` | ||
| 64 | + | ||
| 65 | +``` | ||
| 66 | +$ python3 scripts/pin-gate-audit.py --self-test | ||
| 67 | +SELFTEST selftest_a_reads_a_pin crate_pin golden3-pin.obu | ||
| 68 | +SELFTEST selftest_b_reads_a_pin crate_pin sbpart-pin.obu | ||
| 69 | +SELFTEST selftest_c_embeds_a_raw_string_input crate_pin | ||
| 70 | +SELFTEST selftest_phantom_inside_a_raw_string root-literal embedded-pin.obu | ||
| 71 | +SELFTEST FAIL phantom_gate_counted=[('selftest_phantom_inside_a_raw_string', 'root-literal', ['embedded-pin.obu'])] phantom_name_leaked=[] reclassified=[('selftest_phantom_inside_a_raw_string', 'root-literal', ['embedded-pin.obu'])] missing=[] | ||
| 72 | +selftest_exit=1 | ||
| 73 | +``` | ||
| 74 | + | ||
| 75 | +The phantom is counted as a real `root-literal` gate — the original defect, | ||
| 76 | +reproduced inside the control. A second symptom shows up in the same run: | ||
| 77 | +`selftest_c_embeds_a_raw_string_input` now has an EMPTY name list, because | ||
| 78 | +`fn_bodies` attributed the raw string's `fn` as the last `fn` and cut c's body | ||
| 79 | +short. Restoring the mask restores both. | ||
| 80 | + | ||
| 81 | +## The run | ||
| 82 | + | ||
| 83 | +``` | ||
| 84 | +$ bash scripts/av1-suite-preflight.sh | ||
| 85 | + pin gates: total=9 committed=22 uncommitted=0 ignored=0 assertless=0 | ||
| 86 | +pin_audit_exit=0 state=GREEN | ||
| 87 | +rungs_exit=0 ok_count=14 state=GREEN | ||
| 88 | +VERDICT=GREEN | ||
| 89 | +``` | ||
| 90 | + | ||
| 91 | +`total=9 uncommitted=0` is unchanged from `5da8b247` — the control adds no gate | ||
| 92 | +to the census of the real tree; it runs entirely in the self-test's temp crate. | ||
| 93 | + | ||
| 94 | +## Not done | ||
| 95 | + | ||
| 96 | +1. **Invariant 1's per-line scan still misses a rustfmt-SPLIT real violation.** | ||
| 97 | + Pre-existing, unchanged here, and out of scope: invariant 4 catches that form. | ||
| 98 | +2. The self-test still plants no case for invariant 1's own scan (the | ||
| 99 | + `verify-fixture-library.sh` positive control is a single-line literal). The | ||
| 100 | + new rule is shared by both, so a mask regression reds invariant 4's control; | ||
| 101 | + invariant 1's has no raw-string case of its own. | ||
scripts/pin-gate-audit.pymodified+32 -6
| @@ -250,6 +250,25 @@ fn selftest_b_reads_a_pin() { | |||
| 250 | helper(); | 250 | helper(); |
| 251 | assert!(!p.as_os_str().is_empty()); | 251 | assert!(!p.as_os_str().is_empty()); |
| 252 | } | 252 | } |
| 253 | + | ||
| 254 | +// The SECOND shape, the one that made this audit RED on a tree with no real | ||
| 255 | +// violation in it: a scanner capability test whose INPUT is embedded source. | ||
| 256 | +// The phantom gate below carries the `selftest_` prefix on purpose -- the | ||
| 257 | +// filter above would drop a differently-named one and the control would pass | ||
| 258 | +// for the wrong reason. | ||
| 259 | +#[test] | ||
| 260 | +fn selftest_c_embeds_a_raw_string_input() { | ||
| 261 | + let synthetic = r#" | ||
| 262 | + #[test] | ||
| 263 | + fn selftest_phantom_inside_a_raw_string() { | ||
| 264 | + let fixtures = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/phantom.obu"); | ||
| 265 | + check(&fixtures); | ||
| 266 | + } | ||
| 267 | +"#; | ||
| 268 | + let p = crate_pin("embedded-pin.obu"); | ||
| 269 | + helper(); | ||
| 270 | + assert!(!synthetic.is_empty() && !p.as_os_str().is_empty()); | ||
| 271 | +} | ||
| 253 | """ | 272 | """ |
| 254 | path = os.path.join(d, "lib.rs") | 273 | path = os.path.join(d, "lib.rs") |
| 255 | try: | 274 | try: |
| @@ -266,17 +285,24 @@ fn selftest_b_reads_a_pin() { | |||
| 266 | continue | 285 | continue |
| 267 | code = code_of(b) | 286 | code = code_of(b) |
| 268 | kind = "root-literal" if (ROOT_RE.search(code) or JOIN_RE.search(code)) else "crate_pin" | 287 | kind = "root-literal" if (ROOT_RE.search(code) or JOIN_RE.search(code)) else "crate_pin" |
| 269 | - rows.append((name, kind)) | 288 | + singles = re.findall(r'crate_pin\(\s*"([^"]+)"', code) |
| 289 | + rows.append((name, kind, singles)) | ||
| 270 | bad = [r for r in rows if r[1] != "crate_pin"] | 290 | bad = [r for r in rows if r[1] != "crate_pin"] |
| 271 | missing = [n for n in ("selftest_a_reads_a_pin", "selftest_b_reads_a_pin") | 291 | missing = [n for n in ("selftest_a_reads_a_pin", "selftest_b_reads_a_pin") |
| 272 | if n not in [r[0] for r in rows]] | 292 | if n not in [r[0] for r in rows]] |
| 273 | - ok = not bad and not missing | 293 | + phantom = [r for r in rows if r[0] == "selftest_phantom_inside_a_raw_string"] |
| 274 | - for n, k in sorted(rows): | 294 | + leaked = [r for r in rows if any("phantom" in s for s in r[2])] |
| 275 | - print("SELFTEST\t{}\t{}".format(n, k)) | 295 | + missing = missing + ["selftest_c_embeds_a_raw_string_input"] \ |
| 296 | + if "selftest_c_embeds_a_raw_string_input" not in [r[0] for r in rows] else missing | ||
| 297 | + ok = not bad and not missing and not phantom and not leaked | ||
| 298 | + for n, k, s in sorted(rows): | ||
| 299 | + print("SELFTEST\t{}\t{}\t{}".format(n, k, ",".join(s))) | ||
| 276 | if ok: | 300 | if ok: |
| 277 | - print("SELFTEST\tPASS\ta doc comment between two gates left both counted as crate_pin") | 301 | + print("SELFTEST\tPASS\ta doc comment between two gates left both counted as " |
| 302 | + "crate_pin, and a raw-string input did not become a gate") | ||
| 278 | else: | 303 | else: |
| 279 | - print("SELFTEST\tFAIL\treclassified={} missing={}".format(bad, missing)) | 304 | + print("SELFTEST\tFAIL\tphantom_gate_counted={} phantom_name_leaked={} " |
| 305 | + "reclassified={} missing={}".format(phantom, leaked, bad, missing)) | ||
| 280 | return 0 if ok else 1 | 306 | return 0 if ok else 1 |
| 281 | finally: | 307 | finally: |
| 282 | globals()["ROOT"] = saved_root | 308 | globals()["ROOT"] = saved_root |