rouse-context/scripts
monkopedia-coder d6b7bf7454
Share one anchoring helper across the grep gates (#597) (#697)
Three gates shipped the same defect -- a post-filter meant for ONE field of
`grep`'s `path:line:content` output, applied unanchored to the whole line, so
real violations dropped silently out of the results while the gate reported
clean (#577/#588, #590/#593, #594/#598). This does #597's recommended cheap
half: one small library with the two anchors as named functions and the
reasoning written down once.

`scripts/lib/gate-filters.sh`:

  skip_comment_continuations   content field   ^[^:]*:[0-9]+:[[:space:]]*\*
  exempt_path <basename>       path field      ^([^:]*/)?<basename>:[0-9]+:

Two functions, not one parameterised regex, on purpose: the three instances were
two DIFFERENT anchor shapes, and the bug each time was a category error --
applying a field-specific filter to the whole line -- not a typo. Naming the
field is the remedy. No gate framework; the grep-then-filter shape is fine.

Converted: check-no-production-runblocking.sh, check-no-manual-json.sh.
Deferred: check-no-sensitive-logging.sh, because #692 / PR #695 is live in that
exact file; tracked as #696. check-zombie-screens.sh and
check-apk-distribution.sh have no post-filter of this shape and deliberately do
not source the library.

THE LOAD-BEARING PART IS A COMMENT

The helper is not what caught these bugs, and the file says so before it says
anything about anchoring: every scripts/check-*.sh MUST ship a matching
scripts/tests/<gate>-test.sh wired into CI, because the harness -- not the
shared filter -- is what catches an unanchored post-filter. The same pointer
sits above the `source` line in each converted gate, since a fourth gate will
start life as a copy of a third.

REVIEW RECORD

Reviewed at ec5fee37 (changes requested) and c45035b4 (approved).

The first pass blocked on the library's own header: it documented a calling
convention both of its call sites abandoned in the same PR -- `|| true` on the
pipeline and `$(git rev-parse --show-toplevel)` resolution, against the gates'
`set +e` bracket and `${BASH_SOURCE[0]}`. Transcribed verbatim into a gate and
run through the phase-1 invocation check-shell-lint.sh uses (shellcheck 0.11.0,
-o check-extra-masked-returns,check-set-e-suppressed), the documented example
produced 3 findings and exit 1: SC2312 on the source line, SC2310 twice on the
pipeline. A shared library asserting a false property about itself is the exact
failure mode this file exists to end. c45035b4 corrects it -- comment-only, 14
executable lines identical -- and the corrected example is exit 0 / 0 findings
under the same harness, with the old example retained as a positive control so
the pass means something.

Behaviour preservation was established on a seeded probe corpus planted
identically at ac1b0284 and at the head, since the real tree is clean and
exercises none of the filter: stdout+stderr+exit byte-identical per gate, and
non-vacuous -- both `: *`-carrying real violations survive, nested
AuditDetailScreen.kt is exempt, while MyAuditDetailScreen.kt,
AuditDetailScreenTest.kt and a file that merely names the exempt file stay
reported. All seven pre-existing self-test logs byte-identical; suite 91 -> 111
`ok:` lines. check-shell-lint-test.sh is red identically on both sides for an
environmental reason (actionlint absent locally), not a regression.

One finding worth keeping, because this PR's subject is a shared filter whose
failure mode is being silently wrong: during mutation testing of
gate-filters-test.sh, the dot-escaping mutation first came back GREEN. The test
had not passed -- the `sed` anchor never matched, so nothing was mutated. A
mutation that never applied is indistinguishable from a test with no teeth, and
the two conclusions are opposite. Re-applied with the substitution verified, it
goes red as it should. All six mutations are red: unanchored content filter,
unanchored path filter, the `^[^:]*<base>:[0-9]+:` near-miss #594 recommended
and #598 rejected, dot escaping removed, basename guard removed, and both
filters replaced by `cat`. M1 fails only content-field cases and M2/M3 only
path-field cases, so the two anchor shapes are genuinely discriminated.

Per #657's policy the `|| true` pipelines became `set +e` brackets rather than
`# shellcheck disable=` comments.

Closes #597
2026-09-03 00:31:25 -04:00
..
lib Share one anchoring helper across the grep gates (#597) (#697) 2026-09-03 00:31:25 -04:00
tests Share one anchoring helper across the grep gates (#597) (#697) 2026-09-03 00:31:25 -04:00
backfill-relay-secrets.sh Make a partial secret backfill fail loudly instead of exiting 0 (#686) (#693) 2026-09-02 23:23:12 -04:00
check-apk-distribution.sh Triage the masked-return findings and enable the two checks (#657) (#682) 2026-09-02 13:59:17 -04:00
check-no-manual-json.sh Share one anchoring helper across the grep gates (#597) (#697) 2026-09-03 00:31:25 -04:00
check-no-production-runblocking.sh Share one anchoring helper across the grep gates (#597) (#697) 2026-09-03 00:31:25 -04:00
check-no-sensitive-logging.sh Cover authorization codes in the sensitive-logging gate (#596) (#690) 2026-09-02 23:55:27 -04:00
check-roborazzi-coverage.sh ci: verify the Roborazzi goldens, and prove the check can go red (#628) (#629) 2026-08-28 08:01:25 -04:00
check-roborazzi-step-order.sh Make the step-order gate report an unreadable jobs: block (#678) (#694) 2026-09-03 00:03:17 -04:00
check-shell-lint.sh Triage the masked-return findings and enable the two checks (#657) (#682) 2026-09-02 13:59:17 -04:00
check-zombie-screens.sh Triage the masked-return findings and enable the two checks (#657) (#682) 2026-09-02 13:59:17 -04:00
production-source-dirs.sh Triage the masked-return findings and enable the two checks (#657) (#682) 2026-09-02 13:59:17 -04:00