ci: guard against silently merge-corrupted lockfiles - #240
Merged
willchen96 merged 1 commit intoJul 23, 2026
Conversation
PR Open-Legal-Products#233's CI failed with "npm ci can only install with an existing package-lock.json" even though the file existed: a "Merge branch 'main'" commit had auto-merged backend/package.json and package-lock.json into invalid JSON with no conflict raised, and npm reports an unparseable lockfile as if it were missing. Two guards: .gitattributes marks package-lock.json/bun.lock merge=binary so concurrent lockfile changes surface as explicit conflicts (resolve by regenerating, never hand-merging), and CI parse-checks package.json and the lockfile before npm ci so any corruption that still lands fails with the real reason. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
QA Runner seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
willchen96
approved these changes
Jul 23, 2026
duncanmcqueen
pushed a commit
to duncanmcqueen/mike
that referenced
this pull request
Aug 3, 2026
…e-merge-guard ci: guard against silently merge-corrupted lockfiles
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.
What happened on #233
The backend CI job on #233 failed at
npm ciwith:The lockfile did exist. The real cause: a
Merge branch 'main'commit on the PR branch auto-mergedbackend/package.jsonandbackend/package-lock.json— both modified on each side — and git's line-level text merge spliced the two versions into syntactically invalid JSON without raising a conflict:package.jsonlost the comma after the branch's new"test:stack"script, right where main's"test:coverage"line was merged in.package-lock.jsonlost the two closing-brace lines of thesupertest/cookie-signatureentry, where both sides had inserted different package entries at the same alphabetical position.npm (Arborist) swallows the lockfile parse error and treats the file as absent, hence the misleading "no existing package-lock.json" message. Since git saw no conflict, GitHub showed the branch as cleanly mergeable — nothing looked wrong until npm tried to read the file. (The immediate breakage is fixed on the #233 branch itself; this PR is the prevention.)
Prevention (this PR)
.gitattributes:merge=binaryforpackage-lock.jsonandbun.lock. Generated files shouldn't be text-merged. With the binary driver, any concurrent change surfaces as an explicit conflict, and the documented resolution is to regenerate (git checkout origin/main -- package-lock.json && npm install) instead of hand-merging.npm ciin both backend and frontend jobs:JSON.parseonpackage.jsonandpackage-lock.json. If corruption ever lands anyway, CI fails in one second with the actual reason instead of npm's misleading usage error.Habits that keep this away
maininto a PR branch that touches dependencies, regenerate the lockfile rather than trusting the merge result, and re-runnpm cilocally.npm installshould write it.Verified:
node -e "JSON.parse(...)"passes on both files at main; the workflow change is additive and job-local, so it's safe on trees with or without the other pending test PRs.🤖 Generated with Claude Code