Skip to content

refactor(vis-core): split resolve.rs and type the package manager - #245

Merged
prisis merged 8 commits into
nextfrom
refactor/vis-core-resolve-modules
Nov 25, 2026
Merged

prisis merged 8 commits into
nextfrom
refactor/vis-core-resolve-modules

Conversation

@prisis

@prisis prisis commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

What

Splits vis-core's resolve.rs into one module per verb and replaces the string-typed package manager, error and format with types. Based on next (not on #243: the two PRs touch disjoint files). No behaviour change: argv, bin, warnings and error text are the same for every input I could enumerate (see below). The napi surface is unchanged.

Old -> new

Before After
core/src/resolve.rs (1806 lines, ten resolvers) core/src/resolve/mod.rs (ResolvedCommand, Manager, ResolveError, push_flags, push_each, yarn_workspace_prefix, yarn_foreach_prefix) plus install, add, remove, exec, dlx, why, outdated, link (with unlink), dedupe, pm_command, mirroring src/pm/pm-runner.ts. The 41 unit tests moved with their verb. Public paths and the resolve_*(pm, version, ..) signatures are unchanged.
one if opts.x { args.push("--x".into()) } block per flag, a four-line loop per --filter push_flags(&mut args, &[(opts.x, "--x"), ..]), push_each(&mut args, "--filter", &opts.filter)
pm: &str + validate_pm, nine match pm { .. _ => unreachable!() }, ten version.starts_with("1.") enum Manager { Pnpm, Npm, YarnClassic, YarnBerry, Bun }, built once by Manager::new(pm, version); each verb matches the five variants. The 1. rule is unchanged, so the 1.x that detection reports for a classic yarn.lock header still reads as classic and an unknown version as berry.
Result<_, String> ResolveError (unsupported manager, yarn single workspace, dropped exec flags, unsupported --reverse); Display is the old text. The addon's invalid_arg comment, which said every core error was an unsupported-manager failure, is corrected.
OutdatedOptions.format: String OutdatedFormat { Table, Json, List } with an infallible parse: anything but json and list is Table, which adds no flag, as before
detect.rs: the four names matched inline in three places, two copies of the pop loop plus a third in the pin lookup, five DetectedPackageManager literals, Option<bool> options pm_name everywhere, one walk_up (returns the directory of the hit), one detected builder, plain bool options (the addon's wrapper turns an omitted flag into false)
advisories_napi.rs: a Bridge struct over Arc<Mutex<Option<ThreadsafeFunction>>> a closure over the threadsafe function (IngestProgress is implemented for any FnMut(usize, usize) + Send)

Differences found

None in behaviour. Things I checked or left on purpose:

  • Equivalence. Before editing I kept the old file as a temporary test-only module and compared old and new for every verb over the package managers pnpm, npm, yarn, bun, deno and an empty name, the versions "", 1, 1.x, 1.22.0, 4.0.0, 10.1.0, 11.0.0, latest and 01.2, every combination of the boolean options, and zero, one and two filters plus the package, argument, target, depth, format and subcommand variants of each verb. It compared argv, bin, warnings and the error text, and passed after each commit. It is not committed.
  • Tests edited. The tests that compared the error with a string now call .to_string() on it; nothing else in the moved tests changed. detect.rs gains one test for walk_up (the directory of the hit, and the empty root of a relative path, which the old pop loop also visited).
  • napi surface. pnpm build:native:debug before and after the change produces a byte-identical index.d.ts and index.js; no generated file is committed.
  • Already done on next, so not touched: the dead non-bun global arms in resolve_add and resolve_remove, --reverse (mapped for pnpm, refused elsewhere), the inline foreach prefix in yarn berry exec, and the if-chain in resolve_pm_command (already one match; the four bun pm <verb> arms stay as they read well). Not done by design: making aube a Manager variant, an optional napi feature on vis-core, and the ALLOWED_BINS list in pm_exec.rs.

What ran locally

  • cargo fmt --check, cargo clippy -p vis-core -p vis-cli --all-targets -- -D warnings and cargo clippy -p vis-native -- -D warnings: clean.
  • cargo test -p vis-core -p vis-cli: all pass (63 in vis-core, 480 in the binary, 60 cli, 18 hook, 28 node_parity, 3 golden, 1 routing).
  • vitest with FORCE_COLOR=3, against a release vis-native-cli, the rebuilt addon and the built Node entry: route, routing-fixture, native-binding, pm-runner, pm-pin, pm-exec-x, install-native, sbom-parity, optimize-parity, install-parity, add-parity (1 test skipped in the file), info-dlx-parity, advisories-ingest-progress and advisory-db-schema: 14 files, 3065 passed, 1 skipped.

🤖 Generated with Claude Code

prisis and others added 7 commits November 25, 2026 01:17
resolve.rs held eleven resolvers, their option structs and the shared
yarn scoping helpers in one 1800-line file. Move each verb into
resolve/<verb>.rs (install, add, remove, exec, dlx, why, outdated, link
with unlink, dedupe, pm_command), mirroring src/pm/pm-runner.ts, and keep
ResolvedCommand, validate_pm and the yarn workspace/foreach helpers in
resolve/mod.rs. The public paths are unchanged (`vis_core::resolve::*`)
and each verb's tests moved with it.

No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Every resolver spelled out one `if opts.x { args.push("--x".into()); }`
block per flag and a four-line loop per repeated `--filter`/`--workspace`.
Add `push_flags(&mut args, &[(opts.x, "--x"), ..])` and
`push_each(&mut args, "--filter", &opts.filter)` and use them wherever two
or more flags follow each other. The flag order is unchanged.

No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The resolvers took the manager as a string plus a version and re-derived
the same facts on every call: validate_pm up front, a `match pm` with an
`unreachable!()` arm for the names validate_pm had already let through,
and ten copies of `version.starts_with("1.")` to tell yarn classic from
berry. Build a `Manager` (Pnpm, Npm, YarnClassic, YarnBerry, Bun) once
from (pm, version) and match on it, so each arm is a manager and the
classic/berry split is a pair of arms. The `1.` rule is unchanged, so a
yarn.lock-header version of `1.x` still reads as classic and an unknown
version as berry. The public `resolve_*(pm, version, ..)` signatures and
every message are unchanged.

No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The resolvers returned `Result<_, String>`, so a caller could not tell an
unsupported package manager from a refused flag, and the addon's comment
claimed every core error was the former although `yarn workspace` with
several filters and the `vis exec` flag refusals also return one.

Add `ResolveError` (unsupported package manager, yarn single workspace,
dropped exec flags, unsupported --reverse). Its `Display` is the exact
message of each old string, which the CLI prints after `vis <command>:`
and the addon raises as an `InvalidArg` error, so what users see is
unchanged. Correct the comment on the addon's `invalid_arg`.

No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
OutdatedOptions.format was a String compared against "json" and "list" in
two resolvers, with every other value silently meaning "no format flag".
Make it an `OutdatedFormat` (Table, Json, List). `OutdatedFormat::parse`
keeps the old reading: any value other than `json` and `list` is Table,
which adds no flag, so the CLI's default of `table` and an unknown
`--format` value resolve as before. The addon's option object still takes
a string and parses it.

No behaviour change.

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

detect.rs matched the four manager names inline in three places although
`pm_name` already maps them, walked up the lockfiles and the config files
with two copies of the same pop loop (and a third in the pin lookup), and
built a DetectedPackageManager literal in five places. Use `pm_name`
everywhere, one `walk_up` that returns the directory of the hit, and one
`detected` builder. `Path::ancestors` visits the same directories as the
old pop loop, including the empty root of a relative path; a test pins it.

The core options now take plain bools (`ignore_package_json`,
`ignore_lock_file`, `ignore_argv`) instead of the addon's `Option<bool>`,
and the addon's wrapper turns an omitted flag into false, so the addon's
option object and the detection order are unchanged.

No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The addon wrapped its progress callback in a Bridge struct holding an
Arc<Mutex<Option<ThreadsafeFunction>>> just to implement IngestProgress,
which already has a blanket impl for any `FnMut(usize, usize) + Send`. A
threadsafe function is Send, so a closure over it does the same without
the lock.

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: b0dbdc80-9941-4083-a23a-856bf38d7e2d

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 vis-core resolution into typed, per-verb modules

✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Split package-manager command resolution into per-verb modules while retaining public resolver
 paths and command behavior.
• Replace string-based manager, error, and output-format handling with types shared by the CLI and
 addon.
• Consolidate detection traversal and simplify advisory progress forwarding; retain verb tests and
 add traversal coverage.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 3 capabilities

  • 3 affected capabilities span independent functional scopes: advisory_database_integration, package_manager_integration.
  • The resolver modules, CLI wrappers, and NAPI wrapper all implement the same bounded package-manager integration: translating one vis operation into a package-manager invocation.
  • They are implementation hops of the same end-to-end command behavior, not independent functional scopes.
  • Detection is a distinct externally useful behavior within the same bounded package-manager integration: it returns the selected manager, version, metadata, and workspace status, and may feed command dispatch.
  • It is not a separate deployment or repository scope.
  • This is an independent bounded integration from package-manager detection/resolution: it ingests advisory data into SQLite and reports progress to JavaScript.
  • Its callback adapter does not participate in package-manager command dispatch.
Behavioral complexity 🟡 Medium 🧩 Compatibility cases, Interacting branches

  • Before: command resolution was implemented in one large module with per-manager and Yarn-version branches.
  • After: the implementation is split into operation modules and uses a shared Manager enum plus typed errors, while retaining manager-specific mappings.
  • New correctness condition for compatibility_cases: Manager::new must classify pnpm, npm, Bun, Yarn 1.x, and Yarn 2+ consistently for every resolver.
  • New correctness condition for interacting_branches_or_states: each operation's flags, workspace filters, version-specific behavior, fallback executable, and error/refusal path must remain consistent after extraction and shared helper use.
  • The complexity comes from preserving these cross-operation compatibility cases, not from the source-file split itself.
Potential damage 🟡 Medium 🩹 Recoverable

  • A wrong mapping can make a requested command fail, do nothing, or perform the wrong package-manager operation.
  • Read-only commands are generally recoverable by rerunning after code correction.
  • Install, add, remove, link, and install-like fallbacks can change lockfiles, manifests, links, or installed dependencies; reverting the code does not automatically restore those persistent effects, so recovery may require restoring project state or manually rerunning the intended command.
  • The evidence supports recoverable degradation rather than a serious integrity or financial consequence.
  • Code rollback restores the prior resolver, but persistent manifest/lockfile/install/link effects require user or repository-state repair; no automatic compensation path is shown.
Assessed commit 44d4bd1
Diagram

graph TD
  CLI(["Native CLI"]) --> Detect["PM detection"] --> API["Resolve API"] --> Verbs["Verb modules"] --> Result["Resolved command"]
  NAPI(["NAPI addon"]) --> Progress["Progress callback"]
  NAPI --> Detect
  NAPI --> API
  Result --> CLI
  Result --> NAPI
Loading
High-Level Assessment

Keep the per-verb modules and typed manager with existing public entry points. A data-driven mapping was considered, but the manager- and verb-specific exceptions make explicit branches easier to verify for behavioral equivalence.

Files changed (18) +1899 / -134

Refactor (18) +1899 / -134
exec.rsRender typed exec errors as CLI usage messages +2/-2

Render typed exec errors as CLI usage messages

• Converts parse and resolver errors to strings when constructing exec usage errors, preserving the displayed messages.

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

pm.rsRender typed PM resolver errors for the CLI +1/-1

Render typed PM resolver errors for the CLI

• Converts PM command resolution errors to their display text at the CLI usage-error boundary.

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

pm_family.rsAdapt PM-family commands to typed format and errors +5/-4

Adapt PM-family commands to typed format and errors

• Parses the outdated report format into OutdatedFormat and renders typed resolver errors as usage messages.

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

detect.rsConsolidate package-manager detection traversal +53/-96

Consolidate package-manager detection traversal

• Introduces shared ancestor traversal and detected-result construction while reusing the supported-name parser. Core ignore options become booleans, and a test covers traversal hits and relative and absolute roots.

packages/tooling/vis/native/core/src/detect.rs

add.rsIsolate add command resolution +206/-0

Isolate add command resolution

• Moves add options, manager-specific argument mapping, and their tests into a verb module. Uses typed manager selection and shared flag helpers.

packages/tooling/vis/native/core/src/resolve/add.rs

dedupe.rsIsolate dedupe command resolution +61/-0

Isolate dedupe command resolution

• Moves dedupe mappings, unsupported-manager fallbacks, and the existing test into a dedicated module.

packages/tooling/vis/native/core/src/resolve/dedupe.rs

dlx.rsIsolate dlx execution and package-spec handling +300/-0

Isolate dlx execution and package-spec handling

• Moves dlx options, executable-name derivation, manager-specific invocation logic, and associated tests into one module.

packages/tooling/vis/native/core/src/resolve/dlx.rs

exec.rsIsolate exec resolution and typed flag refusals +275/-0

Isolate exec resolution and typed flag refusals

• Moves exec argument mapping and tests into a verb module. Unsupported selection flags and reverse execution now return ResolveError variants with the existing display text.

packages/tooling/vis/native/core/src/resolve/exec.rs

install.rsIsolate install command resolution +155/-0

Isolate install command resolution

• Moves install options, manager-specific flags and warnings, and tests into a dedicated module using the shared flag helpers.

packages/tooling/vis/native/core/src/resolve/install.rs

link.rsGroup link and unlink resolution +161/-0

Group link and unlink resolution

• Moves link and unlink mappings, pnpm version and path checks, warnings, and tests into one module.

packages/tooling/vis/native/core/src/resolve/link.rs

mod.rsDefine and re-export the typed resolution API +159/-0

Define and re-export the typed resolution API

• Re-exports the per-verb resolvers at their existing public paths. Defines Manager, ResolveError, ResolvedCommand, and shared argument and Yarn workspace helpers.

packages/tooling/vis/native/core/src/resolve/mod.rs

outdated.rsType outdated report formats +124/-0

Type outdated report formats

• Moves outdated resolution and its test into a verb module. OutdatedFormat parses json and list explicitly and treats other values as the default table behavior.

packages/tooling/vis/native/core/src/resolve/outdated.rs

pm_command.rsIsolate PM subcommand translation +102/-0

Isolate PM subcommand translation

• Moves cache, list, pack, view, passthrough, and npm-delegation mappings and their tests into a dedicated module.

packages/tooling/vis/native/core/src/resolve/pm_command.rs

remove.rsIsolate remove command resolution +157/-0

Isolate remove command resolution

• Moves removal options, workspace and global mappings, and existing tests into a verb module using typed manager selection.

packages/tooling/vis/native/core/src/resolve/remove.rs

why.rsIsolate dependency-explanation resolution +123/-0

Isolate dependency-explanation resolution

• Moves why options, manager-specific explanation arguments and warnings, and the existing test into a dedicated module.

packages/tooling/vis/native/core/src/resolve/why.rs

advisories_napi.rsForward ingestion progress through a closure +6/-23

Forward ingestion progress through a closure

• Replaces the mutex-backed progress bridge with a closure capturing the threadsafe NAPI callback.

packages/tooling/vis/native/src/advisories_napi.rs

pm_detect.rsNormalize optional JS detection flags at the boundary +3/-3

Normalize optional JS detection flags at the boundary

• Converts omitted NAPI detection flags to false before passing options to the core's boolean fields.

packages/tooling/vis/native/src/pm_detect.rs

pm_resolve.rsAdapt NAPI resolution to typed core values +6/-5

Adapt NAPI resolution to typed core values

• Converts ResolveError to the same InvalidArg message and parses the JS outdated format into OutdatedFormat. Corrects the comment describing which core errors can occur.

packages/tooling/vis/native/src/pm_resolve.rs

@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 the vouch:trusted PR author is a collaborator, a bot or on the VOUCHED list. label Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@github-actions github-actions Bot added package: vis size:XXL Size of the change, tests and generated files excluded. labels Nov 25, 2026
@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.3 µ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-core-resolve-modules (8134e72) 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:33 — with GitHub Actions Active
@prisis
prisis merged commit a8fb607 into next Nov 25, 2026
32 of 34 checks passed

This branch was successfully deployed

1 active deployment
benchmarks — 8134e72d Deployed Nov 25, 2026 by prisis via Bench native (vis) #416
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