Skip to content

fix(#803): reinstall deps in merge-check's combined-branch test - #806

Merged
admarble merged 5 commits into
mainfrom
feature/803-fix-merge-check-combined-branch-test-runs-npm-
Jul 25, 2026
Merged

admarble merged 5 commits into
mainfrom
feature/803-fix-merge-check-combined-branch-test-runs-npm-

Conversation

@admarble

@admarble admarble commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

sequant merge --check's combined-branch test merged all feature branches into a temp branch and then ran npm test / npm run build without reinstalling dependencies. A batch that changed the lockfile was therefore evaluated against the stale node_modules of whatever branch the user happened to be on — both commands failed with module-not-found errors and the report said BLOCKED, contradicting green PR CI (which does npm ci first) and a clean full-stack worktree. Worse, the failure reason was stderr.slice(0, 500) alone and the failures wrote to stdout, so the report read failed on combined state: with nothing after it.

  • Reinstall before test/build. Diffs the combined state's lockfiles against origin/main and, when they moved, runs a frozen install for the package manager detected from the target repo's lockfile. Frozen (npm ci / --frozen-lockfile / --immutable) rather than plain is deliberate: it mirrors CI, it cannot rewrite the lockfile — which would dirty the temp branch and break the branch restore during cleanup — and it fails loudly on a merged lockfile inconsistent with package.json.
  • Install failures get their own finding and skip test/build, instead of resurfacing downstream as an unexplained test failure.
  • Never-empty failure reasons. resolveFailureReason() falls through stderr → stdout tail (test runners put the summary last) → spawn error → signal → exit code.
  • Timeouts. The flat 2-minute budget killed the process with status: null and no output — a second, independent path to the same empty-reason BLOCKED. Installs now get 5 min, test/build 10, and an expired timeout says so by name.
  • node_modules restored after the original branch is restored; warns (without failing the check) if the resync fails.

Also routes test/build through the detected manager's run script rather than a hardcoded npm, adds ciInstall to PM_CONFIG, and gives detectPackageManagerSync an optional root so detection targets repoRoot instead of process.cwd().

AC Verification

AC Source Description Status Evidence
AC-1 Original Reinstall deps after assembling the combined state, using the detected package manager ✅ Implemented combined-branch-test.ts:320-350; test "reinstalls dependencies before running test/build when the lockfile changed" asserts the install spawn precedes the test spawn
AC-2 Original Lockfile-only combined state no longer reports a false BLOCKED ✅ Implemented Test "does not report a false BLOCKED for a lockfile-only combined state" — passed === true, zero error findings
AC-3 Original Failure findings always carry a non-empty reason ✅ Implemented resolveFailureReason() at combined-branch-test.ts:126-141; 9 cases incl. expect(msg).not.toMatch(/failed on combined state:\s*$/)
AC-4 Original Install failures surfaced distinctly ✅ Implemented combined-branch-test.ts:337-346; test asserts the finding names dependency installation and that npm run test is never spawned
AC-5 Original Regression test covering (a) and (b) ✅ Implemented New combined-branch-test.test.ts, 16 cases. 13 of them fail against the previous behavior (verified by re-running the suite with the install skipped and the stderr-only reason restored)
Derived
AC-6 Error handling (from /spec Quality Plan) Timeouts don't fire on a healthy repo, and an expired one is named rather than empty ✅ Implemented INSTALL_TIMEOUT_MS / TEST_BUILD_TIMEOUT_MS; test "names the signal when the command was killed (timeout)"
AC-7 Side effects (from /spec Quality Plan) node_modules restored after the check, or the user is told ✅ Implemented Cleanup block at combined-branch-test.ts:196-215; tests for both the restore ordering and the warning-on-failure path

Notes on AC-1's premise

AC-1 says "(this repo is pnpm; don't hardcode npm install)". Sequant has package-lock.json and no pnpm-lock.yaml — it's an npm repo. The requirement is still right and is implemented, because merge --check also runs in consumer projects that may be pnpm/yarn/bun; only the parenthetical premise is wrong.

Test plan

  • npm run build — passes
  • npm run lint — passes (0 warnings)
  • npx vitest run src/lib/merge-check/ src/lib/stacks.test.ts src/lib/version-check.test.ts — 244 passed
  • Full npm test — 4056 passed, 2 failed. Both failures (lock-manager.integration, phase-registry.integration) are pre-existing worktree-environment flakes: they pass on main, and they fail in this worktree with the changes stashed (3 failures there, i.e. more without this PR than with it). Both are subprocess-spawn tests hitting a 5s timeout under worktree cold-start.
  • Regression value verified by simulating the old behavior — 13/16 new tests fail

Closes #803

🤖 Generated with Claude Code


Update: QA-flagged gaps closed (commit 1356c24)

The first QA pass recorded four items as stated limitations rather than fixing them. All four are now closed in this PR.

1. End-to-end coverage — new combined-branch-test.integration.test.ts: real bare origin, real clone, real feature branches, real git merge into a real temp branch, and the real git diff that decides whether the lockfile moved. Only the package manager is stubbed (a shell script named npm, first on PATH, that logs its argv and exits with a configurable code). 8 cases: the #109-113 two-branch dependency stack (merged cleanly via reserved non-adjacent lockfile slots), the no-lockfile-change skip, branch + node_modules restore, clean working tree, a real merge conflict, a real install failure, and both empty-stderr variants. 5 of the 8 fail against the pre-fix behavior.

2. Windows — spawnSync("npm", …) cannot resolve the .cmd shims, so this check never worked there. Now sets shell: true on win32 only; the command string is always a PM_CONFIG constant, never user input.

3. Restore lost on throw — runChecks returned whether it had installed, so a throw meant the return value never arrived and node_modules was left on the combined state's tree, precisely when it is most likely inconsistent. Replaced with a mutable InstallState the caller owns, and the flag is now set before the install runs, since a frozen install deletes node_modules up front.

4. Sibling site — report.ts reported gh pr comment failures from stderr alone: the same root cause as the bug this PR fixes. Extracted resolveFailureReason / toCommandResult into command-result.ts and routed both call sites through it.

Separately, the AC-parser gap noted in the QA "next steps" is filed as #808 and fixed in #809 — kept out of this PR because it is a different module.

Verification after these changes: npm run build ✅ · npm run lint ✅ (0 warnings) · npx vitest run src/lib/merge-check/ → 76 passed · CI 5/5 green.

admarble added 3 commits July 25, 2026 00:29
`sequant merge --check` merged every feature branch into a temp branch and
then ran npm test / npm run build without reinstalling dependencies, so a
batch that changed the lockfile was evaluated against stale node_modules and
reported a false BLOCKED — contradicting green PR CI, which does `npm ci`
first. The failure message was `stderr.slice(0, 500)` alone, and the failures
wrote to stdout, so the report said `failed on combined state: ` with nothing
after it.

- Diff the combined state's lockfiles against origin/main and, when they
  moved, run a frozen install for the package manager detected from the
  target repo's lockfile. Frozen (npm ci / --frozen-lockfile / --immutable)
  rather than plain: it mirrors CI, it cannot rewrite the lockfile and dirty
  the temp branch, and it fails loudly on an inconsistent merged lockfile.
- Surface install failures as their own error finding and skip test/build,
  instead of letting them resurface as an unexplained test failure.
- Route test/build through the detected manager's run script, not `npm`.
- resolveFailureReason(): stderr -> stdout tail -> spawn error -> signal ->
  exit code. Never empty.
- Raise the flat 2-minute timeout (install 5 min, test/build 10 min); an
  expired timeout killed the process with status null and no output, a second
  independent path to the same empty-reason BLOCKED.
- Restore the caller's node_modules after the branch is restored; warn
  without failing the check if that resync fails.
- Add ciInstall to PM_CONFIG and an optional root to
  detectPackageManagerSync so detection targets repoRoot, not process.cwd().

Adds combined-branch-test.test.ts (16 cases); 13 of them fail against the
previous behavior.
The cleanup step restored the caller's dependencies with the mutating
`installSilent` command. A plain `npm install` normalizes and rewrites
package-lock.json, so the restore could leave the user's own branch with a
dirty working tree — the same hazard the forward install already avoids by
using a frozen install. (Observed concretely: this repo's new-feature.sh
`npm install` strips `libc` fields from package-lock.json.)

Switch the restore to ciInstall and assert it: the install command must never
be the mutating variant, and there must be exactly two frozen installs, one
either side of the branch restore.
src/commands/run.ts already exports a runCommand (the CLI 'run' entry point).
A second, unrelated runCommand in merge-check made grepping for either
ambiguous. Rename the new one to say what it runs.
admarble added 2 commits July 25, 2026 05:19
Four gaps from the QA review on #803, each of which was recorded as a stated
limitation rather than fixed:

1. No end-to-end coverage. Adds combined-branch-test.integration.test.ts:
   real bare origin, real clone, real feature branches, real `git merge` into
   a real temp branch, and the real `git diff` that decides whether the
   lockfile moved. Only the package manager is stubbed — a shell script named
   `npm`, first on PATH, that logs its argv and exits with a configurable
   code. Covers the #109-113 shape (two branches each adding a dependency,
   merged cleanly via reserved non-adjacent lockfile slots), the no-lockfile-
   change skip, branch + node_modules restore, clean working tree, a real
   merge conflict, a real install failure, and both empty-stderr variants.
   5 of the 8 fail against the pre-fix behavior.

2. Windows. spawnSync("npm", …) cannot resolve the .cmd shims, so the check
   never worked there. Sets shell:true on win32 only; the command string is
   always a PM_CONFIG constant, never user input.

3. Restore lost on throw. runChecks returned whether it had installed, so a
   throw meant the return value never arrived and node_modules was left on
   the combined state's tree — exactly when it is most likely inconsistent.
   Replaced with a mutable InstallState the caller owns, and the flag is now
   set *before* the install runs, since a frozen install deletes node_modules
   up front.

4. Sibling site. report.ts reported `gh pr comment` failures from stderr
   alone — the same root cause as the bug this issue fixes. Extracted
   resolveFailureReason/toCommandResult into command-result.ts and routed
   both call sites through it.
…-check-combined-branch-test-runs-npm-

# Conflicts:
#	CHANGELOG.md
@admarble
admarble merged commit 54eb6c2 into main Jul 25, 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(merge-check): combined-branch-test runs npm test/build without reinstalling deps after a lockfile change → false BLOCKED

1 participant