fix(npm): detect pnpm node-linker=pnp trees as pnpm - #181
Open
Mikola Lysenko (mikolalysenko) wants to merge 1 commit into
Open
fix(npm): detect pnpm node-linker=pnp trees as pnpm#181Mikola Lysenko (mikolalysenko) wants to merge 1 commit into
Mikola Lysenko (mikolalysenko) wants to merge 1 commit into
Conversation
pnpm's own PnP mode (node-linker=pnp in .npmrc) writes a .pnp.cjs loader at the project root just like yarn-berry does, but keeps real package directories in the pnpm virtual store — exactly the layout the CoW guard patches natively. The detector returned YarnBerryPnP for ANY PnP marker, so `apply` refused outright and told the user to run `yarn patch` in a pnpm repo; the vendored probe had the same hole one layer down and refused with vendor_yarn_berry_unsupported. Add a shared carve-out (pnpm_pnp_layout): a PnP marker with pnpm-lock.yaml, an installed pnpm store, and NO yarn.lock classifies as pnpm, so `apply` proceeds under the CoW guard. Anything ambiguous (yarn.lock alongside, or a stale pnpm-lock.yaml with no installed store) keeps the fail-closed yarn-berry refusal. Vendored mode still refuses on such trees — the file: rewiring has no fixtures under pnpm's PnP linker — but now with its own code (vendor_pnpm_pnp_unsupported) and a pnpm remedy: use `scan --mode hosted` or switch node-linker and reinstall. Un-ignores the RED test pnpm_pnp_mode_is_pnpm_not_yarn_berry and adds vendored-probe twins for the pnpm refusal and both ambiguity guards. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Wenxin Jiang (Wenxin-Jiang)
approved these changes
Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Audit finding (2026-08-13, medium, mode: both, pm: pnpm): pnpm's own PnP mode (
node-linker=pnpin.npmrc) writes a.pnp.cjsloader at the project root just like yarn-berry does, but keeps real package directories in the pnpm virtual store (node_modules/.pnpm/<name>@<ver>/node_modules/<name>) — exactly the layout the CoW guard patches natively. Both detection sites classified ANY PnP marker as yarn-berry PnP before checking pnpm markers:detect_npm_pkg_manager(crawlers/pkg_managers.rs) returnedYarnBerryPnP, sosocket-patch applyrefused outright (exit 1) and told the user to runyarn patch— a yarn command in a pnpm repo. The repo itself documented this as a real bug via the#[ignore]d RED testpnpm_pnp_mode_is_pnpm_not_yarn_berry.detect_npm_lock_flavor(vendor/npm_flavor.rs) refusedscan --mode vendoredwithvendor_yarn_berry_unsupportedand the same wrongyarn patchremedy.Concrete failing scenario:
pnpm installwithnode-linker=pnp(layout verified against pnpm 10.28.2), thensocket-patch apply→ refusal with a yarn remedy on a tree socket-patch patches natively.Fix
One shared
pub(crate)helper,pkg_managers::pnpm_pnp_layout(), carves pnpm's PnP mode out of both PnP branches so the two detection sites can never drift on what counts as a pnpm-PnP tree. The reclassification requires ALL of: an installed pnpm store (node_modules/.modules.yamlornode_modules/.pnpm/),pnpm-lock.yamlat the root, and NOyarn.lock.apply: such trees now detect asPnpmand proceed under the existing CoW guard (informational note, no behavior change for real yarn-berry projects).scan --mode vendored: still refuses fail-closed — thefile:rewiring has no fixtures under pnpm's PnP linker — but with a dedicated codevendor_pnpm_pnp_unsupportedand a pnpm-appropriate remedy (usescan --mode hosted, or switch.npmrctonode-linker=isolatedand reinstall) instead ofyarn patch.Ambiguous trees stay the fail-closed yarn-berry refusal: a
yarn.lockalongside the loader (mid-migration multi-PM repo), or a stalepnpm-lock.yamlwith no installed store. These boundaries were already pinned by pre-existing guard tests (pnp_with_both_lockfiles_stays_yarn_berry,pnp_with_stale_pnpm_lockfile_only_stays_yarn_berry), which still pass unchanged.No skipped findings — this lane had a single finding, fixed at both boundaries it names.
Testing
crawlers::pkg_managers::tests::pnpm_pnp_mode_is_pnpm_not_yarn_berry(verified red on pre-fix code:left: YarnBerryPnP, right: Pnpm), now green.vendor::npm_flavor::tests::pnpm_pnp_layout_refuses_with_pnpm_remedy: assertsvendor_pnpm_pnp_unsupported, anode-linker=pnpdiagnosis, thescan --mode hostedremedy, and noyarn patchtext.vendor::npm_flavor::tests::pnpm_pnp_carve_out_stays_yarn_berry_when_ambiguous: yarn.lock alongside, and stale pnpm-lock.yaml without an installed store, both keepvendor_yarn_berry_unsupported.cargo test -p socket-patch-core --lib(2078 passed),cargo test -p socket-patch-cli --test ecosystem_dispatch_e2e(22 passed), pluse2e_safety_yarn_pnp(20 passed; 3 ignored pre-existing RED tests for an unrelated scoping bug),e2e_safety_pnpm(27 passed),in_process_vendor(13 passed),crawler_npm_e2e(58 passed).🤖 Generated with Claude Code
Note
Medium Risk
Changes package-manager and vendor lockfile detection on the safety-critical PnP branch; behavior is constrained by strict carve-out rules and existing guard tests, but wrong classification could still block apply or mis-route vendor errors.
Overview
Fixes misclassification of pnpm’s
node-linker=pnpmode, which writes a root.pnp.cjslike yarn-berry but keeps real packages in the pnpm virtual store—layoutapplyalready patches via CoW.Adds shared
pnpm_pnp_layout()(installed pnpm store +pnpm-lock.yaml+ noyarn.lock) and uses it in bothdetect_npm_pkg_manageranddetect_npm_lock_flavorso they stay aligned.applynow treats qualifying trees as pnpm instead of refusing with a yarn patch remedy.scan --mode vendoredstill fails closed but returnsvendor_pnpm_pnp_unsupportedwith pnpm guidance (scan --mode hostedornode-linker=isolated); ambiguous cases (both lockfiles, stale lockfile without store) keep the yarn-berry refusal.Un-ignores
pnpm_pnp_mode_is_pnpm_not_yarn_berryand adds vendor tests for the new error and ambiguity guards.Reviewed by Cursor Bugbot for commit b3b9fa4. Configure here.