Skip to content

worktree-manager's bare || "npm" fallback disagrees with the PM-aware shell path on manifest-less projects #870

Closed

Description

@admarble

Found by QA on #847 / PR #859.

ensureWorktree's package-manager resolution falls back to a bare string literal instead of detecting:

const pm = (packageManager as keyof typeof PM_CONFIG) || "npm";

This appears at two sites in src/lib/workflow/worktree-manager.ts — :541 and :1223. #847's spec named only :541; the second was found during QA of that PR.

packageManager comes from the worktree manifest, which is a snapshot taken at sequant init. When it is absent (manifest-less or pre-init worktree), the TS path assumes npm while the shell path (templates/scripts/new-feature.sh, PM-aware since #847) detects live from the lockfile. On a pnpm/yarn/bun project without a manifest the two provisioning paths now disagree about which package manager the project uses — the same dual-producer drift class as #833.

Acceptance Criteria

  • AC-1: Both sites in worktree-manager.ts resolve the package manager via detectPackageManagerSync(worktreePath) when the manifest value is absent, instead of falling back to the literal "npm".
  • AC-2: A manifest-less pnpm worktree provisions through the TypeScript path using pnpm's frozen install, matching what new-feature.sh would run for the same project.
  • AC-3: A unit test pins the manifest-absent case for at least one non-npm package manager, so a future revert to the bare || "npm" fails.

Activity

  1. added
    bug
    on Jul 30, 2026
  2. admarble commented on Jul 30, 2026

    @admarble
    ContributorAuthor

    Lineage (duplicate check)

    Not a duplicate, but this is a continuation of #487 — worth reading first.

    #487 ("Use detected package manager in CLI messages and docs", closed 2026-04-06) is the issue that introduced detectPackageManagerSync(), specifically so synchronous startup code could resolve the PM instead of hardcoding npm. It then converted an inventory of npm-hardcoded sites: version-check.ts:225, bin/cli.ts:80, bin/cli.ts:307, plus README and docs.

    worktree-manager.ts was not in that inventory. The two sites here are the same principle applied to sites #487 missed — which is also why the fix is a one-liner per site rather than new machinery: detectPackageManagerSync already exists and is already the established answer.

    Related: #816 introduced the frozen-install resolution these two sites feed; #847 made the shell provisioning path PM-aware, which is what exposed the disagreement.

  3. admarble commented on Jul 30, 2026

    @admarble
    ContributorAuthor

    Plan (/spec)

    Complexity: Standard (3 ACs, 1 directory)

    AC Quality Check

    3/3 pass — no vague, unmeasurable, or open-ended patterns. AC-1 names both call sites, AC-2 names the concrete PM and the cross-path invariant, AC-3 names the mutation that must fail.

    Scope Assessment

    Non-Goals: not stated in the issue body. Inferred from AC-1's wording ("Both sites in worktree-manager.ts"): the three sibling sites in src/commands/update.ts are out of scope — see Open Question 1.

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

    Verdict: ✅ SCOPE_OK


    Acceptance Criteria

    AC-1: Both sites resolve via detectPackageManagerSync(worktreePath) when the manifest value is absent
    Verification: Unit Test
    Scenario: Given installWorktreeDeps(path, undefined, …) / reinstallIfLockfileChanged(path, undefined, …) on a worktree whose lockfile is pnpm-lock.yaml → When the install spawns → Then the command is pnpm's, not npm's.
    Assumptions: both functions already receive worktreePath, so no signature change is needed (verified: worktree-manager.ts:532-536, :1176-1182). The worktree is checked out before either runs, so its lockfile is on disk and detectable.

    AC-2: A manifest-less pnpm worktree provisions with pnpm's frozen install, matching new-feature.sh
    Verification: Unit Test
    Scenario: Given a real temp dir containing only pnpm-lock.yaml → When installWorktreeDeps(dir, undefined, false) runs → Then it spawns pnpm install --frozen-lockfile, which is byte-identical to pm_frozen_install's pnpm) branch in templates/scripts/new-feature.sh:211.
    Assumptions: PM_CONFIG.pnpm.ciInstall remains the single source both paths mirror (already asserted for the shell side by new-feature-frozen-install.integration.test.ts).

    AC-3: A unit test pins the manifest-absent case for a non-npm PM
    Verification: Unit Test + recorded mutation result
    Scenario: Given the AC-2 test → When resolvePackageManager is reverted to the bare || "npm" → Then exactly that test fails.
    Assumptions: per CLAUDE.md's gate-test rule, the mutation is run and its result recorded in the PR body — the test does not count as coverage otherwise.


    Implementation Plan

    Phase 1: Add the resolver (source of truth)

    1. Add resolvePackageManager(declared: string | undefined, root: string): PackageManager to src/lib/stacks.ts, beside detectPackageManagerSync:
      export function resolvePackageManager(
        declared: string | undefined,
        root: string,
      ): PackageManager {
        if (declared && declared in PM_CONFIG) return declared as PackageManager;
        return detectPackageManagerSync(root);
      }
      The declared in PM_CONFIG guard also retires the unsafe as keyof typeof PM_CONFIG cast: today a manifest holding an unrecognized string (say "npm@10") makes PM_CONFIG[pm] undefined and pmConfig.ciInstall throw a TypeError. Membership-checking routes that to detection instead. Python PMs (pip/poetry/uv) are PM_CONFIG keys, so a declared Python PM still wins over the JS-only detector — no regression for Python projects.

    Phase 2: Convert both call sites

    1. worktree-manager.ts:541 (installWorktreeDeps) → const pmConfig = PM_CONFIG[resolvePackageManager(packageManager, worktreePath)];
    2. worktree-manager.ts:1223 (reinstallIfLockfileChanged) → same substitution.

    Both already hold worktreePath; no signature or caller changes.

    Phase 3: Tests

    1. Extend src/lib/workflow/worktree-manager.frozen-install.test.ts (already mocks child_process and drives both functions): add manifest-absent cases using a real temp dir containing pnpm-lock.yaml, asserting the spawned command is pnpm install --frozen-lockfile. A real temp dir avoids mocking fs — detectPackageManagerSync uses existsSync, and the existing child_process mock keeps the install from actually running.
    2. Add direct unit tests for resolvePackageManager: declared-and-known wins; declared-but-unknown falls through to detection; absent falls through to detection; no-lockfile still yields npm.
    3. Mutation-verify per CLAUDE.md: commit first, revert the resolver to || "npm", confirm exactly the AC-2/AC-3 tests fail, restore, record in the PR body.

    Design Review

    1. Where does this logic belong? src/lib/stacks.ts — it already owns PM_CONFIG, LOCKFILE_PRIORITY, and detectPackageManagerSync, and new-feature.sh explicitly names it "SOURCE OF TRUTH". Putting the resolver anywhere else creates a third producer of PM decisions, which is the failure mode this issue is about.
    2. What's the simplest correct approach? Rejected: inlining packageManager ?? detectPackageManagerSync(worktreePath) at both sites. It satisfies AC-1 literally but duplicates the rule at two sites — recreating the drift class in miniature — and leaves the unsafe cast in place. One shared 4-line function costs nothing more.
    3. What existing pattern does this follow? merge-check/combined-branch-test.ts:139, which already calls detectPackageManagerSync(repoRoot) with an explicit root rather than trusting a snapshot. Same shape, same reason.
    4. What would a senior reviewer challenge? "Why not fix the update.ts sites in the same PR?" — see Open Question 1; the helper is deliberately shaped so that change is a one-liner per site whenever it is scheduled.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • No behavior-rule ACs triggered the touchpoint detector — this is runtime TypeScript only, with no skill-prompt duplicate to keep in sync.
    • Behavior change is real but narrow: a manifest-less npm project is unaffected (detection returns npm, same as the old literal). Only pnpm/yarn/bun manifest-less worktrees change, and they change from broken to correct.
    • Risk noted for QA: detectPackageManagerSync defaults to npm when no lockfile at all is present, so a lockfile-less worktree keeps today's behavior — npm ci fails loudly there, which installWorktreeDeps already surfaces (ensureWorktree swallows the provisioning install exit status — npm ci failure yields a silent dependency-less worktree #846).

    Open Questions

    1. Should the three sibling sites in src/commands/update.ts (:113, :128, :296) be fixed in this PR? They carry the byte-identical (manifest.packageManager as keyof typeof PM_CONFIG) || "npm" pattern and are the same drift class, but they run against the project root rather than a worktree and AC-1 scopes this issue to worktree-manager.ts. — Recommendation: file a follow-up issue rather than widen here; the new resolver makes each one a single-line change. Impact if wrong: sequant update keeps writing an npm PM_RUN token and running npm install on manifest-less pnpm/yarn/bun projects until the follow-up lands.

    Recommended Workflow

    Phases: spec → exec → qa
    Quality Loop: disabled (SCOPE_OK, 3 ACs, single-file logic change)
    Reasoning: bug label with a targeted fix → no testgen phase (tests are written directly as part of exec). No UI surface → no test phase.


    Label Review

    Current: bug
    Recommended: bug (unchanged)
    Reason: correctly classified; no UI/frontend surface, and scope is small enough that no complexity label applies.

  4. added
    planned
    on Jul 30, 2026
  5. added 2 commits that reference this issue on Jul 30, 2026
  6. admarble commented on Jul 30, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #870

    PR: #874 · Reviewed commit: b510669a

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original Both sites resolve via detectPackageManagerSync(worktreePath) when the manifest value is absent MET worktree-manager.ts:544 and :1228, both PM_CONFIG[resolvePackageManager(packageManager, worktreePath)]. Grep confirms exactly two non-test call sites and no surviving || "npm" in the file. Neither function needed a signature change — both already held worktreePath.
    AC-2 Original Manifest-less pnpm worktree provisions with pnpm's frozen install, matching new-feature.sh MET Verified by execution, not inspection: the test drives installWorktreeDeps against a real temp dir containing only pnpm-lock.yaml and asserts the spawned argv is pnpm install --frozen-lockfile — byte-identical to pm_frozen_install's pnpm) branch (new-feature.sh:211). Both sides read PM_CONFIG.pnpm.ciInstall, so they cannot drift silently.
    AC-3 Original Unit test pins the manifest-absent case for a non-npm PM, so a revert to || "npm" fails MET Mutation-verified twice — see below.

    Coverage: 3/3 met. Derived ACs: none (no Derived ACs table in the spec plan).


    Mutation verification

    Two independent mutations, each run after committing (so git checkout could restore cleanly):

    1. Revert the resolver body to the bare fallback (return (declared as PackageManager) || "npm";)

    × resolvePackageManager > detects from the lockfile when no manager is declared
    × resolvePackageManager > detects from the lockfile when the declared value is empty
    × resolvePackageManager > detects rather than crashing when the declared value is not a known manager
    × resolvePackageManager > resolves against the given root, not the process cwd
    × manifest-less worktrees (#870) > installWorktreeDeps runs pnpm's frozen install …
    × manifest-less worktrees (#870) > reinstallIfLockfileChanged runs yarn's frozen install …
    Tests  6 failed | 11 passed (17)
    

    2. Revert hasOwnProperty to in

    × routes the inherited Object.prototype key "toString" to detection
    × routes the inherited Object.prototype key "constructor" to detection
    × routes the inherited Object.prototype key "valueOf" to detection
    × routes the inherited Object.prototype key "hasOwnProperty" to detection
    × routes the inherited Object.prototype key "__proto__" to detection
    Tests  5 failed | 17 passed (22)
    

    In both cases exactly the intended tests fail and every pre-existing test still passes — the gates are real and scoped, not incidentally-passing assertions.


    Defect found and fixed during this review

    The first implementation used declared in PM_CONFIG. in walks the prototype chain, so "toString", "constructor", "valueOf", "hasOwnProperty", and "__proto__" all passed the membership test and were returned as if they named a package manager. Indexing PM_CONFIG with one yields an inherited function (or Object.prototype) whose ciInstall is undefined. Confirmed by execution, not reasoning:

    resolved pm = toString | typeof cfg = function | cfg.ciInstall = undefined
    DOWNSTREAM CRASH: Cannot read properties of undefined (reading 'split')
    

    That is an uncaught TypeError during worktree provisioning — the exact crash class the guard was added to close, reintroduced one layer down, while the code comment, commit message, and CHANGELOG all claimed it was closed. Fixed in 8165b530 with Object.prototype.hasOwnProperty.call, a table-driven gate test over all five keys, and corrected wording in all three places.


    CI Status

    Check State Bucket Impact
    build (22.x) SUCCESS pass MET — this job runs npm test (ci.yml:36)
    typecheck SUCCESS pass MET
    validate-skills SUCCESS pass MET
    validate-plugin SUCCESS pass MET
    node-floor-guard SUCCESS pass MET

    CI Summary: 5 passed, 0 pending, 0 failed. Branch is 0 commits behind origin/main; mergeable: MERGEABLE.


    Local test suite — one flake, investigated rather than waved through

    The local full suite failed once with mcp-e2e.integration.test.ts > AC-8: should disconnect SSE client cleanly on SIGTERM (4107 ms). Rather than assume, four measurements:

    Run Result
    Branch, full suite (1st) 4707 passed, 0 failed
    Branch, full suite (2nd, 3rd) 1 failed — the SIGTERM test
    Branch, that file in isolation 8/8 passed
    main, full suite (same machine, same conditions) 4 failed — a different set (cli.integration.test.ts flag-surface tests); the SIGTERM test passed

    main is worse than the branch under identical load, the failing set is not stable across runs, and the file passes in isolation on both branches. These are pre-existing load-dependent integration flakes on this machine, not a regression — and CI's build (22.x), which runs the same npm test, is green on this commit.


    Quality Metrics

    Metric Value Status
    Type issues (any added) 0 OK
    Deleted tests 0 OK
    Files changed 6 OK
    Lines added / deleted +231 / −11 OK
    Security patterns in added lines 0 OK

    Test Coverage Analysis

    Changed file Tier Has tests?
    src/lib/stacks.ts Standard Yes — stacks.resolve-package-manager.test.ts (12 cases)
    src/lib/workflow/worktree-manager.ts Standard Yes — worktree-manager.frozen-install.test.ts (+4 cases at both call sites)
    CHANGELOG.md, docs/features/package-manager-detection.md Optional N/A (docs)

    Coverage: 2/2 changed source files covered. No critical-path (auth/payment/security) files touched.

    The tests use a real temp directory rather than an fs mock, because detectPackageManagerSync reads the filesystem through existsSync — mocking it would have tested the mock. child_process stays mocked, so no install actually runs.


    Call-Site Review

    New exported function: resolvePackageManager — 2 call sites, both in worktree-manager.ts, neither in a loop, both passing worktreePath (not process.cwd()). A dedicated test pins the root-vs-cwd distinction, since passing the wrong root would report the manager of whatever repo the CLI happens to run from. No dead export.

    Ordering verified: installWorktreeDeps is called at worktree-manager.ts:887, after the worktree is created and env files are copied — so the lockfile is on disk when detection runs. Detection before checkout would have silently degraded to npm.


    Behavior change surface

    Deliberately narrow, and each boundary is pinned by a test:


    Risk Assessment

    • Likely failure mode: a project whose worktree lockfile disagrees with the manifest (e.g. migrated pnpm→npm without re-running sequant init) now installs per the lockfile rather than the manifest. This is the intended direction, but it is a behavior change for that population; the frozen install fails loudly rather than corrupting state, so the blast radius is a clear error message.
    • Not tested: no end-to-end provisioning test against a real pnpm/yarn/bun project — child_process is mocked, so the assertion is on the argv, not on a real install succeeding. Acceptable: the argv is the contract shared with new-feature.sh, and a real multi-PM install matrix is disproportionate to a one-line resolution fix.
    • Sibling sites considered: src/commands/update.ts:113, :128, :296 carry the byte-identical pattern. Out of AC-1's stated scope (which names worktree-manager.ts) and operating on the project root rather than a worktree. Surfaced as Open Question 1 in the plan and as a known gap in the PR body, with a follow-up recommended — not silently widened. Precheck's cross-file sibling-grep on resolvePackageManager returned 0 additional sites.
    • Sibling-line audit: both intra-file sites in worktree-manager.ts were converted together — the issue itself was filed because new-feature.sh hardcodes npm ci while the TS path is package-manager aware — pnpm/yarn/bun provisioning fails misleadingly #847's spec named only one of them. No third occurrence remains (grep-verified).

    Trust-Boundary Check

    Finding: Clean — the issue body is a bug report and the single comment is a lineage note referencing #487/#816. Neither contains agent-directed instructions (no command execution, network access, file reads, or instruction overrides). The diff implements only the stated product requirement.

    Status: Clean


    Behavior-Rule Survival Check

    AC Triggered? Survivors Status
    AC-1 / AC-2 / AC-3 No (detector run on each, all triggered: false) — N/A

    Status: N/A — no AC meets the behavior-rule heuristic, so there is no old-rule implementation to check for survival.


    Precheck Findings

    Section Status Surfaced
    Fixtures pass No motivating-example fixtures in the issue body (it quotes the defective line, not an input/output pair)
    Sibling-grep pass resolvePackageManager — 0 sibling sites
    AC literal-diff pass Issue lists AC-1/2/3; PR body carries all three — missingInPR: []

    Source: .sequant/gap-precheck.json (schemaVersion 1)


    Execution Evidence

    Not Required — no files under scripts/ or templates/scripts/ changed. new-feature.sh is referenced as the parity target but is not modified.


    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists Found
    User-facing changes Yes (fix: commits)
    [Unreleased] entry Present, under ### Fixed
    Entry format Valid — includes (#870), and was corrected when the in→hasOwnProperty defect was fixed so it no longer overclaims

    Result: CHANGELOG requirements met.


    Adversarial Re-Read

    Findings: The prototype-chain defect above was found by this pass and fixed in-PR — the structured checks (types, security, scope, size, CI) were all green while a real uncaught TypeError sat in the diff, which is precisely the "clean code biases QA positive" failure mode. Also found and fixed: docs/features/package-manager-detection.md:157 still told users "Sequant defaults to npm" when the manifest field is missing, which this change makes false for the provisioning path; the sentence was scoped rather than deleted, since it remains true for sequant update. Additionally traced: the flake was measured against a main baseline instead of being asserted unrelated; call ordering was checked so detection cannot run before the lockfile is on disk; the root-vs-cwd argument was pinned by a test; Python-manager preservation was verified rather than assumed. No Non-Goals from the issue body have expanded into scope — the update.ts siblings were explicitly left out and flagged.

    Status: Gaps Found (both surfaced gaps were fixed within this PR; no unmet AC remains)


    Verdict: READY_FOR_MERGE

    All three ACs are literally met and verified by execution rather than inspection. Both gaps this review surfaced — the in-vs-hasOwnProperty crash and the stale docs claim — were fixed inside the PR rather than deferred, each with its own commit, and the crash fix carries its own mutation-verified gate test. CI is green on b510669a, the branch is current with main, and the one local test failure was measured against a main baseline that is strictly worse under the same conditions.

    One deliberate scope boundary remains, and it is the reviewer's call rather than a defect: the three identical sites in src/commands/update.ts are left for a follow-up, so sequant update keeps assuming npm on manifest-less pnpm/yarn/bun projects until that lands. resolvePackageManager is shaped so each is a one-line change.

    Documentation

    • docs/features/package-manager-detection.md corrected (the change made its manifest-less claim stale)
    • CHANGELOG [Unreleased] → Fixed entry added
    • README — N/A (no user-facing flag or command added)

    Next Steps

    1. Merge PR fix(#870): resolve worktree package manager from lockfile when manifest is absent #874.
    2. File the follow-up for src/commands/update.ts:113/:128/:296 — same pattern, one line each with the new resolver.
  7. admarble commented on Jul 30, 2026

    @admarble
    ContributorAuthor

    /fullsolve Complete

    Issue: #870 · PR: #874 · Verdict: READY_FOR_MERGE

    Progress

    Phase Iterations Status
    Spec 1/1 Complete — Standard tier, SCOPE_OK, 3 ACs
    Exec 1/1 Complete
    Test — Skipped (no UI surface; bug label only)
    QA 1/2 Complete — 2 gaps found and fixed in-PR, no loop iteration needed

    AC Coverage

    3/3 MET, each verified by execution rather than inspection, and each pinned by a mutation-verified gate test.

    Commits

    SHA Change
    94d963e7 Both worktree-manager.ts sites resolve through the new resolvePackageManager
    8165b530 hasOwnProperty instead of in — QA found the prototype-chain crash
    b510669a Corrected the now-stale docs claim in package-manager-detection.md

    Gaps found by QA and fixed inside the PR

    1. Prototype-chain crash. The first implementation's declared in PM_CONFIG test let "toString", "constructor", "valueOf", "hasOwnProperty", and "__proto__" through, producing an uncaught TypeError: Cannot read properties of undefined (reading 'split') during worktree provisioning — the exact crash class the guard was added to close, while the comment, commit message, and CHANGELOG all claimed it was closed. All structured checks were green at the time.
    2. Stale documentation. docs/features/package-manager-detection.md:157 still said "Sequant defaults to npm" for a missing manifest field, which this change makes false for the provisioning path.

    Verification

    • CI: 5/5 green on b510669a. build (22.x) runs npm test (ci.yml:36), so the suite passed in CI.
    • Mutation testing: two independent mutations; each failed exactly its intended tests and no others.
    • Local flake: one mcp-e2e SIGTERM failure was measured against a main baseline run under identical conditions — main failed 4 different tests while that one passed. Pre-existing load-dependent flakes, not a regression.
    • Branch state: 1 commit behind origin/main (dependabot hono bump, package-lock.json only — no file overlap). mergeable: MERGEABLE, mergeStateStatus: CLEAN. This is below the stale-branch threshold of 5 and does not affect the verdict; the QA comment's "0 commits behind" was accurate when measured at b510669a.

    Known gap (deliberate — needs a decision)

    src/commands/update.ts:113, :128, :296 carry the byte-identical (manifest.packageManager as keyof typeof PM_CONFIG) || "npm" pattern. Left out because AC-1 scopes this issue to worktree-manager.ts and those sites operate on the project root rather than a worktree. Until a follow-up lands, sequant update keeps writing an npm PM_RUN token and running npm install on manifest-less pnpm/yarn/bun projects. resolvePackageManager makes each one a single-line change.

    Risk

    • Likely failure mode: a worktree whose lockfile disagrees with its manifest now installs per the lockfile. Intended, but a behavior change for that population; the frozen install fails loudly rather than corrupting state.
    • Not tested: no end-to-end install against a real pnpm/yarn/bun project — child_process is mocked, so the assertion is on the argv. The argv is the contract shared with new-feature.sh, so this is proportionate to a one-line resolution fix.

    Ready for human review and merge.

  8. added
    ready-for-review
    on Jul 30, 2026
  9. added a commit that references this issue on Jul 30, 2026
  10. admarble commented on Jul 30, 2026

    @admarble
    ContributorAuthor

    QA Addendum — both open gaps closed

    Reviewed commit: 33405d16 · Verdict: READY_FOR_MERGE (unchanged)

    The two items left open in the previous review are now fixed in the PR rather than deferred.

    Gap 1 — sequant update's three sibling sites

    Converted. update.ts:113/:128/:296 all consumed the byte-identical (manifest.packageManager as keyof typeof PM_CONFIG) || "npm".

    Re-examining them for this pass raised their priority above what the original deferral assumed: the manifest field is absent precisely on pre-1.3.0 installs, which is exactly the population the PM_RUN backfill at :113 exists to serve. The site most likely to run with an absent manifest value was the one hardcoding npm — so update wrote an npm PM_RUN token into pnpm/yarn/bun projects, and :296 ran npm install there when package.json changed.

    All three now read a single const pm resolved once, right after the manifest loads. Resolving once rather than converting each site in place is the point: the defect was one rule copied three times, and three copies of the new call would have preserved that shape. Root is process.cwd() — the same directory getManifest and syncSequantMcpPin already read.

    Verification: repo-wide grep confirms no live || "npm" fallback remains in src/ or bin/ (only the comments explaining the old spelling mention it). 4 behavioral tests drive updateCommand with a redirected process.cwd() and a real temp-dir lockfile.

    Mutation 3 — revert the resolution to the bare fallback:

    × backfills PM_RUN from the lockfile, not npm, on a legacy pnpm install
    × writes a yarn PM_RUN on first-time config setup for a yarn project
    Tests  2 failed | 7 passed (9)
    

    Exactly the two lockfile-detection tests fail. The other two new tests keep passing under the mutation — the no-lockfile and manifest-present cases have identical expected results under both implementations, so they are boundary guards, not gates. Recording that distinction rather than claiming "all 4 fail", which would overstate the coverage.

    Gap 2 — branch drift

    origin/main merged in (33405d16); 0 commits behind. The merge carried only the dependabot hono bump (package-lock.json).

    Worth noting: the post-merge install rewrote that lockfile, stripping the libc fields a newer npm had committed — the exact normalization installWorktreeDeps' own comment documents as the reason it uses ciInstall. The rewrite was discarded rather than committed, since committing it would have reverted fields a newer npm wrote.

    Docs and CHANGELOG

    The previous pass had scoped the docs sentence to "sequant update still assumes npm when the field is absent" — this commit makes that false, so both the docs and the CHANGELOG entry were updated to describe the completed behavior rather than the partial state.

    Verification on 33405d16

    • CI: 5/5 green, including build (22.x), which runs npm test.
    • Build / lint: clean after the merge.
    • Gate tests: 31 passing across the three files; three independent mutations recorded, each failing exactly its intended tests.

    Local suite — flakes, measured not assumed

    The local full run showed 8 failures across MCP-serve, semgrep, TUI, and lock-manager. Investigated rather than waved through:

    Check Result
    TUI + lock-manager in isolation Pass
    MCP-serve in isolation Fails a different test each run (or passes)
    semgrep in isolation Fails a different test each run
    Same two files on main 39/39 pass — but a full-suite run on main earlier failed 4 other tests
    Failure mode Error: Test timed out in 30000ms

    These are subprocess-spawning integration tests (real semgrep binary, real MCP SSE server) exceeding their 30 s limit under machine load. The failing set rotates every run and never includes anything on the package-manager path. CI, on a clean runner, is green on this exact commit.

    Verdict: READY_FOR_MERGE

    No open gaps remain. No live || "npm" fallback exists anywhere in the source, the TypeScript and shell provisioning paths agree by construction, and every behavior claim in the PR body is backed by either a mutation-verified test or a recorded measurement.

  11. added a commit that references this issue on Jul 30, 2026
  12. admarble commented on Jul 30, 2026

    @admarble
    ContributorAuthor

    QA Correction — the "flake" was a real regression I introduced

    Commit: 22a3e57d

    My two previous reviews dismissed the local test failures as pre-existing load-dependent flakes. That was wrong. There was a real regression, it came from this PR, and the reasoning that led me to dismiss it is worth recording.

    Root cause

    The #870 tests I added to update.test.ts used:

    vi.spyOn(process, "cwd").mockReturnValue(dir);

    process.cwd is a process global, and vitest.config.ts sets pool: "forks", which reuses a worker across test files. The patch therefore escaped the file that set it and degraded every file that shared that fork.

    Measurement

    Directory, node_modules, and machine held constant; only the source varied. The third row is main's own code checked out inside the feature worktree, which removes environment as a variable entirely:

    Configuration Duration Failures
    main's code, in the feature worktree 205s 0
    branch, update.test.ts removed 211s 0
    branch, only the cwd spy line disabled 230s 2 (its own, expected)
    branch as committed 695s 4 — semgrep ×3, mcp-serve, App.tsx, lock-manager

    One line accounted for ~465s of wall clock and every "unrelated" failure. The poisoned cwd slowed other files in the reused fork enough to blow their timeouts — which is why the symptom presented as scattered, load-dependent timeouts in files that had nothing to do with package-manager resolution.

    Why the earlier reviews missed it

    • update.test.ts runs in 11s on its own. Every per-file and small-batch run came back clean, including a deliberate 3-file leak probe that passed 58/58 three times. Only the full suite exposed it.
    • The failing set rotated between runs, which looks exactly like flakiness — and I stopped at that inference instead of pushing to a controlled comparison.
    • I ran concurrent vitest invocations during one measurement, inflating a run and giving the flake theory false support.
    • The disconfirming evidence was already in the data I had collected: import time went 39s → 148s between runs. Import is module loading, not test logic; no amount of machine noise explains a 4× swing there. I recorded that number and did not act on it.
    • CI was green on the bad commit, which I cited as confirmation. CI's runner is fast enough that the inflated times stayed under the timeouts — so CI could not have caught this, and treating its green as evidence of suite health was a category error.

    Second defect, surfaced by the same investigation

    updateCommand calls syncSequantMcpPin before the template-changes short-circuit, so the non-dry-run #870 cases were rewriting the repo's real .mcp.json on every run. The pre-existing tests never hit it because they all pass --dry-run. I had seen that dirty file twice and reverted it without asking why.

    Fix

    Faking a process global to control one function argument was the wrong lever. The resolver's lockfile semantics are already covered directly, against a real temp dir, in stacks.resolve-package-manager.test.ts (12 cases, mutation-verified). What update.test.ts needs to pin is the wiring — that update consults the resolver, hands it the manifest value and the project root, and lets the answer drive PM_RUN — and that needs no filesystem at all.

    • resolvePackageManager is mocked via importActual, so everything else in stacks.js (notably PM_CONFIG) stays real.
    • mcp-config.js is mocked, ending the .mcp.json write.
    • No process global is touched.

    The rewrite also gates harder. Reverting update.ts to the bare || "npm" now fails 4 of 5 tests, against 2 of 4 before. The one that still passes is the npm case, whose expected value is identical under both implementations — a boundary guard, not a gate.

    Verification

    Check Result
    Full suite, branch, uncontended 229 files, 4717 passed, 0 failures, 190s — below main's own 205s on the same machine
    Repo clean after a test run Yes — no .mcp.json write
    Mutation (update.ts → bare fallback) 4 of 5 fail
    Mutation (resolver body → bare fallback) 6 of 6 fail
    Mutation (hasOwnProperty → in) 5 of 5 fail
    Build / lint Clean

    Verdict: READY_FOR_MERGE

    The three ACs were never in question — the regression was in test hygiene, not in the fix. It is now removed, the coverage it was meant to provide is stronger than before, and the suite is faster on this branch than on main.

    Process note for the record: two consecutive reviews signed off on a commit that tripled suite runtime, and both cited green CI as support. The lesson is that a rotating failure set is a hypothesis, not a conclusion, and the cheap way to settle it is to check out the base commit in the same directory and compare — which took one 205s run and would have caught this immediately.

  13. added a commit that references this issue on Jul 30, 2026
  14. added 6 commits that reference this issue on Sep 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

    bugplannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions