Skip to content

Commit ff603e2

Browse files
committed
Gate the inventory's Rush check on is_rush, as discovery does
The npm-family inventory took rush.json as present via view.exists, so a directory, an implied in-memory directory or a link to a directory named rush.json counted as Rush there while discovery's is_rush (a regular file) said no. Under pnpm lockfile=false the inventory then kept the hosted pin's integrity in a root lock pnpm never reads, while discovery withheld it. Use the shared is_rush gate at both call sites. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ad1abb4 commit ff603e2

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎crates/socket-patch-core/src/vendor/lock_inventory/npm_family.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use super::dedup_prefer_integrity;
1919
use super::npm::inventory_package_lock_in;
2020
use super::pnpm::{
2121
inventory_pnpm_lock_in, inventory_pnpm_lock_rel_in, inventory_pnpm_member_locks_in,
22-
inventory_rush_pnpm_locks_in,
22+
inventory_rush_pnpm_locks_in, is_rush,
2323
};
2424
use super::view::ProjectView;
2525
use super::vlt::inventory_vlt_in;
@@ -52,7 +52,7 @@ pub(crate) async fn inventory_npm_lock(
5252
project_root: &Path,
5353
) -> Result<Option<(NpmLockFlavor, Vec<LockfileEntry>)>, UnsupportedNpmLayout> {
5454
let view = ProjectView::Disk(project_root);
55-
let rush = view.exists("rush.json").await;
55+
let rush = is_rush(view).await;
5656
inventory_npm_lock_raw_in(&view, rush)
5757
.await
5858
.map(|found| found.map(|(flavor, raw)| (flavor, dedup_prefer_integrity(raw))))
@@ -77,7 +77,7 @@ pub(crate) async fn inventory_npm_trees(
7777
pub(super) async fn inventory_npm_trees_raw_in(
7878
view: &ProjectView<'_>,
7979
) -> Result<Vec<LockfileEntry>, UnsupportedNpmLayout> {
80-
let rush = view.exists("rush.json").await;
80+
let rush = is_rush(*view).await;
8181
let mut out = inventory_npm_lock_raw_in(view, rush)
8282
.await?
8383
.map(|(_, entries)| entries)
@@ -90,7 +90,7 @@ pub(super) async fn inventory_npm_trees_raw_in(
9090

9191
/// The routed lock's guarded instances ([`inventory_npm_lock`] before its
9292
/// collapse). With pnpm's `lockfile` setting off ([`lockfile_disabled`];
93-
/// not under Rush, `rush` being whether `rush.json` exists, which runs
93+
/// not under Rush, `rush` being [`is_rush`], the gate discovery shares, which runs
9494
/// pnpm with settings of its own, as in lockfile discovery's
9595
/// `extract_pnpm`), pnpm neither reads nor writes the root or member
9696
/// locks, so a Socket-hosted pin in them is no lockfile basis. Discovery

‎crates/socket-patch-core/src/vendor/lock_inventory/tests.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,17 @@ async fn pnpm_lockfile_off_withholds_hosted_pins() {
926926
integrity(&entries, "left-pad"),
927927
LockIntegrity::Sri("sha512-PATCHED==".into())
928928
);
929+
930+
// A directory named rush.json is not Rush (the gate discovery shares,
931+
// `is_rush`), so the root lock still loses the pin.
932+
let tmp = tempfile::tempdir().unwrap();
933+
write_nested(tmp.path(), "rush.json/placeholder", "").await;
934+
write(tmp.path(), ".npmrc", "lockfile=false\n").await;
935+
write(tmp.path(), "pnpm-lock.yaml", &lock).await;
936+
let entries = inventory_npm_trees(tmp.path()).await.unwrap();
937+
assert_eq!(integrity(&entries, "left-pad"), LockIntegrity::None);
938+
let (_, entries) = inventory_npm_lock(tmp.path()).await.unwrap().unwrap();
939+
assert_eq!(integrity(&entries, "left-pad"), LockIntegrity::None);
929940
}
930941

931942
/// The inventory twin of discovery's

0 commit comments

Comments
 (0)