Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 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
c35865a
Judge a pnpm store under a nested modulesDir from the workspace root
mikolalysenko Dec 2, 2026
0cedc96
Find the workspace root before reading a pnpm store, from its own set…
mikolalysenko Dec 2, 2026
f30c09e
Merge remote-tracking branch 'origin/main' into fix/vex-pnpm-store-ne…
mikolalysenko Dec 2, 2026
0d68d88
Document that the pnpm store root walk stops at the home directory
claude Dec 2, 2026
0297f9b
Merge remote-tracking branch 'origin/main' into fix/vex-pnpm-store-ne…
mikolalysenko Dec 2, 2026
cfe7ce6
Merge remote-tracking branch 'origin/main' into fix/vex-pnpm-store-ne…
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: 1 addition & 1 deletion crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ 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.
**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.

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

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

let not_affected = |patch: &RoutePatch| (patch.advisory(), "not_affected".to_string());
let (code, attested, stderr) = route_vex(&proj, &server);
assert_ne!(code, 0, "{tag}: vex from the root: {attested:?}\n{stderr}");
assert!(attested.is_empty(), "{tag}: {attested:?}\n{stderr}");
assert_eq!(code, 0, "{tag}: vex from the root: {attested:?}\n{stderr}");
for patch in &ROUTE_PATCHES {
// Named as `<name>@<version>`, in a purl when it is the only one.
let release = format!("{}@{ROUTE_VERSION}", patch.name);
assert!(
stderr.contains(&release) && stderr.contains("not_applied"),
"{tag}: every entry is judged, so {} is refused:\n{stderr}",
attested.contains(&not_affected(patch)),
"{tag}: {} must be attested under the nested modulesDir: {attested:?}\n{stderr}",
patch.name
);
}
// A link to the upstream leaf in a member's own modules dir is a way
// to load it: the independent reading finds it, and vex refuses the
// patch until the link is gone.
let link = proj.join("packages/a/sub/node_modules/old-leaf");
std::os::unix::fs::symlink(store.join("leaf@1.0.0/node_modules/leaf"), &link).unwrap();
let reachable = pnpm_links::reachable_store_entries(&proj, &store);
assert!(
reachable.contains("leaf@1.0.0"),
"{tag}: the independent reading must find the link: {reachable:?}"
);
let (code, attested, stderr) = route_vex(&proj, &server);
assert_eq!(code, 0, "{tag}: vex with the link: {attested:?}\n{stderr}");
assert!(
!attested.contains(&not_affected(leaf))
&& stderr.contains("leaf@1.0.0")
&& stderr.contains("not_applied"),
"{tag}: a link from a member's modules dir must refuse leaf: {attested:?}\n{stderr}"
);
std::fs::remove_file(&link).unwrap();
let (code, attested, stderr) = route_vex(&proj, &server);
assert_eq!(code, 0, "{tag}: vex without the link:\n{stderr}");
assert!(
attested.contains(&not_affected(leaf)),
"{tag}: without the link leaf is attested again: {attested:?}\n{stderr}"
);
let (code, attested, stderr) = route_vex(&proj.join("packages/b"), &server);
assert_ne!(code, 0, "{tag}: vex from a member: {attested:?}\n{stderr}");
assert!(attested.is_empty(), "{tag}: {attested:?}\n{stderr}");
Expand Down
52 changes: 37 additions & 15 deletions crates/socket-patch-cli/tests/e2e_vex_redirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2803,24 +2803,31 @@ fn pnpm_hosted_ref_is_hashed_in_a_store_reached_through_a_linked_node_modules()
/// member's dependencies in `<member>/<modulesDir>` (real pnpm 12.25.1
/// layout). The lockfile in the store names the members from the
/// workspace root, and none of them is a directory below `sub/`, which
/// holds the store's `node_modules`. The store's entries are not judged
/// then: the pristine upstream entry is hashed and refuses the patch,
/// although nothing links it. The same workspace without the setting is
/// judged, and attests.
/// holds the store's `node_modules`. The root is the directory whose
/// `modulesDir` setting names that `node_modules`: the store is judged
/// from there, the pristine upstream entry is left out, and the patch is
/// attested, until a link in the member's own modules dir reaches that
/// entry. With no setting to say where the root is, the store's entries
/// are not judged: the upstream entry is hashed and refuses the patch.
#[cfg(unix)]
#[test]
fn pnpm_hosted_ref_is_hashed_in_a_store_under_a_nested_modules_dir() {
fn pnpm_hosted_ref_in_a_store_under_a_nested_modules_dir_is_judged_from_the_root() {
let (pristine, patched) = (
&b"module.exports = 'pristine'\n"[..],
&b"module.exports = 'patched'\n"[..],
);
let purl = "pkg:npm/left-pad@1.3.0";
let routed = format!("left-pad@socket-{}+1.3.0", &UUID[..8]);
for (modules_dir, attests) in [("node_modules", true), ("sub/node_modules", false)] {
for (modules_dir, setting, attests) in [
("node_modules", false, true),
("sub/node_modules", true, true),
("sub/node_modules", false, false),
] {
let case = format!("{modules_dir}, setting {setting}");
let tmp = tempfile::tempdir().unwrap();
let cwd = &tmp.path().join("app");
write_pnpm_member_routing_left_pad(cwd);
if modules_dir != "node_modules" {
if setting {
let workspace = cwd.join("pnpm-workspace.yaml");
let text = std::fs::read_to_string(&workspace).unwrap();
std::fs::write(workspace, format!("{text}modulesDir: {modules_dir}\n")).unwrap();
Expand All @@ -2835,26 +2842,41 @@ fn pnpm_hosted_ref_is_hashed_in_a_store_under_a_nested_modules_dir() {
);
// From `packages/a/<modulesDir>` up to the workspace root.
let up = "../".repeat(2 + modules_dir.split('/').count());
let member_nm = cwd.join("packages/a").join(modules_dir);
pnpm_link(
&format!("{up}{modules_dir}/.pnpm/{routed}/node_modules/left-pad"),
&cwd.join("packages/a").join(modules_dir).join("left-pad"),
&member_nm.join("left-pad"),
);
let (_rt, server) = serve_patch_views(vec![(
UUID.to_string(),
one_file_view(UUID, purl, "package/index.js", pristine, patched),
)]);

let (code, env) = vex_json(cwd, &["--proxy-url", &server.uri()]);
if attests {
assert_attested(cwd, code, &env, UUID, modules_dir);
} else {
assert_eq!(code, Some(1), "{modules_dir}: {env}");
let refused = |what: &str| {
let (code, env) = vex_json(cwd, &["--proxy-url", &server.uri()]);
assert_eq!(code, Some(1), "{case}, {what}: {env}");
assert_eq!(
skipped_reason(&env, purl),
"not_applied",
"{modules_dir}: {env}"
"{case}, {what}: {env}"
);
};

if !attests {
refused("the root is not known");
continue;
}
let (code, env) = vex_json(cwd, &["--proxy-url", &server.uri()]);
assert_attested(cwd, code, &env, UUID, &case);
// A link to the pristine entry in the member's own modules dir.
let old = member_nm.join("old-left-pad");
pnpm_link(
&format!("{up}{modules_dir}/.pnpm/left-pad@1.3.0/node_modules/left-pad"),
&old,
);
refused("a link in the member's modules dir");
std::fs::remove_file(&old).unwrap();
let (code, env) = vex_json(cwd, &["--proxy-url", &server.uri()]);
assert_attested(cwd, code, &env, UUID, &format!("{case}, the link removed"));
}
}

Expand Down
Loading
Loading