Skip to content

fix(fix): follow Yarn 3 lock edges, attribute transitive changes, clean temp clones - #84

Merged
lucasbraum merged 1 commit into
mainfrom
fix/lock-subtree-before-after
Oct 12, 2026
Merged

lucasbraum merged 1 commit into
mainfrom
fix/lock-subtree-before-after

Conversation

@lucasbraum

Copy link
Copy Markdown
Collaborator

What and why

On medusajs/medusa (Yarn 3.2.1), uptide fix react @testing-library/react cmdk react-helmet-async --target 19.3.0 (0.7.4) failed after the install with "Install changed resolutions outside …'s dependency subtree". It listed 52 entries that are inside it: @radix-ui/* 1.0.0 → 1.1.x (cmdk 0.2 → 1.0), jest-*/expect/@types/jest (old deps of @testing-library/jest-dom, a planned companion), and scheduler (react-dom).

Root cause. It wasn't a one-graph scope: lockScope already took the union of the before and after closures. Yarn 2 and 3 (lockfile v4–v6) write a dependency's range without the npm: protocol their entries are keyed by (scheduler: ^0.23.2 points at "scheduler@npm:^0.23.2"). yarnGraph looked edges up as written, found nothing, and dropped every transitive edge. So the scope was just the moved packages themselves, and importer edges compared undefined to undefined, which means importer protection was off for Yarn 3 lockfiles. Yarn 4 and classic write the key as is, so they weren't affected.

Changes

  • Lock graph (Yarn Berry): an edge falls back to the npm: descriptor when the written range has no protocol. Peer declarations are no longer edges; they were never resolved before, and resolving them now would have widened scope through peers. Scope stays the union of both lockfiles' closures: removals reachable before, additions reachable after, version changes reachable in either. Anything reachable only from unmoved roots is still rejected.
  • Report: each allowed transitive change is listed under the moved package that caused it, in the PR/HTML report under Moved with the upgraded packages (collapsed), with the first two shown in the terminal. Example: cmdk 0.2.1 → 1.0.1 replaced @radix-ui/react-dialog 1.0.0 with 1.2.0.
  • Repo pins: a root resolutions / overrides / pnpm.overrides entry keyed name or **/name, which pins a moved package to something its target doesn't satisfy, stops the run right after planning. That's before the baseline and install: 33 s instead of 11 min on medusa. Pins scoped to one dependent (parent/name, parent>name, npm nested) are left alone. Uptide never rewrites them.
  • Yarn 2+ exact pin: yarn set resolution now also runs when the plan rewrote the range. Before, ^16.1.0 resolved 16.3.3 instead of the planned 16.1.0.
  • Temporary clones: removed on exit, including after a failed, unverified or interrupted run, with nothing printed. They're still kept, with the path printed, when export failed or when the clone holds the only copy of verified commits. Signals reach only the main thread, so the CLI's worker reports open clones there (watchInterruptibleClones / removeOnInterrupt). The handlers are removed as soon as the run's work returns, so a later Ctrl-C can't touch a finished or kept clone.

New public CLI flags (for the 1.0 contract)

Flag Commands Meaning
--keep-temp fix, verify keep the temporary clone after the run, even a failed or interrupted one
--debug fix, verify keep the temporary clone; on fix also one progress line per phase (--keep-temp --verbose)
--keep fix, verify previous name, still accepted, hidden from --help

New core exports: describeTransitive, MovedSubtree, TransitiveChange, removeOnInterrupt, watchInterruptibleClones; LockDiff.transitive.

How it was verified

Fixture fixtures/lockfiles/subtree-swap/ covers npm v3, pnpm v9, Yarn classic, Yarn 3 (v6) and Yarn 4 (v8). ui 1 → 2 swaps old-dep → old-leaf for new-dep → new-leaf and moves swap 1.0.0 → 1.2.0. In the control, the unmoved other's shared moves 1.0.0 → 1.1.0.

  • With the fix, all 5 managers pass with the exact attribution, and all 5 reject the control naming only shared (11 tests).
  • With only the Yarn change reverted, the three Yarn 3 cases fail and nothing else does.

Medusa's real lockfiles (before/after dumped from a run), replayed through each guard:

Guard Result
main b90acd5 rejects 52 entries (@jest/*, @radix-ui/*, scheduler, …)
this branch the only violation left is importer root@workspace:. resolutions

That remaining importer violation is medusa's own resolutions pinning @types/react / @types/react-dom to ^18.3.2 / ^18.2.25. The root's new ^19.3.0 has no lock entry because the pin overrides it.

Medusa at 146c46b0ad (no --pr; deps installed with lifecycle scripts disabled): the run stops after 33 s, before baseline and install:

error: package.json pins what this upgrade moves: resolutions["@types/react"] is ^18.3.2 (@types/react → 19.3.0); resolutions["@types/react-dom"] is ^18.2.25 (@types/react-dom → 19.3.0). The install would keep the pinned version. Update or remove those entries and run again; uptide does not rewrite them. Nothing was changed.

Experiment (local, never pushed): medusa with those two resolutions entries set to ^19.3.0. The run passes the lockfile scope guard (install of react 19.3.0 with 4 packages accepted). It then stops at the post-install version check: Requested [email protected], but packages/design-system/icons resolved 17.0.2. That's a separate, pre-existing bug, not fixed here. The check lets a widened peerDependencies range (^18.3.1 || ^19.0.0) overwrite the devDependencies range (^19.3.0) and looks up a descriptor that doesn't exist. It's queued as a follow-up.

Interrupts (real CLI, SIGINT to the node PID mid-run): without a flag, exit 130 and the runs directory is empty. With --keep-temp, exit 130 and the clone is kept. A unit test checks no signal listeners remain after a run.

Suites: pnpm lint (only the existing biome.json schema info), pnpm typecheck, core 1187 passed / 28 skipped, CLI 390 passed.

On the yarn set resolution question: in Yarn 3.2.1 it writes nothing to package.json and leaves the workspace entry in yarn.lock untouched (tested on a scratch project). upgradeInstall restores the root manifest after its temporary resolutions, and an existing test asserts no resolutions remain. So no Uptide-only resolutions reach the commit.

Checklist

  • Tests for the change (a bug fix starts with a failing test): the Yarn 3 fixture cases fail without the fix
  • pnpm lint && pnpm typecheck && pnpm test pass
  • README and docs updated if behavior changed (docs/commands/fix.md, docs/troubleshooting.md, docs/architecture.md)
  • Changeset added if a user would notice (.changeset/lock-subtree-yarn3.md, patch)
  • No new dependency, or it was agreed in an issue
  • No private code, names or paths in fixtures, tests or docs (fixture packages are synthetic; medusa is public)
  • The rules in CONTRIBUTING.md ("Rules that do not bend") still hold

🤖 Generated with Claude Code

https://claude.ai/code/session_01EmiChUUtLdjbg6mNzKqVep


Generated by Claude Code

…an temp clones

Yarn 2 and 3 (lockfile v4 to v6) write a dependency's range without the
`npm:` protocol its entry is keyed by (`scheduler: ^0.23.2` for
`"scheduler@npm:^0.23.2"`). The lock graph looked edges up as written,
found nothing, and dropped every transitive edge: the scope guard saw
only the moved packages themselves, so a new major that swaps its
dependencies (cmdk 0.2 -> 1.0, @radix-ui/* 1.0.0 -> 1.1.x) was rejected
as "outside the dependency subtree", and importer edges compared
undefined to undefined. Edges now fall back to the `npm:` descriptor;
peer declarations are no longer edges. The guard's scope was already
the union of both lockfiles' closures.

- Report: each allowed transitive change is listed under the moved
  package whose subtree accounts for it ("cmdk 0.2.1 -> 1.0.1 replaced
  @radix-ui/react-dialog 1.0.0 with 1.2.0").
- A root resolutions/overrides/pnpm.overrides entry pinning a moved
  package to a version the target does not satisfy stops the run before
  the baseline (medusa pins @types/react to ^18.3.2).
- Yarn 2+: a moved package's descriptor is pinned to the exact planned
  version also when the plan rewrote its range (^16.1.0 resolved 16.3.3).
- Temporary clones are removed on exit, after a failed or interrupted
  run too; --keep-temp (or --debug, also --verbose) keeps one, --keep is
  a hidden alias. The CLI's worker reports clones to the main thread,
  which alone receives signals.

Fixtures: fixtures/lockfiles/subtree-swap (npm, pnpm, Yarn classic,
Yarn 3, Yarn 4) with a control where an unmoved root's dependency moves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EmiChUUtLdjbg6mNzKqVep
Signed-off-by: Claude <[email protected]>
@lucasbraum
lucasbraum marked this pull request as ready for review October 12, 2026 03:21
@lucasbraum
lucasbraum merged commit 5c59257 into main Oct 12, 2026
8 checks passed
@lucasbraum
lucasbraum deleted the fix/lock-subtree-before-after branch October 12, 2026 03:21
@uptide-release uptide-release Bot mentioned this pull request Oct 12, 2026
lucasbraum added a commit that referenced this pull request Oct 12, 2026
… check (0.7.4 regression) (#85)

## What and why

A regression from #79, shipped in 0.7.4. `upgradeInstall` walked a
workspace's sections in the order `dependencies`, `devDependencies`,
`optionalDependencies`, `peerDependencies`. Take a workspace that
declares the moved package as a widened peer (`^18.3.1 || ^19.0.0`,
which #79 introduced) next to a bumped devDependency (`^19.3.0`). There,
the peer range overwrote the installable one:

- **The post-install check** looked up the peer range, which is no
lockfile descriptor. Yarn then read an old copy kept by another package,
and `fix` stopped. On medusajs/medusa (Yarn 3.2.1),
`packages/design-system/icons` gave: `Requested [email protected], but
packages/design-system/icons resolved 17.0.2; verification cannot use a
different target.`
- **npm and pnpm** installed with the peer range temporarily rewritten
to the exact version (`peerDependencies.react: "19.3.0"`).

Now only `dependencies`, `devDependencies` and `optionalDependencies`
feed the install descriptors, `yarn set resolution` and the check. Peer
ranges are validated and widened in the manifest only. A workspace that
declares the package only as a peer isn't checked, since it doesn't
install it.

Rebased onto `main` after #84 landed; one commit, signed off. The only
conflict was the Yarn Berry `set resolution` loop, which #84 had also
changed. The result keeps #84's change (rewritten ranges are pinned too)
and loops over the installed sections only.

## How it was verified

New fixture `fixtures/lockfiles/peer-widened/` for npm (v3), pnpm (v9),
Yarn 3 (lockfile v6) and Yarn 4 (v8). `packages/ui` declares `lib` as
`devDependencies: ^2.0.0` (bumped) and `peerDependencies: ^1.0.0 ||
^2.0.0` (widened), and `old-tool` keeps `[email protected]` in the lockfile. The
test runs the real `upgradeInstall` with the manager mocked to write the
after-lockfile. It asserts that the install succeeds, `lib` resolves to
the target 2.0.0, and the peer range at every install is the widened
one, never an install descriptor.

| | npm | pnpm | Yarn 3 | Yarn 4 |
|---|---|---|---|---|
| `main` (with #84) | ✗ peer installed as `2.0.0` | ✗ peer installed as
`2.0.0` | ✗ resolved 1.0.0 | ✗ resolved 1.0.0 |
| this PR | ✓ | ✓ | ✓ | ✓ |

The Yarn 3 fixtures from #84 and these, run together on the rebased
branch: `subtree-swap`, `pinning-overrides`, `peer-widened` and
`upgrade` all pass (44 tests). With `main`'s `upgrade.ts`, only the four
`peer-widened` cases fail.

On medusa, the same check passes with the dev range (`parseYarn` on
medusa's lockfile: `^19.3.0` → 19.3.0, `^18.3.1 || ^19.0.0` → 17.0.2).
This was the next stop after #84 on a local copy of medusa with its
`@types/react` resolutions pin relaxed.

`pnpm lint` (only the existing `biome.json` schema note), `pnpm build`,
`pnpm typecheck`, `pnpm test`: core 1195 passed / 28 skipped, CLI 393
passed.

## Checklist

- [x] Tests for the change (a bug fix starts with a failing test): all
four fixture cases fail on `main`
- [x] `pnpm lint && pnpm typecheck && pnpm test` pass
- [x] README and docs updated if behavior changed (no documented
behavior changes; the docs already say peers are widened in the
manifest)
- [x] Changeset added if a user would notice
(`.changeset/peer-ranges-not-install-descriptors.md`, patch, names the
0.7.4 regression)
- [x] No new dependency, or it was agreed in an issue
- [x] No private code, names or paths in fixtures, tests or docs
- [x] The rules in CONTRIBUTING.md ("Rules that do not bend") still hold

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01EmiChUUtLdjbg6mNzKqVep

Signed-off-by: Claude <[email protected]>
Co-authored-by: Claude <[email protected]>
lucasbraum pushed a commit that referenced this pull request Oct 12, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and publish to npm
yourself or [setup this action to publish
automatically](https://github.com/changesets/action#with-publishing). If
you're not ready to do a release yet, that's fine, whenever you add more
changesets to main, this PR will be updated.


# Releases
## [email protected]

### Patch Changes

- [#83](#83)
[`bda0b35`](bda0b35)
Thanks [@lucasbraum](https://github.com/lucasbraum)! - Find more of what
an upgrade breaks. Named checks now also compile the files that directly
import a package's importers when what they import depends on the
package, within a 20% memory budget relative to the same program's
estimate (the same files on every machine), so a test calling a wrapped
tool's `execute` is reported. Files the budget leaves out are named per
workspace in the check and fix summaries, `report.json` and the HTML
report. The `ai` pack flags `ToolLoopAgent`, `Agent` and
`ToolLoopAgentSettings` type arguments, whose third position is now the
runtime context, and finds renamed options inside spread objects, behind
`as`/`satisfies`, and in an agent's `stream`/`generate` calls. Breaking
recall: `ai` 36% → 82%, `zod` 71% → 74%, with no false positives.

- [#84](#84)
[`5c59257`](5c59257)
Thanks [@lucasbraum](https://github.com/lucasbraum)! - Yarn 2 and 3
lockfiles: follow dependency references written without the `npm:`
protocol, so a moved package's own subtree is recognized. `fix` no
longer rejects a new major that swaps its dependencies (for example
`cmdk` 0.2 → 1.0 replacing `@radix-ui/*` 1.0.0 with 1.1.x) as "changed
resolutions outside the dependency subtree", and importer resolutions in
these lockfiles are now compared too. Changes reached only from packages
that did not move are still rejected. The report lists each allowed
transitive change under the package that moved it.
  
A root `resolutions`, `overrides` or `pnpm.overrides` entry that pins a
package the upgrade moves now stops the run before the baseline and the
install, naming the entry, instead of failing after the install (on
medusa: 33 s instead of 11 min). With Yarn 2+, a moved package whose
range the plan rewrote is pinned to the exact planned version too (it
resolved the newest match before).
  
Temporary clones are removed on exit, including after a failed or
interrupted run. `--keep-temp` (or `--debug`, which also prints every
phase) keeps one; `--keep` still works as before.

- [#85](#85)
[`0af3fed`](0af3fed)
Thanks [@lucasbraum](https://github.com/lucasbraum)! - Fix a 0.7.4
regression: when a workspace declares the upgraded package both in
`peerDependencies` and in `dependencies` or `devDependencies`, the
widened peer range (for example `^18.3.1 || ^19.0.0`) replaced the
installable range in the install and in the check that follows it. With
Yarn it is no lockfile descriptor, so the check read an old copy and
`fix` stopped with "Requested [email protected], but … resolved 17.0.2". Peer
ranges are now only validated and widened in the manifest:
`dependencies`, `devDependencies` and `optionalDependencies` alone feed
the install, `yarn set resolution` and the check.

- [#86](#86)
[`191c89e`](191c89e)
Thanks [@lucasbraum](https://github.com/lucasbraum)! - Fix `uptide pr
--yes` opening a ready-for-review pull request when `--draft` is
omitted. New pull requests now default to drafts, matching `fix --pr
--yes` and the migration report's instructions.

- [#81](#81)
[`ac01a01`](ac01a01)
Thanks [@lucasbraum](https://github.com/lucasbraum)! - Respect the
repository's JavaScript compiler setting when selecting scoped analysis
roots. This prevents an `escapedName` crash during upgrades in mixed
TypeScript/JavaScript monorepos while preserving analysis of enabled
JavaScript files.

Co-authored-by: uptide-release[bot] <338861287+uptide-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants