Skip to content

ensureWorktree swallows the provisioning install exit status — npm ci failure yields a silent dependency-less worktree #846

Closed

Description

@admarble

Found during pre-2.10.0 release verification.

ensureWorktree runs the provisioning install and discards the result:

// worktree-manager.ts:843-848
const [cmd, ...args] = pmConfig.ciInstall.split(" ");
spawnSync(cmd, args, { cwd: worktreePath, stdio: "pipe" });

No status check. The sibling call site at :1191 does check and warns on failure.

This asymmetry matters more after #816/#826 switched provisioning to a frozen install. npm install used to self-heal a stale or absent lockfile; npm ci hard-fails (exit 1, no node_modules). So a project with no lockfile, or one out of sync with package.json, now yields a silently dependency-less worktree and the failure only surfaces later as a confusing phase error.

Acceptance Criteria

  • AC-1: ensureWorktree checks the install exit status and surfaces a warning naming the failure, matching the sibling site at :1191.
  • AC-2: The warning includes the resolved install command so the user can rerun it.
  • AC-3: A test provisions a worktree in a repo with no lockfile and asserts the failure is reported rather than swallowed.

Activity

  1. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (3 ACs, 1 directory)

    AC Quality Check

    All three ACs are specific and measurable — each names a concrete site (:1191 as the model), a concrete artifact (the resolved command), or a concrete test setup (repo with no lockfile). No vague/unmeasurable/open-ended patterns. ✅

    Scope Assessment

    Non-Goals: Not stated in the issue. Implicit boundary is sound: fix only the swallowed status at ensureWorktree's provisioning install — do not change the frozen-install (npm ci) decision itself (that's #816/#826, deliberate) and do not make a failed install throw/abort (warn-and-continue, matching the sibling at :1191).

    Metric Value Status
    Feature count 1 ✅
    AC items 3 ✅
    Directory spread 1 (src/lib/workflow) ✅

    Verdict: ✅ SCOPE_OK


    Acceptance Criteria

    AC-1: ensureWorktree checks install exit status and surfaces a warning naming the failure (matching :1191)

    Verification: Unit Test
    Scenario: Given a provisioned worktree where the install spawnSync returns status !== 0 → When ensureWorktree runs the provisioning install → Then a chalk.yellow warning is emitted to the console carrying the captured stderr, and the function returns a WorktreeInfo (warn-and-continue, not throw), mirroring reinstallIfLockfileChanged at :1191.
    Assumptions: Provisioning install failure is non-fatal — consistent with the sibling site, which warns and returns rather than aborting.

    AC-2: The warning includes the resolved install command so the user can rerun it

    Verification: Unit Test
    Scenario: Given the same failing install (pm = npm, ciInstall = "npm ci") → When the warning is emitted → Then the message text contains the resolved command string npm ci. Note the sibling at :1191 currently does not print the command — AC-2 requires this site to go one better, so assert the command substring explicitly.
    Assumptions: pmConfig.ciInstall is the exact rerunnable command (already the case: [cmd, ...args].join(" ")).

    AC-3: A test provisions a worktree in a repo with no lockfile and asserts the failure is reported rather than swallowed

    Verification: Unit Test (mocked child_process), or Integration Test (real temp repo) — see Design Review Q2.
    Scenario: Given a repo/worktree with no lockfile so npm ci hard-fails (status: 1, empty node_modules) → When provisioning runs → Then the test asserts the warning was emitted (spy on console.log/captured output), i.e. the failure surfaced, not swallowed.
    Assumptions: With child_process mocked (the existing frozen-install.test.ts pattern), "no lockfile" is simulated by making the install-call mock return status: 1 — no real npm ci, so it stays in the fast unit project.


    Implementation Plan

    Phase 1: Extract a testable install helper (recommended)

    1. In src/lib/workflow/worktree-manager.ts, extract the provisioning install snippet (:842-848) into a small helper, e.g. installWorktreeDeps(worktreePath, packageManager, verbose): boolean, that resolves PM_CONFIG[pm].ciInstall, spawns it, checks result.status, and on failure emits chalk.yellow(" ! Dependency install failed (<cmd>): <stderr>") and returns false (true on success). This mirrors why reinstallIfLockfileChanged is a standalone, directly-drivable function.
    2. Call the helper from ensureWorktree inside the existing if (!existsSync(nodeModulesPath)) block.

    Phase 2: Test (AC-3)

    1. Add a case to src/lib/workflow/worktree-manager.frozen-install.test.ts (or a sibling *.test.ts): mock spawnSync install call to return status: 1, spy on console.log, assert (a) a yellow warning fired and (b) it contains npm ci. Covers AC-1, AC-2, AC-3 in one fast, mocked test.

    Alternative (no extraction): capture const installResult = spawnSync(...) inline in ensureWorktree and add the status check + warning there. Fewer moving parts, but AC-3 then has to drive the whole ensureWorktree (git worktree add, settings copy, …) or mock a large surface — the extraction is what keeps the test cheap and matches the codebase's own precedent.


    Design Review

    1. Where does this logic belong? In worktree-manager.ts, alongside ensureWorktree and reinstallIfLockfileChanged. A dedicated installWorktreeDeps helper is the natural home and de-duplicates the ciInstall.split(" ") + spawn pattern now living at two sites.
    2. What's the simplest correct approach? Check spawnSync(...).status !== 0 and warn — the same three lines reinstallIfLockfileChanged already has. The only judgment call is helper-extraction (testability) vs inline (minimal). Recommend extraction because it's the difference between a fast mocked unit test and a heavy/slow one — see Open Questions.
    3. What existing pattern does this follow? reinstallIfLockfileChanged:1191-1203 — capture result, if (status !== 0) { console.log(chalk.yellow(...)); return false; }. Reuse verbatim, adding the resolved command to the message for AC-2.
    4. What would a senior reviewer challenge? "Why not just fix it inline in five lines?" → because AC-3 demands a test that provisions a worktree; without a drivable helper that test is disproportionately expensive or forces a real npm ci. "Should a failed install abort instead of warn?" → No; the sibling warns-and-continues and the AC says "matching the sibling site," so warn-and-continue is the contract.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • stderr may be empty on some failures — npm ci with no lockfile writes a clear message to stderr, but guard the trim so an empty stderr still yields a useful warning (the resolved command alone is enough to act on). Covered by AC-2's command-in-message requirement.
    • Sibling-site scan: the two ciInstall.split(" ") sites are the reinstall (:1191, already guarded) and this provisioning site (:843, the bug). No third unguarded install site — the cp/settings spawnSync calls are not dependency installs. Scope is complete as written.

    Open Questions

    1. Extract installWorktreeDeps helper vs inline fix? — Recommendation: extract. Impact if inline: AC-3 must mock getGitRoot + git worktree add + settings copy or run a real npm ci, making the test slow/flaky (real subprocess ⇒ must be renamed *.integration.test.ts to escape the 5s unit timeout). Extraction keeps it a fast mocked unit test.
    2. Should the warning respect verbose? — Recommendation: always emit (like :1191), regardless of verbose. A silently dependency-less worktree is exactly the failure this issue exists to make loud; gating it behind verbose would re-bury it.

    Recommended Workflow

    Phases: spec → exec → qa
    Quality Loop: disabled (SCOPE_OK, single-directory bug fix)
    Reasoning: Focused CLI/library bug with clear ACs. Skip testgen — AC-3's single mocked test is written directly in exec against the existing frozen-install.test.ts harness; a stub generator adds no value for one case. No UI ⇒ no test phase. Not security-sensitive.


    Label Review

    Current: (none)
    Recommended: bug
    Reason: Regression-class defect (swallowed exit status) surfaced by the #816/#826 frozen-install switch; single focused fix.
    Quality Loop: Won't auto-enable — SCOPE_OK.

    → gh issue edit 846 --add-label bug

  2. added
    bug
    planned
    on Jul 29, 2026
  3. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    Exec Progress Update

    Implemented per the /spec plan (Phase 1 helper extraction + Phase 2 mocked test).

    AC Coverage

    AC Description Status Evidence
    AC-1 Check install exit status, warn naming the failure (matching :1191) ✅ installWorktreeDeps checks installResult.status !== 0 → chalk.yellow warning carrying trimmed stderr; returns false (warn-and-continue, not throw)
    AC-2 Warning includes the resolved install command ✅ Message Dependency install failed (${command})… with command = [cmd, ...args].join(" "); named even when stderr is empty
    AC-3 Test provisions with no lockfile, asserts failure reported not swallowed ✅ New suite in worktree-manager.frozen-install.test.ts mocks spawnSync → status: 1, spies console.log, asserts warning + npm ci substring

    Implementation

    • src/lib/workflow/worktree-manager.ts — extracted installWorktreeDeps(worktreePath, packageManager, verbose): boolean (marked @internal), mirroring reinstallIfLockfileChanged's status check and adding the resolved command to the message. ensureWorktree's provisioning block now calls it inside the existing if (!existsSync(nodeModulesPath)) guard.
    • src/lib/workflow/worktree-manager.frozen-install.test.ts — added a 3-case suite (failure surfaces stderr + command; command named on empty stderr; success returns true + no warning).
    • CHANGELOG.md — ### Fixed entry under [Unreleased].

    Quality Plan Alignment

    Dimension Addressed Notes
    Error Handling ✅ Empty-stderr guard (command alone is actionable) — Quality Plan item covered by dedicated test case
    Test Coverage ✅ AC-1/2/3 in one fast mocked test; sibling-site scan confirmed no third unguarded install site
    Best Practices ✅ Always emits (not gated behind verbose), per Open Question 2

    Derived ACs: None in spec comment.

    Checks

    Check Result
    npm run build ✅ Passed
    npm run lint ✅ Passed (0 warnings)
    npx vitest run src/lib/workflow/worktree-manager ✅ 14 passed (6 in frozen-install file)

    PR

    Created: #854

  4. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #846

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original ensureWorktree checks install exit status and surfaces a warning naming the failure, matching :1191 ✅ MET installWorktreeDeps (worktree-manager.ts:530) has if (installResult.status !== 0) → chalk.yellow warning carrying trimmed stderr, returns false (warn-and-continue, not throw). ensureWorktree calls it inside the existing !existsSync(node_modules) guard. Mirrors the sibling at :1239.
    AC-2 Original Warning includes the resolved install command ✅ MET Message is Dependency install failed (${command})… where command = [cmd, ...args].join(" ") → npm ci. Named even when stderr is empty (dedicated test).
    AC-3 Original A test provisions with no lockfile and asserts the failure is reported, not swallowed ✅ MET worktree-manager.frozen-install.test.ts: mocks spawnSync → status: 1 (the no-lockfile npm ci hard-fail), spies console.log, asserts the warning fired + surfaces stderr + contains npm ci. Mocked child_process is the sanctioned approach per the /spec plan (keeps it a fast unit test).

    Coverage: 3/3 AC items fully met (0 derived ACs)


    CI Status

    Check State Bucket Impact
    node-floor-guard SUCCESS pass ✅ MET
    validate-plugin SUCCESS pass ✅ MET
    validate-skills SUCCESS pass ✅ MET
    typecheck SUCCESS pass ✅ MET
    build (22.x) SUCCESS pass ✅ MET

    CI Summary: 5 passed, 0 pending, 0 failed (waited for build (22.x) to reach terminal state before finalizing).


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 3 OK
    Lines added +120 -
    Lines deleted -21 -

    Local: npm run build ✅ · npm run lint ✅ (0 warnings) · npx vitest run …worktree-manager ✅ 14 passed.


    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/lib/workflow/worktree-manager.ts Standard ✅ Yes worktree-manager.frozen-install.test.ts (new suite covers the extracted installWorktreeDeps)

    Coverage: 1/1 changed source file has corresponding tests. No critical-path (auth/payment/security) files touched.


    Code Review

    Strengths:

    Issues: None.

    Suggestions: None blocking. The call site intentionally ignores the returned boolean (warn-and-continue), consistent with the sibling — correct, not a defect.


    Call-Site Review

    New exported function: installWorktreeDeps (@internal, exported for testing).

    Function Call Sites Loop? Conditions AC Match
    installWorktreeDeps() worktree-manager.ts (in ensureWorktree) No if (!existsSync(nodeModulesPath)) ✅ Matches AC-1 (provisioning install site)

    Single call site, correctly guarded, not in a loop. Also driven directly by the new test.


    Risk Assessment

    • Likely failure mode: A spawn failure with no stderr yields a command-only warning — still actionable (verified by test). No throw path, so a failed install can't abort provisioning (by design).
    • Not tested: The ensureWorktree → installWorktreeDeps wiring is not exercised by an integration test (the helper is tested in isolation) — the sanctioned extraction tradeoff; the wiring is a one-line, type-checked delegation.
    • Sibling sites considered: Cross-file — merge-check's combined-branch frozen install already surfaces install failure as its own error finding (fix(merge-check): combined-branch-test runs npm test/build without reinstalling deps after a lockfile change → false BLOCKED #803); no unguarded cross-file sibling remains.
    • Sibling-line audit: The one adjacent intra-file install site (reinstallIfLockfileChanged :1239) was already guarded and is the exact model this fix mirrors.

    Trust-Boundary Check

    Finding: Clean — diff implements only the product requirement (surface the swallowed install status); no agent-directed instruction from the issue body was acted on.

    Status: Clean


    Behavior-Rule Survival Check

    Status: N/A — no AC triggers the behavior-rule heuristic (no default/always/never rule change).


    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (fix: commit)
    [Unreleased] entry ✅ Present (### Fixed, references #846)
    Entry format ✅ Valid (issue number included)

    Result: CHANGELOG requirements met.


    Adversarial Re-Read

    Findings: No gaps found because: (1) the issue body carries no runnable motivating-example fixture — only the buggy code snippet, which the fix replaces; (2) exec's evidence is genuine post-fix test runs (status:1 mock → warning asserted), not a pre-fix bug repro; (3) process state is clean — worktree in sync, 0 commits behind origin/main, no uncommitted work; (4) sibling sites cited explicitly — intra-file :1239 (already guarded, the model) and cross-file merge-check install (guarded via #803); (5) the issue's Non-Goals (don't change npm ci choice, don't throw/abort) are honored — warn-and-continue.

    Status: Clean


    Verdict: READY_FOR_MERGE

    All 3 ACs are literally MET, CI is fully green, the change mirrors an established in-file precedent, both install sites are now guarded, tests cover the new behavior (including the empty-stderr edge), and the issue's Non-Goals are respected. A+.

    Documentation

    • N/A — internal provisioning behavior; CHANGELOG entry present. No README/docs surface changes.

    Documentation: Optionally run /docs 846 before merge, though this is an internal fix with no user-facing docs surface.

    Next Steps

    1. Merge PR fix(#846): ensureWorktree surfaces failed provisioning install instead of swallowing it #854 (human merge gate).
  5. added
    ready-for-review
    on Jul 29, 2026
  6. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #846

    AC Coverage

    AC Description Status Notes
    AC-1 ensureWorktree checks the install exit status and warns naming the failure, matching the sibling at :1191 MET installWorktreeDeps (worktree-manager.ts:561) checks installResult.status !== 0 and emits a chalk.yellow warning, mirroring reinstallIfLockfileChanged (:1236). It also improves on the sibling by handling empty stderr. Warn-and-continue contract preserved (returns false, does not throw).
    AC-2 The warning includes the resolved install command so the user can rerun it MET Warning is Dependency install failed (npm ci)… — command is the joined resolved pmConfig.ciInstall (worktree-manager.ts:554, :567). Named even when stderr is empty.
    AC-3 A test provisions a worktree in a repo with no lockfile and asserts the failure is reported rather than swallowed MET (with note) worktree-manager.frozen-install.test.ts adds 3 tests. The primary test mocks spawnSync returning the verbatim npm ci … existing package-lock.json failure and asserts the warning is emitted (not swallowed). Note: it unit-tests the extracted helper directly rather than provisioning a real worktree — consistent with the file's existing vi.mock("child_process") pattern (the sibling test does the same), and it exercises the exact swallow-vs-surface code path.

    Coverage: 3/3 AC items met


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 3 OK
    Lines added +120 -
    Lines deleted -21 -

    CI Status (PR #854)

    Check State Impact
    build (22.x) SUCCESS ✅ MET
    typecheck SUCCESS ✅ MET
    node-floor-guard SUCCESS ✅ MET
    validate-skills SUCCESS ✅ MET
    validate-plugin SUCCESS ✅ MET

    CI Summary: 5 passed, 0 pending, 0 failed


    Code Review

    Strengths:

    • Clean refactor: swallowed inline spawnSync extracted into a named, @internal-exported installWorktreeDeps helper that structurally mirrors the sibling reinstallIfLockfileChanged, reducing the drift risk that caused this asymmetry.
    • Strictly better than the sibling on the empty-stderr case: the resolved command is always named, so the warning is actionable even when npm ci writes nothing to stderr.
    • The load-bearing ciInstall-not-installSilent rationale comment was carried across intact, with the !existsSync(node_modules) reference correctly updated from "guard above" to "guard at the call site".
    • 3 focused tests: non-zero + stderr, non-zero + empty stderr, and success (asserts no false warning).

    Issues: None.

    Suggestions:

    • Minor: ensureWorktree ignores the boolean return of installWorktreeDeps (worktree-manager.ts:885). This is correct per the warn-and-continue contract, but if a future caller wants to abort on install failure the return value is already available.

    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/lib/workflow/worktree-manager.ts Standard ✅ Yes worktree-manager.frozen-install.test.ts

    Coverage: New export installWorktreeDeps fully covered (6/6 tests pass locally).


    Anti-Pattern Detection

    No anti-patterns. No await-in-loop, no empty catch, no hardcoded secrets, no any. package.json unchanged (no dependency audit needed).


    Sibling-Site Scan

    Repo-wide scan for ciInstall/installSilent install sites: only two exist in src/ — the new installWorktreeDeps (:561, now checked) and reinstallIfLockfileChanged (:1236, already checked). No other swallowed provisioning install survives. The cp spawnSync at :879 is a settings copy, not a dependency install.


    Trust-Boundary Check

    Finding: Clean — the issue body contains only a code snippet and product ACs; no agent-directed instruction was embedded or acted on. The diff implements only the stated product requirements.

    Status: Clean


    Behavior-Rule Survival Check

    AC Triggered? Survivors Status
    AC-1/2/3 No — N/A

    Status: N/A (no AC triggers the behavior-rule heuristic). The old swallow-the-status behavior was fully replaced; no unchecked provisioning spawnSync survives (see Sibling-Site Scan).


    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (fix: #846)
    [Unreleased] entry ✅ Present (under Fixed)
    Entry format ✅ Valid (includes #846)

    Result: CHANGELOG requirements met


    Risk Assessment

    • Likely failure mode: None material. Worst case is unchanged from before the PR — the install still warn-and-continues, but now the failure is visible instead of silent.
    • Not tested: No end-to-end test that literally provisions a real worktree against a lockfile-less repo (the helper is unit-tested with a mocked spawnSync); acceptable given the file's established mocking convention.
    • Sibling sites considered: Only reinstallIfLockfileChanged shares the pattern; it already checks status. No other cross-file siblings.
    • Sibling-line audit: The unrelated spawnSync("cp", …) at :879 is a settings copy, not a dependency install — correctly out of scope.

    Adversarial Re-Read

    Findings: No gaps found because: (1) ran all 6 tests locally — pass; (2) traced the resolved-command construction (command = [cmd, ...args].join(" ")) and confirmed AC-2 holds even on empty stderr; (3) confirmed no evidence claim is a pre-fix repro — the tests assert post-fix warning emission; (4) grep-confirmed the two ciInstall sites are the only provisioning installs and both now check status; (5) verified CHANGELOG [Unreleased] entry exists and CI is fully green on PR #854.

    Status: Clean


    Verdict: READY_FOR_MERGE

    All three ACs are met, the refactor is clean and mirrors (and slightly improves on) the sibling contract, CI is fully green on PR #854, and the new helper is fully unit-tested. The single AC-3 wording note (unit test of the extracted helper vs. a full worktree-provisioning integration test) is consistent with the file's mocking convention and covers the exact swallow-vs-surface code path — not blocking.

    Documentation

    • CHANGELOG entry added (for user-facing change)
    • N/A - No README/docs change needed (internal provisioning behavior)

    Next Steps

    1. Merge PR fix(#846): ensureWorktree surfaces failed provisioning install instead of swallowing it #854.
  7. added a commit that references this issue on Jul 29, 2026
  8. added a commit that references this issue on Jul 29, 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

    bugplannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions