Repository navigation
fix(worktree): frozen installs so provisioning cannot dirty the lockfile - #816
Merged
Merged
Conversation
Worktree provisioning ran `npm install --silent`, which normalizes and rewrites package-lock.json whenever the local npm disagrees with the npm that committed it. Observed on run #814 (2026-07-26): local npm 10.9.8 stripped the `libc` fields dependabot's newer npm had written, so the freshly created worktree started with an unstaged lockfile before any work happened. One dirty file, three failures that do not look related: - rebaseBeforePR hit "cannot rebase: You have unstaged changes" and fell into its generic else-branch -- there is no stash or dirty-tree pre-check, because an unstaged file was never anticipated on a worktree the tool itself just created. The #295 stale-base guard silently never ran, and since batch-executor discards the RebaseResult, the run log recorded plain success. - checkWorktreeFreshness counted the file as uncommitted work, so a stale worktree was kept ("Commit or stash changes, then re-run") no matter how far behind main it drifted -- recreation could never trigger. - createCheckpointCommit scopes staging to the branch's own diff; the lockfile was out of scope, so chain mode printed "Skipping checkpoint ... unrelated dirty file(s)" and returned false on every link, breaking chain resume (#760). Fix: both install sites -- provisioning (ensureWorktree) and the post-rebase reinstall (reinstallIfLockfileChanged) -- now use pmConfig.ciInstall, the frozen install that never rewrites the lockfile. This is the substitution #803 already made for merge-check's combined-branch test, for the same reason; ciInstall has existed in PM_CONFIG since then with the comment "lockfile-faithful, never rewrites it" and had no other consumer. The provisioning site is guarded by !existsSync(node_modules), so npm ci's wipe-and-reinstall has nothing to wipe. For the reinstall site, frozen is what the function's own name promises: it exists because a rebase pulled in a NEW lockfile, so the job is to install exactly what that lockfile says. Trade-off acknowledged: npm ci fails hard when package.json and the lockfile disagree, where npm install would silently "heal" the lockfile -- but that healing is precisely the defect. The new test drives the real exported reinstallIfLockfileChanged with child_process mocked and asserts the spawned command is `npm ci`, plus a PM_CONFIG invariant that no node PM's ciInstall aliases a rewriting install. Verified to fail against the pre-fix code and pass after. The provisioning site itself is not directly driven (it needs real git plumbing); it is covered by the PM_CONFIG invariant and pinned by comment. Not fixed here, recorded for follow-up: batch-executor.ts discards rebaseBeforePR's result, so a failed pre-PR rebase still never reaches the run log. Full suite: 195/195 files, 4101 passed.
This was referenced Jul 26, 2026
Closed
admarble
added a commit
that referenced
this pull request
Jul 27, 2026
…rty the lockfile (#827) #816 made this substitution for the TypeScript worktree-manager path but missed this script, which still used `npm install --silent` at all three sites. `npm install` normalizes and rewrites package-lock.json whenever the local npm disagrees with the npm that committed it — observed here as npm 10 stripping the `libc` fields a newer npm wrote via dependabot. Every freshly provisioned worktree therefore started with an unstaged lockfile, and that single dirty file cascades into three unrelated-looking failures: `rebaseBeforePR` refuses to run so the #295 stale-base guard silently never fires (while the run log still says success), `checkWorktreeFreshness` counts it as uncommitted work so stale worktrees are never recreated, and chain checkpoints skip on an "unrelated dirty file", breaking chain resume (#760) on every link. Reproduced live: provisioning the worktree for this very issue left `package-lock.json` modified with 12 deletions before any edit. `npm ci` never rewrites the lockfile, and the enclosing `[ ! -d node_modules ]` guard means it only ever runs against an absent node_modules — exactly its precondition. Extracted to a `frozen_install` helper so the three sites cannot drift, with an explicit failure path (AC-4): a bare `set -e` abort would leave a half-provisioned worktree with no explanation, so the helper names the cause (lockfile out of sync with package.json) and the remedy. Edits templates/scripts/ — scripts/new-feature.sh is a symlink to it.
This was referenced Jul 28, 2026
admarble
added a commit
that referenced
this pull request
Jul 29, 2026
…d of swallowing it (#854) Extract the frozen provisioning install into installWorktreeDeps, which mirrors reinstallIfLockfileChanged's status check: on a non-zero exit it warns (chalk.yellow) naming the resolved command so the user can rerun it, and warn-and-continues rather than aborting. Previously ensureWorktree ran the install and discarded the result, so after #816/#826 switched to a frozen npm ci a repo with no/stale lockfile yielded a silently dependency-less worktree whose breakage only surfaced later as a confusing phase error. Adds a mocked unit test (no lockfile => npm ci exit 1) asserting the failure is reported, the stderr is surfaced, and the command is named even when stderr is empty. Entire-Checkpoint: 8e84f0faf466
admarble
added a commit
that referenced
this pull request
Jul 29, 2026
…seInt (#855) * fix(#846): ensureWorktree surfaces failed provisioning install instead of swallowing it Extract the frozen provisioning install into installWorktreeDeps, which mirrors reinstallIfLockfileChanged's status check: on a non-zero exit it warns (chalk.yellow) naming the resolved command so the user can rerun it, and warn-and-continues rather than aborting. Previously ensureWorktree ran the install and discarded the result, so after #816/#826 switched to a frozen npm ci a repo with no/stale lockfile yielded a silently dependency-less worktree whose breakage only surfaced later as a confusing phase error. Adds a mocked unit test (no lockfile => npm ci exit 1) asserting the failure is reported, the stderr is surfaced, and the command is named even when stderr is empty. Entire-Checkpoint: 8e84f0faf466 * fix(#845): harden the eight numeric CLI options #833 left on bare parseInt #833 hardened 10 numeric flags with parseWholeNumber but left eight on a bare parseInt, justified in PR #836's AC-6 table by reasoning only about NaN. The unit-suffix misparse the guard exists for (parseInt("30m",10) is 30) was never addressed, so `logs --last 30m` read 30, the two --port flags bound the truncated port silently, and `--max-age 1w` failed *open* — state-cleanup.ts:181 gates on a truthy value, so 1w narrowed a 7-day retention to 1 day and deleted more than asked. All eight sites (status [issue], status --max-age, prompt --wait, logs --last, logs --issue, dashboard --port, serve --port, state clean --max-age) now use the same parseWholeNumber guard, coerced during commander's parse phase so a rejection exits before any server binds or cleanup runs. --wait uses min:0 (prompt.ts:259 reads 0 as "don't block"); the rest use min:1. Tests: extend numeric-flags.integration.test.ts with the issue's eight end-to-end reproductions (proves wiring, not just the coercion) plus the --wait 0 boundary; add a data-driven per-flag table in cli-flags.test.ts pinning reject-suffix (AC-1) and preserve-boundary (AC-4). Mutation-checked the --max-age case: reverting the coercion reaches the fail-open cleanup and the test fails. Entire-Checkpoint: 8a29dcd37f14
This was referenced Jul 29, 2026
admarble
added a commit
that referenced
this pull request
Jul 30, 2026
…ge manager (#859) * fix(#847): new-feature.sh resolves frozen install from detected package manager templates/scripts/new-feature.sh hardcoded `npm ci --silent` in frozen_install() and named package-lock.json in its failure message, while the TypeScript provisioning path (#816) already resolved the frozen install from PM_CONFIG[pm].ciInstall. On pnpm/yarn/bun projects the shell path ran npm ci against a non-npm lockfile and aborted pointing the user at a file their project does not use. - Add detect_package_manager() mirroring stacks.ts LOCKFILE_PRIORITY (bun.lockb/bun.lock > yarn.lock > pnpm-lock.yaml > package-lock.json, npm fallback) plus pm_ci_install/pm_lockfile/pm_recovery tables matching PM_CONFIG.ciInstall (AC-1). - frozen_install() runs the resolved command; its failure message names the resolved lockfile and a PM-appropriate recovery command (AC-3). - Hash the resolved lockfile in the SEQUANT_NPM_CACHE branch instead of a hardcoded package-lock.json, and gate install on package.json. - Add integration test driving the real script with stubbed package managers on PATH (command capture) + a PM_CONFIG drift guard (AC-2). Closes #847 Entire-Checkpoint: 0c0766fcc61a * test(#847): scope PM_CONFIG drift guard to the pm_ci_install table The drift guard matched the whole script, but each ciInstall string also appears in the file's explanatory comment, so mutating the actual pm_ci_install() case table (pnpm -> "npm ci") left the test green — the prose satisfied the substring match. Scope the assertion to the pm_ci_install() function body so a wrong command in the table fails it, per the delimited-region rule in CLAUDE.md § Testing. Mutation-verified: pnpm table entry -> "npm ci" now fails the drift guard (and the three pnpm behavior tests); restored to green. Entire-Checkpoint: fd1915a1cadd * fix(#847): close QA gaps — cover the cache branch and the npm assumptions it hid QA on #859 found the SEQUANT_NPM_CACHE branch and the `bun` arm were modified but untested, and that the PM-aware rewrite dropped npm's `--silent`. Writing the missing tests surfaced four further npm-shaped assumptions in the same file, each now fixed and gated: - `cp -r` → `cp -R` on the cache-hit copy. BSD `cp -r` DEREFERENCES symlinks, so a pnpm node_modules was expanded into real copies and any dangling link (optional dep, foreign-platform `.bin` entry) exited non-zero — `set -e` then left a half-provisioned worktree. Only reachable for pnpm/yarn/bun since this PR made the branch work for them at all. - CACHE_DIR is anchored to MAIN_REPO_DIR. Execution is inside the new worktree by that point, so `../worktrees/.npm-cache` resolved to `worktrees/feature/worktrees/.npm-cache`. - `pm_recovery bun` defers to `pm_lockfile` instead of naming `bun.lockb`: a bun.lock project was told to commit a file it does not have, which is the wrong-file misdirection AC-3 exists to eliminate. - The next-steps hint uses the detected PM's run prefix (`pm_run`, mirroring PM_CONFIG.run) instead of a hardcoded `npm run dev`. - `npm ci --silent` is restored via `pm_quiet_flag` at the call site, so the ciInstall drift guard still matches PM_CONFIG verbatim. - HASH_FILE renamed `.package-lock-hash` → `.lockfile-hash`. Tests: 7 → 15. New coverage for the cache branch (hash of the resolved lockfile, cache-hit reuse with symlink preservation, non-npm project not aborting in the hasher), the bun arm, the quiet flag, the next-steps hint, and a second drift guard over pm_run. Mutation verification recorded in the PR body. * fix(#847): key the cache hash by project; name a missing lockfile as missing Two QA-round-3 gaps: 1. .lockfile-hash was one shared file in ../worktrees/.npm-cache, which every sibling repo under the same parent shares — two projects alternated overwriting it, so both missed the cache every run. Now keyed as .lockfile-hash-$(basename MAIN_REPO_DIR). Thrash-only bug (a hit copies the project's own node_modules), but it defeated the cache entirely for multi-project setups. 2. A manifest-only project (package.json, no lockfile) falls back to npm and 'npm ci' fails because it REQUIRES a lockfile — the error said "The committed package-lock.json is out of sync", describing a file that doesn't exist. frozen_install now branches on the resolved lockfile's existence: missing → 'No <lockfile> found', present → the out-of-sync wording. Recovery command unchanged (it generates the lockfile either way). Mutation results recorded in the PR body.
admarble
added a commit
that referenced
this pull request
Jul 30, 2026
…oning paths (#876) * fix(#871): resolve yarn frozen install per yarn major, in both provisioning 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 * fix(#871): make the shell yarn-major read agree with the TS regex 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. * fix(#871): suppress the stderr leak when a yarn repo has no package.json 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. * fix(#871): close the remaining yarn classic/berry hybrids and QA coverage 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. * test(#871): gate the per-major upgrade hint 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.
7 tasks
admarble
added a commit
that referenced
this pull request
Sep 9, 2026
…rty the lockfile #816 made this substitution for the TypeScript worktree-manager path but missed this script, which still used `npm install --silent` at all three sites. `npm install` normalizes and rewrites package-lock.json whenever the local npm disagrees with the npm that committed it — observed here as npm 10 stripping the `libc` fields a newer npm wrote via dependabot. Every freshly provisioned worktree therefore started with an unstaged lockfile, and that single dirty file cascades into three unrelated-looking failures: `rebaseBeforePR` refuses to run so the #295 stale-base guard silently never fires (while the run log still says success), `checkWorktreeFreshness` counts it as uncommitted work so stale worktrees are never recreated, and chain checkpoints skip on an "unrelated dirty file", breaking chain resume (#760) on every link. Reproduced live: provisioning the worktree for this very issue left `package-lock.json` modified with 12 deletions before any edit. `npm ci` never rewrites the lockfile, and the enclosing `[ ! -d node_modules ]` guard means it only ever runs against an absent node_modules — exactly its precondition. Extracted to a `frozen_install` helper so the three sites cannot drift, with an explicit failure path (AC-4): a bare `set -e` abort would leave a half-provisioned worktree with no explanation, so the helper names the cause (lockfile out of sync with package.json) and the remedy. Edits templates/scripts/ — scripts/new-feature.sh is a symlink to it.
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
Worktree provisioning installed dependencies with a plain
npm install --silent, which rewritespackage-lock.jsonwhenever the local npm disagrees with the npm that committed it. Every freshly provisioned worktree on such a machine started dirty — and that one unstaged file cascaded into three unrelated-looking failures. Both install sites now use the frozen install (ciInstall), which never touches the lockfile.Surfaced by the
Rebase failed: You have unstaged changeswarning in run #814's scrollback; root-caused during the release-validation investigation (see #810's discussion for the sibling instance in merge-check).The cascade (all verified against run #814's worktree)
One dirty
package-lock.json(local npm 10.9.8 strippinglibcfields a newer npm committed via dependabot) caused:rebaseBeforePRnever ran —cannot rebase: You have unstaged changesfell into the generic else-branch (worktree-manager.ts:1326); no stash or dirty-tree pre-check exists because a tool-created worktree was never expected to be dirty. The fix: Rebase worktrees onto main before PR to prevent lockfile drift #295 stale-base guard silently didn't fire, and sincebatch-executor.ts:1298discards theRebaseResult, the run log recorded plain success.checkWorktreeFreshnesscounts the file as uncommitted work, so the stale-and-clean recreate path can never trigger.createCheckpointCommitscopes staging to the branch's own diff; the lockfile is out of scope → "Skipping checkpoint … unrelated dirty file(s)" → chain resume (feat: resume a partially-completed chain from its last good link #760) broken.The fix
Two substitutions,
installSilent→ciInstall:ensureWorktreeprovisioning (worktree-manager.ts:834) — guarded by!existsSync(node_modules), sonpm ci's wipe has nothing to wipe.reinstallIfLockfileChanged(:1178) — frozen is the semantic the function's own name promises: it runs because a rebase pulled in a new lockfile, so the job is installing exactly what it says.ciInstallhas existed inPM_CONFIGsince #803 with the comment "lockfile-faithful, never rewrites it" — this PR gives it its second and third consumers, completing the substitution #803 made for merge-check's combined-branch test.Trade-off, deliberate:
npm cifails hard whenpackage.jsonand the lockfile disagree, wherenpm installwould silently "heal" the lockfile. That healing is precisely the defect.Tests
worktree-manager.frozen-install.test.ts: drives the real exportedreinstallIfLockfileChangedwithchild_processmocked, asserting the spawned command isnpm ci(and not the rewriting install); plus aPM_CONFIGinvariant that no node PM'sciInstallaliases a rewriting install. Verified to fail against the pre-fix code.Not in this PR
batch-executor.ts:1298still discardsrebaseBeforePR's result, so a failed pre-PR rebase remains invisible in the run log. Recorded as follow-up; kept out to hold this to the minimal, precedented substitution before the release.🤖 Generated with Claude Code