Skip to content

fix(discover): count expanded-value sudo RTK_DISABLED bypasses - #4414

Open
lesbass wants to merge 1 commit into
rtk-ai:developfrom
one-pr-a-day:fix/discover-sudo-rtk-disabled-expanded-env
Open

lesbass wants to merge 1 commit into
rtk-ai:developfrom
one-pr-a-day:fix/discover-sudo-rtk-disabled-expanded-env

Conversation

@lesbass

@lesbass lesbass commented Oct 3, 2026

Copy link
Copy Markdown

Summary

Closes #4412. rtk discover undercounted sudo RTK_DISABLED=$VAR … bypasses: with hooks.transparent_prefixes = ["sudo", "sudo -E"], sudo RTK_DISABLED=1 docker ps and RTK_DISABLED=1 sudo docker ps were counted as bypasses (#3808), but the same lines with an expanded value were not.

Root cause

strip_disabled_prefix_for_analytics (src/discover/registry.rs) walked raw lexer::tokenize tokens, which split one shell word at $: RTK_DISABLED=$CI becomes two tokens, RTK_DISABLED= and $CI. The walk treated $CI as the command word, found it unsupported, and fell back to strip_disabled_prefix, which does not peel sudo. The counterfactual was then judged against the sudo-wrapped line, so no savings were reported.

Fix

Walk lexer::coalesce_words instead, exactly as without_rtk_disabled in src/discover/mod.rs already does. Coalescing keeps the whole assignment as one word while still splitting on spaces. The existing operator/redirect/shellism boundary logic is preserved via the coalesced-word spans.

Tests

  • test_strip_disabled_prefix_for_analytics: added $CI variants for sudo-first and sudo-after, plus RTK_DISABLED=$CI docker ps.
  • test_disabled_segment_is_judged_as_typed_without_the_bypass: added end-to-end assertions that sudo RTK_DISABLED=$CI docker ps and RTK_DISABLED=$CI sudo docker ps count as bypasses when sudo is transparent.

Verification

cargo fmt --all --check   # pass
cargo clippy --all-targets # pass
cargo test                # 3843 passed; 0 failed

A missed count, not a wrong one: this only adds lines that were previously omitted from the RTK_DISABLED bucket.

tokenize splits RTK_DISABLED=$CI into two tokens (RTK_DISABLED= and $CI),
so strip_disabled_prefix_for_analytics mistook $CI for the command word,
found it unsupported, and fell back to strip_disabled_prefix, which never
peels sudo. Walk coalesced words instead, keeping the whole assignment as
one word, exactly as without_rtk_disabled already does.

Fixes rtk-ai#4412
@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added analytics bug Something isn't working discover labels Oct 3, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes an undercounting bug in rtk discover where sudo RTK_DISABLED=$VAR ... commands with expanded (variable) values weren't counted as bypasses, because the raw tokenizer split the assignment at $ and lost the sudo-peeling logic. The fix switches strip_disabled_prefix_for_analytics to walk coalesced words instead of raw tokens, matching the approach already used elsewhere, and adds tests covering the expanded-value cases.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4412


Analyzed automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

analytics bug Something isn't working discover

Projects

None yet

Development

Successfully merging this pull request may close these issues.

discover: sudo RTK_DISABLED=$VAR … is not detected as a bypass when sudo is a transparent prefix

1 participant