Repository navigation
Keep npm detector unit tests off the host's yarn config - #2054
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
Conversation
detect_npm_pkg_manager reads YARN_NODE_LINKER, YARN_RC_FILENAME and ~/.yarnrc.yml whenever a PnP loader exists. Its 13 unit tests in pkg_managers and pnpm_layout therefore failed on any machine with a global yarn nodeLinker: 13 fail with HOME/.yarnrc.yml setting nodeLinker: node-modules, 15 with YARN_NODE_LINKER=node-modules. Split out detect_npm_pkg_manager_with, which takes the nodeLinker lookup as a closure (production passes the same yarn_node_linker as before), and point the tests at a cfg(test) hermetic wrapper over YarnEnv::repository_only. YarnPnpLoader gets the same split. A new test pins that the public entry points agree with the hermetic ones when no loader exists. Refs #1919. The two npm_crawler tests that go through the full crawler and the python VIRTUAL_ENV tests are left for follow-ups. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeS6VN7YUHqXUcokkgF
|
bugbot run Generated by Claude Code |
PR SummaryLow Risk Overview Tests use New coverage confirms public vs hermetic agreement when no PnP loader exists (linker lookup not invoked), and that hermetic detection ignores rc files above the temp project root. Reviewed by Cursor Bugbot for commit 2abfc1e. Configure here. |
detect_npm_pkg_manager_hermetic used yarn_node_linker_in over YarnEnv::repository_only(), which still walks every ancestor's .yarnrc.yml. A temp dir outside a git checkout has no read boundary, so an rc file anywhere above TMPDIR (e.g. TMPDIR=$HOME/tmp with a global nodeLinker) still flipped 12 of the converted tests. The helper now reads the project's own .yarnrc.yml only; no hermetic test puts an rc file above the project. Adds a regression test for the rc-above-project case, and asserts the injected linker lookup is never called without a loader. Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeRTCXhYsyXWBxRiqTt
|
bugbot run Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 2abfc1e. Configure here.
|
Ready for review at
Generated by Claude Code |
Final review briefWhat it does. Unit tests for the npm package-manager detector no longer pick up the host's yarn setup ( Risk: low. The production paths are a straight delegation with the same closure, and the new code is Look here
Verified
Changes I made. None. Open questions (not blocking): should the follow-up for #1919 replace the Auto-merge is armed, so approving sends this straight to the merge queue. Generated by Claude Code |
Problem
CI is healthy this run. The merge queue is empty, the last 30 merge_group runs passed, main's push and nightly runs are green, and nothing is queued. So this run takes a priority-4 robustness target from #1919: unit tests that pass only because CI's environment is clean.
detect_npm_pkg_managerreadsYARN_NODE_LINKER,YARN_RC_FILENAMEand~/.yarnrc.ymlwhenever a PnP loader file exists. I reproduced the failures onorigin/main(c09cb0e):cargo test -p socket-patch-core --lib crawlers::HOMEwith.yarnrc.yml→nodeLinker: node-modulespkg_managers, 1pnpm_layout)YARN_NODE_LINKER=node-modulesnpm_crawler)A runner image or a contributor with a global yarn
nodeLinkergets red tests on a clean checkout.Root cause
The tests call the public detector, and it builds
YarnEnv::for_projectfrom the process environment and the home folder.Fix
detect_npm_pkg_manager_with(project_root, yarn_linker)and a privatelive_pnp_marker_in. The nodeLinker lookup is now passed in as a closure. In production the public functions pass the sameyarn_node_linker(scope, root)as before, so behaviour doesn't change.YarnPnpLoader::detectgets the same split (detect_with).#[cfg(test)]hermetic wrappers overYarnEnv::repository_only(). Project-local.yarnrc.ymlfiles are still read.EnvGuardplus#[serial]on purpose. Changing process env while other tests run in parallel is itself a source of flakes.public_detectors_match_the_hermetic_ones_without_a_loaderkeeps the public entry points covered by unit tests.Proof
After the change:
HOME/.yarnrc.yml: 799 passed (was 13 failed)YARN_NODE_LINKER=node-modules: 796 passed, 2 failed. Both arenpm_crawlertests that go through the full crawler; they are listed below.cargo clippy --locked -p socket-patch-core --all-features -- -D warnings(CI's clippy command) is clean, andrustfmt --checkpasses on the touched files.No tests were removed or weakened. Every changed test asserts the same thing on the same fixtures.
Left for follow-ups (#1919)
npm_crawler::global_scope_reads_a_yarn_store_configured_above_the_repositoryandtest_yarn4_pnpm_linker_relocated_store_transitive_packages_are_foundstill fail underYARN_NODE_LINKER. They go throughNpmCrawler, and fixing them needs the env threaded through the crawler.python_crawlertests that fail under an activatedVIRTUAL_ENV.Refs #1919
/code-review high (burn-down agent)
Fixed in 2abfc1e:
.yarnrc.yml. Outside a git checkout that walk has no bound, so anodeLinkerset aboveTMPDIRstill failed 15pkg_managerstests. The helper now reads only the project's own rc file, andhermetic_detector_ignores_an_rc_file_above_the_projectcovers it. With the hostile setup, 3 tests still fail. They are older tests that callyarn_node_linker_indirectly, and this PR doesn't touch them.Not fixed here, deliberately:
yarn_node_linker. That is the Crawler unit tests read the developer's real HOME, YARN_NODE_LINKER and VIRTUAL_ENV: 12 pkg_managers/pnpm_layout tests fail under a user nodeLinker setting #1919 follow-up. The better long-term fix is one test-time override inYarnEnv, not more*_hermetictwins.YarnPnpLoader::detecthard-codesReadScope::Workspace(vex.rs). That predates this PR and is unchanged..env.yarninjection. No test that uses it has an env file.Generated by Claude Code
Generated by Claude Code