Repository navigation
fix(#871): resolve yarn frozen install per yarn major in both provisioning paths - #876
Merged
admarble merged 6 commits intoJul 30, 2026
Conversation
…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
4 tasks
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
deleted the
feature/871-pm-config-yarn-ciinstall-uses-yarn-2-immutable
branch
July 30, 2026 06:39
4 tasks
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PM_CONFIG.yarn.ciInstallwasyarn install --immutable— Yarn 2+ (berry) syntax. Yarn 1 rejects it, and no berry detection existed anywhere: Yarn 1 and berry both useyarn.lock, sodetectPackageManagerSyncmaps it toyarnregardless 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— newdetectYarnMajor(a separate axis from which package manager),YARN_CLASSIC_CI_INSTALL, andresolvePackageManagerConfig(pm, root): a drop-in replacement forPM_CONFIG[pm]wherever the install directory is known. Returning the whole config, not just the string, keeps call sites that thread aPackageManagerConfigonward 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 indetect_yarn_major, andpm_ci_install's yarn arm branches with both commands verbatim in the function body so the scoped drift guard sees them.Detection ladder
packageManager: "yarn@<major>"inpackage.json.yarnrc.ymlpresentyarn.lockheader hasyarn lockfile v1(first 1024 bytes)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@4Corepack 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
detectYarnMajor(stacks.ts) +detect_yarn_major(new-feature.sh); all three signals the AC names are used--frozen-lockfile, Yarn 2+ ->--immutable, both pathsresolvePackageManagerConfigat 3 call sites, pinned inworktree-manager.frozen-install.test.ts. Shell:pm_ci_installyarn arm, pinned in the integration suiteYARN_CLASSIC_CI_INSTALL— yarn is the one PM with two frozen installs--immutablefails the suiteMutation verification
Per CLAUDE.md § Testing, each gate was verified by deleting what it asserts:
pm_ci_installyarn arm collapsed to--immutable(the exact AC-4 scenario)AC-2: a Yarn 1 project runs yarn install --frozen-lockfile,AC-1: a packageManager pin outranks a conflicting lockfile headerexpected '...case "$1" in...' to contain 'yarn install --frozen-lockfile'PM_CONFIG[pm]packageManagerrung deleted from the shell ladder onlyexpected 2 to be 1All mutations reverted; tree matches the committed state.
Test plan
npm test(full suite): passingnpm run build,npm run lint: cleanstacks.test.ts122 passed (+9) ·new-feature-frozen-install.integration.test.ts22 passed (+5) ·worktree-manager.frozen-install.test.ts10 passed (+4)bash -n templates/scripts/new-feature.shclean (shellcheck not installed locally)yarn.lock-> rung 4 -> berry, so they assert--immutableunchanged — no fixture flippedNotes for review
|| "npm"fallback disagrees with the PM-aware shell path on manifest-less projects #870. worktree-manager's bare|| "npm"fallback disagrees with the PM-aware shell path on manifest-less projects #870 has uncommitted work rewriting the same twopmConfiglines inworktree-manager.ts. Mitigated where possible: this PR anchors its newstacks.tsexports aftergetPackageManagerCommandsrather than afterdetectPackageManagerSync, sostacks.tsdoes not conflict. The twoworktree-manager.tshunks do. The designs compose — worktree-manager's bare|| "npm"fallback disagrees with the PM-aware shell path on manifest-less projects #870 answers which PM, this answers which config variant for that PM — so post-merge the line readsresolvePackageManagerConfig(resolvePackageManager(packageManager, worktreePath), worktreePath). Whichever merges second should mergeorigin/main, not rebase.yarn1member toPackageManager. Arguably the truer model and the drift guard would cover it for free, but the type surfaces in settings, doctor,version-check, and templates, so a syntheticyarn1would leak intopmRunand diagnostics — disproportionate for a one-flag difference.PM_CONFIG.yarnis still a berry/classic hybrid beyondciInstall—exec: "yarn dlx"is berry-only,updatePkg: "yarn upgrade"is classic-only. Same root cause;resolvePackageManagerConfigis where those get fixed. Follow-up filed separately.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 apackageManagerpin whose key and value sit on separate lines (legal JSON),detect_yarn_majoranddetectYarnMajorreturned opposite majors, so one of the two provisioning paths ran the flag the other major rejects. Symmetric:yarn@4wrapped over a v1 lockfile gave shell=1/ts=2;yarn@1wrapped over a berry lockfile gave shell=2/ts=1. Root cause:sed/grepare 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 greedysedwould 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/nulldoes not suppress what it looks like it does: a failed<redirection is reported by the shell before the command's own2>/dev/nullapplies, so provisioning a yarn repo with nopackage.jsonleakedpackage.json: No such file or directoryto stderr. The originalsed … file 2>/dev/nullpassed the path as an argument, so its error was suppressible. Behavior was already correct; only the stray line was wrong.Additional verification
sedset -e/pipefailauditset -eis set, so a no-matchgrepcannot abort provisioning; exercised both no-pin cases directlybuild (22.x)runsnpm test, and the agreement test executes the lifted shell function — so the BRE intervals are verified on GNU grep, not only BSDRegression 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-completedAttest 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.yarnis now the berry baseline, with classic applied by the resolverPM_CONFIG.yarnwas a genuine classic/berry hybrid beyondciInstall, the same root cause as this issue. Both halves are fixed via aYARN_CLASSIC_OVERRIDEStable the resolver applies:execyarn dlxfor everyoneyarn dlxnpx(Yarn 1 has nodlx)updatePkgyarn upgradefor everyoneyarn upyarn upgradegetVersionWarningThe
updatePkgone was a live user-facing bug:getVersionWarningprintsRun: <updatePkg> sequant, so sequant's own "new version available" hint told every berry user to run a command berry removed.version-check.tsnow resolves per major instead of readingPM_CONFIGdirectly.installSilentis deliberately left alone and documented: berry'syarn installtakes 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 callnew-feature.sh'spm_quiet_flagalready made for pnpm/bun. Pinned by a test so removing the exemption is a deliberate act.merge-check re-resolves for the combined state
runChecksnow 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 (apackageManagerbump, 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
detectYarnMajorgains the@internal Exported for testingmarker this codebase already uses oninstallWorktreeDeps.package-manager-detection.md's command table now has separate Yarn 1 / Yarn 2+ rows plus a section on major detection;troubleshooting.mdno longer prints one yarn upgrade command for both majors.Correction to
e424f849's commit messageThat 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 reachesdetect_yarn_major— the leak was only observable calling the function directly. Thecat | trfix 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 andset -eproperties where they are reachable.Mutation verification for the new work
updatePkgfrom the classic overridesversion-check.tsto unresolvedgetPackageManagerCommandsPM_CONFIG[pm][ -f package.json ]install guardThe 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.tsxtimeout is #880 / PR #882 — it is theunitproject's 5s default losing to an Ink render under load, and is kept out of this PR.