Repository navigation
test(pacquet): stop ambient pnpm configuration from reaching the suites - #13744
Conversation
Every command the suites spawn inherits the test process's environment, and pnpm reads its settings from `PNPM_CONFIG_*` / `pnpm_config_*` and the npm spellings. One such variable therefore reconfigures the pnpm under test: `pnpm/setup` exports `PNPM_CONFIG_GLOBAL_SHIMS` to keep the runtime it installed authoritative, which made `link_global_bins` write direct shims and failed the global-shims assertions in CI. A contributor with a setting exported in their shell hits the same class of failure locally. Add `CommandTestExt::without_ambient_pnpm_config` and apply it where the suites construct their commands, so a test is configured only by its own `.npmrc` / workspace YAML plus whatever it sets on the command — an explicit `env` still wins, because the removal happens at construction. Two suites already hand-listed the variables they knew to strip; they now share the helper instead. The `packageManager` checks additionally run `exec node`, resolving `node` from `PATH`. A context-aware global shim there honours the deliberately unsatisfiable `devEngines.runtime` pin those fixtures declare and fails to fetch it, so bypass the dispatcher for them. That failure already reproduces on main for anyone whose global pnpm writes context-aware shims; CI has not seen it because the pnpm it installs still writes direct ones. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`perfectionist` wants one `use` per crate root, and pulling the command helper out of `bin` left two. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PR Summary by QodoTest pacquet suites with a hermetic pnpm env overlay
AI Description
Diagram
High-Level Assessment
Files changed (9)
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe testing utilities add ChangesAmbient test environment isolation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Confidence Score: 5/5The PR appears safe to merge. The prior unchecked UTF-8 boundary panic is fixed by non-panicking prefix access and covered by a targeted regression test, leaving no blocking failure. Reviews (2): Last reviewed commit: "fix(pacquet): reject a config variable n..." | Re-trigger Greptile |
Code Review by Qodo
1. Comment references slice alternative
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pnpm/crates/testing-utils/src/command_env.rs`:
- Around line 51-54: Update the prefix check in the environment-name matching
logic to obtain the prefix with str::get(..prefix.len()) before performing the
case-insensitive comparison, so non-ASCII names cannot panic. Extend the
non-matching test cases for this logic to include an inherited variable whose
UTF-8 character crosses the prefix byte boundary.
In `@pnpm/crates/testing-utils/src/command_env/tests.rs`:
- Around line 3-25: Add a behavior-level test alongside the existing
command-environment tests that applies without_ambient_pnpm_config() to a
Command, then sets a pnpm/npm configuration variable via a later explicit env
call. Inspect Command::get_envs() or execute a fixture command to verify the
explicitly assigned variable remains present, proving later .env overrides the
ambient-variable removal.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ab2977ad-081b-4fd9-a707-915ee83cba8e
📒 Files selected for processing (9)
pnpm/crates/cli/tests/suite/_utils/mod.rspnpm/crates/cli/tests/suite/global.rspnpm/crates/cli/tests/suite/global_shims.rspnpm/crates/cli/tests/suite/package_manager_check.rspnpm/crates/cli/tests/suite/with.rspnpm/crates/testing-utils/src/bin.rspnpm/crates/testing-utils/src/command_env.rspnpm/crates/testing-utils/src/command_env/tests.rspnpm/crates/testing-utils/src/lib.rs
Micro-Benchmark ResultsLinux |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13744 +/- ##
=======================================
Coverage 88.10% 88.11%
=======================================
Files 621 622 +1
Lines 101078 101098 +20
=======================================
+ Hits 89056 89079 +23
+ Misses 12022 12019 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The environment is outside this process's control, so a name whose prefix-length byte falls inside a multi-byte character panicked every command construction rather than failing the prefix match. Compare through `str::get` and cover such a name in the rejection test. Also pin the contract the callers depend on: the removal happens at construction so a test that exercises one of these settings can still set it afterwards. `EnvGuard` makes that deterministic instead of leaving it to whatever the runner exports. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Code review by qodo was updated up to the latest commit c3d4da7 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
The crate rename (#13948) collided with every import this branch touches, and two changes collided semantically: - `config.registries` became `registries_by_scope` (#13942), so `publish_options` builds its scoped-registry map from the new field. - main's side of `publish_options` still parsed the resolved access through `Access::parse`. This branch forwards it verbatim on purpose -- pnpm validates only `publishConfig.access`, and dropping an unrecognized configured value falls back to the manifest's, which can be the more permissive level. Kept this branch's resolution, on main's field name. The CLI end-to-end tests became a single target under `tests/suite/` (#13679); git carried the three publish/stage files across and they are registered in `main.rs`. Replace this branch's hand-rolled ambient-config isolation with `without_ambient_pnpm_config()` from #13744, which strips every `pnpm_config_*` / `npm_config_*` spelling rather than the five names spelled out here. `CommandTempCwd` already applies it, so the recursive suite only needs the `XDG_CONFIG_HOME` pin that keeps a developer's global `config.yaml` out; the other two build their own command and call it directly. Repoint the `pacquet_publish::` doc references this branch added at `pnpm_publish::`.
Summary
The pacquet suites spawn
pnpmas a sub-process, and a spawned command inherits the test process's environment. pnpm reads its settings fromPNPM_CONFIG_*/pnpm_config_*(and the npm spellings) via thepacquet_configenv overlay, so a single such variable in the environment reconfigures thousands of tests at once.That is not hypothetical.
pnpm/setupnow exportsPNPM_CONFIG_GLOBAL_SHIMS={"node":false}to$GITHUB_ENVto keep the runtime it installed authoritative (pnpm/setup#25).$GITHUB_ENVapplies to every later step in the job, includingTest pacquet, soconfig.global_shimsresolvednodetoOff,link_global_binswrote a direct shim, andglobal_shims_auto_writes_context_aware_shims_for_node_runtimefailed on ubuntu and macos. A contributor with any pnpm setting exported in their shell hits the same class of failure locally. Two suites had already run into it and hand-listed the variables they knew to strip.This adds
CommandTestExt::without_ambient_pnpm_configin a newpacquet-testing-utils::command_envmodule and applies it where the suites construct their commands —CommandTempCwd::init,_utils::pacquet_in,global.rs::global_command,global_shims.rs::shim_command. The removal happens at construction, so a test that exercises one of these settings deliberately still wins with a laterenv. The two hand-rolled lists now share the helper.It also fixes 4
package_manager_checktests that already fail on main, for a related reason: they runexec node, which resolvesnodefromPATH. Where the globalnodeis a context-aware shim, it honours the deliberately unsatisfiabledevEngines.runtimepin those fixtures declare (99999.0.0) and dies trying to fetch it. CI has not seen this only because the pnpm it installs still writes direct shims — it would have started failing as soon as CI moved to a pnpm that writes context-aware ones, independently of this PR. Those checks are aboutpackageManagerbehaviour, not shim dispatch, so their helper bypasses the dispatcher.Related to #13675.
Squash Commit Body
Checklist
already linked to it solves it.
pnpm/port, or the description notes what still needs porting.Rust test harness only — no TypeScript counterpart exists.
pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Not needed: test-harness only, no published behaviour changes.
Verification
PNPM_CONFIG_GLOBAL_SHIMS={"node":false}; with the fix,global,withandpackage_manager_checkare 323/323 (including the 4 that fail on main).pacquet-clisuite: 1413/1413 passed.package_manager_checkfailures are pre-existing by stashing this change and re-running them against main.cargo fmt --check,cargo clippy --all-targets --workspace -- -D warnings, rustdoc,cargo dylint,typos, andtaploall clean (the full pre-push gate).Written by an agent (Claude Code, claude-opus-5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Bug Fixes
Tests