Skip to content

Run the pnpm of the hosted pnpm tests in the directory's own spelling on Windows - #2245

Merged
Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
fix/pnpm-registry-cleanup-windows
Nov 25, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
fix/pnpm-registry-cleanup-windows

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Tests and one docs sentence: the real-pnpm e2e suites now start pnpm in the canonical spelling of each project directory, which fixes pnpm11_registry_route_is_cleaned_up_when_a_patch_is_not_needed on Windows; the CLI does not change, so there is nothing for the release notes.

Fixes #2235

What failed

Job e2e-windows (windows-latest, e2e_redirect_pnpm_build, ...): the test panics at its first case, removed-scan, on "pnpm dropped the release and still records its override". The lock it prints has two importers for one project:

importers:
  .:        # host, mid and peer-user (socket-bbbbbbbb:1.0.0), as before the command
  ../../../../../../RUNNER~1/AppData/Local/Temp/.tmpG1iNeC/removed-scan:   # host, mid

pnpm remove peer-user exited 0 and wrote its change under a new key. The root importer still asks for peer-user, so the routed release stays in packages: and the assertion fails. The test passes on Linux and macOS, and its pnpm 12 twin passes on the same runner.

Why

The key is the path from the lock's directory to the project's: six levels up, then down again through RUNNER~1. pnpm held two spellings of one directory. A hosted Windows runner has both: the profile is C:\Users\runneradmin, and %TEMP%, where tempfile::tempdir() puts every project of the suite, is C:\Users\RUNNER~1\AppData\Local\Temp. The suite started pnpm with the project as its working directory, in that spelling.

pnpm 11 (read in the 11.27.0 bundle):

  • takes the project directory from fs.realpathSync(<working directory>), Node's JavaScript walk, which resolves links and keeps every other component as spelled, a short name included;
  • searches the workspace root from fs.realpath.native(<working directory>), the operating system's answer, with long names. With a pnpm-workspace.yaml in the project (a routed scan creates one) the lock lives at that root;
  • in pnpm remove mutates the one project at the first spelling and keys it path.relative(lockDir, projectDir) || '.'. pnpm add and pnpm update fall into the same path when no workspace project equals the working directory. pnpm install and pnpm dedupe take their projects from the workspace root.

Measured with pnpm 11.27.0 on macOS, the workspace root given through a symlinked spelling (NPM_CONFIG_WORKSPACE_DIR, which pnpm takes as spelled): remove, add and update add an importer ../../real/<project> and leave . with the removed dependency, the shape of the CI lock; install and dedupe keep the single .; with one spelling all five keep ..

All 19 tests handed pnpm its directory the same way. This is the only one that runs pnpm remove, and the only one that asserts on what pnpm add of an existing dependency leaves in a project with a workspace file.

What changes

  • hermetic::start_in(cmd, dir) in tests/common starts a package manager in hermetic::os_spelling(dir): std::fs::canonicalize without the verbatim \\?\ prefix, the string pnpm computes for the workspace root.
  • Every suite that runs a real pnpm starts it through that step: e2e_redirect_pnpm_build, e2e_redirect_rush_sim, e2e_safety_pnpm, e2e_vendor_pnpm_build, e2e_vendor_rush.
  • socket-patch still gets each directory as the test spelled it, so the suites keep running the CLI on a short-name path. No assertion changes, nothing is skipped.
  • docs/ecosystems.md records the limit below.

The Windows run of the first commit (the hosted suite alone) passed the job: pnpm11_registry_route_is_cleaned_up_when_a_patch_is_not_needed ... ok, 19 of 19.

Were users on Windows affected

Not by socket-patch. It never runs pnpm in a project (its one pnpm call is pnpm root -g, from the home directory, for global scans), and it writes no file system path: pnpm-workspace.yaml gets packages: ['.'], trustLockfile, registry URLs and overrides; in pnpm-lock.yaml it edits overrides:, packages:/snapshots: keys and the values of existing importers, and never adds or renames an importer.

One limit stays reachable and is now in the docs: on Windows, in a project that has a pnpm-workspace.yaml (hosted mode creates one for a pnpm 11 project that had none), pnpm 11 started from a directory spelled with an 8.3 short name records what pnpm add, remove and update change under a second importers: entry and leaves . as it was; that is pnpm's behaviour, and running pnpm from the directory's long name avoids it.

Code review

No defect found in the first commit. Five points, all applied:

  1. The limit users can reach is recorded: one sentence in docs/ecosystems.md beside the rule for creating pnpm-workspace.yaml, and the paragraph above. No product change, no new warning.
  2. os_spelling no longer falls back to the caller's spelling: a directory that cannot be resolved panics there, with its path.
  3. One launcher step for every real-pnpm suite (list above; e2e_vendor_rush was not named in the review and has the same Rush launcher). None of them chose its spelling on purpose. The launchers of socket-patch itself are left alone.
  4. One helper for "canonicalize, then drop the verbatim prefix": member_root (in_process_redirect_pnpm), canonical (sbt drivers) and fixture_root (Gradle driver, a fourth copy) call os_spelling. Left: java_path and file_uri of the sbt drivers, which only drop the prefix, from locations that need not exist and must not be resolved.
  5. The launcher's comment states the invariant in two lines; the mechanism is in the helper's doc, with fs.realpathSync described as it is (links resolved, an 8.3 name kept).

Checked

On macOS, at the head:

  • rustfmt --check --edition 2021 on the changed files.
  • cargo clippy --locked --workspace --all-features -- -D warnings.
  • cargo check --locked --workspace --all-targets --all-features: every target builds. Two unused-import warnings, both in files this change does not touch.
  • The tests that are not ignored, of the 14 CLI targets whose own code or driver changed and of in_process_pnpm_registry_cleanup: 238 passed, none failed. That includes in_process_redirect_pnpm, two new self-tests of the launcher step, and the vendored suite's real pnpm 7, 8 and 10 lifecycles.
  • The core's pnpm_hosted and both golden suites: 72 passed.
  • The failing test and the three other pnpm 11 registry-route tests against a real pnpm 11.27.0 (SOCKET_PATCH_PNPM_E2E_BIN): passed.

Only a Windows run can confirm the rest: e2e_safety_pnpm, e2e_redirect_rush_sim and e2e_vendor_rush now run pnpm in the long spelling there while socket-patch keeps the short one. A test of those legs that fails where it passed before is this change.

🤖 Generated with Claude Code

On Windows the real-pnpm test
`pnpm11_registry_route_is_cleaned_up_when_a_patch_is_not_needed` failed
at its first case: after `pnpm remove peer-user` the lock still held the
routed release of peer-user. pnpm had exited 0 and had not touched the
root importer `.`; it had written the change under a second importer for
the same project,
`../../../../../../RUNNER~1/AppData/Local/Temp/<tmp>/removed-scan`.

That key is the path from the lock's directory to the project's, so pnpm
held two spellings of one directory. The suite starts pnpm in a
directory under the temp directory, which a hosted Windows runner spells
with an 8.3 short name (`C:\Users\RUNNER~1\AppData\Local\Temp`; the
profile is `C:\Users\runneradmin`). pnpm 11 takes the project directory
from its working directory through Node's JavaScript realpath, which
keeps a short name, and searches the workspace root from the same
directory through `fs.realpath.native`, which expands it. With a
pnpm-workspace.yaml in the project (a routed scan creates one) the lock
lives at the workspace root, and `pnpm remove`, `pnpm add` and
`pnpm update` key the project by the path between the two spellings in
place of `.`. `pnpm install` and `pnpm dedupe` take their projects from
the workspace root, which is why the other tests of the target pass
there: they run those, or run `pnpm add` and look only at `packages:`
and the installed files. On Linux and macOS the working directory a
process reads back is already resolved.

pnpm 11.27.0 does the same on macOS when its workspace root is given
through a symlinked spelling: `remove`, `add` and `update` add an
importer `../../real/<project>` and leave `.` with the dependency that
was removed; `install` and `dedupe` keep the single `.`.

`corepack_command`, through which every pnpm of the suite starts, now
sets the working directory to the canonical spelling without the
verbatim prefix, the string pnpm computes for the workspace root.
socket-patch still gets each directory as the test spelled it, so the
suite keeps running the CLI on a short-name path. No assertion changes.

The CLI is not changed: it never runs pnpm in a project, and it writes
no file system path into pnpm-lock.yaml or pnpm-workspace.yaml.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main brought the two changes that the Windows run of this branch still
failed without: the rule that checks the pnpm registry fixtures out as
committed, and the scan futures built off the stack. No conflict.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Only the hosted pnpm e2e suite started pnpm in the canonical spelling
of its project directory. The other suites that run a real pnpm still
handed it the directory as `tempfile` spells it, an 8.3 short name on a
hosted Windows runner, so the next test there that runs `pnpm add`,
`remove` or `update` on pnpm 11 would get a second importer in the lock
again and have to be diagnosed again.

`hermetic::start_in(cmd, dir)` in tests/common sets a package manager's
working directory to `hermetic::os_spelling(dir)`. The pnpm launchers
of e2e_redirect_pnpm_build, e2e_redirect_rush_sim (pnpm, and Rush in
the opt-in leg), e2e_safety_pnpm (`common::pnpm_run`),
e2e_vendor_pnpm_build and e2e_vendor_rush go through it. None of them
chose its spelling on purpose: each passed a directory under its temp
directory. socket-patch is still started in the directory as each test
spells it.

`os_spelling` is the one helper for "canonicalize, then drop the
verbatim prefix": `member_root` of in_process_redirect_pnpm, `canonical`
of the sbt drivers and `fixture_root` of the Gradle driver call it in
place of their own copies. It panics with the path when the directory
cannot be resolved. The first version fell back to the caller's
spelling, which would have brought the failure back with no signal.
`java_path` and `file_uri` of the sbt drivers keep their own strip:
they take locations that need not exist and must not be resolved.

The comment at the hosted suite's launcher said pnpm keeps the project
directory as the process was given it. pnpm takes it from
`fs.realpathSync(cwd)`, which resolves links and leaves an 8.3 name as
spelled, so a symlinked directory does not diverge. The helper's doc
says so, and the launcher states the invariant in two lines.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
On Windows, pnpm 11 started from a directory spelled with an 8.3 short
name, in a project that has a pnpm-workspace.yaml, records what
`pnpm add`, `remove` and `update` change under a second `importers:`
entry of the lock and leaves `.` as it was. Hosted mode creates that
file for a pnpm 11 project that had none, so a user can reach this
after a scan.

It is pnpm's own behaviour and the CLI is not changed: it never runs
pnpm in a project and writes no path into either file.
docs/ecosystems.md now names the limit and the way out (run pnpm from
the directory's long name) beside the rule for creating the file.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 25, 2026 17:05
@cursor

cursor Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Changes are limited to test harness helpers, e2e launchers, and documentation; production CLI behavior is unchanged.

Overview
Fixes flaky Windows hosted-pnpm e2e failures where pnpm 11 wrote a second importers: lock key when the child’s cwd used an 8.3 short name while the workspace root was resolved to the long path.

Adds hermetic::os_spelling (canonicalize, strip \\?\, expand short names) and hermetic::start_in so real pnpm, corepack, npm/Rush launchers set cwd to the OS spelling; run_toolchain and the redirect/vendor/rush e2e helpers use it. Duplicate path helpers in Gradle, sbt, and in-process pnpm tests are replaced with os_spelling. Self-tests cover spelling and missing-directory panics. docs/ecosystems.md documents the remaining user-visible pnpm 11 Windows short-name limit.

No socket-patch product code changes.

Reviewed by Cursor Bugbot for commit 573a638. Configure here.

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 25, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. Test-harness fix for #2235: every suite that runs a real pnpm (and the Rush launchers) now starts it in the directory's canonical spelling, so on a Windows runner whose temp dir is an 8.3 short name (RUNNER~1) pnpm 11 no longer writes a second importers: key on pnpm remove. It also folds three copies of "canonicalize and drop \\?\" into one helper and adds one docs sentence about the pnpm behaviour. No CLI code changes.

Risk: low. Tests and docs only; the CLI still gets each directory as the test spelled it, so short-name coverage of socket-patch itself is kept. No assertion is weakened or skipped.

Look here

  • hermetic.rs:214 os_spelling and :227 start_in (now panics on an unresolvable dir instead of falling back)
  • common/mod.rs:284 and [e2e_redirect_pnpm_build.rs:223](https://github.com/SocketDev/socket-patch/blob/573a638ab85998657f6a58ccd873b5f11dddee78/crates/socket-patch-cli/tests/e2e_redirect_pnpm_build.rs#L223): the launchers that change
  • sbt_e2e_shared/mod.rs:73: sbt and Gradle helpers now go through os_spelling
  • docs/ecosystems.md:420: the documented Windows limit

Verified. Read the whole diff. without_verbatim_prefix (used by os_spelling) strips the same \\?\UNC\ and \\?\C: forms as the removed strip_verbatim and the sbt java_path, and nothing else still calls the removed Gradle helper. CI on this head: ci-ok and clippy green; the Windows workflow-dispatch run of this head is green, including e2e-windows for e2e_redirect_pnpm_build, e2e_safety_pnpm and e2e_redirect_rush_sim e2e_vendor_rush. No review threads open. CHANGELOG.md untouched.

Changes I made. None.

Open questions. None.


Generated by Claude Code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Reviewed the new os_spelling and start_in helpers and every launcher in the five suites. No pnpm, Rush or npm launcher was missed, and the socket-patch launchers keep the test's own spelling as described. No findings.

Merged via the queue into main with commit e57b93c Nov 25, 2026
142 of 144 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/pnpm-registry-cleanup-windows branch November 25, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nightly: pnpm11_registry_route_is_cleaned_up_when_a_patch_is_not_needed fails on Windows (pnpm records the RUNNER~1 short path as a second importer)

3 participants