test(analyses): give the bot-filter guard one matcher and one count - #276
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
/simplifyreview 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_offsetsbut leftcollapses_bot_per_canonicalin 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_offsetsdirectly, and the duplicate is gone.Two gaps that closed with it
A double count, proven not argued
bool_or(is a substring ofhavingnotbool_or(, soHAVING NOT BOOL_OR(is_bot)matched both banned shapes at two different offsets and was reported twice — and thesort/dedupcould not collapse them, since the offsets genuinely differ.Rather than trust the review, the assertion was added first and run against the shipped code:
Both rules now anchor on the same
BOOL_ORtoken, so the dedup does what it looks like it does.Verification
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 misseditems_after_statementshere); 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_rootis 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.