Skip to content

test(pacquet): stop ambient pnpm configuration from reaching the suites - #13744

Merged
zkochan merged 3 commits into
mainfrom
hermetic-test-env
Aug 9, 2026
Merged

zkochan merged 3 commits into
mainfrom
hermetic-test-env

Conversation

@zkochan

@zkochan zkochan commented Aug 9, 2026 •

Copy link
Copy Markdown
Member

Summary

The pacquet suites spawn pnpm as a sub-process, and a spawned command inherits the test process's environment. pnpm reads its settings from PNPM_CONFIG_* / pnpm_config_* (and the npm spellings) via the pacquet_config env overlay, so a single such variable in the environment reconfigures thousands of tests at once.

That is not hypothetical. pnpm/setup now exports PNPM_CONFIG_GLOBAL_SHIMS={"node":false} to $GITHUB_ENV to keep the runtime it installed authoritative (pnpm/setup#25). $GITHUB_ENV applies to every later step in the job, including Test pacquet, so config.global_shims resolved node to Off, link_global_bins wrote a direct shim, and global_shims_auto_writes_context_aware_shims_for_node_runtime failed 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_config in a new pacquet-testing-utils::command_env module 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 later env. The two hand-rolled lists now share the helper.

It also fixes 4 package_manager_check tests that already fail on main, for a related reason: they run exec node, which resolves node from PATH. Where the global node is a context-aware shim, it honours the deliberately unsatisfiable devEngines.runtime pin 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 about packageManager behaviour, not shim dispatch, so their helper bypasses the dispatcher.

Related to #13675.

Squash Commit Body

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.

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.

The scrub covers the shared command constructors. The ad-hoc
`Command::cargo_bin("pnpm")` sites scattered through the suites still inherit
the ambient environment; closing those needs either a sweep of every call
site or a process-wide scrub, which would mean a new dependency and `unsafe`.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
    Rust test harness only — no TypeScript counterpart exists.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
    Not needed: test-harness only, no published behaviour changes.
  • Added or updated tests.
  • Updated the documentation if needed.

Verification

  • Reproduced the CI failure locally by exporting PNPM_CONFIG_GLOBAL_SHIMS={"node":false}; with the fix, global, with and package_manager_check are 323/323 (including the 4 that fail on main).
  • Full pacquet-cli suite: 1413/1413 passed.
  • Confirmed the 4 package_manager_check failures 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, and taplo all clean (the full pre-push gate).

Written by an agent (Claude Code, claude-opus-5).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes

    • Improved command-line test reliability by preventing inherited pnpm and npm configuration from affecting test execution.
    • Ensured global commands and package manager checks run in isolated environments.
    • Preserved required environment settings while bypassing unintended shim and configuration behavior.
  • Tests

    • Added coverage for configuration-variable detection, including case-insensitive names and unrelated environment variables.

zkochan and others added 2 commits August 9, 2026 21:02
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]>
Copilot AI lite review requested due to automatic review settings August 9, 2026 19:10

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Test pacquet suites with a hermetic pnpm env overlay

🐞 Bug fix 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Strip inherited PNPM/NPM config env vars when constructing test commands.
• Centralize sanitization in CommandTestExt::without_ambient_pnpm_config.
• Stabilize packageManager checks by bypassing context-aware shim dispatch for exec node.
Diagram

graph TD
A["Test suites"] --> B(["Command constructors"]) --> C{"Strip ambient\npnpm/npm config"} --> D["Spawn pnpm subprocess"]
E[("Ambient process env")] --> C
B --> F["Explicit per-test env"] --> D
subgraph Legend
direction LR
_1["Test/module"] ~~~ _2(["Builder/helper"]) ~~~ _3{"Decision/filter"} ~~~ _4[("Environment")]
end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use `env_clear()` and rebuild a minimal environment
  • ➕ Maximally hermetic; removes all ambient influence (not just pnpm/npm config).
  • ➕ Avoids missing newly-introduced config env variables in the future.
  • ➖ High maintenance: must reintroduce platform-specific essentials (PATH, HOME, TMPDIR, etc.).
  • ➖ Risk of breaking tests that intentionally rely on ambient tool discovery (e.g., compatibility checks).
2. Sanitize environment once at test harness entry (global test setup)
  • ➕ Single place to enforce hermeticity across all suites.
  • ➕ Reduces the chance of missing a command construction site.
  • ➖ Harder to scope/override per test; global changes can surprise suites that expect inheritance.
  • ➖ Rust test execution is parallel; global env mutation can be racy and non-deterministic.
3. Only strip specific known-bad variables (hand-maintained allow/deny lists per suite)
  • ➕ Very targeted; minimal behavior changes.
  • ➕ Easy to justify per failing test.
  • ➖ Does not scale; new PNPM_CONFIG_/npm_config vars can reintroduce flakes.
  • ➖ Duplicates logic across suites and increases drift.

Recommendation: Keep the PR’s approach: sanitize inherited PNPM/NPM config at Command construction time via a shared helper. It is narrowly scoped (targets only pnpm/npm config overlays + shim-bypass), avoids racy global env mutation, and preserves the ability for tests to deliberately set config via a later explicit env call.

Files changed (9) +117 / -28

Bug fix (1) +12 / -18
package_manager_check.rsBypass shim dispatcher for 'exec node' in packageManager checks +12/-18

Bypass shim dispatcher for 'exec node' in packageManager checks

• Sets 'PNPM_SHIM_BYPASS=1' so 'exec node' doesn’t route through context-aware shims that honor unsatisfiable runtime pins in fixtures. Removes the now-duplicated manual removal list for pnpm/npm config vars, leaving only COREPACK_ROOT clearing when not explicitly set.

pnpm/crates/cli/tests/suite/package_manager_check.rs

Tests (8) +105 / -10
mod.rsSanitize pacquet test command construction +5/-1

Sanitize pacquet test command construction

• Applies 'without_ambient_pnpm_config()' to the shared 'pacquet_in()' helper so suite-spawned pnpm processes don’t inherit PNPM_CONFIG_/npm_config overlays from CI or user shells.

pnpm/crates/cli/tests/suite/_utils/mod.rs

global.rsStrip ambient pnpm config from global suite commands +2/-1

Strip ambient pnpm config from global suite commands

• Adds the command env sanitization step to 'global_command()' after setting PNPM_HOME and PATH, ensuring global-install tests aren’t reconfigured by inherited pnpm/npm env variables.

pnpm/crates/cli/tests/suite/global.rs

global_shims.rsMake global shims suite hermetic to PNPM_CONFIG_* +2/-0

Make global shims suite hermetic to PNPM_CONFIG_*

• Ensures the shim test command is constructed with inherited pnpm/npm config variables removed, preventing CI-provided PNPM_CONFIG_GLOBAL_SHIMS from flipping expected shim behavior.

pnpm/crates/cli/tests/suite/global_shims.rs

with.rsCentralize env stripping in 'with' suite test commands +6/-4

Centralize env stripping in 'with' suite test commands

• Refactors 'test_command' to apply 'without_ambient_pnpm_config()' up front and drops ad-hoc env_remove calls for specific pnpm settings, keeping per-test env overrides intact.

pnpm/crates/cli/tests/suite/with.rs

bin.rsApply pnpm env sanitization in 'CommandTempCwd::init' +6/-4

Apply pnpm env sanitization in 'CommandTempCwd::init'

• Ensures both the cargo-built 'pnpm' and the ambient 'pnpm' commands created by 'CommandTempCwd' start from a sanitized inherited environment, making hermeticity the default for suite command setup.

pnpm/crates/testing-utils/src/bin.rs

command_env.rsAdd 'CommandTestExt' to strip ambient pnpm/npm config env +58/-0

Add 'CommandTestExt' to strip ambient pnpm/npm config env

• Introduces a test-only 'Command' extension trait that removes inherited 'PNPM_CONFIG_*'/'pnpm_config_*', 'NPM_CONFIG_*'/'npm_config_*', and 'PNPM_SHIM_BYPASS' variables at construction time while still allowing later explicit env overrides.

pnpm/crates/testing-utils/src/command_env.rs

tests.rsUnit-test pnpm/npm config env variable detection +25/-0

Unit-test pnpm/npm config env variable detection

• Adds coverage for case-insensitive matching of pnpm/npm config prefixes and ensures critical variables like PNPM_HOME and bare prefixes are not stripped.

pnpm/crates/testing-utils/src/command_env/tests.rs

lib.rsExport 'command_env' module from testing utils +1/-0

Export 'command_env' module from testing utils

• Makes the new command environment helper available to the test suites by exporting the module.

pnpm/crates/testing-utils/src/lib.rs

@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: beba5ff4-4540-4a35-b873-3abfe07c18bb

📥 Commits

Reviewing files that changed from the base of the PR and between 6affe14 and c3d4da7.

📒 Files selected for processing (2)
  • pnpm/crates/testing-utils/src/command_env.rs
  • pnpm/crates/testing-utils/src/command_env/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm/crates/testing-utils/src/command_env.rs

📝 Walkthrough

Walkthrough

The testing utilities add CommandTestExt::without_ambient_pnpm_config(). The method removes inherited pnpm/npm configuration and PNPM_SHIM_BYPASS while preserving PNPM_HOME. CLI test helpers use it, and package-manager checks control PNPM_SHIM_BYPASS and COREPACK_ROOT.

Changes

Ambient test environment isolation

Layer / File(s) Summary
Environment cleanup utility
pnpm/crates/testing-utils/src/command_env.rs, pnpm/crates/testing-utils/src/command_env/tests.rs, pnpm/crates/testing-utils/src/lib.rs
Adds and exports CommandTestExt. The command extension removes matching pnpm/npm configuration variables and PNPM_SHIM_BYPASS, while preserving PNPM_HOME. Tests cover case-insensitive matching and excluded names.
Shared test command migration
pnpm/crates/testing-utils/src/bin.rs, pnpm/crates/cli/tests/suite/_utils/mod.rs, pnpm/crates/cli/tests/suite/global.rs, pnpm/crates/cli/tests/suite/global_shims.rs, pnpm/crates/cli/tests/suite/with.rs
Applies without_ambient_pnpm_config() to shared, global, shim, and with test commands.
Package-manager command controls
pnpm/crates/cli/tests/suite/package_manager_check.rs
Sets PNPM_SHIM_BYPASS for test commands and conditionally removes inherited COREPACK_ROOT. Manual pnpm/npm configuration removal is removed.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • pnpm/pnpm#13287: Both changes modify CLI test command environments, including COREPACK_ROOT, PNPM_SHIM_BYPASS, and ambient configuration.
  • pnpm/pnpm#13731: Both changes modify CLI test helpers and PNPM_SHIM_BYPASS handling.
  • pnpm/pnpm#12813: Both changes control which ambient pnpm/npm configuration variables affect command execution.

Suggested labels: product: pacquet

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hermetic-test-env

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The 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

@qodo-code-review

qodo-code-review Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Comment references slice alternative 📘 Rule violation ⚙ Maintainability ⭐ New
Description
A newly added test-related comment explains behavior by contrasting with a hypothetical slice
approach (e.g., “get, not a slice” / “a slice would panic”) rather than describing the current
behavior and rationale directly. This violates the comment policy against historical/alternative
implementation framing and can become misleading or less future-proof if the implementation changes.
Code

pnpm/crates/testing-utils/src/command_env.rs[R53-56]

+            // `get`, not a slice: the environment is outside this process's
+            // control, and a name whose prefix-length byte falls inside a
+            // multi-byte character would panic every command construction.
+            name.len() > prefix.len()
Relevance

●●● Strong

Similar comment rewrites (avoid hypothetical/old implementation framing) were accepted repeatedly in
this repo.

PR-#13572
PR-#13652
PR-#13727

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Rule 772199 requires comments to describe the current behavior and constraints rather than
referencing past or alternative implementations. In the cited locations, the added comments
explicitly compare the current logic to a hypothetical slice implementation (including mentioning
that a slice would panic and that the code uses get instead), which is commentary about an
alternative approach/failure mode instead of directly stating the present invariant/guarantee being
tested or relied upon.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/testing-utils/src/command_env.rs[53-56]
pnpm/crates/testing-utils/src/command_env/tests.rs[24-26]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Comments were added that explain the code/tests by contrasting with a hypothetical `slice`-based alternative (e.g., “get, not a slice” / “a slice would panic”), but policy requires comments to describe current behavior, guarantees, and constraints directly rather than referencing alternative or historical implementations.

## Issue Context
One comment in `is_pnpm_config_var` was added to justify using `str::get(..)` to avoid panics on invalid UTF-8 boundaries in attacker-controlled environment variable names. Another comment in the tests is meant to explain why a multi-byte character edge case is included in test inputs, but it does so by referring to how a `slice` implementation would behave.

## Fix Focus Areas
- pnpm/crates/testing-utils/src/command_env.rs[53-56]
- pnpm/crates/testing-utils/src/command_env/tests.rs[24-26]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Env-name slice can panic ✓ Resolved 🐞 Bug ☼ Reliability
Description
is_pnpm_config_var slices name[..prefix.len()] on arbitrary UTF-8 env var names, which panics
when prefix.len() is not a UTF-8 character boundary. A single such ambient environment variable
can crash the test process when constructing commands via without_ambient_pnpm_config.
Code

pnpm/crates/testing-utils/src/command_env.rs[R51-54]

+    name.eq_ignore_ascii_case(SHIM_BYPASS)
+        || PREFIXES.iter().any(|prefix| {
+            name.len() > prefix.len() && name[..prefix.len()].eq_ignore_ascii_case(prefix)
+        })
Relevance

●●● Strong

Team often accepts hardening changes preventing panics/DoS from malformed input; this is a
deterministic panic fix.

PR-#13202
PR-#13686

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The helper enumerates ambient environment variable names and passes them to is_pnpm_config_var,
which performs unchecked slicing by a byte length; this can panic when the index is not a UTF-8
boundary.

pnpm/crates/testing-utils/src/command_env.rs[37-41]
pnpm/crates/testing-utils/src/command_env.rs[47-55]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`is_pnpm_config_var` uses `name[..prefix.len()]` to compare prefixes. This can panic for valid UTF-8 env var names where `prefix.len()` lands mid-codepoint.

### Issue Context
The env var names come from `std::env::vars_os()` and are filtered via `to_str()`, so they may contain non-ASCII Unicode. Rust string slicing requires indices to be on UTF-8 character boundaries.

### Fix
Replace the direct slice with a boundary-checked prefix extraction, e.g.:
- `name.get(..prefix.len()).is_some_and(|head| head.eq_ignore_ascii_case(prefix))`
- keep the existing `name.len() > prefix.len()` check to avoid matching bare prefixes.

Optionally add a regression unit test using a valid UTF-8 name whose prefix-length offset is not a char boundary.

### Fix Focus Areas
- pnpm/crates/testing-utils/src/command_env.rs[47-55]
- pnpm/crates/testing-utils/src/command_env/tests.rs[1-25]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context used
✅ Compliance rules (platform): 26 rules

Grey Divider

Tip of the day
💡 Did you know, you can ask Qodo to dismiss a finding you disagree with, with your reason on record

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous review results

Review updated until commit c3d4da7

Results up to commit 6affe14 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. Env-name slice can panic ✓ Resolved 🐞 Bug ☼ Reliability
Description
is_pnpm_config_var slices name[..prefix.len()] on arbitrary UTF-8 env var names, which panics
when prefix.len() is not a UTF-8 character boundary. A single such ambient environment variable
can crash the test process when constructing commands via without_ambient_pnpm_config.
Code

pnpm/crates/testing-utils/src/command_env.rs[R51-54]

+    name.eq_ignore_ascii_case(SHIM_BYPASS)
+        || PREFIXES.iter().any(|prefix| {
+            name.len() > prefix.len() && name[..prefix.len()].eq_ignore_ascii_case(prefix)
+        })
Relevance

●●● Strong

Team often accepts hardening changes preventing panics/DoS from malformed input; this is a
deterministic panic fix.

PR-#13202
PR-#13686

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The helper enumerates ambient environment variable names and passes them to is_pnpm_config_var,
which performs unchecked slicing by a byte length; this can panic when the index is not a UTF-8
boundary.

pnpm/crates/testing-utils/src/command_env.rs[37-41]
pnpm/crates/testing-utils/src/command_env.rs[47-55]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`is_pnpm_config_var` uses `name[..prefix.len()]` to compare prefixes. This can panic for valid UTF-8 env var names where `prefix.len()` lands mid-codepoint.

### Issue Context
The env var names come from `std::env::vars_os()` and are filtered via `to_str()`, so they may contain non-ASCII Unicode. Rust string slicing requires indices to be on UTF-8 character boundaries.

### Fix
Replace the direct slice with a boundary-checked prefix extraction, e.g.:
- `name.get(..prefix.len()).is_some_and(|head| head.eq_ignore_ascii_case(prefix))`
- keep the existing `name.len() > prefix.len()` check to avoid matching bare prefixes.

Optionally add a regression unit test using a valid UTF-8 name whose prefix-length offset is not a char boundary.

### Fix Focus Areas
- pnpm/crates/testing-utils/src/command_env.rs[47-55]
- pnpm/crates/testing-utils/src/command_env/tests.rs[1-25]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@coderabbitai coderabbitai Bot left a comment

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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8adb97e and 6affe14.

📒 Files selected for processing (9)
  • pnpm/crates/cli/tests/suite/_utils/mod.rs
  • pnpm/crates/cli/tests/suite/global.rs
  • pnpm/crates/cli/tests/suite/global_shims.rs
  • pnpm/crates/cli/tests/suite/package_manager_check.rs
  • pnpm/crates/cli/tests/suite/with.rs
  • pnpm/crates/testing-utils/src/bin.rs
  • pnpm/crates/testing-utils/src/command_env.rs
  • pnpm/crates/testing-utils/src/command_env/tests.rs
  • pnpm/crates/testing-utils/src/lib.rs

@github-actions

github-actions Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     11.8±0.06ms    31.7 MB/sec    1.00     11.8±0.04ms    31.7 MB/sec
packument/parse                                  1.00     38.5±0.05µs  1724.2 MB/sec    1.02     39.1±0.12µs  1696.5 MB/sec
tarball/download_dependency                      1.00      2.3±0.05ms  1909.6 KB/sec    1.04      2.4±0.07ms  1829.0 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.00    172.7±1.21ms 92.6 KElem/sec    1.00    173.2±1.43ms 92.4 KElem/sec
workspace_resolution/hoist_heavy                 1.05    244.4±0.73ms        ? ?/sec    1.00    232.8±0.58ms        ? ?/sec

@codecov-commenter

codecov-commenter commented Aug 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.11%. Comparing base (8adb97e) to head (c3d4da7).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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]>
Copilot AI review requested due to automatic review settings August 9, 2026 19:24

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit c3d4da7

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Aug 9, 2026
@zkochan
zkochan merged commit 7ddb297 into main Aug 9, 2026
39 checks passed
@zkochan
zkochan deleted the hermetic-test-env branch August 9, 2026 19:30
KSXGitHub pushed a commit that referenced this pull request Aug 17, 2026
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::`.
@qodo-code-review qodo-code-review Bot mentioned this pull request Oct 11, 2026
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants