Repository navigation
Description
[agent] Found by the architecture refactor routine while running the workspace glob readers against the package managers (lead L198). Checked on main at d987721.
Problem
pnpm lists a project under a test or tests directory as a workspace member when a packages: glob matches it: tests/* lists tests/e2e, and packages/* lists packages/tests. socket-patch's reader of those globs never does. MEMBER_SKIP drops every path that has a test or tests component, and its comment calls them "the directories pnpm never finds workspace projects in (the default ignores of its project finder)". Those are the defaults of pnpm's generic package finder. Its workspace finder passes its own ignore list, which holds node_modules and bower_components only.
Every check that asks "is this directory a member" therefore answers no for such a member, and the run treats it as a standalone project:
Hosted run (scan --mode hosted --yes --json) |
Member at packages/app (control) |
Member at tests/e2e |
|---|---|---|
From the member, which holds a stray pnpm-lock.yaml; the workspace shares the root lock |
exit 1, redirect_workspace_lockfile_elsewhere: "pnpm installs it from the workspace's shared <ws>/pnpm-lock.yaml and ignores its own ./pnpm-lock.yaml" |
exit 0, applied. Rewrites tests/e2e/pnpm-lock.yaml and creates tests/e2e/pnpm-workspace.yaml (trustLockfile: true). The root lock is untouched |
From the member; sharedWorkspaceLockfile: false, each member has its own lock |
exit 1, redirect_pnpm_settings_elsewhere: "pnpm reads trustLockfile only from that file … a pnpm-workspace.yaml created here would be ignored" |
exit 0, applied. Pins the lock and creates tests/e2e/pnpm-workspace.yaml |
From the root; sharedWorkspaceLockfile: false |
packages/app/pnpm-lock.yaml is pinned |
tests/e2e/pnpm-lock.yaml is not pinned, with no warning. The run says applied, exit 0, and rewrittenFiles names the other lock only |
Who it hurts: a pnpm monorepo that keeps an e2e or integration project in the workspace (tests/*, test/*), or has a package named test or tests.
- After the first row, pnpm still installs
tests/e2efrom the root lock, which resolves the upstream release. The run reported a patch that nothing delivers. - After the second row, pnpm 11 and 12 say on the next root install that the new file does nothing (output below). By the control's own message, pnpm 11 and newer then reject the pinned lock (
ERR_PNPM_TARBALL_URL_MISMATCH). - After the third row,
vex --no-verifyat the root attestsnot_affectedfor the package while one member's lock still resolves the upstream tarball.
A lockless member is not affected: redirect_pnpm_lockfile_elsewhere fires for tests/e2e as it does for packages/app.
What pnpm lists
One workspace, packages: ["packages/**", "test/*", "tests/*"], with a package.json in each directory below. pnpm ls -r --depth -1 --json:
| pnpm | Listed |
|---|---|
| 7.33.7, 8.15.9, 9.15.9, 10.28.0, 10.34.9, 11.27.0, 11.28.0, 11.29.0, 12.26.0 | ., packages/a, packages/a/test, packages/a/tests/unit, packages/test, packages/tests, test/e2e, tests/integration |
All nine give the same list. pnpm install --lockfile-only on 10.34.9 and 12.26.0 writes those eight importers (10.34.9 prints "Scope: all 8 workspace projects"). Of the seven below the root, socket-patch's reader calls only packages/a a member.
The two lists, in the bundle of pnpm 10.34.9:
var DEFAULT_IGNORE = ["**/node_modules/**", "**/bower_components/**", "**/test/**", "**/tests/**"];
async function findPackages(root, opts) { ... globOpts.ignore = opts.ignore ?? DEFAULT_IGNORE; ... }
async function findWorkspacePackagesNoCheck(workspaceRoot, opts) {
const pkgs = await findPackages(workspaceRoot, {
ignore: ["**/node_modules/**", "**/bower_components/**"],
includeRoot: true,
patterns: opts?.patterns
});With trustLockfile: true in a pnpm-workspace.yaml inside the member, a root install on pnpm 11.29.0 and 12.26.0 prints:
[WARN] The settings in tests/integration/pnpm-workspace.yaml do not apply, because tests/integration is a project of this workspace. pnpm reads settings only from the pnpm-workspace.yaml at the workspace root.
Evidence on main
A unit probe appended to utils/pnpm_workspace.rs:
let globs: Vec<String> = ["packages/*", "tests/*", "test/*"].iter().map(|s| s.to_string()).collect();
let rel = |s: &str| s.split('/').map(str::to_string).collect::<Vec<_>>();
assert_eq!(lists_member(&globs, &rel("packages/app")), Ok(true));
for member in ["tests/e2e", "test/e2e", "packages/tests", "packages/test"] {
assert_eq!(lists_member(&globs, &rel(member)), Ok(true), "{member}");
}$ cargo test -p socket-patch-core --lib -- probe_test_dirs
thread '…::a_member_under_a_tests_directory_is_a_member' panicked at crates/socket-patch-core/src/utils/pnpm_workspace.rs:2270:13:
assertion `left == right` failed: tests/e2e
left: Ok(false)
right: Ok(true)
test result: FAILED. 0 passed; 1 failed
Three existing unit tests state the reading pnpm contradicts, each with a test directory it expects not to be a member: member_dirs_expand_globs_minus_negations_and_ignored_trees and member_dirs_and_governing_file_agree_on_membership (packages/test under packages/*), and nested_npm_project_finds_a_lockless_project in hosted/governing_root.rs (b/apps/test).
Through the binary, with the bench's stand-in patch API (socket-patch-bench serve pnpm/hosted --bin <cli> --scale 0.02 --work-dir <dir>) and a workspace made from its project (script below). First row of the table, from tests/e2e:
$ socket-patch scan --mode hosted --yes --json # cwd: <ws>/tests/e2e
exit 0
"status": "success", "events": [{"action": "applied", "purl": "pkg:npm/dehino30@24.21.11", ...}]
"warnings": [{"code": "redirect_pnpm_trust_lockfile", "detail": "... `trustLockfile: true` was written to a new pnpm-workspace.yaml ..."}]
$ git status --short
M tests/e2e/pnpm-lock.yaml
?? tests/e2e/pnpm-workspace.yaml
The same state from packages/app:
exit 1
"error": {"code": "redirect_workspace_lockfile_elsewhere", "message": ". is a member of the pnpm workspace rooted at <ws>: pnpm installs it from the workspace's shared <ws>/pnpm-lock.yaml and ignores its own ./pnpm-lock.yaml; run socket-patch from <ws> (the workspace root); nothing was written"}
Third row, from the root with sharedWorkspaceLockfile: false:
exit 0
"events": [{"action": "applied", "purl": "pkg:npm/dehino30@24.21.11", ...}]
"redirect": {"mode": "hosted", "rewrittenFiles": ["packages/app/pnpm-lock.yaml", "pnpm-workspace.yaml"]}
packages/app/pnpm-lock.yaml: 1 line names the patch server
tests/e2e/pnpm-lock.yaml: 0 lines name the patch server
$ socket-patch vex --no-verify --product pkg:npm/root@1.0.0
GHSA-… not_affected inline_mitigations_already_exist pkg:npm/dehino30@24.21.11
Not run: the vex path that verifies files on disk (the bench's installed files are synthetic, so it omits the statement with hash_mismatch), a real pnpm install of the rewritten locks, and the vendored write. In vendored mode the control refuses with vendor_pnpm_settings_elsewhere before any download and the tests/e2e run goes on to download, but the bench serves no vendored artifact.
Where
MEMBER_SKIPand [lists_member](https://github.com/SocketDev/socket-patch/blob/d98772148e4fffb56fa53e9f867e10e1286bb089/crates/socket-patch-core/src/utils/pnpm_workspace.rs#L270-L302), which every membership question goes through: [governing_workspace_file](https://github.com/SocketDev/socket-patch/blob/d98772148e4fffb56fa53e9f867e10e1286bb089/crates/socket-patch-core/src/utils/pnpm_workspace.rs#L1149-L1187) (the member-side refusals), [member_dirs](https://github.com/SocketDev/socket-patch/blob/d98772148e4fffb56fa53e9f867e10e1286bb089/crates/socket-patch-core/src/utils/pnpm_workspace.rs#L466-L522) (the member locks a root run pins) androot_accounts_for_member_lock(the in-memory engine).- The list arrived with the membership reader in Fix 15 open pnpm issues across hosted, vendored and agent modes #1007 (for Hosted and vendored pnpm 11/12 refuse a standalone project nested under an unrelated pnpm-workspace.yaml (not in its
packages:globs) as a "workspace member", and the suggested fix doesn't work (regression from #888) #1006) and was never run against pnpm.
The same class, fixed before
- Hosted scan from a pnpm 11/12 workspace member with its own lock writes trustLockfile into a nested member pnpm-workspace.yaml that pnpm ignores, so the root install fails with ERR_PNPM_TARBALL_URL_MISMATCH #880 and Vendored scan from a pnpm 11/12 workspace member with its own lock writes the override into a nested member pnpm-workspace.yaml that pnpm ignores, so the root frozen install fails and a plain
pnpm installsilently reinstalls the unpatched package #881: apnpm-workspace.yamlwritten into a member, which pnpm ignores. - Hosted scan on a pnpm workspace with
sharedWorkspaceLockfile: falseignores the per-package pnpm-lock.yaml files and reports success while redirecting nothing #492: member locks left unpinned with the shared lock off, and success reported. - Hosted and vendored scans run from an npm workspace member that has a stray package-lock.json of its own rewrite that lock, which npm ignores, and report success while npm installs the unpatched package and VEX attests not_affected #1094 (npm) and Hosted and vendored scans from a Bun workspace member with a stray bun.lock / bun.lockb pin that ignored lock, exit 0, and lock-only VEX attests not_affected while Bun installs the unpatched package #1101 (Bun): a member's stray lock pinned, which its package manager never reads.
Each fix asks lists_member whether the directory is a member, so each has this gap for a member under test or tests.
Planned fix
Make MEMBER_SKIP the list pnpm's workspace finder uses, node_modules and bower_components: one production line. The probe above becomes a test, and the three tests named above change their test expectation.
Tried on a build of main with that line changed, together with the two-line trial fix of #2506; nothing was pushed. The tests/e2e column gives the control's answer in every row, vendored included (vendor_pnpm_settings_elsewhere), the root run lists tests/e2e/pnpm-lock.yaml in rewrittenFiles, and of the 286 existing unit tests of the glob, pnpm workspace, governing-root, crawler and user-patch modules only those three fail.
CLI_CONTRACT.md describes the root run as reading "every member lock the packages: globs name (quoted ! negations applied; node_modules, bower_components, test and tests trees and symlinked directories skipped)". The member-side rows of the table contradict the contract's own refusal rule ("a pnpm-lock.yaml in a member a pnpm-workspace.yaml lists"), so those are settled. For the root run, the sentence states the skip. The fix would drop test and tests from it, because pnpm installs those members. If the skip is meant as policy (as docs/configuration.md excludes discovered roots under tests/ by default), the root run needs a warning that names the lock it left unpinned instead. A word from a maintainer on which would help.
The workspace script
mkpnpmws.py <bench project> <dst> packages/app,tests/e2e 'packages/*,tests/*' dehino30@24.21.11 (the patched package of the bench at --scale 0.02; a scan from a member only sees its direct dependencies, so the script adds it as one). Then, for the first row, copy the bench project's pnpm-lock.yaml into each member; for the other two, also delete the root lock and append sharedWorkspaceLockfile: false to the root pnpm-workspace.yaml. Commit, and run with the environment serve prints.
import json, os, re, shutil, sys
src, dst, members = sys.argv[1], sys.argv[2], sys.argv[3].split(",")
globs = sys.argv[4].split(",")
en, ev = sys.argv[5].split("@")
os.makedirs(dst)
json.dump({"name": "root", "version": "1.0.0", "private": True},
open(os.path.join(dst, "package.json"), "w"))
open(os.path.join(dst, "pnpm-workspace.yaml"), "w").write(
"packages:\n" + "".join(" - '%s'\n" % g for g in globs))
os.makedirs(os.path.join(dst, "node_modules"))
shutil.copytree(os.path.join(src, "node_modules/.pnpm"),
os.path.join(dst, "node_modules/.pnpm"), symlinks=True)
shutil.copy(os.path.join(src, "node_modules/.modules.yaml"),
os.path.join(dst, "node_modules/.modules.yaml"))
lock = open(os.path.join(src, "pnpm-lock.yaml")).read()
m = re.search(r"importers:\n\n \.:\n(.*?)\npackages:\n", lock, re.S)
body = m.group(1).rstrip("\n") + "\n %s:\n specifier: ^%s\n version: %s\n" % (en, ev, ev)
imp = "importers:\n\n .: {}\n\n" + "".join(" %s:\n%s\n" % (mem, body) for mem in members) + "packages:\n"
open(os.path.join(dst, "pnpm-lock.yaml"), "w").write(lock[:m.start()] + imp + lock[m.end():])
pkg = json.load(open(os.path.join(src, "package.json")))
for i, mem in enumerate(members):
d = os.path.join(dst, mem)
os.makedirs(os.path.join(d, "node_modules"))
p = dict(pkg, name="m%d" % i)
p["dependencies"] = dict(p["dependencies"], **{en: "^" + ev})
json.dump(p, open(os.path.join(d, "package.json"), "w"), indent=2)
up = "/".join([".."] * (mem.count("/") + 2))
for e in os.listdir(os.path.join(src, "node_modules")):
s = os.path.join(src, "node_modules", e)
if os.path.islink(s):
os.symlink(up + "/node_modules/" + os.readlink(s), os.path.join(d, "node_modules", e))
os.symlink(up + "/node_modules/.pnpm/%s@%s/node_modules/%s" % (en, ev, en),
os.path.join(d, "node_modules", en))Generated by Claude Code
Activity
refactor: L198, L199 filed as #2505, #2506