Skip to content

fix(#826): frozen install in new-feature.sh so provisioning cannot dirty the lockfile - #827

Merged
admarble merged 1 commit into
mainfrom
feature/826-fix-worktree-new-feature-sh-still-uses-npm-ins
Jul 27, 2026
Merged

admarble merged 1 commit into
mainfrom
feature/826-fix-worktree-new-feature-sh-still-uses-npm-ins

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

scripts/new-feature.sh still used npm install --silent at all three install sites. #816 made exactly this substitution for the TypeScript worktree-manager path — this script was missed by it.

npm install normalizes and rewrites package-lock.json whenever the local npm disagrees with the npm that committed it (here: npm 10 stripping the libc fields a newer npm wrote via dependabot). So every freshly provisioned worktree began life with an unstaged lockfile, and that single dirty file cascades into three unrelated-looking failures:

Found while provisioning the #804 worktree; it would otherwise have ridden along in PR #825.

Change

All three sites now go through a frozen_install helper wrapping npm ci --silent, which never rewrites the lockfile. Extracting the helper means the three sites cannot drift apart — which is how this one got missed in the first place.

The enclosing [ ! -d node_modules ] guard means the install only ever runs against an absent node_modules, which is exactly npm ci's precondition.

Edits templates/scripts/new-feature.sh — scripts/new-feature.sh is a symlink to it, so editing the link would have been a no-op.

AC verification

AC Status Evidence
AC-1 ✅ MET 0 occurrences of npm install --silent remain; 3 frozen_install call sites
AC-2 ✅ MET Verified by running, not inspection — see A/B below
AC-3 ✅ MET Cache-hit path still cp -rs node_modules with no install; cache-miss and cache-init call frozen_install then update the hash file. Only the two install sites changed
AC-4 ✅ MET Failure path exercised against a genuinely out-of-sync lockfile — see below

AC-2: A/B on a scratch worktree at the same commit

$ npm install --silent      # old behavior
dirty files: 1
 M package-lock.json
lockfile diff: 0 insertions, 12 deletions

$ git checkout package-lock.json && rm -rf node_modules
$ npm ci --silent           # fixed behavior
exit: 0
dirty files: 0
node_modules present: yes

The 12 deletions are the libc fields — the exact signature #816 documents.

AC-4: failure path

Injected an out-of-sync dependency into package.json so npm ci genuinely fails, then ran the extracted helper verbatim:

❌ Dependency install failed (npm ci).
   The committed package-lock.json is out of sync with package.json.
   Fix in the main repo, then re-run:
     npm install --package-lock-only && git commit package-lock.json
   Worktree left in place at: /tmp/lockprobe-826
--- exit code: 1 ---

Execution stops there (the probe's trailing "SHOULD NOT REACH HERE" never prints). A bare set -e abort would have exited just as non-zero but left a half-provisioned worktree with no explanation of why — hence the explicit handler rather than relying on set -e.

Test plan

  • bash -n templates/scripts/new-feature.sh — syntax OK
  • A/B lockfile test above (AC-2)
  • Out-of-sync failure path (AC-4)
  • Cache-path structure preserved (AC-3)
  • shellcheck — not installed locally; CI's hooks/shell validation covers it

Non-Goals

  • Migrating this script to the TypeScript worktree-manager path.
  • Generalizing beyond npm (pnpm/yarn) — the script hardcodes npm elsewhere too; separate concern.

Closes #826

…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.
@admarble
admarble merged commit f6a6498 into main Jul 27, 2026
5 checks passed
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.

fix(worktree): new-feature.sh still uses npm install, so provisioning dirties the lockfile (#816 gap)

1 participant