Repository navigation
Commit 2aa1c7c
authored
fix(arborist): validate peerOptional conflicts in no-save mutations (#9605)
## Problem
Arborist currently treats `save=false` as a signal that invalid
`peerOptional` edges from the lockfile can be trusted and skipped. That
is correct for non-mutating lockfile reads such as `npm ci`, but it is
wrong for commands that still mutate the ideal tree and write a new
lockfile while leaving `package.json` unchanged.
For example, `npm update` runs with `save=false`, but it can still
update package versions in `package-lock.json`. If one of those updates
introduces or exposes an invalid optional peer relationship, Arborist
can finish successfully and write a lockfile that a later plain `npm
install` rejects with `ERESOLVE`.
## Fix
This separates two concepts that were previously conflated:
- `#requestedTreeMutation`: whether the command explicitly requested an
add, remove, or update operation.
- `#mutateTree`: whether the ideal-tree build has actually changed the
tree during placement.
Invalid `peerOptional` policy now uses `#requestedTreeMutation` instead
of `#mutateTree`:
- `save=false` + explicit add/rm/update: invalid `peerOptional` edges
are treated as resolver problems.
- `save=false` + no requested mutation: invalid `peerOptional` edges
remain trusted, preserving the existing `npm ci`-style behavior.
The requeue path also uses `#requestedTreeMutation`, so a `save=false`
update can reprocess an already-seen node when a later placement
invalidates one of its `peerOptional` edges.
## Behavior Changed
This fixes bad lockfile output for `save=false` commands that mutate the
dependency graph, including:
- `npm update`
- `npm install <pkg> --no-save`
- other explicit add/rm/update Arborist builds with `save=false`
Those commands should not silently produce an ideal tree or lockfile
containing invalid `peerOptional` edges that a subsequent install
rejects.
## Behavior Preserved
Non-mutating `save=false` builds continue to trust the lockfile. In
those cases, an invalid `peerOptional` edge is still ignored rather than
forcing re-resolution, preserving the behavior needed by `npm ci`-style
lockfile reads.
Fixes #9604.
## Tests
Added regression coverage for:
- `npm update`-style `save=false` mutation rejecting an invalid
`peerOptional` graph instead of writing a bad lockfile.
- `npm install <pkg> --no-save`-style mutation rejecting the same class
of invalid graph.
- `save=false` update requeueing an already-seen node when later
placement invalidates its `peerOptional` edge.
- non-mutating `save=false` builds continuing to ignore invalid
`peerOptional` problem edges.
Validated with:
```sh
git diff --check
npm exec -- tap # from workspaces/arborist
npm run lint --workspace=@npmcli/arborist
```
Co-authored-by: Dale Lakes <[email protected]>1 parent 690bf17 commit 2aa1c7c
2 files changed
Lines changed: 231 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
| |||
401 | 402 | | |
402 | 403 | | |
403 | 404 | | |
404 | | - | |
| 405 | + | |
405 | 406 | | |
406 | 407 | | |
407 | 408 | | |
408 | 409 | | |
409 | 410 | | |
| 411 | + | |
410 | 412 | | |
411 | 413 | | |
412 | 414 | | |
| |||
484 | 486 | | |
485 | 487 | | |
486 | 488 | | |
487 | | - | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
488 | 492 | | |
489 | 493 | | |
490 | 494 | | |
| |||
1176 | 1180 | | |
1177 | 1181 | | |
1178 | 1182 | | |
1179 | | - | |
1180 | | - | |
1181 | | - | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
1182 | 1193 | | |
1183 | 1194 | | |
1184 | 1195 | | |
| |||
1384 | 1395 | | |
1385 | 1396 | | |
1386 | 1397 | | |
1387 | | - | |
1388 | | - | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
1389 | 1403 | | |
1390 | 1404 | | |
1391 | | - | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
1392 | 1408 | | |
1393 | 1409 | | |
1394 | 1410 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4541 | 4541 | | |
4542 | 4542 | | |
4543 | 4543 | | |
4544 | | - | |
4545 | | - | |
4546 | | - | |
| 4544 | + | |
4547 | 4545 | | |
4548 | 4546 | | |
4549 | | - | |
4550 | | - | |
4551 | | - | |
| 4547 | + | |
| 4548 | + | |
| 4549 | + | |
| 4550 | + | |
| 4551 | + | |
| 4552 | + | |
| 4553 | + | |
| 4554 | + | |
| 4555 | + | |
| 4556 | + | |
| 4557 | + | |
| 4558 | + | |
| 4559 | + | |
| 4560 | + | |
| 4561 | + | |
| 4562 | + | |
| 4563 | + | |
| 4564 | + | |
| 4565 | + | |
| 4566 | + | |
| 4567 | + | |
| 4568 | + | |
| 4569 | + | |
| 4570 | + | |
| 4571 | + | |
| 4572 | + | |
| 4573 | + | |
| 4574 | + | |
| 4575 | + | |
| 4576 | + | |
| 4577 | + | |
| 4578 | + | |
| 4579 | + | |
| 4580 | + | |
| 4581 | + | |
| 4582 | + | |
| 4583 | + | |
| 4584 | + | |
| 4585 | + | |
| 4586 | + | |
| 4587 | + | |
| 4588 | + | |
| 4589 | + | |
| 4590 | + | |
4552 | 4591 | | |
4553 | 4592 | | |
4554 | 4593 | | |
| |||
4573 | 4612 | | |
4574 | 4613 | | |
4575 | 4614 | | |
4576 | | - | |
4577 | 4615 | | |
4578 | 4616 | | |
4579 | 4617 | | |
| |||
4586 | 4624 | | |
4587 | 4625 | | |
4588 | 4626 | | |
4589 | | - | |
4590 | | - | |
4591 | | - | |
4592 | | - | |
4593 | 4627 | | |
4594 | 4628 | | |
4595 | 4629 | | |
4596 | 4630 | | |
4597 | 4631 | | |
4598 | | - | |
| 4632 | + | |
4599 | 4633 | | |
4600 | 4634 | | |
4601 | 4635 | | |
4602 | 4636 | | |
4603 | 4637 | | |
4604 | | - | |
| 4638 | + | |
| 4639 | + | |
| 4640 | + | |
| 4641 | + | |
| 4642 | + | |
| 4643 | + | |
| 4644 | + | |
| 4645 | + | |
| 4646 | + | |
| 4647 | + | |
| 4648 | + | |
| 4649 | + | |
| 4650 | + | |
| 4651 | + | |
| 4652 | + | |
| 4653 | + | |
| 4654 | + | |
| 4655 | + | |
| 4656 | + | |
| 4657 | + | |
| 4658 | + | |
| 4659 | + | |
| 4660 | + | |
| 4661 | + | |
| 4662 | + | |
| 4663 | + | |
| 4664 | + | |
| 4665 | + | |
| 4666 | + | |
| 4667 | + | |
| 4668 | + | |
| 4669 | + | |
| 4670 | + | |
| 4671 | + | |
| 4672 | + | |
| 4673 | + | |
| 4674 | + | |
| 4675 | + | |
| 4676 | + | |
| 4677 | + | |
| 4678 | + | |
| 4679 | + | |
| 4680 | + | |
| 4681 | + | |
| 4682 | + | |
| 4683 | + | |
| 4684 | + | |
| 4685 | + | |
| 4686 | + | |
| 4687 | + | |
| 4688 | + | |
| 4689 | + | |
| 4690 | + | |
| 4691 | + | |
| 4692 | + | |
| 4693 | + | |
| 4694 | + | |
| 4695 | + | |
| 4696 | + | |
| 4697 | + | |
| 4698 | + | |
| 4699 | + | |
| 4700 | + | |
| 4701 | + | |
| 4702 | + | |
| 4703 | + | |
| 4704 | + | |
| 4705 | + | |
| 4706 | + | |
| 4707 | + | |
| 4708 | + | |
| 4709 | + | |
| 4710 | + | |
| 4711 | + | |
| 4712 | + | |
| 4713 | + | |
| 4714 | + | |
| 4715 | + | |
| 4716 | + | |
| 4717 | + | |
| 4718 | + | |
| 4719 | + | |
| 4720 | + | |
| 4721 | + | |
| 4722 | + | |
| 4723 | + | |
| 4724 | + | |
| 4725 | + | |
| 4726 | + | |
| 4727 | + | |
| 4728 | + | |
| 4729 | + | |
| 4730 | + | |
| 4731 | + | |
| 4732 | + | |
| 4733 | + | |
| 4734 | + | |
| 4735 | + | |
| 4736 | + | |
| 4737 | + | |
| 4738 | + | |
| 4739 | + | |
| 4740 | + | |
| 4741 | + | |
| 4742 | + | |
| 4743 | + | |
| 4744 | + | |
| 4745 | + | |
| 4746 | + | |
| 4747 | + | |
| 4748 | + | |
| 4749 | + | |
| 4750 | + | |
| 4751 | + | |
| 4752 | + | |
| 4753 | + | |
| 4754 | + | |
| 4755 | + | |
| 4756 | + | |
| 4757 | + | |
| 4758 | + | |
| 4759 | + | |
| 4760 | + | |
| 4761 | + | |
| 4762 | + | |
| 4763 | + | |
| 4764 | + | |
| 4765 | + | |
| 4766 | + | |
| 4767 | + | |
| 4768 | + | |
| 4769 | + | |
| 4770 | + | |
| 4771 | + | |
| 4772 | + | |
| 4773 | + | |
| 4774 | + | |
| 4775 | + | |
| 4776 | + | |
| 4777 | + | |
| 4778 | + | |
| 4779 | + | |
| 4780 | + | |
| 4781 | + | |
| 4782 | + | |
| 4783 | + | |
| 4784 | + | |
| 4785 | + | |
| 4786 | + | |
| 4787 | + | |
| 4788 | + | |
| 4789 | + | |
| 4790 | + | |
| 4791 | + | |
| 4792 | + | |
| 4793 | + | |
| 4794 | + | |
| 4795 | + | |
| 4796 | + | |
| 4797 | + | |
| 4798 | + | |
4605 | 4799 | | |
4606 | 4800 | | |
4607 | 4801 | | |
| |||
0 commit comments