Skip to content

fix(worktree): npm ci runs at the worktree root even when the package lives in a subdirectory — EUSAGE on every provision #1243

Closed

Description

@admarble

What

In a repo whose Node package lives in a subdirectory (e.g. agent/package.json + agent/package-lock.json, with no package.json at the repo root), every worktree sequant run provisions prints:

!  Dependency install failed (npm ci): npm error code EUSAGE
npm error The `npm ci` command can only install with an existing package-lock.json …

Phases then start with no node_modules anywhere in the worktree. Seen in 4/4 and 2/2 worktrees across two sequant run batches in admarble/varius on 2026-09-30 (sequant 2.18.0; banner Stack unknown).

Root cause

src/lib/workflow/worktree-manager.ts (~L760) runs pmConfig.ciInstall with cwd: worktreePath unconditionally for npm. pip and uv already resolve ciInstall to CI_INSTALL_SKIP when there's nothing to install (#1196 AC-2, #1217), but npm has no equivalent guard for a missing root lockfile or package.json.

Proposed

  1. Minimum: when neither package.json nor a lockfile exists at the worktree root, resolve npm's ciInstall to CI_INSTALL_SKIP and print "Skipping dependency install — no package.json at the worktree root", the same way pip does.
  2. Optional: a run.installDir (or detected single-subdirectory package) setting so the install runs where the package actually is.

Acceptance Criteria

  • AC-1: A worktree whose root has no package.json or lockfile logs a skip, not Dependency install failed, and returns true. Evidence: npx vitest run src/lib/workflow/worktree-manager.test.ts -t "no root package.json" reports ≥ 1 passed, 0 failed (mutation-verified: removing the guard reintroduces the npm ci call).
  • AC-2: A root with package.json + package-lock.json still runs npm ci (unchanged). Evidence: an existing or added test in the same file passes.

Non-Goals

  • Workspace or monorepo install orchestration beyond the optional installDir.

🤖 Generated with Claude Code

Activity

  1. admarble commented on Oct 8, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (2 ACs, 2 directories)

    Key finding: the root cause is already fixed on main

    The report was taken on sequant 2.18.0. #1196 (ded03e54, first in v2.19.0) added hasManifestForPackageManager() (src/lib/stacks.ts:397) and a guard in installWorktreeDeps (src/lib/workflow/worktree-manager.ts ~L732). With no root package.json, it logs Skipping dependency install — no manifest found for npm and returns true. That covers the agent/package.json layout from varius. Two tests already pin it: worktree-manager.test.ts:~195 and worktree-manager.frozen-install.test.ts:249.

    What is left:

    1. The log text differs from the issue ("no manifest found for npm" vs "no package.json at the worktree root"). The message is less helpful for the subdirectory layout.
    2. AC-1's Evidence: filter (-t "no root package.json") matches no existing test name. It cannot pass until a test with that name exists, so the AC is checkable only after work.
    3. Root package.json present but no lockfile still hits npm ci EUSAGE. That case is intentionally a loud failure (frozen-install.test.ts:99) and is outside this issue's AC.

    AC Quality Check

    • AC-1 Evidence is non-vacuous (fails today, 0 tests match). The "mutation-verified" claim needs the marker in the PR body, naming the test file path first.
    • AC-2 Evidence is vague ("an existing or added test"). Tighten it to worktree-manager.frozen-install.test.ts > "spawns npm ci…" (L52), which already passes. It gates nothing new, so it is a regression pin only.
    • Non-Goals present.

    Scope Assessment

    Features 1, ACs 2, directories 2. ✅ SCOPE_OK. Optional item 2 (run.installDir) is deferred (see Open Questions).

    Acceptance Criteria

    AC-1: no root package.json or lockfile → skip logged, returns true

    Verification: Unit Test
    Scenario: Given a tmp dir with only agent/package.json + agent/package-lock.json → When installWorktreeDeps(dir, undefined, false) → Then true, no non-git spawn, log contains no package.json at the worktree root.
    Assumptions: the -t filter string must appear in the new test title.

    AC-2: root package.json + package-lock.json still runs npm ci

    Verification: Unit Test (existing, frozen-install.test.ts:52)

    Implementation Plan

    1. worktree-manager.ts: in the skip branch, for Node package managers print Skipping dependency install — no package.json at the worktree root (keep the "no manifest found for " wording for Python PMs, or fold both into a helper). Check that the existing toContain("no manifest found") assertion at worktree-manager.test.ts ~L197 is updated in the same change.
    2. worktree-manager.test.ts: add it("skips … no root package.json …") for the subdirectory-package layout. Assert the spawn mock is not called for a non-git command.
    3. Mutation-verify: remove the guard, confirm that test fails, restore, and record the Mutation-verified: marker with the file path first.
    4. Check templates/scripts/new-feature.sh for the same unconditional npm ci (it mirrors the pm_ci_install table). If it lacks a manifest guard, note it as a follow-up.

    Design Review

    1. Where does this belong? installWorktreeDeps, the single install site. The guard already lives there.
    2. Simplest approach? Message and test only. Rejected: re-implementing the guard in stacks.ts npm ciInstall via CI_INSTALL_SKIP. The existing pre-check already precedes it, so that would duplicate it.
    3. Pattern / recurrence? Manifest-skip pattern: fix(worktree): TS provisioning runs npm ci / pip install -q in repos with no manifest to install from — the shell path guards, TS doesn't #1196 (pip/non-Node), fix(stacks): uv ciInstall is a bare uv pip install -q — use uv sync --frozen with uv.lock, else requirements or skip #1217 (uv), fix(stacks): detectPackageManagerSync is JS-only — a uv/poetry repo without a declared packageManager resolves to npm and skips its install #1231 (JS-only detection). This is the 4th touch of provisioning install. It is a separate branch of the same guard, not a re-patch of the same line, so extend that guard rather than adding a parallel one.
    4. Reviewer challenge: "Isn't this already fixed?" Yes. The PR should say so, narrow to the message and a named test, and close the issue.
    5. Producers/consumers: the install guard is read by ensureWorktree and the rebase re-install path (frozen-install.test.ts). new-feature.sh is a second producer of worktree installs (see step 4).

    Open Questions

    1. Close as mostly-fixed, or implement run.installDir? Recommendation: implement only the message and test now; file installDir separately if the user still wants installs inside a subdirectory. Impact if wrong: subdirectory repos still get no node_modules, just without an error.
    2. Root package.json but no lockfile: keep the loud npm ci failure? Recommendation: yes (out of scope).

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: small, unit-test-verified change; the bug-style fix needs no testgen.

    Label Review

    Current: none. Recommended: bug. → gh issue edit 1243 --add-label bug

  2. added
    planned
    on Oct 8, 2026
  3. admarble commented on Oct 8, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 2/2 met

    Gaps:

    • Optional run.installDir follow-up (install inside a subdirectory package) has no terminal state — ⚠️ unresolved
    • Python package-manager set is duplicated across two files; a new Python PM would need both updated — dropped: non-blocking polish noted in PR body

    Suggestions:

    • isPython at src/lib/workflow/worktree-manager.ts:737 repeats the pip | poetry | uv check that is already in hasManifestForPackageManager (src/lib/stacks.ts:401). If a new Python manager is added, someone has to update both places. A shared isPythonPackageManager(pm) helper would fix this. The PR body flags the same weakness.
  4. added a commit that references this issue on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    planned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions