Skip to content

feat(updaters): add Gradle version catalog TOML updater - #597

Merged
ruromero merged 4 commits into
guacsec:mainfrom
ruromero:TC-5412
Jul 30, 2026
Merged

feat(updaters): add Gradle version catalog TOML updater#597
ruromero merged 4 commits into
guacsec:mainfrom
ruromero:TC-5412

Conversation

@ruromero

@ruromero ruromero commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • New src/updaters/toml_updater.js module with updateTomlVersions() API
  • Supports centralized version.ref, inline version = "x.y.z", and string shorthand patterns
  • Position-based regex replacement preserves TOML comments and formatting
  • Handles group/name notation alongside module notation
  • 21 new tests covering all patterns, edge cases, and error handling

Implements TC-5412

Test plan

  • Centralized version updates via version.ref
  • Inline version updates
  • String shorthand updates
  • Group/name notation support
  • Formatting and comment preservation
  • Malformed TOML fail-safe
  • Idempotency verification
  • npm run lint passes
  • npm test passes

Summary by Sourcery

Add a TOML updater for Gradle version catalogs and comprehensive tests and fixtures to validate version update behavior.

New Features:

  • Introduce updateTomlVersions helper to update dependency versions in Gradle libs.versions.toml catalogs using centralized and inline version declarations.

Tests:

  • Add extensive toml_updater test suite and TOML fixtures covering centralized refs, inline and shorthand versions, edge cases, malformed input, and idempotency.

@sourcery-ai

sourcery-ai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a new TOML-based Gradle version catalog updater and comprehensive tests/fixtures to support updating dependency versions via centralized refs, inline declarations, and shorthand strings while preserving formatting and comments.

File-Level Changes

Change Details Files
Introduce updateTomlVersions TOML updater for Gradle version catalogs using smol-toml and regex-based, position-aware replacement.
  • Add updateTomlVersions() to parse libs.versions.toml with smol-toml and apply versionChanges for given groupId/artifactId pairs.
  • Build a library index from [libraries] entries supporting module, group/name, and string shorthand formats to resolve modules.
  • Implement detection of centralized version.ref versus inline version or shorthand versions and branch update behavior accordingly.
  • Use regex-based replacement helpers to update [versions] section entries and inline versions in-place while preserving layout and comments.
  • Track applied vs skipped updates with structured reasons for no-op, missing entries, missing refs, malformed TOML, or unchanged versions.
src/updaters/toml_updater.js
Add tests and fixtures validating TOML updater behavior across centralized, inline, shorthand, edge, malformed, and idempotent cases.
  • Create libs.versions.toml fixture representing typical Gradle version catalog with centralized refs, inline versions, shorthand strings, bundles, plugins, and BOM-managed entries.
  • Add toml_updater.test.js suites covering centralized version.ref updates, inline and shorthand updates, unmatched and BOM-managed entries, comment/section preservation, idempotency, multiple changes per call, malformed/degenerate TOML handling, and edge cases including group/name and complex version strings.
test/updaters/toml_updater.test.js
test/updaters/fixtures/libs.versions.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/updaters/toml_updater.js" line_range="238-247" />
<code_context>
+ * @param {string} newVersion - replacement version string
+ * @returns {string} updated content
+ */
+function replaceInlineVersion(content, alias, oldVersion, newVersion) {
+	const escapedAlias = escapeRegExp(alias)
+	const escapedOld = escapeRegExp(oldVersion)
+	const pattern = new RegExp(
+		`^(\\s*${escapedAlias}\\s*=\\s*\\{[^}]*version\\s*=\\s*")${escapedOld}("[^}]*\\}\\s*)$`,
+		'm'
+	)
+	const result = content.replace(pattern, `$1${newVersion}$2`)
+	if (result !== content) {
+		return result
+	}
+	const stringPattern = new RegExp(
+		`^(\\s*${escapedAlias}\\s*=\\s*"[^:]+:[^:]+:)${escapedOld}("\\s*)$`,
+		'm'
+	)
+	return content.replace(stringPattern, `$1${newVersion}$2`)
+}
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Handle failure to match inline versions to avoid false positives in `applied`

`replaceInlineVersion` can return the original `content` when neither regex matches (e.g. formatting differences or the version being in a different position), but the caller still records this as applied. Consider detecting when no replacement occurs and propagating that information so the caller can mark the change as skipped instead. For example, return `{ content, replaced: boolean }` or compare the result with the input and act accordingly.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/updaters/toml_updater.js
@codecov-commenter

codecov-commenter commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.42647% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.04%. Comparing base (a9624b2) to head (cb043e4).

Files with missing lines Patch % Lines
src/updaters/toml_updater.js 97.42% 7 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #597      +/-   ##
==========================================
+ Coverage   90.84%   91.04%   +0.20%     
==========================================
  Files          39       40       +1     
  Lines        8363     8635     +272     
  Branches     1453     1501      +48     
==========================================
+ Hits         7597     7862     +265     
- Misses        766      773       +7     
Flag Coverage Δ
unit-tests 91.04% <97.42%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/updaters/toml_updater.js 97.42% <97.42%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/updaters/toml_updater.js Outdated
Comment thread src/updaters/toml_updater.js Outdated
@ruromero

ruromero commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Verification Report for TC-5412 (commit 8edd65e)

Check Result Details
Review Feedback WARN 3 code change requests → 3 sub-tasks created (TC-5447, TC-5448, TC-5449)
Root-Cause Investigation N/A Defects are universal knowledge (JS regex replacement semantics); implement-task phase gap
Scope Containment PASS 3 files match task spec exactly, 0 out-of-scope, 0 unimplemented
Diff Size PASS +638 lines across 3 new files; proportionate for updater module + tests + fixture
Commit Traceability PASS Commit 8edd65e references TC-5412 in body
Sensitive Patterns PASS No secrets or credentials detected
CI Status PASS All 5 CI checks pass (lint/test Node 22+24, Sourcery, PR title, commit messages)
Acceptance Criteria WARN 5/6 met; criterion #2 (inline versions) has 2 edge-case bugs flagged by reviewer
Test Quality PASS 21 tests with JSDoc docs, no repetitive patterns; Eval Quality: N/A
Test Change Classification ADDITIVE New test file with 21 test cases
Verification Commands PASS npm run lint: 0 errors; npm test: all 21 toml_updater tests pass

Overall: WARN

Runtime Verification (manual)

The updateTomlVersions function was exercised directly through 17 programmatic test scenarios covering all declared patterns plus adversarial edge cases:

# Scenario Result
1–9 Centralized ref, inline, shorthand, group/name, BOM-managed, nonexistent, multi-change, idempotency, malformed TOML All PASS
10 Comment & formatting preservation PASS
11 Regex-special chars in version (1.0.0+build.123) PASS — escapeRegExp() handles correctly
12 Partial version match (3.8.4 vs 3.8.40) PASS — regex anchoring prevents cross-contamination
13 Extra whitespace around = signs PASS
14 Multiline library entries PASS
15 Shared version.ref (two libraries, one update) PASS
16 $1 in newVersion BUGver$1ifyvermyver = "ify" (regex backreference corruption)
17 Duplicate module entries Acceptable — last-alias-wins behavior

Issues Requiring Attention

1. $ in newVersion corrupts output (TC-5447)
replaceVersionInSection and replaceInlineVersion pass newVersion directly into String.prototype.replace() replacement string. JS treats $1, $&, $$ as special patterns. Confirmed via runtime: newVersion='ver$1ify' produces vermyver = "ify". Fix: use a replacer function (match, p1, p2) => ... instead of template literal.

2. Unused section parameter (TC-5448)
replaceVersionInSection(content, section, key, oldVersion, newVersion) declares section but never references it. Dead code.

3. replaceInlineVersion false positives (TC-5449)
When neither regex matches, the function returns original content unchanged, but caller unconditionally pushes to applied[]. Should compare before/after and push to skipped if unchanged.


This comment was AI-generated by sdlc-workflow/verify-pr v0.13.7.

ruromero and others added 4 commits July 30, 2026 17:24
Implements TC-5412

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Assisted-by: Claude Code
…ion strings

String.prototype.replace() treats $1, $$, $& as special patterns in
replacement strings. Switch all three .replace() calls in
replaceVersionInSection and replaceInlineVersion to use arrow function
replacers, avoiding $ interpretation entirely.

Implements TC-5447

Assisted-by: Claude Code
…onInSection

The section parameter was declared but never referenced in the function
body. Removed from the signature, JSDoc, and the single call site.

Implements TC-5448

Assisted-by: Claude Code
Compare content before/after replaceInlineVersion and push to skipped
instead of applied when the regex does not match. Prevents false
positives in the applied results for entries with formatting the
single-line regex cannot handle.

Implements TC-5449

Assisted-by: Claude Code
@ruromero
ruromero enabled auto-merge (squash) July 30, 2026 18:55
@ruromero
ruromero merged commit de62188 into guacsec:main Jul 30, 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.

3 participants