Repository navigation
feat: add automated dependency bump checker and changelog validator - #267
Conversation
a6b2b18 to
cd10640
Compare
16089f8 to
3d0c830
Compare
- Rename defaultBranch to baseBranch (more accurate terminology)
- Add --remote option (default: 'origin') for customizing remote name
- Default base branch is now ${remote}/main instead of local 'main'
- Remove misleading fallback logic in getMergeBase that could give wrong results
- Rename getGitDiff to getManifestGitDiff for clarity
- Remove unnecessary try/catch in getManifestGitDiff (git diff returns 0 for no changes)
63df851 to
5804a00
Compare
|
@metamaskbot publish-preview |
|
A preview build for this branch has been published. You can configure your project to use the preview build with this identifier: See these instructions for more information about preview builds. |
…angelog validation - Integrate dependency checking into validate command with --checkDeps flag - Add new CLI options: --fromRef, --toRef, --remote, --baseBranch, --currentPr - Auto-detect git reference from merge-base when --fromRef not provided - Validate dependency/peerDependency bumps with exact version matching - Auto-fix missing entries with --fix flag (requires --currentPr) - Support renamed packages via existing --tagPrefixBeforePackageRename option - Add comprehensive unit tests for parseDependencyDiff and getDependencyChangesForPackage - Add unit tests for updateChangelogWithDependencies - Add dependency validation tests for validateChangelog - Refactor parseDependencyDiff to be internal (not exported) - Update CHANGELOG.md with new feature documentation
2e6df05 to
57a884e
Compare
- Rename DiffParseResult to DependencyCheckResult - Pass dependencyResult object directly to validateChangelog - Fix validation to check correct changelog section (Unreleased vs version)
validateChangelog already parses the changelog, so include the parsed Changelog instance on the error. updateChangelogWithDependencyBumps now accepts an optional pre-parsed changelog to skip re-reading and re-parsing the file.
Extract validateReleaseCandidateState, validatePrLinks, validateDependencyBumps, validateFormatting, and validateNonEmptyReleases from the monolithic validateChangelog.
Move validate-command.ts, cli-utils.ts, and the test into src/validate-command/ with an index.ts barrel. validate-changelog.ts stays at src/ since it's part of the public API.
parsePossibleDependencyBumpDescription now recognizes: - Update `dep` from `old` to `new` - Upgrade `dep` from `old` to `new` - Bump/Update/Upgrade `dep` to `new` (no "from") in addition to the existing Bump `dep` from `old` to `new` pattern.
Remove the fs mock — tests now write real changelog files to a temp directory. getDependencyChanges is still mocked since it needs git.
- Use discriminated union for UpdateChangeOptions (mirrors AddChangeOptions) - Update description and dependencyBump together consistently - Improve error messages to be more descriptive
getDependencyChanges now throws a specific BaseRefNotFoundError when the base ref can't be auto-detected, instead of returning null. Callers catch the error for a clearer control flow.
Use addToStart: false so auto-added dependency bump entries appear below manually written entries, not above them.
- Fix no-shadow violations by renaming catch params and function params - Fix prettier formatting issues - Fix JSDoc descriptions and @returns/@PARAM tags in test helpers - Move beforeEach/afterEach hooks inside describe block - Add error message to toThrow() assertion - Fix import ordering
|
@metamaskbot publish-preview |
|
A preview build for this branch has been published. You can configure your project to use the preview build with this identifier: See these instructions for more information about preview builds. |
| `Dependency \`${depChange.dependency}\` has a changelog entry but ${expected} is expected`, | ||
| ); | ||
| } | ||
| missingEntries.push(depChange); |
There was a problem hiding this comment.
Wrong-breaking check misleads when stale correct entry exists
Low Severity
In validateDependencyBumps, when findDependencyBumpChangelogEntry finds a stale-version match with the correct isBreaking status (result.existingEntry is set but hasExactMatch is false), the code still runs the wrong-breaking check. If a second entry for the same dependency also exists with the opposite breaking status, the code throws InvalidChangelogError about wrong BREAKING prefix — even though a correct-breaking entry exists and just needs a version update. This prevents the fix handler from updating the stale entry. The wrong-breaking search at the point where result.existingEntry is already populated is too aggressive.
Reviewed by Cursor Bugbot for commit c2d2ddf. Configure here.
There was a problem hiding this comment.
This doesn't make sense. If we find a changelog entry for the dependency change, and the "BREAKING" status is correct but the version is not, then it should not hit the logic between lines 352 and 357.
We probably should have a separate check for whether the version is correct or not. Or, we could change the existing error message so it says something like:
Expected to find changelog entry: 'Bump `@metamask/accounts-controller` from ^1.0.0 to ^1.1.0' but found 'Bump `@metamask/accounts-controller` from ^1.0.0 to ^1.3.0'
In other words, we handle any kind of differences, not just those where "BREAKING" was specified when it was not supposed to be or vice versa.
There was a problem hiding this comment.
Good catch — fixed in f937c9c. The wrong-breaking check now only runs when no correct-breaking entry exists at all, so stale entries get updated instead of erroring.
mcmire
left a comment
There was a problem hiding this comment.
One last Cursor comment we might want to address.
Only check for wrong isBreaking status when no entry with the correct breaking status exists at all. Previously, a stale-version match with the correct breaking status would still trigger the wrong-breaking error if a second entry with the opposite status also existed.
The message now says "Fixed N entry/entries (added or updated)" instead of always saying "Added N missing entries".
|
@metamaskbot publish-preview |
|
A preview build for this branch has been published. You can configure your project to use the preview build with this identifier: See these instructions for more information about preview builds. |
|
@cursor review |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 5 total unresolved issues (including 4 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9c0acc9. Configure here.
| entryIndex: entryCheck.entryIndex, | ||
| dependencyBump: { | ||
| ...bump, | ||
| oldVersion: existingOldVersion ?? bump.oldVersion, |
There was a problem hiding this comment.
Nullish coalescing preserves empty string as oldVersion
Medium Severity
When parsePossibleDependencyBumpDescription parses a short-form entry like "Update dep to 1.5.0" (no "from" clause), it sets oldVersion: ''. Later in updateChangelogWithDependencyBumps, the expression existingOldVersion ?? bump.oldVersion uses nullish coalescing (??), which only falls back for null/undefined — not for empty string. So '' ?? bump.oldVersion evaluates to '', and formatDependencyBumpDescription then produces the malformed output Bump `dep` from `` to `2.0.0` with empty backticks. The ?? operator here needs to be || (or an explicit empty-string check) to properly fall back when existingOldVersion is ''.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 9c0acc9. Configure here.
There was a problem hiding this comment.
Yes this is unhandled, but considering how rare this is, it's okay. We will deal with this bug when it comes.


Summary
Adds
--checkDepsflag tovalidatecommand to detect missing dependency bump entries in changelogs.dependenciesandpeerDependenciesinpackage.jsonbetween git refs usinggit showJSON comparison (ignores devDependencies)--fix --currentPr <number>, automatically adds or updates missing entriesgit log**BREAKING:**prefixBump,Update, andUpgradeforms when parsing existing entriesAPI changes
Changelog.addChange()accepts optionaldependencyBumpfor structured bump metadataChangelog.updateChange()method for modifying existing entries (union-typed options likeaddChange)parsePossibleDependencyBumpDescription()recognizes Bump/Update/Upgrade patterns for round-trip fidelityMissingDependencyEntriesErrorcarries the parsedChangeloginstance andcurrentVersionfor reuse by fix handlersvalidateChangelogsplit into focused helpers:validateReleaseCandidateState,validatePrLinks,validateDependencyBumps,validateFormatting,validateNonEmptyReleasesgetDependencyChanges,BaseRefNotFoundError,DependencyCheckResult,DependencyBump,MissingDependencyEntriesErrorFile structure
src/validate-command/— groups CLI validation logic (validate.ts,cli-utils.ts,index.ts)src/find-dependency-bump-changelog-entry.ts— finds existing dep bump entries in parsed changelogsrc/update-changelog-with-dependency-bumps.ts— adds/updates dep bump entriessrc/get-dependency-changes.ts— compares package.json across git refsCLI options
--checkDeps— enable dependency bump validation--fromRef <ref>— starting git ref (auto-detects from merge-base if omitted)--toRef <ref>— ending git ref (defaults toHEAD)--remote <name>— remote for base branch auto-detection (defaults toorigin)--baseBranch <ref>— base branch ref (defaults to<remote>/main)--currentPr <number>— PR number for changelog entries (required with--fix)Usage
Testing in MetaMask/core
Note
Medium Risk
Moderate risk because it expands CLI validation behavior, adds git-based ref auto-detection, and introduces new changelog mutation paths (
--fix) that could affect CI outcomes and changelog contents if edge cases are missed.Overview
Adds a new
validate --checkDepsmode that comparesdependencies/peerDependenciesinpackage.jsonbetween git refs (auto-detecting a merge-base when possible) and validates that matching dependency-bump entries exist in the appropriate changelog section.When
--fix --currentPris provided, missing or stale dependency bump entries are automatically added/updated (including PR number merging and**BREAKING:**handling for peer dependency bumps) via new helper modules and a newChangelog.updateChange()API.Refactors validation CLI wiring by moving validate logic into
src/validate-command/, adds a smallfswrapper, teachesparseChangelogto recognizeBump/Update/Upgradedependency bump formats, exports new dependency-checking APIs/errors fromindex.ts, and updates docs/tests/coverage thresholds accordingly.Reviewed by Cursor Bugbot for commit 9c0acc9. Bugbot is set up for automated code reviews on this repo. Configure here.