Repository navigation
refactor(vis): split secrets.rs - #243
Conversation
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>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
PR Summary by QodoRefactor native vis secrets into focused modules
AI Description
Merge Risk
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent |
|
Thank you for following the naming conventions! 🙏 |
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
|
ⓘ 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. |
What
Splits the native
vis secretscommand into modules and tidies three smaller things in the nativesecurity listand typosquat code. No behaviour change on any reachable path (one error path is noted below).Old -> new
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_DIRandRULESET_FILEconstantssecurity_list: allow keys kept as(String, bool), classified (@*,*,name@version) again inis_pattern_allowedand instatus, falsy entries carried alongAllow { key, Pattern }(AnyVersion,Prefix,Exact); both the approval check and the status loop read the enumsecurity_list::config()(107 lines)config()plusallow_bins,first_seen,allowed_keyssecurity_list::report()with the JSON nested six deep,drift()redefining thetext/stringsclosuresBuildEntry::to_json,BinConflict::to_json, sharedtextandstringshelperstyposquat::scan_manifestrepeating the alias prefix list and the line-terminator checkalias()returningAlias::{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:answerlists the rules afterscan_dirssucceeded with the same options, and both read the ruleset through the same loader. The new testa_ruleset_the_scanner_rejects_fails_the_scan_and_the_rule_listing_alikepins that both calls fail together for a bad ruleset, so the listing can never fail after a good scan.vis_config::read(&cwd) != Absentcheck insecrets::context.quiet_contextalready returns false when anyvis.config.*exists in the directory or an ancestor, and that is exactly whenreadis notAbsent(both walk the same names withexists()), so the check could never be true.installScripts.allowentries 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.allowis kept: it distinguishes "noallowobject" 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).FORCE_COLOR=3, against a releasevis-native-cli, the rebuilt addons and the built Node entry:c82d3fa3):install-parity,install-native,add-parity(1 test skipped in the file),info-dlx-parity,typosquat-parityandsecurity-list-parityall pass;secrets-parity(73/73),route,routing-fixture,native-binding,pm-runner,pm-pin,pm-exec-x,sbom-parityandoptimize-paritypass.scan_manifestis only called frominstall, so the typosquat commit cannot reach these.dist, the secret-scanner addon and the vis addon, and against a debugvisbinary the secrets suite does not finish in reasonable time, so they need a release binary.🤖 Generated with Claude Code