Repository navigation
fix(package-manager): don't wipe node_modules on an included-deps change - #12676
Conversation
|
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 (2)
📝 WalkthroughWalkthroughThe installer now treats ChangesModules layout drift handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing Touches🧪 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 |
PR Summary by QodoPrevent node_modules purge when only included dependency set changes Description
Diagram
High-Level Assessment
Files changed (2)
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@pacquet/crates/package-manager/src/install/tests.rs`:
- Around line 5924-6006: The current tests only exercise the helper checks and
do not cover the real purge path in Install::run_inner, so add an install-level
regression that seeds a custom non-pnpm entry in node_modules, changes included
via the same setup used by
is_modules_yaml_consistent/is_modules_yaml_layout_consistent, runs the install
flow, and asserts the entry survives when only included drifts. Keep the
layout-drift case using Install::run_inner or the install path to confirm
genuine nodeLinker drift still triggers the destructive wipe. Use the existing
symbols Install::run_inner, is_modules_yaml_consistent, and
is_modules_yaml_layout_consistent to locate the relevant setup.
🪄 Autofix (Beta)
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: a732afd2-fecc-4236-a15e-eb9d796d207a
📒 Files selected for processing (2)
pacquet/crates/package-manager/src/install.rspacquet/crates/package-manager/src/install/tests.rs
Code Review by Qodo
1. TOCTOU .bin delete escape
|
|
Code review by qodo was updated up to the latest commit bcc5b3a |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12676 +/- ##
==========================================
- Coverage 85.62% 85.02% -0.60%
==========================================
Files 413 415 +2
Lines 64343 65395 +1052
==========================================
+ Hits 55093 55602 +509
- Misses 9250 9793 +543 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Integrated-Benchmark Report (Linux)Commit: Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.1181952479,
"stddev": 0.17554946713391562,
"median": 4.0441736184,
"user": 3.91673118,
"system": 3.54157746,
"min": 3.9532051209000003,
"max": 4.3856812069,
"times": [
4.3182766659,
4.3856812069,
3.9775572389000002,
4.3798633899,
4.121589809900001,
3.9532051209000003,
4.0579335439,
3.9737840279000003,
3.9836477819000002,
4.0304136929
]
},
{
"command": "pacquet@main",
"mean": 4.0346684328,
"stddev": 0.1242958481146948,
"median": 3.9850285009,
"user": 3.8562378799999997,
"system": 3.5181251599999994,
"min": 3.9280498619,
"max": 4.3534200589,
"times": [
4.3534200589,
4.1059499849000005,
3.9743273559000003,
3.9881122879,
3.9798638749000004,
3.9280498619,
4.0552242419,
4.0397477769000005,
3.9400441709000003,
3.9819447139
]
},
{
"command": "pnpr@HEAD",
"mean": 2.0646891602,
"stddev": 0.09617322723595541,
"median": 2.0343385344,
"user": 2.62009878,
"system": 3.0538826599999997,
"min": 1.9516272809,
"max": 2.2739522529,
"times": [
2.0411648519,
2.0198556409,
1.9998647448999998,
1.9516272809,
2.1838500769,
2.0791375109000003,
2.0275122169,
2.2739522529,
2.0692162619000003,
2.0007107639
]
},
{
"command": "pnpr@main",
"mean": 2.1241352767,
"stddev": 0.10801556627644346,
"median": 2.0964134019000005,
"user": 2.62192428,
"system": 3.03580096,
"min": 1.9703110519,
"max": 2.3076403009,
"times": [
2.0186664579,
2.3076403009,
2.0703063619,
2.0754207309000003,
1.9703110519,
2.2761389529000002,
2.1249135279,
2.0903593429000003,
2.2051285789,
2.1024674609000003
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.63561099018,
"stddev": 0.0071163489244726996,
"median": 0.6346870976800001,
"user": 0.37493010000000004,
"system": 1.3247316199999999,
"min": 0.62712164368,
"max": 0.6505872606800001,
"times": [
0.63116674968,
0.63423570568,
0.6505872606800001,
0.63470961668,
0.6349454906800001,
0.63466457868,
0.63668741068,
0.64418643868,
0.62712164368,
0.62780500668
]
},
{
"command": "pacquet@main",
"mean": 0.67069659578,
"stddev": 0.07234256698860606,
"median": 0.64885582318,
"user": 0.3985999,
"system": 1.3312666199999998,
"min": 0.63187691968,
"max": 0.87272051968,
"times": [
0.63570241268,
0.67266366268,
0.6551979436800001,
0.63352651868,
0.65256882468,
0.64006519968,
0.66750113468,
0.63187691968,
0.64514282168,
0.87272051968
]
},
{
"command": "pnpr@HEAD",
"mean": 0.71896429468,
"stddev": 0.08196332609886878,
"median": 0.6910226766800001,
"user": 0.3942464,
"system": 1.37153942,
"min": 0.68459413368,
"max": 0.95119494768,
"times": [
0.70823567068,
0.6878874646800001,
0.68683773468,
0.68745069368,
0.69250517368,
0.70296315968,
0.68954017968,
0.68459413368,
0.95119494768,
0.6984337886800001
]
},
{
"command": "pnpr@main",
"mean": 0.71953634418,
"stddev": 0.050652151796588815,
"median": 0.70424162968,
"user": 0.4064685,
"system": 1.3649192200000002,
"min": 0.67304191868,
"max": 0.8419502506800001,
"times": [
0.72256162568,
0.67304191868,
0.68730034968,
0.70355046668,
0.70493279268,
0.71324309468,
0.69960690768,
0.8419502506800001,
0.76896660668,
0.68020942868
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.22755747356,
"stddev": 0.022508739744230826,
"median": 4.224261934559999,
"user": 3.7397687999999993,
"system": 3.40186954,
"min": 4.18671265356,
"max": 4.25829102256,
"times": [
4.18671265356,
4.22563658856,
4.21347376456,
4.25829102256,
4.24037752856,
4.22288728056,
4.20913574056,
4.25512759256,
4.217468215559999,
4.24646434856
]
},
{
"command": "pacquet@main",
"mean": 4.263647302259999,
"stddev": 0.041719831248167444,
"median": 4.26551199106,
"user": 3.8121061999999997,
"system": 3.4236671400000005,
"min": 4.21094059856,
"max": 4.34224319756,
"times": [
4.27647825256,
4.34224319756,
4.231575343559999,
4.22209369456,
4.21094059856,
4.29039872256,
4.25493662756,
4.22821932156,
4.2760873545599996,
4.30349990956
]
},
{
"command": "pnpr@HEAD",
"mean": 2.21716240856,
"stddev": 0.1232367148520933,
"median": 2.21607345856,
"user": 2.4573305,
"system": 2.9415990400000003,
"min": 2.04849995956,
"max": 2.39226317456,
"times": [
2.32397301456,
2.0919196635599997,
2.04849995956,
2.35233744656,
2.14568224856,
2.29454985856,
2.0902518025599996,
2.16604923856,
2.39226317456,
2.26609767856
]
},
{
"command": "pnpr@main",
"mean": 2.2329265885599994,
"stddev": 0.16396244791217657,
"median": 2.24326615956,
"user": 2.492037,
"system": 2.91819954,
"min": 1.96756291256,
"max": 2.42071899356,
"times": [
2.15235256056,
2.2536969715599997,
2.23283534756,
2.40404818256,
1.96756291256,
2.14361943056,
2.42071899356,
2.39000901056,
2.0057624485599996,
2.35866002756
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.3547703405799998,
"stddev": 0.0192336931704276,
"median": 1.34787732268,
"user": 1.32319626,
"system": 1.70669234,
"min": 1.33229816768,
"max": 1.38602790368,
"times": [
1.3526427566800001,
1.36415319468,
1.38602790368,
1.36348684668,
1.3409388766800001,
1.33229816768,
1.34311188868,
1.33733742168,
1.34284475468,
1.38486159468
]
},
{
"command": "pacquet@main",
"mean": 1.3787542700800002,
"stddev": 0.03913160439435337,
"median": 1.36536158668,
"user": 1.38393546,
"system": 1.7099556399999998,
"min": 1.3481739076800001,
"max": 1.48061887768,
"times": [
1.36302389168,
1.36569496868,
1.48061887768,
1.3481739076800001,
1.36502820468,
1.38684760368,
1.39872768268,
1.35557809768,
1.37408099568,
1.3497684706800002
]
},
{
"command": "pnpr@HEAD",
"mean": 0.6668551368800001,
"stddev": 0.03434203949927823,
"median": 0.65523357768,
"user": 0.33383456,
"system": 1.3028117399999999,
"min": 0.6441516276800001,
"max": 0.7614133576800001,
"times": [
0.65138603368,
0.65383776268,
0.6566293926800001,
0.65087065468,
0.64886259568,
0.7614133576800001,
0.6720282186800001,
0.66088085768,
0.6684908676800001,
0.6441516276800001
]
},
{
"command": "pnpr@main",
"mean": 0.6814904785800001,
"stddev": 0.07553231568459584,
"median": 0.6548077481800001,
"user": 0.34742185999999997,
"system": 1.2886436399999996,
"min": 0.6456404706800001,
"max": 0.89400475168,
"times": [
0.67152331068,
0.64805459968,
0.6580564666800001,
0.6473160036800001,
0.65155902968,
0.65051155768,
0.6739904466800001,
0.6456404706800001,
0.89400475168,
0.67424814868
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.01137995126,
"stddev": 0.04728046700522441,
"median": 2.99928337646,
"user": 1.7908327200000003,
"system": 1.96969282,
"min": 2.96118971496,
"max": 3.12197788696,
"times": [
2.99885916596,
2.98364621096,
2.9811111709600002,
2.99970758696,
3.00221643296,
3.06334320596,
2.96118971496,
3.01474398596,
3.12197788696,
2.98700415096
]
},
{
"command": "pacquet@main",
"mean": 3.0364087309599994,
"stddev": 0.055644027502695634,
"median": 3.03247282296,
"user": 1.8308645199999998,
"system": 1.9789139199999997,
"min": 2.97453653896,
"max": 3.16683499296,
"times": [
3.03459894996,
3.05144540196,
3.06757547996,
3.04270342396,
2.98984809396,
3.02920480996,
2.97699292196,
2.97453653896,
3.16683499296,
3.03034669596
]
},
{
"command": "pnpr@HEAD",
"mean": 0.6712957873600002,
"stddev": 0.011940258684582785,
"median": 0.66533014146,
"user": 0.34186651999999995,
"system": 1.31587282,
"min": 0.65869593796,
"max": 0.69195129396,
"times": [
0.69195129396,
0.67944859596,
0.66515173196,
0.65951614596,
0.66291050296,
0.67668484896,
0.6655085509600001,
0.66499554696,
0.65869593796,
0.68809471796
]
},
{
"command": "pnpr@main",
"mean": 0.68972861706,
"stddev": 0.014363594023492129,
"median": 0.69164662796,
"user": 0.35033262,
"system": 1.31392602,
"min": 0.6632422999600001,
"max": 0.71186221096,
"times": [
0.67700165696,
0.69430906996,
0.6632422999600001,
0.69545645696,
0.69681163196,
0.68435116396,
0.67934633796,
0.71186221096,
0.70592115596,
0.68898418596
]
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 7.0167554890999995,
"stddev": 0.16221333262712798,
"median": 6.969743558799999,
"user": 4.146090620000001,
"system": 3.8462867599999995,
"min": 6.8398191843,
"max": 7.2773878103,
"times": [
6.8816641043,
6.8398191843,
7.2334893163,
6.9779238963,
7.1894510533,
6.8869903753,
7.0451221553,
7.2773878103,
6.8741437743,
6.9615632213
]
},
{
"command": "pacquet@main",
"mean": 7.0261142854,
"stddev": 0.22063112844978558,
"median": 6.9652964768,
"user": 4.16734912,
"system": 3.8644747600000002,
"min": 6.7892872353,
"max": 7.4192826583,
"times": [
7.2892137323,
6.9335556733,
6.9614794653,
7.4192826583,
7.2233186173,
6.9691134883,
6.7932683903,
7.0730873303,
6.7892872353,
6.8095362633
]
},
{
"command": "pnpr@HEAD",
"mean": 5.020113191399999,
"stddev": 0.08817229272078031,
"median": 5.0159396158,
"user": 2.75456772,
"system": 3.29600286,
"min": 4.8905668613,
"max": 5.1317468413,
"times": [
4.9047811613,
5.0317546903,
5.1317468413,
4.9964541943,
5.0928972563,
4.8905668613,
4.9408685563,
5.1080807503,
5.0001245413,
5.1038570613
]
},
{
"command": "pnpr@main",
"mean": 5.0535513386,
"stddev": 0.15370980480514487,
"median": 5.059137103299999,
"user": 2.75164022,
"system": 3.3052125599999997,
"min": 4.8337583133,
"max": 5.3583920723,
"times": [
4.9238206383,
4.9282368533,
4.8337583133,
5.3583920723,
5.0727181813,
4.9832436453,
5.0700810333,
5.0481931733,
5.0836541443,
5.2334153313
]
}
]
} |
|
| Branch | pr/12676 |
| Testbed | pnpr |
⚠️ WARNING: No Threshold found!Without a Threshold, no Alerts will ever be generated.
Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the--ci-only-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 2,217.16 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 671.30 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 666.86 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 2,064.69 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 5,020.11 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 718.96 ms |
|
Code review by qodo was updated up to the latest commit 3cf61e6 |
|
Code review by qodo was updated up to the latest commit 3cf61e6 |
3cf61e6 to
8f188f0
Compare
|
Code review by qodo was updated up to the latest commit 8f188f0 |
1 similar comment
|
Code review by qodo was updated up to the latest commit 8f188f0 |
|
Code review by qodo was updated up to the latest commit 2f7e816 |
1 similar comment
|
Code review by qodo was updated up to the latest commit 2f7e816 |
2f7e816 to
9c07355
Compare
|
Code review by qodo was updated up to the latest commit 9c07355 |
|
Code review by qodo was updated up to the latest commit 9c07355 |
When `.modules.yaml` recorded a different `included` set than the current install wants — e.g. switching `pnpm install --prod` <-> a full install, or toggling `--no-optional` — `modules_consistent_with` reported the directory inconsistent, which drove the purge that empties `node_modules` of everything except pnpm's own and dotfile entries. A user's non-pnpm contents (a vendored directory, stray files placed in `node_modules`) were deleted silently on that routine flag change. pnpm never purges the root project's node_modules for an included mismatch: its `validateModules` only treats included drift as purge-worthy for non-root importers (the `lockfileDir !== rootDir` guard), and an included change is otherwise satisfied by relinking. Split the consistency check: the purge gate now uses `modules_layout_consistent_with`, which compares every layout-determining setting *except* `included`. The up-to-date fast path keeps using `modules_consistent_with` (which still compares `included`), so a `--prod`<->full switch still forces a reinstall — the relink (`filter_lockfile_for_current` + the removed-alias pruning in `create_virtual_store`) adds or removes the right dependencies without destroying the directory. pnpm already behaves this way, so no TypeScript-side change is needed. Co-authored-by: Claude <[email protected]>
…guard Addresses the review on this PR: the helper-level checks proved the `modules_consistent_with` / `modules_layout_consistent_with` split but never drove the real purge path in `Install::run`. Add an install-level regression that runs a full install, drops a user's own non-pnpm file into node_modules, then re-installs with `--prod` (an included drift) and asserts the file survives — and finally re-installs with a drifted virtual-store-dir-max-length (a real layout change) and asserts the file is wiped. Without the split, step two would purge the directory and the assertion would fail. Co-authored-by: Claude <[email protected]>
pacquet-cli stale_pin_dedupe::refreshes_stale_transitive_pin_to_higher_direct_dep_version is a deterministic mock-registry test (passed 13/13 locally and on macOS/Windows CI). It only flaked under ubuntu's parallel nextest load, so this empty commit re-triggers CI. Co-authored-by: Claude <[email protected]>
9c07355 to
609eafe
Compare
|
Code review by qodo was updated up to the latest commit 609eafe |
1 similar comment
|
Code review by qodo was updated up to the latest commit 609eafe |
… included drift With the purge gate keyed off layout drift only, an included change (pnpm install --prod <-> full, --no-optional) no longer wipes node_modules — but nothing removed the direct-dep links the previous install created for the now-excluded groups, so dev deps (and their .bin shims) stayed resolvable after a production-mode reinstall. Add a targeted prune that runs exactly when the purge is skipped for an included drift: diff each importer's direct-dep names between the old and new group selections using the current lockfile, remove the excluded links and their bin shims, and leave everything else alone. Mirrors pnpm's removeDirectDependency prune. Removal is conservative: importer keys are validated, aliases go through safe_join_modules_dir, only symlinks/junctions are removed (a user's real file or directory is never touched; hoisted-linker real dirs are left to its own orphan diff), and bin names come from the same sanitized set the shim writer uses. Also wire the purge-regression test helper's http_client and http_client_arc from a single ThrottledClient, and move the test project's manifest inside the project root so the fresh and frozen install paths anchor importer symlinks in the same directory, as they do in production. Addresses the review findings on pnpm#12676.
|
All three Qodo findings are addressed in 8acfc55:
Verified with the full Written by an agent (Claude Code, claude-fable-5). |
|
Code review by qodo was updated up to the latest commit 8acfc55 |
|
Code review by qodo was updated up to the latest commit 8acfc55 |
…ce root The prune deleted through paths joined from the on-disk layout without the canonical containment check the purge applies, so a symlinked node_modules resolving outside the workspace — or a symlinked `.bin/` or `@scope/` intermediate — could redirect the removals at external files. Canonicalize each importer's modules dir and require it to stay within the canonical workspace root before any removal (operating on the canonical path closes the check-to-use gap), and skip removals that would reach through a `.bin/` or `@scope/` component that is not a real directory (junction-aware via read_symlink_dir). Addresses the follow-up review finding on pnpm#12676.
|
Code review by qodo was updated up to the latest commit bd0691d |
|
Code review by qodo was updated up to the latest commit bd0691d |
Summary
When
.modules.yamlrecorded a differentincludeddependency set thanthe current install wants — switching
pnpm install --prod<-> a fullinstall, or toggling
--no-optional—modules_consistent_withreportednode_modulesinconsistent, which drives the purge that empties thedirectory of everything except pnpm's own and dotfile entries. A user's
non-pnpm contents (a vendored directory, stray files placed directly in
node_modules) were deleted silently on that routine flag change.pnpm never purges the root project's
node_modulesfor an includedmismatch: its
validateModulesonly treats included drift as purge-worthy for non-root importers (the
lockfileDir !== rootDirguard), and an included change is satisfied byrelinking plus a targeted prune of the removed deps — not by wiping the
directory.
This splits the consistency check and adds the targeted prune:
modules_layout_consistent_with, whichcompares every layout-determining setting except
included.modules_consistent_with(which still compares
included), so a--prod<->full switch stillforces a reinstall.
prune_direct_deps_excluded_by_groupspass runs exactly whenthe purge is skipped for an included drift: it diffs each importer's
direct-dep names between the old and new group selections (via the
current lockfile) and removes the now-excluded links and their
.binshims — mirroring pnpm'sremoveDirectDependencyprune. Soexcluded dev deps do not stay resolvable after a
--prodreinstall.Removal is conservative: importer keys are validated, aliases go
through
safe_join_modules_dir, only symlinks/junctions are removed(a user's real file or directory is never touched; hoisted-linker real
directories are handled by its own orphan diff), and bin names come
from the same sanitized set the shim writer uses.
The relink that follows re-creates everything the new selection wants,
so correctness of the switch is preserved while the directory — and the
user's own contents — are left intact.
Parity
pnpm already behaves this way (
validateModules+ the modules-cleanerprune), so this is the pacquet side catching up — no TypeScript-side
change is needed. pnpm's
pnpm:root removed/stats.removedemissionsremain unported (pacquet currently emits a hardcoded
removed: 0placeholder); that slice is unchanged here.
Squash Commit Body
Checklist
Written by an agent (Claude Code, claude-opus-4-8; revised by Claude Code, claude-fable-5).