From c1b62f2d1c99cf7d1326dee5a5b59e8e68e034ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 30 Sep 2026 02:32:41 +0300 Subject: [PATCH] scripts: plant the raw-string shape in the pin audit's own self-test Closes the not-done from lane-av1pinauditfix: --self-test planted only the PROSE shape, so the new rule's negative control rested on the live tree's 11 -> 9 / 4 -> 0 count change instead of on a committed case. A mask regression would have gone unnoticed. A third synthetic gate embeds a raw string containing a synthetic gate that reproduces the forbidden root literal -- the exact shape pin_inventory_tests has in the real tree, and the one that made the audit red on a tree with no real violation in it. The phantom carries the `selftest_` prefix ON PURPOSE. self_test skips any fn whose name does not start with selftest_, so a differently-named phantom would be filtered out and the control would pass for the wrong reason. With the prefix a broken mask makes the phantom appear as a row and the control fails. Three assertions: the real gate is present and still crate_pin; the phantom gate is absent from the rows; and no row's pin names contain `phantom`. Mutation -- mask disabled in read_source: SELFTEST selftest_phantom_inside_a_raw_string root-literal SELFTEST FAIL phantom_gate_counted=[('selftest_phantom_inside_a_raw_string', 'root-literal', ...)] selftest_exit=1 which also shows a second symptom: the real gate's name list goes EMPTY, because fn_bodies attributed the raw string's `fn` and cut its body short. Restored, both are green again. Green: SELFTEST PASS a doc comment between two gates left both counted as crate_pin, and a raw-string input did not become a gate selftest_exit=0 pin gates: total=9 committed=22 uncommitted=0 ignored=0 assertless=0 pin_audit_exit=0 state=GREEN VERDICT=GREEN total=9 uncommitted=0 is unchanged from 5da8b247: the control runs entirely in the self-test's temp crate and adds no gate to the census of the real tree. --- lanes/av1pinselftest.report.md | 101 +++++++++++++++++++++++++++++++++ scripts/pin-gate-audit.py | 38 +++++++++++-- 2 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 lanes/av1pinselftest.report.md diff --git a/lanes/av1pinselftest.report.md b/lanes/av1pinselftest.report.md new file mode 100644 index 00000000..f2e6786b --- /dev/null +++ b/lanes/av1pinselftest.report.md @@ -0,0 +1,101 @@ +# lanes/av1pinselftest — the self-test now plants the shape that actually bit + +Branch `lane-av1pinselftest`, base main `5da8b247` (the merge of +`lane-av1pinauditfix`). Scripts only. + +This closes the one item `lanes/av1pinauditfix.report.md` declared not-done: +the audit's `--self-test` planted only the PROSE shape, so the new rule's +negative control rested on the live tree's 11→9 / 4→0 count change rather than +on a committed case. + +## What the control now plants + +A third synthetic gate whose body embeds a **raw string** containing a synthetic +gate that reproduces the forbidden root literal — the exact shape +`pin_inventory_tests` has in the real tree, and the shape that made the audit red: + +```rust +#[test] +fn selftest_c_embeds_a_raw_string_input() { + let synthetic = r#" + #[test] + fn selftest_phantom_inside_a_raw_string() { + let fixtures = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/phantom.obu"); + check(&fixtures); + } +"#; + let p = crate_pin("embedded-pin.obu"); + helper(); + assert!(!synthetic.is_empty() && !p.as_os_str().is_empty()); +} +``` + +**The phantom carries the `selftest_` prefix on purpose.** `self_test` skips any +`fn` whose name does not start with `selftest_`, so a differently-named phantom +would be filtered out and the control would pass for the wrong reason — the +vacuity trap. With the prefix, a broken mask makes the phantom appear as a row +and the control fails. + +Three assertions, all new: + +1. `selftest_c_embeds_a_raw_string_input` is present and classified `crate_pin` + (it is a real gate and must not be lost); +2. `selftest_phantom_inside_a_raw_string` is **absent** from the rows — `fn_bodies` + must not resurrect it; +3. no row's pin names contain `phantom` — the name must not leak either. + +## GREEN + +``` +$ python3 scripts/pin-gate-audit.py --self-test +SELFTEST selftest_a_reads_a_pin crate_pin golden3-pin.obu +SELFTEST selftest_b_reads_a_pin crate_pin sbpart-pin.obu +SELFTEST selftest_c_embeds_a_raw_string_input crate_pin embedded-pin.obu +SELFTEST PASS a doc comment between two gates left both counted as crate_pin, and a raw-string input did not become a gate +selftest_exit=0 +``` + +## RED — mutation: the mask disabled in `read_source` + +```diff +- return mask_embedded_source(fh.read()) ++ return fh.read() # MUTATED: mask disabled +``` + +``` +$ python3 scripts/pin-gate-audit.py --self-test +SELFTEST selftest_a_reads_a_pin crate_pin golden3-pin.obu +SELFTEST selftest_b_reads_a_pin crate_pin sbpart-pin.obu +SELFTEST selftest_c_embeds_a_raw_string_input crate_pin +SELFTEST selftest_phantom_inside_a_raw_string root-literal embedded-pin.obu +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=[] +selftest_exit=1 +``` + +The phantom is counted as a real `root-literal` gate — the original defect, +reproduced inside the control. A second symptom shows up in the same run: +`selftest_c_embeds_a_raw_string_input` now has an EMPTY name list, because +`fn_bodies` attributed the raw string's `fn` as the last `fn` and cut c's body +short. Restoring the mask restores both. + +## The run + +``` +$ bash scripts/av1-suite-preflight.sh + pin gates: total=9 committed=22 uncommitted=0 ignored=0 assertless=0 +pin_audit_exit=0 state=GREEN +rungs_exit=0 ok_count=14 state=GREEN +VERDICT=GREEN +``` + +`total=9 uncommitted=0` is unchanged from `5da8b247` — the control adds no gate +to the census of the real tree; it runs entirely in the self-test's temp crate. + +## Not done + +1. **Invariant 1's per-line scan still misses a rustfmt-SPLIT real violation.** + Pre-existing, unchanged here, and out of scope: invariant 4 catches that form. +2. The self-test still plants no case for invariant 1's own scan (the + `verify-fixture-library.sh` positive control is a single-line literal). The + new rule is shared by both, so a mask regression reds invariant 4's control; + invariant 1's has no raw-string case of its own. diff --git a/scripts/pin-gate-audit.py b/scripts/pin-gate-audit.py index 1450eed4..a0794dc7 100755 --- a/scripts/pin-gate-audit.py +++ b/scripts/pin-gate-audit.py @@ -250,6 +250,25 @@ fn selftest_b_reads_a_pin() { helper(); assert!(!p.as_os_str().is_empty()); } + +// The SECOND shape, the one that made this audit RED on a tree with no real +// violation in it: a scanner capability test whose INPUT is embedded source. +// The phantom gate below carries the `selftest_` prefix on purpose -- the +// filter above would drop a differently-named one and the control would pass +// for the wrong reason. +#[test] +fn selftest_c_embeds_a_raw_string_input() { + let synthetic = r#" + #[test] + fn selftest_phantom_inside_a_raw_string() { + let fixtures = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/phantom.obu"); + check(&fixtures); + } +"#; + let p = crate_pin("embedded-pin.obu"); + helper(); + assert!(!synthetic.is_empty() && !p.as_os_str().is_empty()); +} """ path = os.path.join(d, "lib.rs") try: @@ -266,17 +285,24 @@ fn selftest_b_reads_a_pin() { continue code = code_of(b) kind = "root-literal" if (ROOT_RE.search(code) or JOIN_RE.search(code)) else "crate_pin" - rows.append((name, kind)) + singles = re.findall(r'crate_pin\(\s*"([^"]+)"', code) + rows.append((name, kind, singles)) bad = [r for r in rows if r[1] != "crate_pin"] missing = [n for n in ("selftest_a_reads_a_pin", "selftest_b_reads_a_pin") if n not in [r[0] for r in rows]] - ok = not bad and not missing - for n, k in sorted(rows): - print("SELFTEST\t{}\t{}".format(n, k)) + phantom = [r for r in rows if r[0] == "selftest_phantom_inside_a_raw_string"] + leaked = [r for r in rows if any("phantom" in s for s in r[2])] + missing = missing + ["selftest_c_embeds_a_raw_string_input"] \ + if "selftest_c_embeds_a_raw_string_input" not in [r[0] for r in rows] else missing + ok = not bad and not missing and not phantom and not leaked + for n, k, s in sorted(rows): + print("SELFTEST\t{}\t{}\t{}".format(n, k, ",".join(s))) if ok: - print("SELFTEST\tPASS\ta doc comment between two gates left both counted as crate_pin") + print("SELFTEST\tPASS\ta doc comment between two gates left both counted as " + "crate_pin, and a raw-string input did not become a gate") else: - print("SELFTEST\tFAIL\treclassified={} missing={}".format(bad, missing)) + print("SELFTEST\tFAIL\tphantom_gate_counted={} phantom_name_leaked={} " + "reclassified={} missing={}".format(phantom, leaked, bad, missing)) return 0 if ok else 1 finally: globals()["ROOT"] = saved_root