Skip to content

fix(#871): resolve yarn frozen install per yarn major in both provisioning paths - #876

Merged
admarble merged 6 commits into
mainfrom
feature/871-pm-config-yarn-ciinstall-uses-yarn-2-immutable
Jul 30, 2026
Merged

admarble merged 6 commits into
mainfrom
feature/871-pm-config-yarn-ciinstall-uses-yarn-2-immutable

Conversation

@admarble

@admarble admarble commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

PM_CONFIG.yarn.ciInstall was yarn install --immutable — Yarn 2+ (berry) syntax. Yarn 1 rejects it, and no berry detection existed anywhere: Yarn 1 and berry both use yarn.lock, so detectPackageManagerSync maps it to yarn regardless of major. Every Yarn 1 project's frozen provisioning install therefore failed.

Both provisioning paths are fixed in one change, as the issue requires — fixing either alone recreates the divergence #847 existed to close, and the drift guard fails on a one-sided edit.

  • stacks.ts — new detectYarnMajor (a separate axis from which package manager), YARN_CLASSIC_CI_INSTALL, and resolvePackageManagerConfig(pm, root): a drop-in replacement for PM_CONFIG[pm] wherever the install directory is known. Returning the whole config, not just the string, keeps call sites that thread a PackageManagerConfig onward correct with a one-line change.
  • worktree-manager.ts — both install sites resolve against the worktree.
  • merge-check/combined-branch-test.ts — a third consumer with the identical defect (three install commands + two user-facing messages), fixed by the same substitution. Beyond the literal AC wording; called out in the spec comment rather than smuggled in.
  • new-feature.sh — mirrors the ladder in detect_yarn_major, and pm_ci_install's yarn arm branches with both commands verbatim in the function body so the scoped drift guard sees them.

Detection ladder

# Signal Verdict
1 packageManager: "yarn@<major>" in package.json that major
2 .yarnrc.yml present berry
3 yarn.lock header has yarn lockfile v1 (first 1024 bytes) 1
4 nothing recognizable berry (pre-#871 default)

The ordering follows one rule: flag acceptance is decided by the yarn binary that runs, not by the lockfile it reads. A yarn-1 lockfile under a yarn@4 Corepack pin still gets --immutable, because yarn 4 is what executes and yarn 4 rejects --frozen-lockfile.

Both implementations use the same sed shape and the same 1024-byte header window, so they cannot disagree about a directory — and an integration test replays every fixture through both to prove it rather than assert it.

AC Verification

AC Source Description Status Evidence
AC-1 Original Yarn major detected, not assumed berry Implemented detectYarnMajor (stacks.ts) + detect_yarn_major (new-feature.sh); all three signals the AC names are used
AC-2 Original Yarn 1 -> --frozen-lockfile, Yarn 2+ -> --immutable, both paths Implemented TS: resolvePackageManagerConfig at 3 call sites, pinned in worktree-manager.frozen-install.test.ts. Shell: pm_ci_install yarn arm, pinned in the integration suite
AC-3 Original ciInstall drift guard still passes, tables in lockstep Implemented Guard passes and was extended to also require YARN_CLASSIC_CI_INSTALL — yarn is the one PM with two frozen installs
AC-4 Original Test covers both majors; a Yarn 1 fixture with --immutable fails the suite Implemented 4 provisioning tests + cross-path agreement test; mutation-verified below

Mutation verification

Per CLAUDE.md § Testing, each gate was verified by deleting what it asserts:

Mutation Expected Result
Shell pm_ci_install yarn arm collapsed to --immutable (the exact AC-4 scenario) Yarn 1 fixture tests fail 2 failed: AC-2: a Yarn 1 project runs yarn install --frozen-lockfile, AC-1: a packageManager pin outranks a conflicting lockfile header
Same mutation, drift guard alone Extended guard fails 1 failed: expected '...case "$1" in...' to contain 'yarn install --frozen-lockfile'
Both TS sites reverted to PM_CONFIG[pm] TS-path tests fail 3 failed, incl. the failure-warning test (a warning naming berry's command would send a Yarn 1 user to rerun the command that just failed)
packageManager rung deleted from the shell ladder only Cross-path agreement test fails 1 failed, naming the diverging fixture: expected 2 to be 1

All mutations reverted; tree matches the committed state.

Test plan

  • npm test (full suite): passing
  • npm run build, npm run lint: clean
  • stacks.test.ts 122 passed (+9) · new-feature-frozen-install.integration.test.ts 22 passed (+5) · worktree-manager.frozen-install.test.ts 10 passed (+4)
  • bash -n templates/scripts/new-feature.sh clean (shellcheck not installed locally)
  • The two pre-existing yarn tests seed a contentless yarn.lock -> rung 4 -> berry, so they assert --immutable unchanged — no fixture flipped

Notes for review

Closes #871

Generated with Claude Code


Update: QA found and closed a cross-path divergence

The first commit shipped a real bug that QA caught before merge, and the fix received its own adversarial pass which caught a second one.

c71f1c55 — the AC-2 defect. For a packageManager pin whose key and value sit on separate lines (legal JSON), detect_yarn_major and detectYarnMajor returned opposite majors, so one of the two provisioning paths ran the flag the other major rejects. Symmetric: yarn@4 wrapped over a v1 lockfile gave shell=1/ts=2; yarn@1 wrapped over a berry lockfile gave shell=2/ts=1. Root cause: sed/grep are line-oriented so [[:space:]]* cannot span a newline, while the JS regex's \s* can. This was exactly the dual-producer drift class #833/#847 exist to close — and it contradicted the comment the first commit itself added.

The fix collapses newlines before matching (cat … | tr '\n' ' ') and takes the first match (grep -o | head -1) instead of sed's greedy last-match. The second half is needed because of the first: once the file is one line, a greedy sed would take the last pin, which is a fresh divergence for a file carrying two pins. Both comments were corrected to say what the code actually does and name the inputs that diverged.

e424f849 — a regression the fix introduced. tr '\n' ' ' < package.json 2>/dev/null does not suppress what it looks like it does: a failed < redirection is reported by the shell before the command's own 2>/dev/null applies, so provisioning a yarn repo with no package.json leaked package.json: No such file or directory to stderr. The original sed … file 2>/dev/null passed the path as an argument, so its error was suppressible. Behavior was already correct; only the stray line was wrong.

Additional verification

Check Result
Cross-path fuzz, 17 edge inputs through both implementations 17/17 agree (was 15/17)
Mutation: drop the newline collapse wrapped-pin fixture fails
Mutation: keep collapse, restore greedy sed two-pins fixture fails — not caught by the other fixture
set -e / pipefail audit only set -e is set, so a no-match grep cannot abort provisioning; exercised both no-pin cases directly
Linux/GNU grep CI build (22.x) runs npm test, and the agreement test executes the lifted shell function — so the BRE intervals are verified on GNU grep, not only BSD

Regression fixtures added to the cross-path agreement test (wrapped pin both directions, two-pins first-match) plus the same two inputs asserted directly in stacks.test.ts, so the invariant is gated rather than asserted in prose.

Known flake, not from this change: src/ui/tui/App.test.tsx's stale-completedAt test failed once under full-suite load. This diff imports no TUI code, the file passes 4/4 in isolation, and CI's full run is green — it is #866's Ink fake-timer test being load-sensitive.

Final QA verdict: READY_FOR_MERGE (4/4 ACs MET) — see the review on issue #871.


Update 2: all QA-recorded gaps closed

The two QA passes recorded four non-blocking gaps and one out-of-scope item. All are now fixed here, plus one correction to a claim an earlier commit's message overstated.

PM_CONFIG.yarn is now the berry baseline, with classic applied by the resolver

PM_CONFIG.yarn was a genuine classic/berry hybrid beyond ciInstall, the same root cause as this issue. Both halves are fixed via a YARN_CLASSIC_OVERRIDES table the resolver applies:

Field Was Berry Classic Consumer
exec yarn dlx for everyone yarn dlx npx (Yarn 1 has no dlx) none today — table correctness
updatePkg yarn upgrade for everyone yarn up yarn upgrade getVersionWarning

The updatePkg one was a live user-facing bug: getVersionWarning prints Run: <updatePkg> sequant, so sequant's own "new version available" hint told every berry user to run a command berry removed. version-check.ts now resolves per major instead of reading PM_CONFIG directly.

installSilent is deliberately left alone and documented: berry's yarn install takes no --silent, but the field has no consumer anywhere, and guessing berry's quiet spelling with no yarn binary to verify against would trade a dead-config wart for a real one — the same call new-feature.sh's pm_quiet_flag already made for pnpm/bun. Pinned by a test so removing the exemption is a deliberate act.

merge-check re-resolves for the combined state

runChecks now resolves against the tree it is about to install into, after the merges land, instead of reusing the caller's pre-merge resolution. A merged branch can move the yarn major (a packageManager bump, a new .yarnrc.yml), and installing the combined tree with the pre-merge flag fails on an unknown option — a false BLOCKED, the exact failure class #803's install was added to prevent. The outer resolution is kept for the restore install, which correctly describes the pre-merge tree because it runs after checking the original branch back out. One up-front resolution cannot serve both.

Coverage gaps closed

  • merge-check gains direct yarn-major tests — both majors, the failure message, and the combined-vs-restore re-resolution. It was covered only through the resolver's own tests.
  • detectYarnMajor gains the @internal Exported for testing marker this codebase already uses on installWorktreeDeps.
  • Docs, both locations: package-manager-detection.md's command table now has separate Yarn 1 / Yarn 2+ rows plus a section on major detection; troubleshooting.md no longer prints one yarn upgrade command for both majors.

Correction to e424f849's commit message

That message claimed the stderr leak affected "provisioning a yarn repo with no package.json". It did not. The install is gated on [ ! -d node_modules ] && [ -f package.json ] (#847's non-JS skip), so that provisioning path never reaches detect_yarn_major — the leak was only observable calling the function directly. The cat | tr fix is still correct and is kept, but it is a footgun removal, not a user-visible bug fix. Writing the end-to-end test is what surfaced this; that test now pins the real behavior (install skipped), and a second function-level test pins the stderr and set -e properties where they are reachable.

Mutation verification for the new work

Mutation Expected Observed
Drop updatePkg from the classic overrides exact-field test fails 1 failed
Revert version-check.ts to unresolved getPackageManagerCommands per-major hint test fails Initially nothing failed — the fix was ungated, so a test was added; now 1 fails
Revert merge-check to the pre-merge up-front resolution combined-vs-restore test fails 1 failed
Revert merge-check to raw PM_CONFIG[pm] yarn-major tests fail 2 failed
Delete the [ -f package.json ] install guard absent-package.json tests fail 2 failed

The second row is worth calling out: mutation testing caught that my own fix shipped without a gate.

Unrelated flake, now fixed separately: the App.test.tsx timeout is #880 / PR #882 — it is the unit project's 5s default losing to an Ink render under load, and is kept out of this PR.

…ioning paths

PM_CONFIG.yarn.ciInstall was `yarn install --immutable`, which is Yarn 2+
(berry) syntax. Yarn 1 rejects it, and no berry detection existed anywhere:
Yarn 1 and berry both use `yarn.lock`, so detectPackageManagerSync maps it to
"yarn" regardless of major. Every Yarn 1 project's frozen provisioning install
therefore failed, identically on both paths -- the TypeScript path
(worktree-manager.ts, #816) read PM_CONFIG.yarn.ciInstall directly and the
shell path (new-feature.sh, #847) mirrored the same string.

- stacks.ts: add detectYarnMajor (a separate axis from "which package
  manager"), YARN_CLASSIC_CI_INSTALL, and resolvePackageManagerConfig(pm,
  root) -- a drop-in replacement for PM_CONFIG[pm] wherever the install
  directory is known. Returning the whole config keeps call sites that thread
  a PackageManagerConfig onward correct with a one-line change.
- worktree-manager.ts: both install sites resolve against the worktree.
- merge-check/combined-branch-test.ts: third consumer with the identical
  defect; same substitution, fixing three commands and two messages at once.
- new-feature.sh: mirror the ladder in detect_yarn_major and branch
  pm_ci_install's yarn arm, with both commands verbatim in the function body.

Detection order -- packageManager pin, then .yarnrc.yml, then the yarn.lock
header, then berry as the pre-#871 default -- follows one rule: flag
acceptance is decided by the yarn binary that RUNS, not by the lockfile it
reads. A yarn-1 lockfile under a yarn@4 pin still gets --immutable.

The two implementations use the same sed shape and the same 1024-byte header
window so they cannot disagree about a directory; an integration test replays
every fixture through both. The pm_ci_install drift guard now also requires
the classic command, so the shell table cannot silently lose a yarn major.

Tests: 122 in stacks.test.ts, 22 in the new-feature integration suite, 10 in
worktree-manager.frozen-install.test.ts. Build and lint clean.

Fixes #871
admarble added 4 commits July 29, 2026 23:00
QA on this issue found a real cross-path divergence: for a `packageManager`
pin whose key and value sit on separate lines -- legal JSON --
`detect_yarn_major` and `detectYarnMajor` returned OPPOSITE majors, so one of
the two provisioning paths ran the flag the other major rejects. Symmetric:
`yarn@4` wrapped over a v1 lockfile gave shell=1/ts=2, and `yarn@1` wrapped
over a berry lockfile gave shell=2/ts=1. That is exactly the dual-producer
drift class #833/#847 exist to close, and it contradicted the comment the
first commit added claiming the two paths "cannot disagree about a given file".

Root cause: sed/grep are line-oriented, so `[[:space:]]*` cannot span a
newline, while the JS regex's `\s*` can.

Fix, in `detect_yarn_major`:
- `tr '\n' ' '` collapses newlines BEFORE matching, so a wrapped pin is read.
- `grep -o | head -1` takes the FIRST match, matching `String.match`. A greedy
  `sed 's/.*"packageManager"…/'` would take the LAST -- a second divergence the
  newline collapse would otherwise introduce for a file carrying two pins (e.g.
  one nested under `volta`).

Corrected the comments in both files: matching on text does not make the two
paths agree for free, and each now says which inputs diverged and why.

Regression coverage: the cross-path agreement test gains the two wrapped-pin
cases (both directions) and the two-pins first-match case, so the invariant is
gated rather than asserted in prose. `stacks.test.ts` gains the same two
inputs directly. Re-fuzzed 17 edge inputs through both implementations --
wrapped pins, tabs, space-before-colon, CRLF, nested pin, `yarn@stable`,
`yarn@v1`, `+sha224` suffix, a pnpm pin, package.json-as-directory, absent
lockfile, empty lockfile, header past the 1024-byte window, empty .yarnrc.yml
-- all 17 now agree.

Build and lint clean. 156 tests pass across the three affected files.
Self-review of the previous commit: `tr '\n' ' ' < package.json 2>/dev/null`
does not suppress what it looks like it suppresses. A failed `<` redirection is
reported by the SHELL before the command's own `2>/dev/null` takes effect, so
provisioning a yarn repo with no package.json printed a stray
`package.json: No such file or directory` to stderr. The old `sed … file
2>/dev/null` form passed the path as an argument, so its error WAS the
command's own and was suppressed -- i.e. this was a regression introduced by
the newline-collapse fix, not a pre-existing condition.

Behavior was already correct (exit 0, correct major, `set -e` not tripped since
pipefail is not set); only the stray line was wrong. `cat package.json
2>/dev/null | tr` makes the error the command's own and suppressible.

No test caught it because the integration harness's seedProject always writes a
package.json, so the absent-file path is never exercised end to end.

Verified: stderr is now empty for both the absent-package.json and
no-packageManager-field cases, both still return the correct major under
`set -e`, and all 17 cross-path fuzz inputs still agree.
…rage gaps

Fixes every gap the QA passes on this issue recorded as non-blocking, plus one
correction to a claim the previous commit's message overstated.

PM_CONFIG.yarn is now the BERRY baseline, with classic spellings applied by
resolvePackageManagerConfig via a YARN_CLASSIC_OVERRIDES table. That closes two
further hybrids of the same root cause as this issue:

- `exec` was `yarn dlx` for everyone. Berry-only -- Yarn 1 has no `dlx`, so
  classic resolves to `npx`. No consumer today, so this is table correctness.
- `updatePkg` was `yarn upgrade` for everyone. Classic-only -- berry renamed it
  to `yarn up`. This one HAD a consumer: getVersionWarning prints
  `Run: <updatePkg> sequant`, so sequant's own upgrade hint told every berry
  user to run a command their yarn removed. version-check.ts now resolves per
  major instead of reading PM_CONFIG directly.

`installSilent` is deliberately left at the classic spelling: berry's
`yarn install` takes no `--silent`, but the field has no consumer and guessing
berry's quiet spelling with no yarn binary to verify against would trade a
dead-config wart for a real one -- the same call new-feature.sh's
pm_quiet_flag already made for pnpm/bun. Documented as the one known remaining
hybrid, and pinned by a test so removing the exemption is deliberate.

merge-check now re-resolves for the COMBINED state inside runChecks, after the
merges land, instead of reusing the caller's pre-merge resolution. A merged
branch can move the yarn major (a packageManager bump, a new .yarnrc.yml), and
installing the combined tree with the pre-merge flag fails on an unknown option
-- a false BLOCKED, the exact failure class #803's install was added to prevent.
The outer resolution is kept for the restore install, which correctly describes
the pre-merge tree because it runs after checking the original branch back out.

Coverage gaps closed:
- merge-check gains direct yarn-major tests (both majors, the failure message,
  and the combined-vs-restore re-resolution) -- it was covered only through the
  resolver's own tests.
- `detectYarnMajor` gains the `@internal Exported for testing` marker this
  codebase already uses on installWorktreeDeps.
- Docs updated in both locations: the command-mapping table in
  package-manager-detection.md now has separate Yarn 1 / Yarn 2+ rows plus a
  section on major detection, and troubleshooting.md's update-command comment
  no longer prints one yarn spelling for both majors.

CORRECTION to e424f84's message: it claimed the stderr leak affected
"provisioning a yarn repo with no package.json". It did not. The install is
gated on `[ ! -d node_modules ] && [ -f package.json ]` (#847's non-JS skip), so
that provisioning path never reaches detect_yarn_major at all -- the leak was
only observable calling the function directly. The `cat | tr` fix is still
correct and is kept, but it is a footgun removal, not a user-visible bug fix.
Writing the end-to-end test is what surfaced this; that test now pins the real
behavior (install skipped), and a second function-level test pins the stderr
and `set -e` properties where they are actually reachable.

Build and lint clean. 314 tests pass across the affected unit suites, 24 in the
new-feature integration suite.
M2 mutation showed the version-check.ts fix was ungated: reverting it to
getPackageManagerCommands broke no test. Separate file from
version-check.test.ts because that one mocks fs wholesale, which stops
detectYarnMajor from reading the fixtures that decide the answer.
…-yarn-ciinstall-uses-yarn-2-immutable

# Conflicts:
#	CHANGELOG.md
#	src/lib/workflow/worktree-manager.frozen-install.test.ts
#	src/lib/workflow/worktree-manager.ts
@admarble
admarble merged commit 65f2a33 into main Jul 30, 2026
5 checks passed
@admarble
admarble deleted the feature/871-pm-config-yarn-ciinstall-uses-yarn-2-immutable branch July 30, 2026 06:39
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.

PM_CONFIG.yarn.ciInstall uses Yarn 2+ --immutable, which Yarn 1 rejects — no berry detection exists

1 participant