Skip to content

fix(snapshots): Generate Paparazzi 1.x compatible snapshot test code#1142

Merged
runningcode merged 3 commits intomainfrom
no/paparazzi-1x-compat
Apr 13, 2026
Merged

fix(snapshots): Generate Paparazzi 1.x compatible snapshot test code#1142
runningcode merged 3 commits intomainfrom
no/paparazzi-1x-compat

Conversation

@runningcode
Copy link
Copy Markdown
Contributor

@runningcode runningcode commented Apr 13, 2026

What

The generated ComposablePreviewSnapshotTest now compiles against both Paparazzi 1.x and 2.x. Previously it only worked with 2.x.

Why

HtmlReportWriter(maxPercentDifference = tolerance) doesn't compile against Paparazzi 1.x because the 1.x constructor has no maxPercentDifference parameter. In 2.x, maxPercentDifference is required (no default), so the no-arg HtmlReportWriter() doesn't compile there. The generated code must differ per version.

How

The plugin detects the Paparazzi major version from the declared testImplementation dependencies at configuration time and passes it to GenerateSnapshotTestsTask. The task conditionally generates HtmlReportWriter() for v1 or HtmlReportWriter(maxPercentDifference = tolerance) for v2+. Defaults to v2 when the version can't be determined.

#skip-changelog

🤖 Generated with Claude Code

The generated ComposablePreviewSnapshotTest called
HtmlReportWriter(maxPercentDifference=...) which only compiles against
Paparazzi 2.x. In 1.x, HtmlReportWriter has no maxPercentDifference
parameter and accepts a no-arg constructor instead.

Detect the Paparazzi version from the declared testImplementation
dependencies and conditionally generate the appropriate
HtmlReportWriter constructor call for each major version.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

Comment thread plugin-build/src/main/kotlin/io/sentry/android/gradle/AndroidComponentsConfig.kt Outdated
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Unparseable version crashes instead of using fallback default
    • Wrapped SemVer.parse in a try-catch block to return the default value 2 when version parsing fails, preventing IllegalArgumentException crashes for unparseable versions like dynamic version ranges.

Create PR

Or push these changes by commenting:

@cursor push 9482252459
Preview (9482252459)
diff --git a/plugin-build/src/main/kotlin/io/sentry/android/gradle/AndroidComponentsConfig.kt b/plugin-build/src/main/kotlin/io/sentry/android/gradle/AndroidComponentsConfig.kt
--- a/plugin-build/src/main/kotlin/io/sentry/android/gradle/AndroidComponentsConfig.kt
+++ b/plugin-build/src/main/kotlin/io/sentry/android/gradle/AndroidComponentsConfig.kt
@@ -500,7 +500,13 @@
       val dep = project.configurations.findByName("testImplementation")
         ?.allDependencies
         ?.find { it.group == "app.cash.paparazzi" && it.name == "paparazzi" }
-      dep?.version?.let { SemVer.parse(it).major } ?: 2
+      dep?.version?.let {
+        try {
+          SemVer.parse(it).major
+        } catch (e: IllegalArgumentException) {
+          2
+        }
+      } ?: 2
     }
 
     val generateTask =

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0633ad4. Configure here.

Comment thread plugin-build/src/main/kotlin/io/sentry/android/gradle/AndroidComponentsConfig.kt Outdated
runningcode and others added 2 commits April 13, 2026 14:05
Extract version parsing into a testable parseMajorVersion() function
that takes the leading digits from the version string instead of
requiring strict semver. This handles dynamic versions like "1.+" which
SemVer.parse() would reject, causing the task to fail.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…EVEL

When a preview doesn't specify an apiLevel, use the compileSdkVersion
from detectEnvironment() (which reflects the project's actual
compileSdk) instead of overriding it with a hardcoded MAX_API_LEVEL=36.
The hardcoded value caused Renderer.configureBuildProperties to crash on
Paparazzi 1.3.5 when its bundled layoutlib didn't support the SDK level.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@runningcode runningcode merged commit bb29e02 into main Apr 13, 2026
20 of 21 checks passed
@runningcode runningcode deleted the no/paparazzi-1x-compat branch April 13, 2026 16:22
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.

2 participants