Skip to content

fix(provider-core): npm provider updates into a prefix the server can't write stay manual (carry upstream #30302) - #525

Draft
scuttletoby wants to merge 3 commits into
mainfrom
carry/upstream-30302
Draft

scuttletoby wants to merge 3 commits into
mainfrom
carry/upstream-30302

Conversation

@scuttletoby

Copy link
Copy Markdown
Owner

Carries upstream PR pingdotgg#30302 (open, CONFLICTING upstream; fixes upstream issue pingdotgg#30281) onto fork main.

Problem

A provider CLI installed with sudo npm install -g sits in a root-owned npm prefix (/usr/local on macOS, /usr or /usr/local on Linux). T3 still offered a one-click Update, which runs npm install -g --prefix <prefix> ... as the server's user. That always fails with EACCES on npm's first rename, and the popover shows only npm's last log line.

What the carry does (upstream's change)

Before it offers the npm-global update, the maintenance resolver checks whether the server can write the two directories npm's reify renames in: the package's parent (the scope directory for a scoped package) and <prefix>/bin. If either is definitely denied (EACCES), the install becomes manual-only, the same as Chocolatey or MacPorts installs: no Update, left out of Update all, and the advisory shows Version X is out. T3 Code runs <path>; update it with the app or tool that installed it. with sudo npm install -g --prefix <prefix> --allow-scripts=<pkg> <pkg>@latest to copy. A missing directory or any other error keeps today's one-click update. Windows is skipped, because its access() ignores directory ACLs. The resolver is shared, so every npm-managed provider gets this.

Conflict resolution

Since upstream opened pingdotgg#30302, main's npm-global branch gained its own npm outdated -g --prefix version lookup (upstream pingdotgg#24062) and a latestVersionCacheKey. The PR switched the manual result to the generic npm view lookup. The carry keeps main's lookup and cache key on the manual result instead, and the PR's test now expects the npm outdated probe rather than npm view. Apart from that, the resolver code and both tests are exactly as in pingdotgg#30302. Julius Marminge (the upstream author) is the commit author.

The second commit adds the FORK_CHANGES.md line. Drop that line, and this carry, when upstream merges pingdotgg#30302: the nightly follow brings in the upstream commit, and its conflict is in this one hunk.

Verification

  • packages/provider-core/src/server/maintenanceResolver.test.ts: the 2 new cases (...when the package scope is read-only, ...when the prefix bin is read-only) fail on main (expected { …(5) } to be null) and pass with the fix. The file passes in full (122 tests). They skip as root and on Windows, where directory modes do not stop writes.

  • vp run check:changed: passed.

  • Writable user prefix still offers the update: existing case, npm install -g --prefix <tmp> ... with no sudo.

  • Real npm (11.x, Linux): a real npm install -g --prefix <tmp> of a scoped package, with @scope and bin set to 555, fails on a re-install with EACCES / syscall rename. The resolver on that prefix gives:

    prefix dirs main this PR
    555 (read-only) update npm install -g --prefix <tmp> ... no update; manual sudo npm install -g --prefix <tmp> --allow-scripts=@example/package-tool @example/package-tool@latest
    755 (user-owned) update npm install -g --prefix <tmp> ... same as main
  • macOS: the same path with the host platform set to darwin gives the same manual result as Linux. The check is plain POSIX access(W_OK), so nothing in it is specific to macOS. I have not run it on a real Mac.

  • Windows: context.platform !== "win32" returns before any access() call, so the Windows result is unchanged by construction. A simulated win32 run on Linux gave identical output on main and with the fix, but that layout does not reach the npm branch, so it is weak evidence.

State question

  • Runs again: nothing is stored. The answer is worked out again when the capabilities cache expires, so a user who updates by hand with sudo or chowns the prefix gets one-click updates back on the next refresh. Manual and one-click results share the same version cache key, because the lookup is the same.
  • Stops half-way (an update interrupted mid-rename): in the manual case T3 never starts an npm run, so it cannot leave a half-renamed prefix. If an earlier interrupted run left the package directory renamed away, the binary no longer resolves and the resolver never reaches this branch (as on main). If it left bin missing, the check reads it as writable (npm creates it), as upstream intends.
  • Old or empty state: no contract or schema change. Older clients read the same canUpdate / updateCommand advisory fields. An empty or partial prefix (directories missing) is treated as writable, which is today's behaviour.
  • Not covered (same as upstream): a read-only filesystem (EROFS) is not PermissionDenied, so it still offers the one-click update. An unscoped package whose own directory is root-owned inside a user-owned lib/node_modules is not checked (only the parent is). The sudo command runs root's npm from secure_path, which may differ from a version manager's npm.

Upstream fit

This is upstream's own open PR, unchanged except for the conflict hunk above. It needs no fork setting and touches no fork seam. If upstream rebases pingdotgg#30302 differently, take their version and drop this.

General vs project

All general: upstream's fix, plus one FORK_CHANGES.md line. No host, machine, path or person is named.

Claude Opus 5.5 (claude-opus-5-5) in Claude Code.

🤖 Generated with Claude Code

juliusmarminge and others added 3 commits November 19, 2026 12:19
…'t write stay manual

Carried from upstream PR 30302 (open, fixes upstream issue 30281), which
conflicts with upstream main as it stands.

When a provider CLI was installed with `sudo npm install -g` into a
root-owned prefix, T3 offered a one-click Update that ran
`npm install -g --prefix <prefix> ...` unprivileged and always failed with
EACCES. Before offering the npm-global update, the resolver now checks that
the server can write the package's parent directory and `<prefix>/bin`, the
two places npm's reify renames in. When either is definitely denied, the
install is manual-only: no Update, not in Update all, and
`sudo npm install -g --prefix <prefix> --allow-scripts=<pkg> <pkg>@latest`
is shown to copy. A missing directory or any other error keeps the
one-click update, and Windows is skipped (its access() ignores directory
ACLs).

Conflict resolution: since the PR was opened, main's npm-global branch
gained its own `npm outdated -g --prefix` version lookup and a
latestVersionCacheKey. The manual-only result keeps both, instead of the
PR's switch to the configured `npm view` lookup, and the PR's test now
expects the `npm outdated` probe. The resolver code and tests are
otherwise as in the PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop this line when upstream merges that PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby
scuttletoby marked this pull request as draft November 19, 2026 12:46
@scuttletoby

scuttletoby commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner Author

Parked (draft), like #43: the carry adds 116 lines to two upstream files with no seam entry, which goes against thin add-ons. The machine that hit the problem now installs provider CLIs into a user-owned prefix, so the update works there without this change. When upstream merges its PR 30302, the nightly follow brings it in with no seam needed; close this PR then.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants