Skip to content

test(branding): add allowlist-style branding scan + pin ~50 known-debt strings (#67) - #71

Merged
thehoff merged 1 commit into
developfrom
test/branding-lint-allowlist-67
May 18, 2026
Merged

thehoff merged 1 commit into
developfrom
test/branding-lint-allowlist-67

Conversation

@thehoff

@thehoff thehoff commented May 18, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #67. Replaces regression-style branding lint (catch known leak patterns) with allowlist-style scan (catch ANY case-insensitive \brtk\b in src/*.rs not matching an explicit rule). Future leaks fail at test time, not at user-report time.

What it catches

17 named allowlist rules covering:

  • Filesystem paths (.rtk/filters.toml, ~/.rtk/, ...)
  • RTK_* env var identifiers
  • Upstream attribution (rtk-ai/rtk, RTK AI Labs, [email protected])
  • SQLite rtk_cmd column name
  • format!("rtk X") tracking labels in src/discover/registry.rs only (consumed by hook caller — see scope: standardise rewrite_command output prefix ( vs ) #62)
  • vec!["rtk", ...] argv[0] test fixtures
  • Per-line // branding-lint: allow legacy markers (preserved)
  • ALLOWED_FUNCTION_PREFIXES for legacy-handling helpers (preserved)
  • Constant/type identifiers (RTK_MD, RtkBlockUpsert, etc.)
  • Comment-only mentions of issue numbers / commit hashes (preserved)

Known-debt catalogue (~50 strings)

Agent B's broad scan caught ~50 user-visible RTK strings the rebrand sweep missed. All pinned in a KNOWN_UNBRANDED_TEXT_NEEDLES allowlist so the test passes on develop, but any new leak class outside this list fails immediately. Notable categories worth follow-up cleanup:

  1. src/discover/report.rs — "RTK Discover", "Already using RTK:", table headers
  2. src/analytics/cc_economics.rs — "RTK Cmds", "RTK compresses CLI outputs"
  3. src/analytics/session_cmd.rs — "RTK Session Overview", "RTK", "Adoption" headers
  4. src/analytics/gain.rs — "RTK Parse Failures"
  5. src/hooks/init.rs — uninstall flow: "RTK was not installed", "would uninstall RTK", etc.
  6. src/core/telemetry_cmd.rs — "RTK collects anonymous usage metrics"
  7. src/cmds/cloud/container.rs — "Usage: rtk docker logs", "Usage: rtk kubectl logs"
  8. src/main.rs — "Usage: rtk proxy", "Use: rtk init --agent X"
  9. src/hooks/integrity.rs — "To restore: rtk init -g", "To inspect: rtk verify"
  10. src/cmds/git/git.rs — "[full diff: rtk git diff --no-compact]"
  11. src/parser/mod.rs — [RTK:PASSTHROUGH]/[RTK:DEGRADED] parser markers
  12. src/hooks/hook_cmd.rs — [rtk hook] stderr prefix
  13. src/learn/report.rs — "RTK Learn" header
  14. src/core/telemetry.rs — X-RTK-Token HTTP header (programmatic — probably keep)

A clean-up round is suitable for a separate PR; this PR is the detection layer.

Self-tests

4 leak-simulation tests assert the allowlist correctly REJECTS deliberate leaks (init-message-style, error-prefix-style, novel eprintln!, novel panic!). A future "too broad" rule edit fails fast.

Verified

  • cargo test --test branding_lint — 4 pass, runtime 0.24s
  • cargo test --bin contextcrawler — 2119 pass / 0 fail
  • Existing branding_lint_no_forbidden_upstream_literals_in_src retained as the regression-style backstop
  • Existing branding_lint_config_files_pin_canonical_package_name retained
  • Only file changed: tests/branding_lint.rs (+890 lines)

Closes #67.

Adds `branding_lint_no_unrecognised_rtk_references_in_src` — an
allowlist-style scan complementing the existing `FORBIDDEN_TOKENS`
regression backstop. The new test fails on ANY case-insensitive
`\brtk\b` in `src/*.rs` not matched by an explicit named allowlist
rule, catching new leak classes at test time instead of via user
report (the v0.1.8 → v0.1.9 whack-a-mole that drove this issue).

Allowlist categories (17 named rules):
  - filesystem-path (.rtk/, ~/.rtk/, hook scripts, integrity sidecar)
  - env-var-shape (any `RTK_*` identifier)
  - upstream-attribution (rtk-ai/rtk, RTK AI Labs, [email protected])
  - hook-protocol-literal (over-the-wire JSON values, parser markers)
  - test-fixture-argv0 (`vec!["rtk", ...]` in clap-parse tests)
  - tracking-label-string (rtk_cmd DB column, registry expectations)
  - hook-rewrite-output-literal (env-prefix / chain-preserve outputs)
  - raw-string-tracking-literal (`Some(r#"...rtk..."#.into())`)
  - known-unbranded-text-debt (enumerated cleanup-tracked surface)
  - doc-comment-example (`/// use rtk::xxx;`)
  - module-internal-identifier (`let rtk = ...`, `rtk_cmd:`, ...)
  - per-line allow marker (existing `// branding-lint: allow legacy`)
  - structural-needle (LEGACY_RTK_MD_FILES, etc)
  - history-comment (issue-# / commit-hash references in comments)
  - internal-comment mention (// or //! — NOT ///)
  - rustdoc-comment mention (/// — clap-help leak risk; see
    FORBIDDEN_TOKENS for specific-phrasing pin)
  - test-only fixture text (cargo banners, JSONL test fixtures,
    assertion diagnostics inside known test modules)

Implementation notes:
  - Tracks multi-line raw-string state so `r#"..."#` literals
    containing fixture text are exempted en bloc
  - Sanity self-test: 4 leak simulations are asserted to be REJECTED
    by the allowlist (init-message, error-prefix, novel eprintln,
    novel panic) so a future "too broad" rule edit fails fast
  - Runs in <0.3s on full src/ (well under the 2s budget)
  - Failure messages name file:line + offending substring +
    available rule list, with explicit FIX OPTIONS guidance

Existing tests retained:
  - `branding_lint_no_forbidden_upstream_literals_in_src` —
    regression-style FORBIDDEN_TOKENS backstop (pins specific
    leak-class phrasings)
  - `branding_lint_canonical_name_present_in_init` — inverse-rebrand
    sanity check
  - `branding_lint_config_files_pin_canonical_package_name` —
    Cargo.toml + release-please-config.json pinning

Passes on develop tip with no production source changes (the
known-unbranded-text-debt rule enumerates the existing rebrand-
incomplete surface explicitly so each entry is auditable). Future
NEW user-visible RTK leaks fail this test instead of shipping.

Closes #67.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thehoff
thehoff merged commit 6024a56 into develop May 18, 2026
@thehoff
thehoff deleted the test/branding-lint-allowlist-67 branch May 18, 2026 14:02
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.

test(branding): replace regression-style FORBIDDEN_TOKENS with broad allowlist-based scan

1 participant