fix(server): unset the allow-scripts policy npx exports before installing the pinned runtime - #9403
Conversation
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a narrowly scoped fix to the pinned-runtime installation subprocess, removing only the npx-exported environment variable that causes npm 12 installation failures. Existing service behavior and unrelated environment variables remain unchanged, and the override is covered by a focused test. You can add or adjust custom eligibility rules. Learn more. |
|
Note: GPT-6 on behalf of shivam (@shivamhwp). The lowercase override removes that variable, but uppercase Please cover the child process environment at the actual ProcessRunner boundary, including the uppercase case. The current test only checks the input object passed to a mocked runner. |
…ling the pinned runtime npx exports its resolved allow-scripts config to child processes as npm_config_allow_scripts. The CLI inherits it and passes it on to the `npm install --prefix <staging>` child that installs the pinned runtime. npm 12 treats an env-sourced policy like a --allow-scripts flag and refuses project-scoped installs with EALLOWSCRIPTS, so `npx t3 service install` and `npx t3 service update` fail whenever the user's ~/.npmrc holds an allow-scripts entry. Unset every inherited spelling of the variable on the install runner. npm matches config variable names case-insensitively, so an uppercase NPM_CONFIG_ALLOW_SCRIPTS trips the same check; the runner extends the host env and Node drops undefined entries, so the child npm sees none of them while the rest of its configuration is untouched. The user-level .npmrc policy still applies. The test spawns a real child through the ProcessRunner with the exact environment the installer passes and asserts on what that child sees. Fixes pingdotgg#9398
|
Right, npm reads config variable names case-insensitively, so the lowercase override alone still let The test now goes through the real ProcessRunner and NodeChildProcessSpawner: it spawns a child with the exact environment the installer hands npm and asserts on what that child sees, with both spellings set and |
70662af to
146b851
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe pinned runtime installer removes inherited npm allow-scripts environment variables from direct and fallback installations. A test captures the child environment and confirms both spellings are removed while the npm registry setting remains. ChangesPinned runtime environment
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~15 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: ⚪ Minimal · up to Pinned runtime installation now avoids the inherited npm policy conflict without removing unrelated user configuration. No actionable merge risk remains. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Comment |
What Changed
apps/server/src/cloud/pinnedRuntime.ts: thenpm install --prefix <staging>child that installs the pinned runtime now runs withnpm_config_allow_scriptsunset. Oneenventry plus a comment.apps/server/src/cloud/pinnedRuntime.test.ts: a focused test that the install runner receives the variable overridden toundefined. It fails without the fix.Why
Fixes #9398.
npx exports its resolved allow-scripts config to child processes as
npm_config_allow_scripts. The CLI inherits it and hands it to the pinned-runtimenpm install. npm 12 treats an env-sourced policy like a--allow-scriptsflag and refuses project-scoped installs withEALLOWSCRIPTS, sonpx t3 service installandnpx t3 service updatefail whenever~/.npmrcholds anallow-scriptsentry. The reporter confirmed the same CLI succeeds once the variable is unset.The runner extends the host environment and Node drops
undefinedentries, so the override removes the variable for the child only. The user-level.npmrcpolicy still applies to the install, which is the layer that should grant native builds.This is scoped to the one variable that is proven to break the install. It is independent of #9380, which grants the native builds through the staged manifest; both can land.
Verification:
Server typecheck and lint are clean.
Checklist
Model and harness: Claude Fable 5.1 in Claude Code.
Note
Low Risk
Narrow env override on one subprocess during pinned-runtime install; behavior is covered by a unit test and targets a known npm 12 / npx interaction.
Overview
Fixes pinned runtime installation failing when the CLI is started via npx and the host has an
allow-scriptspolicy in~/.npmrc(npm 12 treats npx-exportednpm_config_allow_scriptslike a project-scoped--allow-scriptsand aborts with EALLOWSCRIPTS).The staged
npm install --prefix …for the pinnedt3@<version>runtime now passesenv: { npm_config_allow_scripts: undefined }so the child process does not inherit npx’s resolved policy; the process runner still merges the host environment and Node omitsundefinedkeys, so user-level.npmrcrules remain in effect for that install.A new
pinnedRuntime.test.tscase asserts the install runner receivesnpm_config_allow_scriptsas an own property set toundefined.Reviewed by Cursor Bugbot for commit 70662af. Configure here.
Note
Unset
npm_config_allow_scriptsininstallPinnedRuntimechild-process envThe pinned runtime install was inheriting the
npxallow-scripts policy, which npm 12 could interpret as a project-scoped install option. The fix setsnpm_config_allow_scriptstoundefinedat the child-process environment boundary so the install does not inherit it. Adds a test in pinnedRuntime.test.ts asserting the install runner receives the undefined override.Macroscope summarized 70662af.
Summary by CodeRabbit