From 349338f855d8721b26a51bf1dbe42cf9f412ea93 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Tue, 1 Dec 2026 21:48:57 -0500 Subject: [PATCH 1/2] Expect vendor_unwired after pnpm 11.0.0 to 11.0.2 rewrite a vendored lock entry The pinned pnpm matrix failed on pnpm 11.0.0 in one cell of the vendored suite: the lock is put back while the overrides stay, a plain `pnpm install` writes it again, and `vex` was expected to attest once more. It exits 1 with `vendor_unwired` there. That verdict is right. pnpm 11.0.0 to 11.0.2 write the lock entry of a `file:` tarball without its `tarball` when they resolve it themselves (measured: 11.0.2 drops it, 11.0.3 keeps it, as do pnpm 9.0.0 to 10.34.9 and 12.0.0 on). The installed tree holds the patched bytes, but a frozen install of that lock from an empty store asks the registry for the release and fails on the vendored integrity (ERR_PNPM_TARBALL_INTEGRITY), so the lock wires nothing an install is sure to consume. The released 5.1.0 answers the same way, and running the scan again writes the entry back. - The cell expects `vendor_unwired` on those three releases, after checking that the lock has no tarball and that a frozen install of it from an empty store fails. Every other pnpm must still attest. - `vendor --check` said "no lockfile or config references" the artifact and that "a fresh install gets the unpatched package". Neither holds here: the lock still names it, and the install fails. It now reports `wiring incomplete`, names the lock and the pnpm releases, and points at `scan --mode vendored` as well as `vendor` (a project vendored through the scan has no manifest for `vendor` to read). - The matrix gains 11.0.3 as the other side of the boundary, and 11.29.0 and 12.25.1, the newest release of each line. The matrix workflow had been switched off since 2026-10-09, so the cell never ran on 11.0.0 in CI. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/pnpm-compatibility.yml | 2 +- crates/socket-patch-cli/CLI_CONTRACT.md | 6 +- .../socket-patch-cli/src/commands/vendor.rs | 33 ++++++++ .../tests/e2e_vendor_pnpm_build.rs | 80 ++++++++++++++++-- .../socket-patch-cli/tests/e2e_vex_vendor.rs | 84 +++++++++++++++++++ docs/ecosystems.md | 11 +++ docs/testing/pnpm-compatibility.md | 15 +++- 7 files changed, 220 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pnpm-compatibility.yml b/.github/workflows/pnpm-compatibility.yml index 135e525ff2..6808baf893 100644 --- a/.github/workflows/pnpm-compatibility.yml +++ b/.github/workflows/pnpm-compatibility.yml @@ -109,7 +109,7 @@ jobs: - node: '16.20.2' pnpm: 4.0.0 4.14.4 5.0.0 5.18.11 6.0.0 6.35.1 7.0.0 7.33.7 8.0.0 8.15.9 - node: '24.11.1' - pnpm: 9.0.0 9.15.9 10.0.0 10.33.0 10.34.5 11.0.0 11.27.0 12.0.0 12.4.2 + pnpm: 9.0.0 9.15.9 10.0.0 10.33.0 10.34.5 11.0.0 11.0.3 11.27.0 11.29.0 12.0.0 12.4.2 12.25.1 steps: - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 with: diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index 81490f9481..a307fc1057 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -3444,7 +3444,11 @@ entry; re-vendoring cannot reach it, #1511), or, for npm and PyPI, a dependency resolves any more (`dependency removed`; `scan --mode vendored --prune` reverts the entry), or, for PyPI, a project file that still names the artifact while nothing installs from it (`wiring incomplete`, naming the file; re-lock, then -re-vendor or revert, #1374). For a package-lock entry, drift also includes a +re-vendor or revert, #1374), or a `pnpm-lock.yaml` that still names the +artifact in an entry pnpm does not install from (`wiring incomplete`, naming +the lock: pnpm 11.0.0 to 11.0.2 rewrite the entry of a `file:` tarball +without its `tarball`, and a frozen install of that lock fails; re-run +`scan --mode vendored` or `vendor`). For a package-lock entry, drift also includes a `package-lock.json` / `npm-shrinkwrap.json` entry for the vendored `name@version` that `vendor` would rewire but that does not resolve to the vendored artifact (#588); the reason names that entry. It also includes any entry for that diff --git a/crates/socket-patch-cli/src/commands/vendor.rs b/crates/socket-patch-cli/src/commands/vendor.rs index db946837ea..a5e2d6f1d5 100644 --- a/crates/socket-patch-cli/src/commands/vendor.rs +++ b/crates/socket-patch-cli/src/commands/vendor.rs @@ -608,6 +608,10 @@ pub(crate) async fn dispatch_revert_one_opts( /// * a pnpm lock wires the artifact through an override the project's /// settings do not declare, so pnpm does not install that lock (#2382): /// the extractor's own diagnostic, which names the file and the remedy; +/// * a pnpm lock still names the artifact, but its entry is not one pnpm +/// installs from (pnpm 11.0.0 to 11.0.2 rewrite the entry of a `file:` +/// tarball without its `tarball`): name the lock, since "no lockfile +/// references it" would be false; /// * otherwise a relock dropped the reference while the package stayed. async fn unwired_check_failure( discovery: &socket_patch_core::vex::discover::Discovery, @@ -678,6 +682,35 @@ async fn unwired_check_failure( ); } } + // A pnpm lock that still names the artifact, though not as an entry + // pnpm installs from. pnpm 11.0.0 to 11.0.2 leave one: they write the + // entry of a `file:` tarball without its `tarball` when they rewrite + // the lock, and a frozen install of that lock fails on the integrity + // instead of installing the package. + if entry.ecosystem == "npm" { + let locks: Vec = discovery + .recognized_files( + &entry.uuid, + socket_patch_core::vex::discover::WiringMode::Vendored, + ) + .into_iter() + .filter(|file| { + file.file_name() + .is_some_and(|name| name == "pnpm-lock.yaml") + }) + .map(|file| file.display().to_string()) + .collect(); + if !locks.is_empty() { + return format!( + "wiring incomplete: {} still names {dir}, but not as an entry pnpm installs \ + from, so a fresh install fails or gets the unpatched package (pnpm 11.0.0 to \ + 11.0.2 write the lock entry without its tarball when they rewrite the lock; \ + pnpm 11.0.3 and later keep it); re-run `socket-patch scan --mode vendored` or \ + `socket-patch vendor` to rewire it", + locks.join(", ") + ); + } + } format!( "wiring missing: no lockfile or config references {dir} any more, so a fresh install \ gets the unpatched package; re-run `socket-patch vendor` to rewire it" diff --git a/crates/socket-patch-cli/tests/e2e_vendor_pnpm_build.rs b/crates/socket-patch-cli/tests/e2e_vendor_pnpm_build.rs index 3d7f72b66b..863fd5cb54 100644 --- a/crates/socket-patch-cli/tests/e2e_vendor_pnpm_build.rs +++ b/crates/socket-patch-cli/tests/e2e_vendor_pnpm_build.rs @@ -141,6 +141,20 @@ fn keeps_relative_file_overrides(pm: &str) -> bool { matches!(parts.as_slice(), [7, minor, _] if *minor <= 17) } +/// pnpm 11.0.0-11.0.2 write the lock entry of a `file:` tarball without its +/// `tarball` when they resolve it themselves (measured 2026-12-01: 11.0.2 +/// drops it, 11.0.3 keeps it, as do 9.0.0-10.34.9 and 12.0.0 on). The lock +/// then names the artifact in its key, importer and override, but a frozen +/// install of it from an empty store asks the registry for the release and +/// fails on the vendored integrity (`ERR_PNPM_TARBALL_INTEGRITY`). +fn drops_file_tarball_on_relock(pm: &str) -> bool { + let Some(v) = pm.strip_prefix("pnpm@") else { + return false; + }; + let parts: Vec = v.split('.').filter_map(|p| p.parse().ok()).collect(); + matches!(parts.as_slice(), [11, 0, patch] if *patch <= 2) +} + /// pnpm 9.0.0-9.0.4: the last releases that absolutize a `file:` override's /// importer specifier (measured 2026-09-22: 9.0.4 refuses the relative /// spelling under `--frozen-lockfile`, 9.0.5 accepts it). @@ -1049,13 +1063,65 @@ fn assert_manifestless_vendored_vex( patched, "[{tag}] a plain install must re-apply the overrides (vendored bytes)" ); - // The lock pnpm just rewrote wires the artifact again. - let out = run_vex(&bin, fresh, &VexRun::online(&api)); - assert_eq!(out.code, Some(0), "[{tag}] reinstalled: {out}"); - assert_attested(out.doc(), purl, UUID, Marker::Vendored, VENDOR_VULNS); - eprintln!( - "VEX-CELL vendored [{tag}] lock-only-revert(overrides kept): attested once reinstalled" - ); + let relocked = std::fs::read_to_string(&lock).unwrap(); + if drops_file_tarball_on_relock(pm) { + // This pnpm wrote the entry without its tarball. The installed + // tree holds the vendored bytes, but the lock no longer says + // where the package comes from: a frozen install of it from an + // empty store fails (offline it has no tarball to take, online + // the registry's fails the vendored integrity). So the lock + // wires nothing an install is sure to consume, and nothing is + // attested until the entry is written again. + assert!( + !relocked.contains("tarball: file:"), + "[{tag}] this pnpm is listed as dropping the tarball when it writes the lock:\n\ + {relocked}" + ); + let empty = fresh.with_file_name("store-relocked"); + std::fs::remove_dir_all(fresh.join("node_modules")).unwrap(); + let frozen = corepack( + fresh, + pm, + &[ + "install", + "--frozen-lockfile", + "--offline", + "--store-dir", + empty.to_str().unwrap(), + ], + ); + assert!( + !frozen.status.success(), + "[{tag}] a frozen install of the lock pnpm rewrote must fail from an empty \ + store: {frozen:?}" + ); + let out = run_vex(&bin, fresh, &VexRun::online(&api)); + assert_ne!( + out.code, + Some(0), + "[{tag}] relocked without a tarball: {out}" + ); + assert_absent(out.doc.as_ref(), purl); + assert_not_attested(&out.envelope, purl, "vendor_unwired"); + eprintln!( + "VEX-CELL vendored [{tag}] lock-only-revert(overrides kept): not attested, pnpm \ + rewrote the lock without the tarball" + ); + } else { + // The lock pnpm just rewrote wires the artifact again (pnpm + // 9 and later write the tarball beside the integrity). + assert!( + pnpm_major(pm).is_none_or(|major| major < 9) || relocked.contains("tarball: file:"), + "[{tag}] the lock pnpm rewrote must record the tarball:\n{relocked}" + ); + let out = run_vex(&bin, fresh, &VexRun::online(&api)); + assert_eq!(out.code, Some(0), "[{tag}] reinstalled: {out}"); + assert_attested(out.doc(), purl, UUID, Marker::Vendored, VENDOR_VULNS); + eprintln!( + "VEX-CELL vendored [{tag}] lock-only-revert(overrides kept): attested once \ + reinstalled" + ); + } std::fs::write(&lock, &lock_wired).unwrap(); }); eprintln!("MANIFEST-LESS VENDORED VEX OK ({tag})"); diff --git a/crates/socket-patch-cli/tests/e2e_vex_vendor.rs b/crates/socket-patch-cli/tests/e2e_vex_vendor.rs index 0efc064f9d..be8de0ffa8 100644 --- a/crates/socket-patch-cli/tests/e2e_vex_vendor.rs +++ b/crates/socket-patch-cli/tests/e2e_vex_vendor.rs @@ -3058,6 +3058,90 @@ fn vendored_pnpm_pin_with_the_lock_off_needs_its_override() { assert_vendored_attested(cwd, purl, "the override routes it without a lock"); } +/// pnpm 11.0.0 to 11.0.2 write the lock entry of a `file:` tarball without +/// its `tarball` when they rewrite the lock (measured 2026-12-01 against +/// real pnpm: 11.0.2 drops it, 11.0.3 keeps it). The lock still names the +/// artifact in its key, its importer and its override, but a frozen install +/// of it from an empty store asks the registry for the release and fails on +/// the vendored integrity. So the lock wires nothing an install is sure to +/// consume: `vex` does not attest the patch, and `vendor --check` fails the +/// entry, naming the lock that still names the artifact instead of saying +/// that no lockfile does. The same lock with the tarball attests and +/// verifies (the control). +#[test] +fn pnpm_lock_entry_rewritten_without_its_tarball_is_not_attested() { + let tmp = tempfile::tempdir().unwrap(); + let cwd = tmp.path(); + let uuid = "55555555-5555-4555-8555-555555555555"; + let purl = "pkg:npm/foo@1.0.0"; + let rel = write_foo_ledger( + cwd, + uuid, + b"patched foo\n", + &[("package.json", "override"), ("pnpm-lock.yaml", "lock")], + ); + std::fs::write( + cwd.join("package.json"), + format!( + r#"{{"name":"app","version":"0.1.0","dependencies":{{"foo":"1.0.0"}},"pnpm":{{"overrides":{{"foo@1.0.0":"file:{rel}"}}}}}}"# + ), + ) + .unwrap(); + std::fs::write( + cwd.join("pnpm-workspace.yaml"), + format!("packages:\n - '.'\noverrides:\n foo@1.0.0: file:{rel}\n"), + ) + .unwrap(); + // The lock as pnpm writes it for the override, with and without the + // tarball of the entry. + let lock = |tarball: &str| { + format!( + "lockfileVersion: '9.0'\n\nsettings:\n autoInstallPeers: true\n \ + excludeLinksFromLockfile: false\n\noverrides:\n foo@1.0.0: file:{rel}\n\n\ + importers:\n\n .:\n dependencies:\n foo:\n \ + specifier: file:{rel}\n version: file:{rel}\n\npackages:\n\n \ + foo@file:{rel}:\n \ + resolution: {{integrity: sha512-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=={tarball}}}\n \ + version: 1.0.0\n\nsnapshots:\n\n foo@file:{rel}: {{}}\n" + ) + }; + let check = || { + let out = cli() + .args(["vendor", "--check", "--cwd", cwd.to_str().unwrap()]) + .output() + .expect("invoke vendor --check"); + let said = format!( + "{}{}", + String::from_utf8_lossy(&out.stdout), + String::from_utf8_lossy(&out.stderr) + ); + (out.status.code(), said) + }; + + std::fs::write( + cwd.join("pnpm-lock.yaml"), + lock(&format!(", tarball: file:{rel}")), + ) + .unwrap(); + assert_vendored_attested(cwd, purl, "the entry records its tarball"); + let (code, said) = check(); + assert_eq!(code, Some(0), "the wiring is intact: {said}"); + + std::fs::write(cwd.join("pnpm-lock.yaml"), lock("")).unwrap(); + assert_never_attested(cwd, purl); + let (code, said) = check(); + assert_eq!(code, Some(1), "{said}"); + for part in [ + "wiring incomplete: pnpm-lock.yaml still names", + uuid, + "pnpm 11.0.3 and later keep it", + "socket-patch scan --mode vendored", + ] { + assert!(said.contains(part), "{part:?} is missing: {said}"); + } + assert!(!said.contains("wiring missing"), "{said}"); +} + /// REVIEW (#1033, audit B04): a pnpm lock that also holds a package with /// `bundledDependencies` naming the vendored package (or `true`, bundling /// every dependency) ships a copy pnpm unpacks from that package's own diff --git a/docs/ecosystems.md b/docs/ecosystems.md index 7511b68ec4..c8fa5bf3e5 100644 --- a/docs/ecosystems.md +++ b/docs/ecosystems.md @@ -264,6 +264,17 @@ Each Legacy format has an upgrade path and an undo path. Both work in v5: then gives the entry to add. Not checked this way: a Rush lock, a lock entry that records no override, and a declaration `socket-patch` cannot read (an inline `overrides:` mapping, a `package.json` that is not JSON). + **pnpm 11.0.0 to 11.0.2 unwire a vendored package when they rewrite the + lock.** An install that changes `pnpm-lock.yaml`, or `pnpm add`, writes + the entry of a `file:` tarball without its `tarball` on these three + releases (11.0.3 and later, and pnpm 9, 10 and 12, keep it). The + installed tree still holds the patched files, but a frozen install of + that lock from an empty store asks the registry for the release and + fails on the vendored integrity (`ERR_PNPM_TARBALL_INTEGRITY`), so it + never installs the unpatched package. `vendor --check` fails the entry + (`wiring incomplete`, naming the lock) and `vex` omits it + (`vendor_unwired`). Running `socket-patch scan --mode vendored` again + writes the entry back; pnpm 11.0.3 or later keeps it. **One mode for a package and its dependency.** pnpm 12.23 and newer refuse a lock in which a package fetched from a hosted patch depends on a local file (`ERR_PNPM_LOCAL_SUBDEP_NOT_ALLOWED`), on every install, frozen or diff --git a/docs/testing/pnpm-compatibility.md b/docs/testing/pnpm-compatibility.md index d11deb9c47..89462b3642 100644 --- a/docs/testing/pnpm-compatibility.md +++ b/docs/testing/pnpm-compatibility.md @@ -25,14 +25,14 @@ discovery and tarball endpoints are local test servers. | 8.0.0, 8.15.9 | 16.20.2 | 6.0, per-peer package resolutions | | 9.0.0, 9.15.9 | 24.11.1 | 9.0, packages/snapshots split | | 10.0.0, 10.33.0, 10.34.5 | 24.11.1 | 9.0 | -| 11.0.0, 11.27.0, 12.0.0, 12.4.2 | 24.11.1 | 9.0, hosted URLs require lockfile trust or the registry route | +| 11.0.0, 11.0.3, 11.27.0, 11.29.0, 12.0.0, 12.4.2, 12.25.1 | 24.11.1 | 9.0, hosted URLs require lockfile trust or the registry route | This samples each released major from 1 through 12 and important major boundaries; it is not an exhaustive test of every historical patch release or future release. Pre-lockfile releases cannot use hosted lockfile redirection. Vendored mode has a separate compatibility contract in `docs/ecosystems.md`. -The 24 supported versions exercise scan and explicit-UUID hosted entry points, idempotency, +The 27 supported versions exercise scan and explicit-UUID hosted entry points, idempotency, warm installs, verified VEX, a clean reinstall, a fresh frozen install with a dead registry and empty store, an ordinary install, byte-exact rollback, lock-only discovery, and rejection of tampered hosted tarballs. pnpm >=6 also @@ -46,6 +46,17 @@ hosted URL even on a frozen install. For early shrinkwrapVersion 3 locks with no positive minor version, upgrade to a tested release (1.43.1 or newer) and regenerate the lock before redirecting, or use installed-file agent mode. +The same matrix runs the vendored suite (`e2e_vendor_pnpm_build`) on each +version. One of its cells puts the lock back as it was while the overrides +stay, lets a plain `pnpm install` write the lock again, and expects `vex` to +attest once more. pnpm 11.0.0 to 11.0.2 are the exception: they write the +entry of a `file:` tarball without its `tarball` (measured: 11.0.2 drops it, +11.0.3 keeps it, as do 9.0.0 to 10.34.9 and 12.0.0 on). A frozen install of +that lock from an empty store then fails (`ERR_PNPM_TARBALL_INTEGRITY` online, +no tarball offline), so the cell expects `vex` to omit the patch as +`vendor_unwired` there, and the matrix pins 11.0.0 and 11.0.3 as the two sides +of the boundary. Running the scan again writes the entry back. + Captured locks under `crates/socket-patch-core/tests/fixtures/pnpm-hosted/` keep grammar coverage in ordinary offline tests. Additional tests cover LF/CRLF, nested peer suffixes, quoted keys and URLs, unrelated versions, From c0e50d43c6db6262fcb046992e2fa1c4052ab871 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Tue, 1 Dec 2026 22:28:27 -0500 Subject: [PATCH 2/2] Read a pnpm lock entry that lost its tarball as the vendored entry it is Review of the first commit found that its `vendor --check` wording fired for any dead entry whose patch a pnpm lock still mentions, and that the remedy it names did not always work. Both come from one place: the lock reader took a `name@file:` entry with an integrity and no tarball (what pnpm 11.0.0 to 11.0.2 write) for a `file:` directory of the user's. Nothing then kept the ledger entry: - `scan --mode vendored` on a checkout with no installed tree skipped it as "no longer used by the lockfile" and left the lock as it was; - `scan --mode vendored --prune` there reverted the vendored patch (measured against the production patch service on pnpm 11.0.0: the artifact and the override were removed). The reader now recognises the entry by its key, withholds it, and says why. So `vex` still omits the patch (`vendor_unwired`), `vendor --check` reports the reader's own reason (`wiring incomplete`, naming the lock, the pnpm releases and the remedy), the prune keeps the patch, and the next vendored scan writes the entry back, with or without an installed tree. A `file:` directory dependency, which records no integrity, is read as before, and a lock that was resolved from the registry again gets the old message and no mention of a pnpm release. The real-pnpm cell also runs `vex` with the patched tree still installed, and checks that the frozen install fails for want of the tarball. Co-Authored-By: Claude Fable 5.2 --- .../socket-patch-cli/src/commands/vendor.rs | 44 ++----- .../tests/e2e_vendor_pnpm_build.rs | 30 +++-- .../socket-patch-cli/tests/e2e_vex_vendor.rs | 33 ++++- .../socket-patch-core/src/vex/discover/mod.rs | 18 +++ .../socket-patch-core/src/vex/discover/npm.rs | 121 ++++++++++++++++++ docs/ecosystems.md | 6 +- docs/testing/pnpm-compatibility.md | 6 +- 7 files changed, 208 insertions(+), 50 deletions(-) diff --git a/crates/socket-patch-cli/src/commands/vendor.rs b/crates/socket-patch-cli/src/commands/vendor.rs index a5e2d6f1d5..aeca0aa3bd 100644 --- a/crates/socket-patch-cli/src/commands/vendor.rs +++ b/crates/socket-patch-cli/src/commands/vendor.rs @@ -608,10 +608,11 @@ pub(crate) async fn dispatch_revert_one_opts( /// * a pnpm lock wires the artifact through an override the project's /// settings do not declare, so pnpm does not install that lock (#2382): /// the extractor's own diagnostic, which names the file and the remedy; -/// * a pnpm lock still names the artifact, but its entry is not one pnpm -/// installs from (pnpm 11.0.0 to 11.0.2 rewrite the entry of a `file:` -/// tarball without its `tarball`): name the lock, since "no lockfile -/// references it" would be false; +/// * a pnpm lock still names the artifact in an entry that records no +/// tarball (pnpm 11.0.0 to 11.0.2 rewrite the entry of a `file:` tarball +/// so): the extractor's own diagnostic again, since "no lockfile +/// references it, a fresh install gets the unpatched package" would be +/// false twice over; /// * otherwise a relock dropped the reference while the package stayed. async fn unwired_check_failure( discovery: &socket_patch_core::vex::discover::Discovery, @@ -654,6 +655,12 @@ async fn unwired_check_failure( if let Some(diag) = discovery.pnpm_override_undeclared(&entry.uuid) { return format!("wiring incomplete: {}", diag.detail); } + // A pnpm lock still names the artifact in an entry that records no + // tarball (pnpm 11.0.0 to 11.0.2 rewrite it so): the lock is not gone, + // and an install of it fails instead of getting the unpatched package. + if let Some(diag) = discovery.pnpm_tarball_dropped(&entry.uuid) { + return format!("wiring incomplete: {}", diag.detail); + } // Only the npm-family and Python extractors record every lock entry // (`resolved_elsewhere`), so only there does "no lock resolves it" // prove the dependency is gone rather than unreadable. @@ -682,35 +689,6 @@ async fn unwired_check_failure( ); } } - // A pnpm lock that still names the artifact, though not as an entry - // pnpm installs from. pnpm 11.0.0 to 11.0.2 leave one: they write the - // entry of a `file:` tarball without its `tarball` when they rewrite - // the lock, and a frozen install of that lock fails on the integrity - // instead of installing the package. - if entry.ecosystem == "npm" { - let locks: Vec = discovery - .recognized_files( - &entry.uuid, - socket_patch_core::vex::discover::WiringMode::Vendored, - ) - .into_iter() - .filter(|file| { - file.file_name() - .is_some_and(|name| name == "pnpm-lock.yaml") - }) - .map(|file| file.display().to_string()) - .collect(); - if !locks.is_empty() { - return format!( - "wiring incomplete: {} still names {dir}, but not as an entry pnpm installs \ - from, so a fresh install fails or gets the unpatched package (pnpm 11.0.0 to \ - 11.0.2 write the lock entry without its tarball when they rewrite the lock; \ - pnpm 11.0.3 and later keep it); re-run `socket-patch scan --mode vendored` or \ - `socket-patch vendor` to rewire it", - locks.join(", ") - ); - } - } format!( "wiring missing: no lockfile or config references {dir} any more, so a fresh install \ gets the unpatched package; re-run `socket-patch vendor` to rewire it" diff --git a/crates/socket-patch-cli/tests/e2e_vendor_pnpm_build.rs b/crates/socket-patch-cli/tests/e2e_vendor_pnpm_build.rs index 863fd5cb54..fc331b336b 100644 --- a/crates/socket-patch-cli/tests/e2e_vendor_pnpm_build.rs +++ b/crates/socket-patch-cli/tests/e2e_vendor_pnpm_build.rs @@ -1077,6 +1077,14 @@ fn assert_manifestless_vendored_vex( "[{tag}] this pnpm is listed as dropping the tarball when it writes the lock:\n\ {relocked}" ); + // With the patched tree still installed, and without it. + let not_attested = |state: &str| { + let out = run_vex(&bin, fresh, &VexRun::online(&api)); + assert_ne!(out.code, Some(0), "[{tag}] relocked, {state}: {out}"); + assert_absent(out.doc.as_ref(), purl); + assert_not_attested(&out.envelope, purl, "vendor_unwired"); + }; + not_attested("the patched tree installed"); let empty = fresh.with_file_name("store-relocked"); std::fs::remove_dir_all(fresh.join("node_modules")).unwrap(); let frozen = corepack( @@ -1090,19 +1098,19 @@ fn assert_manifestless_vendored_vex( empty.to_str().unwrap(), ], ); - assert!( - !frozen.status.success(), - "[{tag}] a frozen install of the lock pnpm rewrote must fail from an empty \ - store: {frozen:?}" + let said = format!( + "{}{}", + String::from_utf8_lossy(&frozen.stdout), + String::from_utf8_lossy(&frozen.stderr) ); - let out = run_vex(&bin, fresh, &VexRun::online(&api)); - assert_ne!( - out.code, - Some(0), - "[{tag}] relocked without a tarball: {out}" + // Offline pnpm has no tarball to take; online it is the + // registry's, which fails the vendored integrity. + assert!( + !frozen.status.success() && said.contains("TARBALL"), + "[{tag}] a frozen install of the lock pnpm rewrote must fail for want of the \ + tarball, from an empty store: {said}" ); - assert_absent(out.doc.as_ref(), purl); - assert_not_attested(&out.envelope, purl, "vendor_unwired"); + not_attested("no tree installed"); eprintln!( "VEX-CELL vendored [{tag}] lock-only-revert(overrides kept): not attested, pnpm \ rewrote the lock without the tarball" diff --git a/crates/socket-patch-cli/tests/e2e_vex_vendor.rs b/crates/socket-patch-cli/tests/e2e_vex_vendor.rs index be8de0ffa8..51116063da 100644 --- a/crates/socket-patch-cli/tests/e2e_vex_vendor.rs +++ b/crates/socket-patch-cli/tests/e2e_vex_vendor.rs @@ -3132,14 +3132,41 @@ fn pnpm_lock_entry_rewritten_without_its_tarball_is_not_attested() { let (code, said) = check(); assert_eq!(code, Some(1), "{said}"); for part in [ - "wiring incomplete: pnpm-lock.yaml still names", + "wiring incomplete: pnpm-lock.yaml: packages entry", uuid, - "pnpm 11.0.3 and later keep it", + "records no tarball for it", + "pnpm 11.0.3 and later keep the tarball", + "ERR_PNPM_TARBALL_INTEGRITY", "socket-patch scan --mode vendored", ] { assert!(said.contains(part), "{part:?} is missing: {said}"); } - assert!(!said.contains("wiring missing"), "{said}"); + assert!( + !said.contains("wiring missing") && !said.contains("gets the unpatched package"), + "{said}" + ); + + // A lock that pnpm resolved from the registry again and that keeps only + // the override line is another state: no pnpm release is to blame, and + // the message must not name one. + std::fs::write( + cwd.join("pnpm-lock.yaml"), + format!( + "lockfileVersion: '9.0'\n\nsettings:\n autoInstallPeers: true\n \ + excludeLinksFromLockfile: false\n\noverrides:\n foo@1.0.0: file:{rel}\n\n\ + importers:\n\n .:\n dependencies:\n foo:\n specifier: 1.0.0\n \ + version: 1.0.0\n\npackages:\n\n foo@1.0.0:\n \ + resolution: {{integrity: sha512-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==}}\n\n\ + snapshots:\n\n foo@1.0.0: {{}}\n" + ), + ) + .unwrap(); + let (code, said) = check(); + assert_eq!(code, Some(1), "{said}"); + assert!( + !said.contains("11.0."), + "no pnpm release caused this: {said}" + ); } /// REVIEW (#1033, audit B04): a pnpm lock that also holds a package with diff --git a/crates/socket-patch-core/src/vex/discover/mod.rs b/crates/socket-patch-core/src/vex/discover/mod.rs index 87cd922d56..0a5667bd6a 100644 --- a/crates/socket-patch-core/src/vex/discover/mod.rs +++ b/crates/socket-patch-core/src/vex/discover/mod.rs @@ -1823,6 +1823,24 @@ impl Discovery { }) } + /// The diagnostic of a vendored pnpm lock entry of patch `uuid` that + /// was withheld because it records no tarball + /// (`npm::PNPM_TARBALL_DROPPED`: pnpm 11.0.0 to 11.0.2 write it so): + /// it names the lock, what an install of it does, and the remedy. + pub fn pnpm_tarball_dropped(&self, uuid: &str) -> Option<&Diag> { + self.withheld + .iter() + .filter(|w| w.uuid == uuid && w.mode == WiringMode::Vendored) + .find_map(|w| { + self.diagnostics.iter().find(|d| { + d.code == DIAG_REF_INVALID + && d.file == w.file + && d.detail.contains(npm::PNPM_TARBALL_DROPPED) + && d.detail.contains(uuid) + }) + }) + } + /// Whether any lock discovery read resolves `purl` (any spelling) at /// all: wired to a Socket patch, contested, or from elsewhere /// ([`Discovery::resolved_elsewhere`]). diff --git a/crates/socket-patch-core/src/vex/discover/npm.rs b/crates/socket-patch-core/src/vex/discover/npm.rs index 0f3df40970..8eafd98565 100644 --- a/crates/socket-patch-core/src/vex/discover/npm.rs +++ b/crates/socket-patch-core/src/vex/discover/npm.rs @@ -92,6 +92,11 @@ const PNPM_MANIFEST: &str = "package.json"; /// finds the diagnostic by it. pub(crate) const PNPM_OVERRIDE_UNDECLARED: &str = "the lock records the override"; +/// What the diagnostic of a vendored pnpm entry that records no tarball +/// says of it ([`pnpm_entry_ref`]); +/// [`Discovery::pnpm_tarball_dropped`] finds the diagnostic by it. +pub(crate) const PNPM_TARBALL_DROPPED: &str = "records no tarball for it"; + pub(crate) async fn extract(ctx: &DiscoverCtx<'_>, out: &mut Discovery) { let mut locks: Vec = Vec::new(); let mut twin_present = false; @@ -1825,6 +1830,44 @@ fn pnpm_entry_ref( return; }; let Some(tarball) = resolution.tarball() else { + // The entry of a vendored tarball, by its key, with an integrity + // and no tarball: what pnpm 11.0.0 to 11.0.2 write when they + // resolve a `file:` tarball themselves (11.0.3 and later, and pnpm + // 9, 10 and 12, keep the tarball). The override and the importer + // still route the package to the artifact, so the entry is not + // gone; but a frozen install of this lock from an empty store asks + // the registry for the release and fails on the vendored + // integrity. It is withheld: not attested, kept by the prune, and + // written again by the next vendored run. + let vendored = match classify_pnpm_key(key) { + PnpmKey::V9File { path, .. } | PnpmKey::LegacyFile { path } => { + ctx.locate(path, LocateOpts::LITERAL_CHECKED).vendored + } + PnpmKey::Registry { .. } | PnpmKey::Other => None, + }; + if let Some(vref) = vendored.filter(|_| resolution.integrity().is_some()) { + out.diag( + DIAG_REF_INVALID, + file, + format!( + "{label}: packages entry {key:?} names the vendored artifact of patch {} \ + but {PNPM_TARBALL_DROPPED} (pnpm 11.0.0 to 11.0.2 write the entry of a \ + `file:` tarball so when they rewrite the lock; pnpm 11.0.3 and later keep \ + the tarball). A frozen install of this lock from an empty store asks the \ + registry for the release and fails on the vendored integrity \ + (ERR_PNPM_TARBALL_INTEGRITY); not counted. Re-run `socket-patch scan \ + --mode vendored` or `socket-patch vendor` to write the entry again, and \ + commit the lock", + vref.uuid + ), + ); + out.withheld.push(super::Recognized { + uuid: vref.uuid, + mode: WiringMode::Vendored, + file: PathBuf::from(file), + }); + return; + } // A plain registry entry (integrity only) or a directory/git dep. out.resolved_elsewhere_in(file, tree.part, pnpm_registry_key_purl(key)); copies.extend(pnpm_file_copy(package, true)); @@ -5081,6 +5124,84 @@ mod tests { assert_eq!(live.vendor_entry_in_use(p.root(), &entry).await, Some(true)); } + /// pnpm 11.0.0 to 11.0.2 write the lock entry of a `file:` tarball + /// without its `tarball` when they rewrite the lock (measured against + /// real pnpm: 11.0.2 drops it, 11.0.3 keeps it). The override and the + /// importer still route the package to the artifact, but a frozen + /// install of that lock from an empty store asks the registry for the + /// release and fails on the vendored integrity. Such an entry was read + /// as a `file:` directory of the user's, so nothing kept the ledger + /// entry: `scan --mode vendored` skipped it as no longer used, and + /// `scan --prune` reverted the patch. It is dead to the liveness gate + /// and still wiring to the prune GC, with a reason that names the + /// cause and the remedy. A `file:` directory is not taken for one. + #[tokio::test] + async fn pnpm_entry_without_its_tarball_is_dead_but_kept_by_the_prune_gc() { + let rel = format!(".socket/vendor/npm/{UUID_B}/left-pad-1.3.0.tgz"); + let entry: crate::vendor::state::VendorEntry = serde_json::from_value(serde_json::json!({ + "ecosystem": "npm", + "basePurl": "pkg:npm/left-pad@1.3.0", + "uuid": UUID_B, + "artifact": { "path": rel, "sha256": "" }, + "wiring": [{ "file": "pnpm-lock.yaml", "kind": "lock", "action": "added" }], + })) + .unwrap(); + let p = Project::new(); + p.write( + "package.json", + format!(r#"{{"name":"app","pnpm":{{"overrides":{{"left-pad@1.3.0":"file:{rel}"}}}}}}"#), + ); + let wired = pnpm_vendored_lock(""); + let dropped = wired.replace(&format!(", tarball: file:{rel}"), ""); + assert_ne!(dropped, wired); + + p.write("pnpm-lock.yaml", &dropped); + let dead = p.discover().await; + assert_refs(&dead, &[]); + assert!(dead.shadowed.is_empty() && dead.unattested.is_empty()); + assert!(!dead.vendor_entry_live(p.root(), &entry).await); + assert_eq!( + dead.vendor_entry_liveness(p.root(), &entry).await, + Some(false) + ); + assert_eq!(dead.vendor_entry_in_use(p.root(), &entry).await, Some(true)); + assert_eq!(dead.withheld.len(), 1); + assert!(dead.pnpm_override_undeclared(UUID_B).is_none()); + let detail = &dead + .pnpm_tarball_dropped(UUID_B) + .expect("the entry's own diagnostic") + .detail; + for part in [ + "pnpm-lock.yaml: packages entry", + UUID_B, + "records no tarball for it", + "pnpm 11.0.3 and later keep the tarball", + "ERR_PNPM_TARBALL_INTEGRITY", + "socket-patch scan --mode vendored", + ] { + assert!(detail.contains(part), "{part:?} is missing: {detail}"); + } + + // With its tarball the entry is a ref again. + p.write("pnpm-lock.yaml", &wired); + let live = p.discover().await; + assert!(live.vendor_entry_live(p.root(), &entry).await); + assert!(live.withheld.is_empty() && live.pnpm_tarball_dropped(UUID_B).is_none()); + + // A `file:` directory dependency records no tarball either, and no + // integrity: it is the user's, as before. + p.write( + "pnpm-lock.yaml", + "lockfileVersion: '9.0'\n\nimporters:\n\n .:\n dependencies:\n left-pad:\n \ + specifier: file:../lp\n version: file:../lp\n\npackages:\n\n \ + left-pad@file:../lp:\n resolution: {directory: ../lp, type: directory}\n\n\ + snapshots:\n\n left-pad@file:../lp: {}\n", + ); + let directory = p.discover().await; + assert!(directory.withheld.is_empty()); + assert!(directory.pnpm_tarball_dropped(UUID_B).is_none()); + } + /// Which pnpm reads the overrides comes from the pins package.json /// commits, read conservatively, then from what only one generation of /// pnpm writes into a lock (#2382). Committed files only: the same diff --git a/docs/ecosystems.md b/docs/ecosystems.md index c8fa5bf3e5..d3a58fa389 100644 --- a/docs/ecosystems.md +++ b/docs/ecosystems.md @@ -273,8 +273,10 @@ Each Legacy format has an upgrade path and an undo path. Both work in v5: fails on the vendored integrity (`ERR_PNPM_TARBALL_INTEGRITY`), so it never installs the unpatched package. `vendor --check` fails the entry (`wiring incomplete`, naming the lock) and `vex` omits it - (`vendor_unwired`). Running `socket-patch scan --mode vendored` again - writes the entry back; pnpm 11.0.3 or later keeps it. + (`vendor_unwired`). The entry still counts as in use: `scan --prune` + keeps the vendored patch, and running `socket-patch scan --mode + vendored` again writes the entry back, with or without an installed + tree. pnpm 11.0.3 or later keeps it. **One mode for a package and its dependency.** pnpm 12.23 and newer refuse a lock in which a package fetched from a hosted patch depends on a local file (`ERR_PNPM_LOCAL_SUBDEP_NOT_ALLOWED`), on every install, frozen or diff --git a/docs/testing/pnpm-compatibility.md b/docs/testing/pnpm-compatibility.md index 89462b3642..52a7a28613 100644 --- a/docs/testing/pnpm-compatibility.md +++ b/docs/testing/pnpm-compatibility.md @@ -55,7 +55,11 @@ entry of a `file:` tarball without its `tarball` (measured: 11.0.2 drops it, that lock from an empty store then fails (`ERR_PNPM_TARBALL_INTEGRITY` online, no tarball offline), so the cell expects `vex` to omit the patch as `vendor_unwired` there, and the matrix pins 11.0.0 and 11.0.3 as the two sides -of the boundary. Running the scan again writes the entry back. +of the boundary. The lock reader takes such an entry for the vendored one +it is (by its key, with an integrity and no tarball), not for a `file:` +directory of the user's: the patch is not attested, `scan --prune` keeps +it, and running the scan again writes the entry back. Before that, a prune +on a checkout with no installed tree reverted the patch. Captured locks under `crates/socket-patch-core/tests/fixtures/pnpm-hosted/` keep grammar coverage in ordinary offline tests. Additional tests cover