Skip to content

refactor(vis): split secrets.rs - #243

Merged
prisis merged 5 commits into
nextfrom
refactor/vis-split-secrets
Nov 25, 2026
Merged

prisis merged 5 commits into
nextfrom
refactor/vis-split-secrets

Conversation

@prisis

@prisis prisis commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

What

Splits the native vis secrets command into modules and tidies three smaller things in the native security list and typosquat code. No behaviour change on any reachable path (one error path is noted below).

Old -> new

Before After
cli/src/secrets.rs (1261 lines, five jobs) cli/src/secrets/mod.rs (parse, context, answer, run), filter.rs (shadowing, heuristics, masking, false positives), baseline.rs (fingerprints, loader), sarif.rs (SARIF model, renderer, rule-id collation), report.rs (JSON and text renderers). Each block of tests moved with its functions; the test count is unchanged (18, plus one new).
RULESET: [&str; 4] read through [..3] and [3] PACKAGE_DIR and RULESET_FILE constants
security_list: allow keys kept as (String, bool), classified (@*, *, name@version) again in is_pattern_allowed and in status, falsy entries carried along each truthy key parsed once into Allow { key, Pattern } (AnyVersion, Prefix, Exact); both the approval check and the status loop read the enum
security_list::config() (107 lines) config() plus allow_bins, first_seen, allowed_keys
security_list::report() with the JSON nested six deep, drift() redefining the text/strings closures BuildEntry::to_json, BinConflict::to_json, shared text and strings helpers
typosquat::scan_manifest repeating the alias prefix list and the line-terminator check one alias() returning Alias::{None, Target, Unreadable}

Differences found

  • list_rules(..).unwrap_or_default() -> .ok()? (SARIF path). This is the one change in behaviour: when listing the rules fails, the run now goes to Node instead of printing a SARIF rule table with no rules. It only matters on an error path that I could not reach: answer lists the rules after scan_dirs succeeded with the same options, and both read the ruleset through the same loader. The new test a_ruleset_the_scanner_rejects_fails_the_scan_and_the_rule_listing_alike pins that both calls fail together for a bad ruleset, so the listing can never fail after a good scan.
  • Dropped the second vis_config::read(&cwd) != Absent check in secrets::context. quiet_context already returns false when any vis.config.* exists in the directory or an ancestor, and that is exactly when read is not Absent (both walk the same names with exists()), so the check could never be true.
  • Falsy installScripts.allow entries are dropped when the config is read rather than skipped in two loops. They never matched anything or counted as excess, so the report is the same.
  • DriftInput.allow is kept: it distinguishes "no allow object" from an empty one, which the drift check needs.

What ran locally

  • cargo fmt --check, cargo clippy -p vis-core -p vis-cli --all-targets -- -D warnings: clean.
  • cargo test -p vis-core -p vis-cli: all pass (481 unit tests in the binary, 60 cli, 18 hook, 28 node_parity, 3 golden, 1 routing; 62 + 2 in vis-core).
  • vitest with FORCE_COLOR=3, against a release vis-native-cli, the rebuilt addons and the built Node entry:
    • on the head commit (c82d3fa3): install-parity, install-native, add-parity (1 test skipped in the file), info-dlx-parity, typosquat-parity and security-list-parity all pass;
    • on the commit before the typosquat change: secrets-parity (73/73), route, routing-fixture, native-binding, pm-runner, pm-pin, pm-exec-x, sbom-parity and optimize-parity pass. scan_manifest is only called from install, so the typosquat commit cannot reach these.
  • The parity suites skip silently without a built dist, the secret-scanner addon and the vis addon, and against a debug vis binary the secrets suite does not finish in reasonable time, so they need a release binary.

🤖 Generated with Claude Code

prisis and others added 4 commits November 25, 2026 00:05
secrets.rs held five jobs in one 1260-line file. Move them into a
secrets/ directory, each with the tests of its functions:

- mod.rs: argument parsing, the machine context, the run
- filter.rs: generic-rule shadowing, false-positive heuristics, masking
- baseline.rs: baseline fingerprints and the baseline loader
- sarif.rs: the SARIF model and renderer, and the rule-id collation
- report.rs: the JSON and plain-text renderers

No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Name the package directory and the ruleset file as two constants
  instead of one array read through slices.
- Drop the second vis.config check in the context: the quiet context
  already rules out any vis.config file in the directory and its
  ancestors, which is exactly when the config reads as absent.
- Hand the run to Node when the rule listing fails, instead of printing
  a SARIF rule table with no rules. The listing reads the ruleset the
  same way the scan just did, so this only changes a path that cannot
  follow a successful scan; a test pins that both calls fail together.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
`vis security list` kept the allow-list keys as raw strings and re-ran
the same suffix classification (`@*`, `*`, name@version) in both the
approval check and the status loop. Parse each truthy key once into an
`Allow` with a `Pattern` enum, and let both read the enum. Falsy keys
never matched anything, so they are dropped when the config is read.

Also split the 107-line config reader into allow_bins, first_seen and
allowed_keys, and give BuildEntry and BinConflict `to_json` so the report
no longer nests the JSON by hand.

No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
scan_manifest repeated the alias prefix list and the line-terminator
check that alias_target already carried. Return an Alias (none, a
target, or unreadable for a value the TypeScript regex cannot match) from
one function and match on it in the scan.

No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 315b936a-22c8-4482-90db-aa9ce760f3f5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@qodo-code-review

qodo-code-review Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Refactor native vis secrets into focused modules

✨ Enhancement 🕐 40+ Minutes

Grey Divider

AI Description

• Split native secrets scanning, filtering, baselines, and rendering into focused modules.
• Simplify security-list allow patterns, JSON assembly, and typosquat alias handling.
• Preserve normal output; delegate to Node if SARIF rule listing fails.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 3 capabilities

  • 3 affected capabilities span independent functional scopes: dependency installation safety integration, installed-package security list integration, secrets scanning CLI integration.
  • The changed modules collectively implement one bounded end-to-end behavior: dispatching a working-tree secrets scan, applying its post-scan policy, and emitting the selected report.
  • Baseline, filter, report, and SARIF modules are producer/consumer hops of that same scan capability rather than independent capabilities.
  • The allowlist parser, package walk, triage, drift calculation, and JSON serializer together produce one bounded security-list report.
  • They are implementation hops of the same package-audit behavior, not separate functional scopes.
  • The alias classifier and manifest scanner directly determine whether the install preflight is clean or delegated.
  • This is a distinct user outcome from security-list reporting, so it is a separate bounded functional scope despite both being security-related.
Behavioral complexity 🟡 Medium 🧩 Compatibility cases

  • Before: allowlist matching and stale/version-drift reporting separately interpreted string patterns, with special cases for name@*, prefix *, exact names, and optional pinned versions.
  • After: the change parses each truthy key into AnyVersion, Prefix, or Exact and reuses that classification for both decisions.
  • New correctness condition: parsing precedence must remain compatible with the existing pattern grammar and pinVersions behavior; the implementation preserves the established precedence and branches.
  • No new cross-component invariant or concurrency condition is introduced.
Potential damage 🟡 Medium 🩹 Incorrect results

  • Conditionally, a configuration-sensitive native scan can omit configured rules or apply the wrong scan options, causing false negatives, false positives, or an incorrect nonzero exit status.
  • The output is masked and no persistent state is written by this path, so the primary consequence is an incorrect scan result rather than persistent corruption or direct secret disclosure.
  • Reverting the dispatch/configuration change restores the Node path; an affected invocation can then be rerun.
  • Any CI or review decision based on the prior result must be rerun manually.
  • There is no native persistent state repair prerequisite.
Assessed commit c82d3fa
Diagram

graph TD
  CLI["vis CLI"] --> Secrets["Secrets coordinator"] --> Scanner["Scanner core"] --> Filter["Findings filter"] --> Report["JSON text reports"]
  Secrets --> Baseline["Baseline loader"] --> Filter
  Filter --> Sarif["SARIF renderer"]
  Secrets --> Sarif
  Secrets --> Node["Node fallback"]
Loading
High-Level Assessment

Keep the focused module split and parse allow patterns once at the configuration boundary. A broader shared abstraction with the Node implementation would add scope without improving this behavior-preserving Rust refactor.

Files changed (8) +1564 / -206

Refactor (8) +1564 / -206
baseline.rsIsolate baseline fingerprints and loading +124/-0

Isolate baseline fingerprints and loading

• Moves baseline key generation, file loading, and their existing tests out of the former monolithic secrets file.

packages/tooling/vis/native/cli/src/secrets/baseline.rs

filter.rsIsolate finding filtering and masking +247/-0

Isolate finding filtering and masking

• Moves generic-rule shadowing, false-positive heuristics, masking, and baseline suppression alongside their tests.

packages/tooling/vis/native/cli/src/secrets/filter.rs

mod.rsCoordinate the modular secrets command +427/-0

Coordinate the modular secrets command

• Retains parsing, native-context checks, scan orchestration, and Node delegation while wiring in the extracted modules. Names the package directory and ruleset file separately, removes a redundant config check, and delegates on SARIF rule-listing failure; a new test checks that a rejected ruleset fails both scanning and rule listing.

packages/tooling/vis/native/cli/src/secrets/mod.rs

report.rsIsolate JSON and text rendering +176/-0

Isolate JSON and text rendering

• Moves the existing finding serializers, JSON and grouped-text renderers, and their tests into a reporting module.

packages/tooling/vis/native/cli/src/secrets/report.rs

sarif.rsIsolate SARIF rendering and rule ordering +372/-0

Isolate SARIF rendering and rule ordering

• Moves the SARIF model, renderer, URI encoding, locale-sensitive rule ordering, and associated tests into one module.

packages/tooling/vis/native/cli/src/secrets/sarif.rs

mod.rsSimplify security-list configuration and report assembly +91/-117

Simplify security-list configuration and report assembly

• Extracts allow-bin, first-seen, and ordered allow-key parsing, retaining only truthy allow keys for classification. Reuses JSON helpers and delegates entry serialization to the scan types without changing the report shape.

packages/tooling/vis/native/cli/src/security_list/mod.rs

scan.rsClassify allow patterns once for security triage +89/-59

Classify allow patterns once for security triage

• Introduces parsed allow-pattern variants shared by approval, excess, and version-drift checks. Moves build-entry and bin-conflict JSON conversion onto their types and adapts existing tests to truthy parsed keys.

packages/tooling/vis/native/cli/src/security_list/scan.rs

typosquat.rsUnify dependency alias parsing +38/-30

Unify dependency alias parsing

• Replaces duplicated alias-prefix and line-terminator checks with an alias result that distinguishes targets from values requiring Node delegation. Extends alias tests for line-terminator cases.

packages/tooling/vis/native/cli/src/typosquat.rs

@github-actions github-actions Bot added the vouch:trusted PR author is a collaborator, a bot or on the VOUCHED list. label Nov 25, 2026
@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@github-actions github-actions Bot added package: vis size:XXL Size of the change, tests and generated files excluded. labels Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@codspeed

codspeed Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

🆕 3 new benchmarks
⏩ 113 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 transform/transform_ts[470] N/A 355.4 µs N/A
🆕 transform/transform_ts[47000] N/A 16 ms N/A
🆕 transform/transform_ts[9400] N/A 3.3 ms N/A

Comparing refactor/vis-split-secrets (c7582f8) with next (1078fa9)2

Open in CodSpeed

Footnotes

  1. 113 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on next (a65ddee) during the generation of this report, so 65c051d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo did not review this PR because this workspace reached its daily trial limit of 100 reviews. Reviews start again at 00:00 UTC. Choose a plan to continue now.

@prisis
prisis deployed to benchmarks November 25, 2026 08:05 — with GitHub Actions Active
@prisis
prisis merged commit b2ddc1c into next Nov 25, 2026
33 of 34 checks passed

This branch was successfully deployed

1 active deployment
benchmarks — c7582f8e Deployed Nov 25, 2026 by prisis via Bench native (vis) #414
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: vis size:XXL Size of the change, tests and generated files excluded. vouch:trusted PR author is a collaborator, a bot or on the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant