Repository navigation
fix(#803): reinstall deps in merge-check's combined-branch test - #806
Merged
admarble merged 5 commits intoJul 25, 2026
Merged
Conversation
`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.
5 tasks
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
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sequant merge --check's combined-branch test merged all feature branches into a temp branch and then rannpm test/npm run buildwithout reinstalling dependencies. A batch that changed the lockfile was therefore evaluated against the stalenode_modulesof whatever branch the user happened to be on — both commands failed with module-not-found errors and the report saidBLOCKED, contradicting green PR CI (which doesnpm cifirst) and a clean full-stack worktree. Worse, the failure reason wasstderr.slice(0, 500)alone and the failures wrote to stdout, so the report readfailed on combined state:with nothing after it.origin/mainand, 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 withpackage.json.resolveFailureReason()falls through stderr → stdout tail (test runners put the summary last) → spawn error → signal → exit code.status: nulland 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_modulesrestored after the original branch is restored; warns (without failing the check) if the resync fails.Also routes test/build through the detected manager's
runscript rather than a hardcodednpm, addsciInstalltoPM_CONFIG, and givesdetectPackageManagerSyncan optionalrootso detection targetsrepoRootinstead ofprocess.cwd().AC Verification
combined-branch-test.ts:320-350; test "reinstalls dependencies before running test/build when the lockfile changed" asserts the install spawn precedes the test spawnpassed === true, zero error findingsresolveFailureReason()atcombined-branch-test.ts:126-141; 9 cases incl.expect(msg).not.toMatch(/failed on combined state:\s*$/)combined-branch-test.ts:337-346; test asserts the finding names dependency installation and thatnpm run testis never spawnedcombined-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)/specQuality Plan)INSTALL_TIMEOUT_MS/TEST_BUILD_TIMEOUT_MS; test "names the signal when the command was killed (timeout)"/specQuality Plan)node_modulesrestored after the check, or the user is toldcombined-branch-test.ts:196-215; tests for both the restore ordering and the warning-on-failure pathNotes on AC-1's premise
AC-1 says "(this repo is pnpm; don't hardcode
npm install)". Sequant haspackage-lock.jsonand nopnpm-lock.yaml— it's an npm repo. The requirement is still right and is implemented, becausemerge --checkalso runs in consumer projects that may be pnpm/yarn/bun; only the parenthetical premise is wrong.Test plan
npm run build— passesnpm run lint— passes (0 warnings)npx vitest run src/lib/merge-check/ src/lib/stacks.test.ts src/lib/version-check.test.ts— 244 passednpm test— 4056 passed, 2 failed. Both failures (lock-manager.integration,phase-registry.integration) are pre-existing worktree-environment flakes: they pass onmain, 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.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 bareorigin, real clone, real feature branches, realgit mergeinto a real temp branch, and the realgit diffthat decides whether the lockfile moved. Only the package manager is stubbed (a shell script namednpm, first onPATH, 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_modulesrestore, 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.cmdshims, so this check never worked there. Now setsshell: trueon win32 only; the command string is always aPM_CONFIGconstant, never user input.3. Restore lost on throw —
runChecksreturned whether it had installed, so a throw meant the return value never arrived andnode_moduleswas left on the combined state's tree, precisely when it is most likely inconsistent. Replaced with a mutableInstallStatethe caller owns, and the flag is now set before the install runs, since a frozen install deletesnode_modulesup front.4. Sibling site —
report.tsreportedgh pr commentfailures fromstderralone: the same root cause as the bug this PR fixes. ExtractedresolveFailureReason/toCommandResultintocommand-result.tsand 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.