Skip to content

Commit dfa9a96

Browse files
Judge a pnpm store under a nested modulesDir from the workspace root (#2353) (#2437)
* Stop vex judging the pnpm store entry an in-place install leaves behind After the `pnpm install` that a scan asks for, run over an existing `node_modules`, pnpm links the project to a new virtual-store entry and keeps the upstream one with nothing linking to it: `<name>@socket-<id>+<version>` beside `<name>@<version>` after a hosted scan on pnpm 11.20 and later (the release is routed through the registry of its patch), and `<name>@file+...` after a vendored scan on every pnpm. `vex` counted the leftover as an installed copy. It omitted the hosted patch as `not_applied` and exited 1, or warned `vendored_tree_out_of_sync` for the vendored one, and the reinstall it asked for changed nothing (#2353). The live-copy filter that skips Bun's orphaned store entries now skips pnpm's too. A pnpm entry is live when a link reaches it from an importer's `node_modules` (the root, and the members named by the lockfile in the store or by `pnpm-lock.yaml`), from the hoist directory `node_modules/.pnpm/node_modules`, from a live entry's own `node_modules`, or from the `node_modules` in which a checked copy was found. A copy that a link reaches is always judged, so an unpatched one still refuses or warns. Every entry is kept, as before, wherever the walk cannot be sure it read every link: on Windows, under `node-linker=hoisted` or `shamefully-hoist`, with a moved virtual store or another store layout, without the install record or the lockfile in the store, when a directory or a link cannot be read, when a lockfile lists its importers in a layout pnpm does not write or names a member that is no directory, when an importer's `node_modules` or the hoist directory holds a package as a real directory, and when no link reaches the store at all. `apply --check` verifies through the same copy lookup, so it follows the same rule. The scan's listing keeps its own test (the packages of the lockfile in the store), and `rollback` and `remove` resolve without the filter, so they still restore an unlinked entry. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Test vex, apply --check and rollback over an unlinked pnpm store entry Hand-built pnpm stores in the shapes real pnpm leaves (#2353): - `vex` over a hosted patch routed through its registry attests from the entry the importer links, and refuses the patch while that copy is pristine, whichever entry it is in and whatever an unlinked entry holds; - `vex` over a vendored patch does not warn `vendored_tree_out_of_sync` for the upstream entry nothing links, and still warns for an unpatched linked copy; - `apply --check` is in sync when the linked copy is patched and drift when it is not; - `rollback` still restores a patched entry that nothing links. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Run the in-place pnpm install and vex in the real-pnpm suites The registry-route legs (pnpm 11 and 12) and the vendored capstone (each pnpm of its matrix from 9 up) now also run the install a scan asks for over a `node_modules` that holds the upstream packages, in a second checkout so the project under test stays as it was. Each leg checks that pnpm kept the upstream entry in the store and linked the patched one, that `vex` attests from the linked copy (hosted) or does not warn (vendored), and that a linked copy put back on the upstream bytes is refused or warned about again (#2353). The capstone's first `vex`, which runs before any reinstall, now also expects the `vendored_tree_out_of_sync` warning: the project still links the upstream package there. The scan's files are written anew in the second checkout: pnpm 10.0 takes files no newer than its last install for unchanged and skips the install. The legs do not run on Windows, where the check keeps judging every store entry. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Document which pnpm store entries vex and apply --check judge `docs/ecosystems.md` says which links make a pnpm store entry an installed copy and where every entry is still judged; the CLI contract says the same for the verification basis of `vex` and `apply --check`; the pnpm compatibility notes record what the in-place install leaves in the store on each measured pnpm and which tests cover it (#2353). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Refuse a pnpm importers section that a line at column 0 cuts short `lock_text_member_importers_exact` promises `None` for a lock whose importers it may misread, but a line at column 0 that is no top-level key (the markers of a merge conflict) ended the `importers` section and the members after it were left out without a word. The walk that judges which pnpm store entries are live reads its seeds from that list, so a member it does not hear of is a `node_modules` it does not read. Inside the section, only a plain top-level key ends it now; any other line at column 0 gives `None` (#2353). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Keep a pnpm store entry that any searched node_modules still reaches The walk that tells `vex` and `apply --check` which pnpm store entries are live read the links of the project's `node_modules`, the hoist directory and the members the lockfiles name. Two installs it judged wrong, each time dropping an unpatched copy that node still loads (#2353): - A `node_modules` that no lockfile names. A directory that left the workspace keeps the links of its last install: with real pnpm 11.27.0, `packages/b/node_modules/mkdirp` still links `mkdirp@0.5.1`, whose `minimist` link still points at the upstream `minimist@0.0.8` entry after member `a` moved to the patched one. Hosted `vex` attested `not_affected`, vendored `vex` lost its `vendored_tree_out_of_sync` warning and `apply --check` read in sync. - A `node_modules` the crawl reaches through a link (a git worktree that shares the main checkout's install). The members were read below the link's target, not below the crawled project, so an entry only the project's own member links was dropped and a hosted patch was attested from the lock's pin with nothing hashed. The walk now takes the `node_modules` roots the crawl searched and reads the links of every one of them, so an entry is live when any reaches it, through other entries too. It keeps every entry unless the store's own `node_modules` is among those roots as the real directory of its project. Each store is judged once per run (`LiveStoreEntries`), by the same links for `vex`'s record check and its hosted one: the second lookup used to judge the store again from the hosted copies alone. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Judge a pnpm store in a checkout of part of its workspace Two smaller points of the walk over a pnpm store's links (#2353): - A member the lockfiles name that is not on disk made the walk keep every entry, so `vex` kept refusing a hosted patch over the entry an in-place install left behind wherever part of a workspace is checked out (a container image that copies some members; real pnpm 11.27.0 installs that frozen, and both lockfiles still name the rest). A path that is not there links nothing, so the walk goes on; one that is there and is no directory still keeps every entry. - A child of the store whose type could not be read was left out of the entries, so a copy in it read as one nothing links. The walk keeps every entry now when the type of a child that is not hidden cannot be read. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Test vex and apply --check over a node_modules no lockfile names Hand-built pnpm trees where the check passed while node still loads the pristine copy (#2353): - a directory that left the workspace still links a package whose dependency link points at the upstream entry: `vex` refuses the hosted patch while that `node_modules` is there and attests once it is gone, and `apply --check` reads drift, then in sync; - a worktree whose `node_modules` is a link to the main checkout's, and whose own member reaches the pristine entry: the copy is hashed and the patch refused, where it was attested from the lock's pin. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Correct the docs on which links keep a pnpm store entry The contract said a copy that a link reaches is always hashed, which was not true of a link in a `node_modules` that no lockfile names. It and `docs/ecosystems.md` now say which links are read: those of every `node_modules` the crawl searches, of the members the lockfiles name, of the hoist directory and of each reached entry. They also say that a link in a `node_modules` the crawl does not search is not read, that a store reached through a linked `node_modules` or from inside a member is not judged, and that a member that is not on disk links nothing (#2353). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Test that a lockfile's member is read where the crawl does not look With every searched `node_modules` read, the members in the unit fixtures were reached without the lockfiles, so nothing held the lockfile's members in place. A member below `vendor/`, which the crawl skips, has no other word of it: the entry it alone links stays live when the lockfile in the store names it, when only `pnpm-lock.yaml` does and under a quoted key, and is an orphan when neither names it (#2353). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Judge a pnpm store entry by every link below the scanned project After the in-place `pnpm install` that a hosted or vendored scan asks for, the upstream `<name>@<version>` entry stays in `node_modules/.pnpm` with nothing linking to it, and `vex` and `apply --check` refused the patch for it (#2353). The first rule on this branch proved such an entry dead by walking the links pnpm should have written: the crawl's roots, the lockfiles' members, the hoist dir. Two reviews each found a layout it did not read, where a copy that still loads was left out: a link under a directory the crawl skips by name, a link in a real package's own `node_modules`, a `modulesDir` of more than one level. The rule now reads the links there are. For a package version whose copies sit in two or more entries of one store, every symbolic link below the outer of the scanned directory and the store's project is listed, in every directory whatever its name, and resolved, never followed. An entry is kept when a link outside the store's entries resolves into it, or a link inside a kept entry does. The closure is needed: on pnpm 11.29.0 and 12.25.1 a hosted scan gives a package that names the patched one as a peer a new entry too, and its old entry keeps its link to the old one. A version that sits in one entry is not judged, and the project is not read for it, so a removed package and an upgraded-away version are hashed as on main. Every entry is kept where a link may have gone unread: on Windows, when the two directories are unrelated, when the install record is not the isolated linker's over this store, when a lockfile is missing or not laid out as pnpm writes it, when a lockfile names an importer that is not a directory inside the store's project, when a directory or a link cannot be read, past 1,000,000 directories, and when no link resolves into any entry. Five more cases keep entries that the sweep alone would leave out. The first four were reproduced with real node against a store that pnpm 12.25.1 left: - A copy that sits in the store but in none of its entries (a real directory of the hoist dir, which every store package resolves through) was dropped whenever its version sat in two entries. Only a copy in an entry dir is judged now. - A link whose target is spelled another way than the store's path was not matched to its entry. macOS reaches every volume under `/System/Volumes/Data` as well, and `canonicalize` keeps that spelling. A link that leaves the trees read is now checked against the store by file identity, and every entry is kept when it lies in the store. - Node looks a package up in the `node_modules` of every directory above the one it starts in. Each `node_modules` above the swept directory is swept as well. - A link to a directory outside the trees read (a `link:` dependency on another checkout) leads to a `node_modules` that is not read, which may link back into the store. Every entry is kept then. - A link that resolves to a child of the store which could be an entry and is not one of those listed cannot be matched to an entry: a file system that folds case need not give an entry's listed spelling back (macOS does). Every entry is kept then. This one was not reproduced: no such file system was at hand. The unit tests are rewritten for the rule: the hosted and the vendored leftover, the peer pair, a link from each kind of place, the gate, and one case for every condition that keeps all entries. Each of the first four cases above has a test that was seen to fail without its change. The CLI hands the filter the scanned directory in place of the crawl's `node_modules` roots. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Test vex over the in-place pnpm install in a workspace, link by link The real-pnpm suites ran the in-place install in a one-importer project. Two more legs per pnpm (11 and 12, on the registry route) run it in a workspace where the patched package is hoisted and is also the peer dependency of a tarball package. That is the layout in which the old entry of the dependent keeps its link to the old entry of the patched package (#2353): - `vex` attests both patches after the install. - A link to the upstream entry from `vendor/`, `dist/`, a hidden directory or a real package's own `node_modules` makes `vex` refuse the patch as `not_applied` until the link is gone. - Under `modulesDir: sub/node_modules` the store sits in `sub/node_modules/.pnpm` and each member's links in `<member>/sub/node_modules` (measured on pnpm 10.12.1, 10.34.9, 11.29.0 and 12.25.1; 9.15.9 and 10.11.1 keep the store in `node_modules/.pnpm`). Every entry is hashed there, so both patches stay refused. A run from a member finds no patch to attest: the scan's files are the workspace root's. `tests/common/pnpm_links.rs` reads the links a second time, with its own walk and none of the crates' code. Where `vex` attests, no path from outside the store's entries may lead into an entry that holds the upstream bytes; where a link was added, it must find that link. The registry-route leg and the vendored capstone that already ran the install use it too, and the capstone links the upstream entry from `vendor/` to see the warning come back. Offline, the hosted suite builds the nested `modulesDir` store by hand. The store of another checkout now holds both entries of the package, so that the test shows unrelated directories keeping them, and not a version that sits in one entry. `apply --check` is run from inside a workspace member: it is in sync while nothing links the entry that holds the original bytes, and a link to that entry from `vendor/` at the workspace root is drift, which shows that the whole project is read. Ran with `SOCKET_PATCH_PNPM_E2E_REQUIRED=1` on pnpm 12.23.0 and 11.29.0 (the route legs), 10.34.9, 9.15.9 and 11.29.0 (the vendored capstone) and 12.25.1 (its pinned matrix leg). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Document which pnpm store entries vex judges under the link sweep `CLI_CONTRACT.md`, `docs/ecosystems.md` and the pnpm compatibility notes described the first rule of this branch: the links of the `node_modules` the crawl searches, of the lockfiles' members and of the hoist directory. They now describe the rule in the code (#2353): - which entries are left out, and that only a package version that sits in two entries of one store is judged at all; - the tree whose links are read, and the `node_modules` above it; - every condition under which all entries are still hashed; - what was measured with real pnpm: the pair of old entries a hosted scan leaves when the patched package is a peer dependency, the `.bin` shims, and where a `modulesDir` of more than one level puts the store. What the sweep costs, for the record. Release builds, `vex --offline` on a pnpm 12.25.1 project of 1,222 store entries (7,377 directories, 4,111 links), 40 runs of each binary, interleaved, on a machine that was busy with other work (load average 21 to 34). The base is this branch's merge base, 1b3f422: state of the project merge base this branch one entry per patched version 50 / 75 ms 51 / 73 ms four versions in two entries each 44 / 98 ms 218 / 365 ms (minimum / median) Where no version sits in two entries nothing is read, and the run costs what it cost before. Where one does, the links are read once: 172 to 326 ms on that project, 0.8 to 1.8 s on a tree of 29,120 directories, and 5.6 to 7.6 s on one of 235,697, against 0.12 s and 4.8 s for `find -type l` on the first and the last. A project whose patched package has two peer variants pays for the sweep on every run, leftover or not. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Read no links above the scanned project for a pnpm store The sweep that decides which entries of a pnpm store an install links (#2353) also read each node_modules of a directory above the scanned one. pnpm writes no link there into a store below it, so the read only guarded against a link placed by hand, and it had a cost: with the rule that keeps every entry when a link leads to a directory that is not read, a project that sits in another pnpm workspace's checkout was never judged (that workspace links its members from its own node_modules), every judged run read the outer install, and the outcome depended on directories nobody scanned. The links read are now those below the scanned directory, or below the project that holds the store when the scan started inside it. A link to a directory outside it still keeps every entry. The docs say what is not read: links above that directory, a path to an entry that a file spells out, and NODE_PATH. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Check that no file names an upstream pnpm entry after the in-place install pnpm writes the path of a store entry into the launchers of a package's commands (node_modules/.bin), where no link shows it. Measured on pnpm 11.29.0 and 12.25.1, hosted and vendored, in a single project and a workspace: the install that changes the entry rewrites the launchers, and afterwards the only file that names the upstream entry's directory is the launcher inside that entry. The patched package of the real-pnpm workspace legs now ships a command, and the in-place leg reads every file below the project: none outside the upstream entries may name one of them, and a launcher must name the entry of the patch's registry. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Run the macOS path-spelling case only where the temp dir is on the data volume The case that reaches the leftover entry through /System/Volumes/Data asserted that the temp dir is on the volume mounted there. It is on a stock macOS, and the case now runs only then, so a runner whose temp dir sits on another volume skips it instead of failing. Also formats the launcher assertion of the real-pnpm in-place leg. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Fix the review findings on the pnpm link sweep - A link to a named pipe could hang vex and apply --check: the check that a link's target is no other spelling of the store opened each path. It now compares device and inode from stat and opens nothing. - A link that reaches the store through another spelling of its path inside the swept tree was dropped (a file system that folds case and keeps the typed spelling), so the entry behind it read as unlinked. The spelling check now runs on every target that is not below the store as spelled, inside the tree or outside it. - The sweep ran for the peer variants of a patched package, which hold the same bytes, on every vex and apply --check. A store is now judged for a version only when its copies in two or more entries do not hold the same bytes: leaving out a copy that holds the same bytes as the others changes no verdict, so the project is not read for them. - The sweep kept every link in memory with no bound and gave up only after 1,000,000 directories. Links count against the budget, which is 500,000 directories and links (a monorepo with a store of 5,200 entries holds about 98,000 and 20,000). - A copy in the hoist dir or a hidden child of the store counted as a second entry, so a version in one entry was judged against the docs. - A run from a git checkout that is a member of a workspace rooted above it read the outer workspace. The project above the scanned directory is now read only inside the checkout, as other upward lookups are. - An assert message held a run of spaces. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Follow a link to a file outside the project, and leave an entry out only beside a linked copy Findings of a second review of the pnpm link sweep (#2353): - A link to a file outside the scanned directory was accepted, but node loads that file from where it is and looks its packages up in the node_modules above it. A member that left the workspace keeps the links pnpm wrote for it, so `scripts/gen.js -> ../../shared/gen.js` loaded the leftover while apply --check reported the patch in place. The package links of each node_modules above such a file now count like the links below the project, and every entry is kept when one cannot be read. - With no entry of a version linked, every copy was dropped and the package read as not installed, where one unlinked entry is hashed. An entry is now left out only beside a linked entry of the same version. - A link to the store directory itself was ignored though the contract says a link into the store that names no entry keeps every entry. It does now. - A link that loops or passes through a file kept every entry. Nothing is loaded through one, so it is left out like a link whose target is gone. - The byte comparison read files with a bare read; it goes through the reader that refuses a pipe, as the crawlers' guard requires. - The contract said every entry is hashed when a lockfile is missing; a missing pnpm-lock.yaml is fine, and the text now says which reads count. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Reword two sentences of the pnpm store entry docs The list of rules gained a point, so "the last case" named the wrong one, and "a link is never followed" now has one exception. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Keep every pnpm entry when a link leads to a file below a node_modules outside the project Findings of a third review of the pnpm link sweep (#2353), all on the step that read the node_modules above a file a link leads to outside the scanned directory: - A link there that spelled the store's path another way, a link to a directory with a node_modules of its own, and a linked @scope were not followed, so a leftover that node reaches in two hops was left out. - The step listed node_modules directories anywhere on disk, and an unreadable one changed the verdict. Nothing outside the scanned directory is read any more. A link to a file outside it keeps every entry when a directory above that file holds a node_modules, which is where node looks up the packages of a file it loads from there (a member that left the workspace keeps the links pnpm wrote for it). This asks one stat per directory, stops at the home directory as git's own lookup does, and covers every chain that starts in those node_modules. A link to an interpreter under the home directory, as in a virtualenv, changes nothing. Also: a directory that is removed while the sweep runs (a build's temp dir) no longer makes the store unjudgeable for that run. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Compare bundled dependencies in the pnpm byte check, and skip it where no store is judged Findings of a fourth review of the pnpm link sweep (#2353): - The comparison of two copies of a version left out each package's whole node_modules. Dependencies a package bundles are unpacked there, so two copies that differ only in a bundled dependency read as the same bytes and were never judged by their links. Only node_modules/.bin is left out, which is all pnpm 11.29.0 and 12.25.1 write there. - The copies were read through on Windows, in a --global run and for a store already found unjudgeable, where the result cannot matter. - One unit case linked to a file outside the project without the guard its siblings have, so it failed on a machine with a node_modules above the temp dir. - The docs did not say that copies over 64 MB or 50,000 files are not compared. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Name pnpm prune as the way to drop a leftover store entry Where a store is not judged (Windows, a link to a directory outside the project, a nested modulesDir), the upstream entry an in-place install leaves behind still reads as an unpatched copy. pnpm prune removes it at once on pnpm 11.29.0 and 12.25.1 (measured on the registry route), so the docs name it beside a clean node_modules. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Judge a pnpm store under a nested modulesDir from the workspace root Under a `modulesDir` of more than one level (`sub/node_modules`), pnpm 10.12 and later put the virtual store in `<modulesDir>/.pnpm` and each member's links in `<member>/<modulesDir>`. The lockfile in the store names the members from the workspace root, but the store was taken to belong to the directory beside its `node_modules`, where no member is. So every entry was kept, and the entry an in-place install leaves behind refused the patch (#2353). The root is now looked up: the directory beside the store's `node_modules`, or the nearest one above it whose `modulesDir` setting (`pnpm-workspace.yaml`, or `modules-dir` in `.npmrc`) names that `node_modules`, whichever holds every importer of both lockfiles. It is read like any other file a project run looks up above the scanned directory: not past the checkout, and not at the home directory. The members' links are below the root, so the sweep reads them, and a link in a member's own modules dir keeps an entry like any other. pnpm before 10.12 moves the links and the install record under a `modulesDir` and leaves the store in `node_modules/.pnpm` (measured on 9.15.9 and 10.11.1). The record is read from the modules dir there, and counts only when it names the store. Where no setting in the project says which directory installs into that `node_modules` (the setting came from pnpm's global config), the root is not known and every entry is kept, as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Find the workspace root before reading a pnpm store, from its own settings Review of the nested modulesDir change found that the root lookup read too much and trusted too much: - An install record of another linker beside the store (`pnp`, `hoisted`) was overruled by an older isolated record in a modules dir, so a store whose packages are loaded by path could be judged by its links. A record beside the store now decides; the one in a modules dir counts only where there is none beside it. - The install record, the lockfiles and the importers of a project above the scanned directory were read before the check that it may be read at all. The root is now found first, and nothing of a store is read unless a root that may be read holds it. - The `modulesDir` setting was taken from any `pnpm-workspace.yaml` or `.npmrc` above the candidate, the home directory's among them. Only the candidate's own two files count. - Every judged store paid for a walk up its ancestors. The walk happens only when `pnpm-lock.yaml` is not beside `node_modules`, which is the layout a nested modulesDir leaves. - The home rule also stopped at the scanned directory itself, so a project whose root is the home directory was not judged. - With a modulesDir of three levels, a scan from a subdirectory stopped at the first directory unrelated to it and never reached the root. - When the lockfile in the store names the root alone, `pnpm-lock.yaml` at the root was not read, so an importer outside the root went unseen. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Document that the pnpm store root walk stops at the home directory The walk that finds a workspace root above a nested modulesDir skips a directory above the scanned one that is the home directory or above it, like every other upward lookup of a project run. The lists of cases where every store entry is hashed only named the git checkout bound. Assisted-by: Claude Code:claude-opus-5-5 --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 2440352 commit dfa9a96

7 files changed

Lines changed: 415 additions & 76 deletions

File tree

‎crates/socket-patch-cli/CLI_CONTRACT.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ Recognition rules that hold for every ecosystem:
894894
| Hosted: a discovered patch-host reference (or a live pre-v5 redirect-ledger record) | The installed copies the build **consumes** through the hosted wiring are hash-verified when any exist: the Go replacement module, never the pristine `M@v` in the module cache; the Socket-registry cargo source dir; maven's suffixed version. Installed evidence wins: `hash_mismatch` / `not_applied` are omitted. With **nothing installed**, a discovered reference whose lock pins the artifact (or whose format's rewriter never writes a pin) attests from that pin, which is the same evidence as in-run `scan --mode hosted --vex`. A pre-v5 ledger-only record, or a reference whose required pin is missing, stays `package_not_found`. So do purls that `--ecosystems` kept out of the crawl, because "not installed" has to mean the crawler looked. The same goes for npm purls when an installed pnpm tree records its virtual store outside the project (`enableGlobalVirtualStore`, or a `virtualStoreDir` that climbs out): transitive deps there are invisible to the crawler. A pnpm `modulesDir` inside the project is crawled. A Composer purl is omitted as `composer_install_unread` instead when `composer.json`'s `config.vendor-dir` puts the install outside the project (an absolute path, `~/…`, `$VAR/…`, or one that climbs out) and an install is there (its `composer/installed.json` exists, or the directory cannot be resolved): the crawler reads no tree outside the project that only a project file names, so that install was not checked and may predate the redirect (#686). While nothing is installed there the pin still attests, and with `COMPOSER_VENDOR_DIR` set to the directory the crawler reads it and the installed bytes decide. A yarn Plug'n'Play project (`.pnp.cjs` / `.pnp.js`) has no tree to crawl: an npm purl there attests from the lock's pin only when the PnP loader itself resolves it through the patch (berry names the hosted url, yarn 1 the resolved url's `#<sha1>` in its cache folder). A loader written before the lock was rewired runs the registry copy, so the purl stays omitted until `yarn install` rewrites it (#519). | `(redirected)` |
895895
| Agent: a manifest record with no live hosted/vendored wiring | The installed tree, unchanged. **Every** installed copy the crawler finds for the purl (npm nests duplicates of one `name@version`; pnpm, vlt, Bun and Deno stores add peer-variant copies and copies bundled inside other packages) must hash to the patched bytes, as `apply` patches every copy (Maven: every copy a build consumes, Gradle hash dirs included — see [Gradle builds](#gradle-builds-v50)). One unpatched copy omits the purl with that copy's tag (`not_applied` / `hash_mismatch`). | none |
896896

897-
**Unlinked store entries.** In every row an installed copy is one the install can load. Bun never prunes `node_modules/.bun`, and pnpm keeps a `node_modules/.pnpm` entry it no longer uses (pnpm 7–11 for up to 7 days, pnpm 12 until `pnpm prune`). After the in-place install that a hosted or vendored scan asks for, the project links a new entry (on pnpm, `<name>@socket-<id>+<version>` for a release routed through the registry of its patch and `<name>@file+…` for a vendored tarball, `file+…` on pnpm 8 and earlier), and the upstream `<name>@<version>` entry stays in the store, pristine. An entry that no link leads into is not an installed copy: `vex` and `apply --check` do not hash it, so it neither omits a patch as `not_applied` nor warns `vendored_tree_out_of_sync`. For pnpm this applies to a package version only when its copies sit in two or more entries of one store and do not hold the same bytes in each; a version in one entry is hashed as before, linked or not, and so are copies that hold the same bytes (the peer variants of a package), since leaving one out would change no verdict; copies of more than 64 MB or 50,000 files are not compared and count as holding other bytes. For a version in two entries, every symbolic link is read below the scanned directory (or below the project that holds the store, when the scan started inside it), in every directory whatever its name; nothing above that directory is read. A link that leads nowhere (no target, a loop, a path through a file) is left out. An entry is hashed when a link outside the store's entries resolves into it, or a link inside a hashed entry does; the entries left out are those that only other left-out entries link, and only beside a hashed entry of the same version: when none of a version's entries is linked, all are hashed as before (a hosted scan leaves such a pair when the patched package is a peer dependency: the dependent gets a new entry, and its old entry keeps its link to the old one). A copy in the store but in none of its entries is always hashed. Only links are read, not a path to an entry that a file spells out or `NODE_PATH` names. Every store is judged once per run, by the same links for the record check and the hosted one. Where a link may have gone unread, every entry is hashed: on Windows; when the scanned directory and the store's project are unrelated (`--global`, a `node_modules` linked from another checkout), or the store's project lies above the git checkout the run started in; under `node-linker=hoisted`, `shamefully-hoist` or a moved virtual store; when the install record or the lockfile in the store is missing or unreadable, `pnpm-lock.yaml` is unreadable, or either lists its importers in a way pnpm does not write; when a lockfile names an importer that is not a directory inside the store's project (also a `modulesDir` of more than one level); when a directory or a link cannot be read, or the directory holds more than 500,000 directories and links; when a link resolves to a directory outside the directory that was read, to a file outside it that has a `node_modules` in a directory above it (the home directory and above are not looked at), to the store itself, or into the store by a path that names none of its entries (another spelling of the store's path or of an entry's name); and when no link resolves into any entry (`docs/ecosystems.md`, "npm: which `node_modules` trees are crawled", has the list). `rollback` and `remove` restore unlinked entries too.
897+
**Unlinked store entries.** In every row an installed copy is one the install can load. Bun never prunes `node_modules/.bun`, and pnpm keeps a `node_modules/.pnpm` entry it no longer uses (pnpm 7–11 for up to 7 days, pnpm 12 until `pnpm prune`). After the in-place install that a hosted or vendored scan asks for, the project links a new entry (on pnpm, `<name>@socket-<id>+<version>` for a release routed through the registry of its patch and `<name>@file+…` for a vendored tarball, `file+…` on pnpm 8 and earlier), and the upstream `<name>@<version>` entry stays in the store, pristine. An entry that no link leads into is not an installed copy: `vex` and `apply --check` do not hash it, so it neither omits a patch as `not_applied` nor warns `vendored_tree_out_of_sync`. For pnpm this applies to a package version only when its copies sit in two or more entries of one store and do not hold the same bytes in each; a version in one entry is hashed as before, linked or not, and so are copies that hold the same bytes (the peer variants of a package), since leaving one out would change no verdict; copies of more than 64 MB or 50,000 files are not compared and count as holding other bytes. For a version in two entries, every symbolic link is read below the scanned directory (or below the project that holds the store, when the scan started inside it), in every directory whatever its name; nothing above that directory is read. A link that leads nowhere (no target, a loop, a path through a file) is left out. An entry is hashed when a link outside the store's entries resolves into it, or a link inside a hashed entry does; the entries left out are those that only other left-out entries link, and only beside a hashed entry of the same version: when none of a version's entries is linked, all are hashed as before (a hosted scan leaves such a pair when the patched package is a peer dependency: the dependent gets a new entry, and its old entry keeps its link to the old one). A copy in the store but in none of its entries is always hashed. Only links are read, not a path to an entry that a file spells out or `NODE_PATH` names. Every store is judged once per run, by the same links for the record check and the hosted one. Where a link may have gone unread, every entry is hashed: on Windows; when the scanned directory and the store's project are unrelated (`--global`, a `node_modules` linked from another checkout), or the store's project lies above the git checkout the run started in or, above the scanned directory, is the home directory or above it; under `node-linker=hoisted`, `shamefully-hoist` or a moved virtual store; when the install record or the lockfile in the store is missing or unreadable, `pnpm-lock.yaml` is unreadable, or either lists its importers in a way pnpm does not write; when a lockfile names an importer that is not a directory inside the workspace's root (under a `modulesDir` of more than one level, the directory whose `modulesDir` setting names the store's `node_modules`); when a directory or a link cannot be read, or the directory holds more than 500,000 directories and links; when a link resolves to a directory outside the directory that was read, to a file outside it that has a `node_modules` in a directory above it (the home directory and above are not looked at), to the store itself, or into the store by a path that names none of its entries (another spelling of the store's path or of an entry's name); and when no link resolves into any entry (`docs/ecosystems.md`, "npm: which `node_modules` trees are crawled", has the list). `rollback` and `remove` restore unlinked entries too.
898898

899899
**Liveness gates.** These gates run before hashing, and `--no-verify` / `--vex-no-verify` skips only the hashing, never the gates:
900900

‎crates/socket-patch-cli/tests/e2e_redirect_pnpm_build.rs‎

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3938,11 +3938,13 @@ async fn pnpm11_registry_route_in_place_install_is_judged_by_every_link() {
39383938
/// `node_modules/.pnpm`). The lockfile in the store still names the
39393939
/// members by their paths from the workspace root, and none of them is a
39403940
/// directory below `sub/`, the directory that holds the store's
3941-
/// `node_modules`. `vex` cannot tell which directory the members' links
3942-
/// are below, so it keeps every entry: the upstream entries the in-place
3943-
/// install left behind refuse both patches as `not_applied`, as before
3944-
/// #2353, although nothing links them. A run from a member finds no patch
3945-
/// to attest: the scan's files are the workspace root's.
3941+
/// `node_modules`. The root is the directory whose `modulesDir` setting
3942+
/// names that `node_modules`, and `vex` judges the store from there: the
3943+
/// upstream entries the in-place install left behind are left out, and
3944+
/// both patches are attested. A link to the upstream `leaf` from a
3945+
/// member's own modules dir refuses its patch until the link is gone. A
3946+
/// run from a member finds no patch to attest: the scan's files are the
3947+
/// workspace root's.
39463948
#[cfg(unix)]
39473949
async fn registry_route_in_place_install_under_a_nested_modules_dir(pm: &str, tag: &str) {
39483950
if !has_corepack_pm(pm) {
@@ -3993,18 +3995,41 @@ async fn registry_route_in_place_install_under_a_nested_modules_dir(pm: &str, ta
39933995
"{tag}: {unpatched:?} hold the upstream leaf, unlinked: {reachable:?}"
39943996
);
39953997

3998+
let not_affected = |patch: &RoutePatch| (patch.advisory(), "not_affected".to_string());
39963999
let (code, attested, stderr) = route_vex(&proj, &server);
3997-
assert_ne!(code, 0, "{tag}: vex from the root: {attested:?}\n{stderr}");
3998-
assert!(attested.is_empty(), "{tag}: {attested:?}\n{stderr}");
4000+
assert_eq!(code, 0, "{tag}: vex from the root: {attested:?}\n{stderr}");
39994001
for patch in &ROUTE_PATCHES {
4000-
// Named as `<name>@<version>`, in a purl when it is the only one.
4001-
let release = format!("{}@{ROUTE_VERSION}", patch.name);
40024002
assert!(
4003-
stderr.contains(&release) && stderr.contains("not_applied"),
4004-
"{tag}: every entry is judged, so {} is refused:\n{stderr}",
4003+
attested.contains(&not_affected(patch)),
4004+
"{tag}: {} must be attested under the nested modulesDir: {attested:?}\n{stderr}",
40054005
patch.name
40064006
);
40074007
}
4008+
// A link to the upstream leaf in a member's own modules dir is a way
4009+
// to load it: the independent reading finds it, and vex refuses the
4010+
// patch until the link is gone.
4011+
let link = proj.join("packages/a/sub/node_modules/old-leaf");
4012+
std::os::unix::fs::symlink(store.join("leaf@1.0.0/node_modules/leaf"), &link).unwrap();
4013+
let reachable = pnpm_links::reachable_store_entries(&proj, &store);
4014+
assert!(
4015+
reachable.contains("leaf@1.0.0"),
4016+
"{tag}: the independent reading must find the link: {reachable:?}"
4017+
);
4018+
let (code, attested, stderr) = route_vex(&proj, &server);
4019+
assert_eq!(code, 0, "{tag}: vex with the link: {attested:?}\n{stderr}");
4020+
assert!(
4021+
!attested.contains(&not_affected(leaf))
4022+
&& stderr.contains("leaf@1.0.0")
4023+
&& stderr.contains("not_applied"),
4024+
"{tag}: a link from a member's modules dir must refuse leaf: {attested:?}\n{stderr}"
4025+
);
4026+
std::fs::remove_file(&link).unwrap();
4027+
let (code, attested, stderr) = route_vex(&proj, &server);
4028+
assert_eq!(code, 0, "{tag}: vex without the link:\n{stderr}");
4029+
assert!(
4030+
attested.contains(&not_affected(leaf)),
4031+
"{tag}: without the link leaf is attested again: {attested:?}\n{stderr}"
4032+
);
40084033
let (code, attested, stderr) = route_vex(&proj.join("packages/b"), &server);
40094034
assert_ne!(code, 0, "{tag}: vex from a member: {attested:?}\n{stderr}");
40104035
assert!(attested.is_empty(), "{tag}: {attested:?}\n{stderr}");

‎crates/socket-patch-cli/tests/e2e_vex_redirect.rs‎

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,24 +2803,31 @@ fn pnpm_hosted_ref_is_hashed_in_a_store_reached_through_a_linked_node_modules()
28032803
/// member's dependencies in `<member>/<modulesDir>` (real pnpm 12.25.1
28042804
/// layout). The lockfile in the store names the members from the
28052805
/// workspace root, and none of them is a directory below `sub/`, which
2806-
/// holds the store's `node_modules`. The store's entries are not judged
2807-
/// then: the pristine upstream entry is hashed and refuses the patch,
2808-
/// although nothing links it. The same workspace without the setting is
2809-
/// judged, and attests.
2806+
/// holds the store's `node_modules`. The root is the directory whose
2807+
/// `modulesDir` setting names that `node_modules`: the store is judged
2808+
/// from there, the pristine upstream entry is left out, and the patch is
2809+
/// attested, until a link in the member's own modules dir reaches that
2810+
/// entry. With no setting to say where the root is, the store's entries
2811+
/// are not judged: the upstream entry is hashed and refuses the patch.
28102812
#[cfg(unix)]
28112813
#[test]
2812-
fn pnpm_hosted_ref_is_hashed_in_a_store_under_a_nested_modules_dir() {
2814+
fn pnpm_hosted_ref_in_a_store_under_a_nested_modules_dir_is_judged_from_the_root() {
28132815
let (pristine, patched) = (
28142816
&b"module.exports = 'pristine'\n"[..],
28152817
&b"module.exports = 'patched'\n"[..],
28162818
);
28172819
let purl = "pkg:npm/left-pad@1.3.0";
28182820
let routed = format!("left-pad@socket-{}+1.3.0", &UUID[..8]);
2819-
for (modules_dir, attests) in [("node_modules", true), ("sub/node_modules", false)] {
2821+
for (modules_dir, setting, attests) in [
2822+
("node_modules", false, true),
2823+
("sub/node_modules", true, true),
2824+
("sub/node_modules", false, false),
2825+
] {
2826+
let case = format!("{modules_dir}, setting {setting}");
28202827
let tmp = tempfile::tempdir().unwrap();
28212828
let cwd = &tmp.path().join("app");
28222829
write_pnpm_member_routing_left_pad(cwd);
2823-
if modules_dir != "node_modules" {
2830+
if setting {
28242831
let workspace = cwd.join("pnpm-workspace.yaml");
28252832
let text = std::fs::read_to_string(&workspace).unwrap();
28262833
std::fs::write(workspace, format!("{text}modulesDir: {modules_dir}\n")).unwrap();
@@ -2835,26 +2842,41 @@ fn pnpm_hosted_ref_is_hashed_in_a_store_under_a_nested_modules_dir() {
28352842
);
28362843
// From `packages/a/<modulesDir>` up to the workspace root.
28372844
let up = "../".repeat(2 + modules_dir.split('/').count());
2845+
let member_nm = cwd.join("packages/a").join(modules_dir);
28382846
pnpm_link(
28392847
&format!("{up}{modules_dir}/.pnpm/{routed}/node_modules/left-pad"),
2840-
&cwd.join("packages/a").join(modules_dir).join("left-pad"),
2848+
&member_nm.join("left-pad"),
28412849
);
28422850
let (_rt, server) = serve_patch_views(vec![(
28432851
UUID.to_string(),
28442852
one_file_view(UUID, purl, "package/index.js", pristine, patched),
28452853
)]);
2846-
2847-
let (code, env) = vex_json(cwd, &["--proxy-url", &server.uri()]);
2848-
if attests {
2849-
assert_attested(cwd, code, &env, UUID, modules_dir);
2850-
} else {
2851-
assert_eq!(code, Some(1), "{modules_dir}: {env}");
2854+
let refused = |what: &str| {
2855+
let (code, env) = vex_json(cwd, &["--proxy-url", &server.uri()]);
2856+
assert_eq!(code, Some(1), "{case}, {what}: {env}");
28522857
assert_eq!(
28532858
skipped_reason(&env, purl),
28542859
"not_applied",
2855-
"{modules_dir}: {env}"
2860+
"{case}, {what}: {env}"
28562861
);
2862+
};
2863+
2864+
if !attests {
2865+
refused("the root is not known");
2866+
continue;
28572867
}
2868+
let (code, env) = vex_json(cwd, &["--proxy-url", &server.uri()]);
2869+
assert_attested(cwd, code, &env, UUID, &case);
2870+
// A link to the pristine entry in the member's own modules dir.
2871+
let old = member_nm.join("old-left-pad");
2872+
pnpm_link(
2873+
&format!("{up}{modules_dir}/.pnpm/left-pad@1.3.0/node_modules/left-pad"),
2874+
&old,
2875+
);
2876+
refused("a link in the member's modules dir");
2877+
std::fs::remove_file(&old).unwrap();
2878+
let (code, env) = vex_json(cwd, &["--proxy-url", &server.uri()]);
2879+
assert_attested(cwd, code, &env, UUID, &format!("{case}, the link removed"));
28582880
}
28592881
}
28602882

0 commit comments

Comments
 (0)