Skip to content

fix(#847): new-feature.sh resolves frozen install from detected package manager - #859

Merged
admarble merged 5 commits into
mainfrom
feature/847-new-feature-sh-hardcodes-npm-ci-while-the-ts-path-
Jul 30, 2026
Merged

admarble merged 5 commits into
mainfrom
feature/847-new-feature-sh-hardcodes-npm-ci-while-the-ts-path-

Conversation

@admarble

@admarble admarble commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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 a pnpm/yarn/bun project the shell path ran npm ci against a non-npm lockfile and aborted with "package-lock.json out of sync" — pointing the user at a file their project doesn't use.

  • Add detect_package_manager() mirroring src/lib/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.
  • frozen_install() runs the resolved command and its failure message names the resolved lockfile + a PM-appropriate recovery command.
  • Co-located sibling fixes: the SEQUANT_NPM_CACHE branch hashes the resolved lockfile instead of a hardcoded package-lock.json, and the install step is gated on package.json existing so non-JS projects skip it.

Pre-PR AC Verification

AC Source Description Status Evidence
AC-1 Original Resolve install command from detected PM, not hardcoded npm ✅ Implemented new-feature.sh detect_package_manager() + pm_ci_install(); tests: pnpm→pnpm install --frozen-lockfile, yarn→yarn install --immutable, npm→npm ci
AC-2 Original A pnpm project provisions successfully through the shell path ✅ Implemented Integration test provisions a pnpm fixture (command capture) and asserts the worktree is left clean (no rewritten lockfile)
AC-3 Original On no-matching-lockfile failure, error names the actual expected lockfile ✅ Implemented frozen_install() failure block uses pm_lockfile/pm_recovery; test asserts stderr names pnpm-lock.yaml + pnpm install --lockfile-only, never package-lock.json

Test plan

  • npx vitest run __tests__/new-feature-frozen-install.integration.test.ts — 7 passed
  • npm run build — passes (no TS changes)
  • npm run lint — passes
  • bash -n templates/scripts/new-feature.sh — syntax OK

Mutation verification (gate tests ship with a recorded result, per CLAUDE.md § Testing)

Mutation Expected failure Result
Remove && [ -f "package.json" ] install gate gate: no package.json skips install ✅ only that test failed (1/7)
pm_lockfile pnpm → package-lock.json AC-3 ✅ only that test failed (1/7)
pm_ci_install pnpm → npm ci AC-1/AC-2 pnpm + AC-2 clean + AC-3 + drift guard ✅ 4/7 failed

The drift guard was initially a whole-file substring match, which the mutation exposed as tautological — each ciInstall string also appears in the file's explanatory comment, so the pnpm-table mutation left it green. Rescoped to the pm_ci_install() function body (second commit); re-running the same mutation now fails it. All restored to green.

Closes #847

🤖 Generated with Claude Code


QA follow-up pass (commit 9133875d)

QA found the SEQUANT_NPM_CACHE branch and the bun arm were modified but untested, and that resolving from PM_CONFIG.ciInstall silently dropped npm's --silent. Writing the missing tests surfaced four more npm-shaped assumptions in the same file — all fixed here, each gated by a mutation-verified test.

Fix Why it mattered
cp -r → cp -R on the cache-hit copy BSD cp -r dereferences symlinks. A pnpm node_modules is a farm of relative links into .pnpm/, so the copy was expanded into full 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 because this PR made the branch work for them. -R preserves links on BSD and GNU alike, and is more faithful for npm's own .bin/ entries.
CACHE_DIR 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 — one level below where the worktrees live.
pm_recovery bun defers to pm_lockfile A bun.lock project was told to git commit bun.lockb, a file it does not have — the same wrong-file misdirection AC-3 exists to eliminate.
Next-steps hint uses pm_run The hint hardcoded npm run dev on a package-manager-aware script. pm_run mirrors PM_CONFIG.run (yarn takes no run).
npm ci --silent restored via pm_quiet_flag Applied at the call site, so the ciInstall drift guard still matches PM_CONFIG verbatim. Only npm gets a flag — yarn has no equivalent and pnpm/bun's are untested here.
HASH_FILE → .lockfile-hash The name no longer under-describes its contents. Invalidates any existing cache once; self-heals.

Tests: 7 → 15. New coverage for the cache branch (resolved-lockfile hash, 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 (round 2)

Mutation Expected failure Result
pm_quiet_flag npm --silent → empty quiet-install test ✅ 1/15 failed, exactly that test
pm_recovery bun → hardcoded bun.lockb bun.lock-only AC-3 test ✅ 1/15 failed, exactly that test
pm_run pnpm → npm run next-steps hint + pm_run drift guard ✅ 2/15 failed, exactly those
cp -R → cp -r symlink-preservation test ✅ 1/15 failed, exactly that test
CACHE_DIR → cwd-relative both cache-path tests ✅ 2/15 failed, exactly those
pm_ci_install bun → npm ci bun AC-1 + ciInstall drift guard ✅ 2/15 failed, exactly those

All restored to green (15/15). origin/main merged and the CHANGELOG.md conflict resolved in 2eb9751a.

Two items were deliberately not folded in, as separate follow-ups: the TS-side || "npm" fallback (worktree-manager.ts:541 and :1223 — two sites, not the one the spec named), and yarn install --immutable being Yarn 2+ syntax that Yarn 1 ignores (a pre-existing stacks.ts:103 defect that must be fixed in both paths at once, never one alone).

Round 3 — QA-gap fixes (8cd3717b)

Two residual gaps from the round-2 second look:

Gap Fix
.lockfile-hash was one shared file in ../worktrees/.npm-cache, which every sibling repo under the same parent shares — two projects alternated overwriting it, missing the cache every run (thrash-only: a hit copies the project's own node_modules, so it could never produce a wrong copy) Keyed per project: .lockfile-hash-$(basename "$MAIN_REPO_DIR")
A manifest-only project (package.json, no lockfile) falls back to npm; npm ci fails because it requires a lockfile, and the error said "The committed package-lock.json is out of sync" — describing a file that doesn't exist frozen_install branches on the resolved lockfile's existence: missing → No <lockfile> found — <cmd> requires a committed lockfile; present → the out-of-sync wording. Recovery command unchanged (it generates the lockfile either way)

Tests: 15 → 17 (manifest-only error wording; stale shared-name hash file is not read as a cache hit).

Mutation verification (round 3)

Mutation Expected failure Result
HASH_FILE → shared .lockfile-hash keyed-hash-write, cache-hit (pre-seeds keyed file), shared-file-ignored tests ✅ 3/17 failed, exactly those
missing-lockfile branch removed (always "out of sync") manifest-only AC-3 test ✅ 1/17 failed, exactly that test

Restored to green (17/17) between and after mutations.

admarble added 2 commits July 29, 2026 10:39
…ge 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
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
admarble added 2 commits July 29, 2026 21:04
…re-sh-hardcodes-npm-ci-while-the-ts-path-

# Conflicts:
#	CHANGELOG.md
…ions 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.
…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
admarble merged commit 5cbd5f3 into main Jul 30, 2026
5 checks passed
@admarble
admarble deleted the feature/847-new-feature-sh-hardcodes-npm-ci-while-the-ts-path- branch July 30, 2026 03:08
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.

new-feature.sh hardcodes npm ci while the TS path is package-manager aware — pnpm/yarn/bun provisioning fails misleadingly

1 participant