Skip to content

test(analyses): give the bot-filter guard one matcher and one count - #276

Merged
emrecdr merged 1 commit into
mainfrom
test/bot-filter-guard-one-matcher
Aug 14, 2026
Merged

test(analyses): give the bot-filter guard one matcher and one count#276
emrecdr merged 1 commit into
mainfrom
test/bot-filter-guard-one-matcher

Conversation

@emrecdr

@emrecdr emrecdr commented Aug 14, 2026

Copy link
Copy Markdown
Owner

A /simplify review pass over #274 (four independent angles: reuse, simplification, efficiency, altitude). Three of the four converged on the same root cause; each finding below was verified against source before acting.

One matcher, not two

Widening the guard to read whole files added collapse_offsets but left collapses_bot_per_canonical in place. Call sites confirmed: the guard calls only the former, the self-test calls only the latter.

So the anti-vacuity test — the one whose whole purpose is to prove the guard can fail — was proving a copy correct while the code that decides the gate went unexercised. Either could regress with CI green. That is the failure the module doc warns about, one layer down inside the test written to prevent it.

The self-test now runs against collapse_offsets directly, and the duplicate is gone.

Two gaps that closed with it

  • The wrapped-call layout that test(analyses): scan the whole file for the bot-filter collapse #274 exists to catch had no committed test. The repro that found the bug was exploratory. It is now a fixture.
  • The byte-vs-char offset fix had no test either, despite the commit message crediting a regression test for catching it — that test was never committed. There is now one, asserting the offset lands on the construct, which a char-indexed table would fail.

A double count, proven not argued

bool_or( is a substring of havingnotbool_or(, so HAVING NOT BOOL_OR(is_bot) matched both banned shapes at two different offsets and was reported twice — and the sort/dedup could not collapse them, since the offsets genuinely differ.

Rather than trust the review, the assertion was added first and run against the shipped code:

before: assertion `left == right` failed  left: 2  right: 1
after:  3 passed; 0 failed

Both rules now anchor on the same BOOL_OR token, so the dedup does what it looks like it does.

Verification

  • Count assertion fails at 2 before, passes at 1 after.
  • Planted wrapped call → guard fails naming ownership.rs:33: BOOL_OR(, the line the construct sits on. File restored.
  • cargo fmt --all --check = 0; cargo clippy --workspace --all-targets --all-features -- -D warnings = 0 (the full CI invocation — a narrower run missed items_after_statements here); guard tests = 0.

Also

Dropped a .max(start) that cannot change its result (a push always grows the string) and hoisted a loop-invariant path strip.

Left alone: workspace_root is duplicated byte-for-byte across eleven guard tests, with the file walker and violation-reporting boilerplate close behind. Real, but pre-existing and cross-cutting — folding it in here would turn a targeted cleanup into an unrelated refactor across eight-plus files.

Widening the guard to read whole files left the per-line matcher in place.
It stayed compiled and stayed tested, but nothing called it — so the pinned
spellings proved a copy correct while the code deciding the gate went
unexercised. Two implementations of one rule, either able to drift with CI
green: the failure the module doc warns about, one layer down inside the
test written to prevent it.

There is now a single matcher. The spelling cases run against it, joined by
the wrapped-call layout the widening existed for, and by a case that pins
the reported location — multi-byte prose ahead of a match is what separates
a byte-indexed offset table from a char-indexed one, and that fix had
shipped with no test at all.

Making the self-test real surfaced a double count. `bool_or(` is a substring
of `havingnotbool_or(`, so `HAVING NOT BOOL_OR(is_bot)` matched both banned
shapes at two offsets and was reported twice, overstating how much there was
to fix; the sort-and-dedup that looked like it guaranteed uniqueness was
comparing distinct offsets and could not collapse them. Both rules now
anchor on the same `BOOL_OR` token, so the dedup does what it appears to.

Proven against the shipped code rather than argued: the count assertion was
added first and failed at two, then passed at one. A wrapped call planted in
the scanned directory fails the guard naming `ownership.rs` and the line the
construct is written on. Also drops a `.max(start)` that could not change
its result — a push always grows the string — and hoists a loop-invariant
path strip.

Found by a reuse/simplification/efficiency/altitude review pass; the
cross-file duplication it also found (`workspace_root` in eleven guard
tests) is left alone as a separate concern.
@emrecdr
emrecdr merged commit fbc9c93 into main Aug 14, 2026
14 checks passed
@emrecdr
emrecdr deleted the test/bot-filter-guard-one-matcher branch August 14, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants