Repository navigation
test(filters): assert all builtin toml match_command patterns are anchored - #3807
Conversation
KuSh
left a comment
There was a problem hiding this comment.
Test-only diff (31 lines) — the anchor fix itself already landed in cab2283. I validated it in a throwaway worktree: merges cleanly onto latest develop, full suite green (2931 passed), and both new tests are non-vacuous — reverting src/filters/liquibase.toml to the unanchored (?:^|/)liquibase(?:\s|$) makes both fail. So the guards do catch the exact bug from #3757.
No correctness issues. Requesting changes on four coverage gaps, three of them empirically verified — the anchor assertion is weaker than the class of pattern it's meant to prevent, the discover test largely tests a path other than the one it claims, and #3757's required /usr/bin/liquibase update case is missing (and behaves opposite to what the issue states).
|
Added direct built-in TOML coverage so the Liquibase tests cannot be bypassed by the native registry or RTK_NO_TOML. The anchor check now rejects top-level alternation, and the current path-qualified behavior is pinned explicitly. Formatting, Linux clippy, and all three focused regression tests pass. |
An unanchored top-level branch matches a path component or wrapper argument mid-command, so a filter selecting on argv[0] activates on `timeout 5 /usr/bin/liquibase update` and rewrites the wrapper. Gate both loaders on a shared `is_fully_anchored` predicate, which splits on top-level `|` and requires every branch to be `^`-anchored (inline flag groups such as `(?i)` are stripped first). This covers project-local and global filters, which are user-authored and were previously unguarded; the built-in invariant test reads raw patterns so the gate cannot hide an unanchored built-in from it. Cover the rewrite path end to end with a bare `jj` control, fold the wrapper cases into the existing liquibase path test, and accept per-branch anchoring such as `^pnpm\b|^npm\b`. Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
Verified in a dedicated worktree. All four round-one comments are fixed, each confirmed by mutation rather than by reading:
- Reverting
src/filters/liquibase.tomlto the unanchored(?:^|/)liquibase(?:\s|$)fails the guards. - Setting it to
^liquibase\b|/liquibase\b— the top-level-alternation case that passed the oldstarts_with('^')check — now fails too. - Both still fail with
RTK_NO_TOML=1, so the coverage is no longer env-dependent.
cargo fmt --all, cargo clippy --all-targets (clean) and cargo test --all pass, both on the branch and merged onto the latest develop (2981 passing).
I pushed one commit (3522477) addressing the follow-up review findings:
- The anchoring rule moved into a shared
is_fully_anchoredpredicate applied at load time in both loaders, so it now covers project-local and global filters. Those are user-authored and were unguarded — which is where #3757 said the durable fix belonged. Unanchored filters are skipped with a warning instead of misfiring. - The built-in invariant test now reads raw patterns from
BUILTIN_TOML, so the new gate cannot hide an unanchored built-in from the assertion. - Per-branch anchoring (
^pnpm\b|^npm\b) and inline flags ((?i)^tool\b) are accepted rather than rejected with a misleading message. - The rewrite path is covered end to end through
jj(TOML-only, never in theRULEStable), with the bare case as a positive control so the wrapper assertions cannot pass vacuously. - The wrapper cases are folded into the existing
test_liquibase_match_command_ignores_path_substring, next to its rationale comment.
Summary
Pins that every built-in TOML filter
match_commandis anchored on every top-level branch, so a pattern cannot match a path component or subcommand mid-line. A filter selects on argv[0], but its regex runs against the whole command line, so an unanchored branch makestimeout 5 /usr/bin/liquibase updateactivate the liquibase filter and rewrite the wrapper.The anchoring rule is now enforced at load time by a shared
is_fully_anchoredpredicate applied to both loaders (match_patterns_inandTomlFilterRegistry::parse_and_compile), so it also covers project-local and global filters. Those are user-authored and were previously unguarded — which is where #3757 said the durable fix belonged. Unanchored filters are skipped with a warning rather than silently misfiring.Refs #3757
Validation
test_builtin_all_filters_match_command_anchored— checks every built-in filter, reading raw patterns fromBUILTIN_TOMLso the load-time gate cannot hide an unanchored built-in from the assertion. Accepts per-branch anchoring (^pnpm\b|^npm\b) and inline flags ((?i)^tool\b); rejects^liquibase\b|/liquibase\band(?:^|/)liquibase(?:\s|$).test_unanchored_user_filter_is_rejected_by_both_loaders— pins that a user-authored unanchored filter is dropped by both load paths, keepingMATCH_SETand the compiled registry in agreement.test_liquibase_match_command_ignores_path_substring— extended with the wrapper cases (timeout,nohup) alongside the existing path-substring assertions and their rationale comment.test_toml_filter_rewrites_bare_command_but_not_wrapped_invocations— exercises the rewrite path end to end viajj, which is covered only by a TOML filter and never by the nativeRULEStable. The bare case acts as a positive control so the wrapper assertions cannot pass vacuously.test_path_qualified_liquibase_is_not_rewritten— pins the currentNonefor/usr/bin/liquibase update, with a comment recording that this diverges from Unanchoredmatch_commandinliquibase.tomlrewrites any command containing/liquibase#3757's requested behavior.cargo fmt --all,cargo clippy --all-targets(clean),cargo test --all(all passing), verified both on this branch and merged onto the latestdevelop.Note on #3757
Changed
ClosestoRefs. That issue's third required-coverage bullet asks for/usr/bin/liquibase updateto still be rewritten; this branch pins the currentNoneas a characterization test instead.That
Noneis itself a bug, tracked in #3757 rather than fixed here.classify_commandcorrectly reports the command asSupported— it is a liquibase invocation and RTK can filter it — but the rewrite path matchesRULES.rewrite_prefixesagainst the un-normalizedcmd_part, finds no prefix, and drops it. So every path-qualified invocation of every supported command silently skips filtering (/usr/bin/grep,/usr/bin/makebehave the same), andrtk discoveradvertises an optimization the hook then declines.The fix is to normalize
cmd_partbefore that match, which is a behavior change beyond this PR's test-and-guard scope. When it lands,test_path_qualified_liquibase_is_not_rewrittenshould be updated to assert the rewrite rather than deleted, so the path-qualified case stays covered. #3757 stays open until then.