Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0c02126
Stop vex judging the pnpm store entry an in-place install leaves behind
mikolalysenko Dec 1, 2026
fe6afe1
Test vex, apply --check and rollback over an unlinked pnpm store entry
mikolalysenko Dec 1, 2026
8ce3e68
Run the in-place pnpm install and vex in the real-pnpm suites
mikolalysenko Dec 1, 2026
c297208
Document which pnpm store entries vex and apply --check judge
mikolalysenko Dec 1, 2026
e4c56c7
Refuse a pnpm importers section that a line at column 0 cuts short
mikolalysenko Dec 1, 2026
2a14437
Keep a pnpm store entry that any searched node_modules still reaches
mikolalysenko Dec 1, 2026
3ff92e9
Judge a pnpm store in a checkout of part of its workspace
mikolalysenko Dec 1, 2026
08a9155
Test vex and apply --check over a node_modules no lockfile names
mikolalysenko Dec 1, 2026
2d4c713
Correct the docs on which links keep a pnpm store entry
mikolalysenko Dec 1, 2026
c77a1fa
Test that a lockfile's member is read where the crawl does not look
mikolalysenko Dec 1, 2026
e644e58
Judge a pnpm store entry by every link below the scanned project
mikolalysenko Dec 1, 2026
c12ac25
Test vex over the in-place pnpm install in a workspace, link by link
mikolalysenko Dec 1, 2026
c86a2fd
Document which pnpm store entries vex judges under the link sweep
mikolalysenko Dec 1, 2026
cf93664
Read no links above the scanned project for a pnpm store
mikolalysenko Dec 1, 2026
3fe9cde
Check that no file names an upstream pnpm entry after the in-place in…
mikolalysenko Dec 1, 2026
6c2404c
Merge remote-tracking branch 'origin/main' into fix/vex-pnpm-stale-st…
mikolalysenko Dec 1, 2026
30a96ca
Run the macOS path-spelling case only where the temp dir is on the da…
mikolalysenko Dec 1, 2026
c8332da
Fix the review findings on the pnpm link sweep
mikolalysenko Dec 1, 2026
ab7a2fe
Follow a link to a file outside the project, and leave an entry out o…
mikolalysenko Dec 1, 2026
2257266
Reword two sentences of the pnpm store entry docs
mikolalysenko Dec 1, 2026
05477b7
Keep every pnpm entry when a link leads to a file below a node_module…
mikolalysenko Dec 1, 2026
7a25662
Merge remote-tracking branch 'origin/main' into fix/vex-pnpm-stale-st…
mikolalysenko Dec 2, 2026
5488819
Compare bundled dependencies in the pnpm byte check, and skip it wher…
mikolalysenko Dec 2, 2026
b8d98e5
Name pnpm prune as the way to drop a leftover store entry
mikolalysenko Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@ Recognition rules that hold for every ecosystem:
| 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)` |
| 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 |

**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.

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

* A **vendor ledger entry** attests only while some lockfile or config still wires its artifact. Otherwise it is omitted as `vendor_unwired`. The exception is a hosted takeover: the same package with a live redirect record falls through to that hosted claim.
Expand Down
7 changes: 4 additions & 3 deletions crates/socket-patch-cli/src/commands/vex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::commands::vex_sources::{
self, Plan, RunApiClient, Sources, GO_WORKSPACE_OVERRIDE, RECORD_MISMATCH, RECORD_UNAVAILABLE,
REDIRECT_UNWIRED, VENDOR_UNWIRED, WIRING_CONFLICT,
};
use crate::ecosystem_dispatch::{find_manifest_package_copies_reusing, JvmScope};
use crate::ecosystem_dispatch::{find_manifest_package_copies_judged, JvmScope};
use crate::json_envelope::{Command, Envelope, EnvelopeError, PatchAction, PatchEvent, RunWarning};
use crate::ui::plural;

Expand Down Expand Up @@ -1006,8 +1006,8 @@ async fn generate_vex(
if quiet {
verifying.set("Finding installed packages");
}
let copies =
find_manifest_package_copies_reusing(&purls, common, quiet, params.npm_prior.as_ref())
let (copies, mut live_stores) =
find_manifest_package_copies_judged(&purls, common, quiet, params.npm_prior.as_ref())
.await;
verifying.set("Verifying installed patches");
// The record check: every copy of each purl; for Maven, every copy
Expand All @@ -1026,6 +1026,7 @@ async fn generate_vex(
&plan.hosted,
&copies,
params.npm_prior.as_ref(),
&mut live_stores,
)
.await;
let vendor = VendorContext {
Expand Down
16 changes: 12 additions & 4 deletions crates/socket-patch-cli/src/commands/vex_consumed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use std::path::{Path, PathBuf};

#[cfg(not(test))]
use socket_patch_core::crawlers::npm_crawler::with_store_peer_variant_copies;
use socket_patch_core::crawlers::npm_crawler::LiveStoreEntries;
use socket_patch_core::crawlers::{
CargoCrawler, CrawlerOptions, Ecosystem, GoCrawler, MavenCrawler,
};
Expand All @@ -65,7 +66,9 @@ use crate::ecosystem_dispatch::{
/// the installed-tree lookup. `installed` is that lookup's every-copy
/// result ([`crate::ecosystem_dispatch::find_manifest_package_copies_reusing`] over
/// the record view, which holds every hosted purl), including npm store
/// variants. The shared-location ecosystems read it instead of crawling
/// variants, and `live` the judgement of the npm stores' live entries that
/// lookup made, which this one shares: it drops no copy that lookup kept.
/// The shared-location ecosystems read it instead of crawling
/// the tree a second time. `prior`
/// (embedded hosted `scan --vex` only) is scan's npm crawl of the same
/// tree: the identity fallback takes its packages instead of crawling the
Expand All @@ -75,6 +78,7 @@ pub(crate) async fn hosted_consumed_copies(
hosted: &BTreeMap<String, HostedWiring>,
installed: &HashMap<String, Vec<PathBuf>>,
prior: Option<&NpmCrawlSnapshot>,
live: &mut LiveStoreEntries,
) -> HashMap<String, HostedCopies> {
let mut out = HashMap::new();
if hosted.is_empty() {
Expand Down Expand Up @@ -115,10 +119,10 @@ pub(crate) async fn hosted_consumed_copies(
},
);
}
// An orphaned Bun store entry is no consumed copy; the
// An orphaned Bun or pnpm store entry is no consumed copy; the
// installed lookup dropped its own, this drops the ones the alias
// and identity fallbacks' variant expansion added.
socket_patch_core::crawlers::npm_crawler::retain_live_store_copies(
live.retain_live_copies(
out.iter_mut()
.filter(|(purl, _)| npm.contains(purl))
.map(|(_, copies)| &mut copies.paths),
Expand Down Expand Up @@ -464,7 +468,11 @@ mod tests {
)]);
VARIANT_INPUTS
.scope(std::cell::RefCell::new(Vec::new()), async {
let mut found = hosted_consumed_copies(common, &hosted, installed, None).await;
// The judgement `vex` hands over: the installed lookup's,
// made for the scanned directory.
let mut live = LiveStoreEntries::new(Some(common.cwd.clone()));
let mut found =
hosted_consumed_copies(common, &hosted, installed, None, &mut live).await;
let paths = found.remove(&purl).unwrap().paths;
let calls = VARIANT_INPUTS.with(|inputs| inputs.borrow().clone());
(paths, calls)
Expand Down
30 changes: 24 additions & 6 deletions crates/socket-patch-cli/src/ecosystem_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::{Path, PathBuf};
use crate::args::GlobalArgs;

use socket_patch_core::crawlers::npm_crawler::{
build_npm_purl, parse_package_name, retain_live_store_copies, with_store_peer_variant_copies,
build_npm_purl, parse_package_name, with_store_peer_variant_copies, LiveStoreEntries,
};
use socket_patch_core::crawlers::walk_pool;
use socket_patch_core::crawlers::CargoCrawler;
Expand Down Expand Up @@ -1338,6 +1338,21 @@ pub async fn find_manifest_package_copies_reusing(
quiet: bool,
prior: Option<&NpmCrawlSnapshot>,
) -> HashMap<String, Vec<PathBuf>> {
find_manifest_package_copies_judged(purls, common, quiet, prior)
.await
.0
}

/// [`find_manifest_package_copies_reusing`], with the judgement of the npm
/// stores' live entries that its copies went through. A caller that
/// resolves more copies of the same tree (`vex`'s hosted lookup) filters
/// them by it, so the two lookups agree on every store entry.
pub(crate) async fn find_manifest_package_copies_judged(
purls: &[String],
common: &GlobalArgs,
quiet: bool,
prior: Option<&NpmCrawlSnapshot>,
) -> (HashMap<String, Vec<PathBuf>>, LiveStoreEntries) {
let partitioned = partition_purls(purls, common.ecosystems.as_deref());
let crawler_options = common.crawler_options();
let mut copies = dispatch_find_with_npm_links(
Expand All @@ -1361,10 +1376,13 @@ pub async fn find_manifest_package_copies_reusing(
with_store_peer_variant_copies(common.read_scope(), std::mem::take(paths)).await;
}
}
// A Bun store entry nothing links any more (Bun never prunes `.bun`)
// is no copy the install loads, so the check skips it (#599). Rollback
// and remove, which resolve without this, still restore it.
retain_live_store_copies(
// A Bun or pnpm store entry nothing links any more (Bun never prunes
// `.bun`; pnpm keeps the entry an in-place install replaced) is no
// copy the install loads, so the check skips it (#599, #2353). A pnpm
// entry is judged by every link below the scanned project.
// Rollback and remove, which resolve without this, still restore it.
let mut live = LiveStoreEntries::new((!common.is_global()).then(|| common.cwd.clone()));
live.retain_live_copies(
copies
.iter_mut()
.filter(|(purl, _)| purl.starts_with("pkg:npm/"))
Expand Down Expand Up @@ -1422,7 +1440,7 @@ pub async fn find_manifest_package_copies_reusing(
.await;
}
copies.retain(|_, paths| !paths.is_empty());
copies
(copies, live)
}

// ── JVM copies ──────────────────────────────────────────────────────────
Expand Down
Loading
Loading