Skip to content

A hosted scan from a pnpm workspace member under tests/ or test/ pins a lock pnpm never reads and writes a pnpm-workspace.yaml pnpm ignores: applied, exit 0; with the shared lock off, a root run leaves that member's lock unpinned #2505

Backlog

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/e2e from 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-verify at the root attests not_affected for 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

The same class, fixed before

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

  1. added
    bug
    arch-audit
    on Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedarch-auditbugpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions