Commit a51e5be
feat(snapshot): Write per-image sidecar metadata during test execution (#1127)
* feat(snapshot): Write per-image sidecar metadata during test execution
The sentry-cli `build snapshots` command supports per-image metadata via
companion JSON sidecar files, but this was disconnected from the preview
metadata the plugin already knows about.
This adds a `SentrySnapshotHandler` to the generated Paparazzi test that
writes each rendered image (with its screenshotId as filename) plus a
companion JSON sidecar to `build/sentry-snapshots/images/`. The sidecar
includes `display_name`, `image_file_name`, `group`, `className`, and
`methodName` fields that sentry-cli merges into the upload manifest.
The upload task's `snapshotsPath` is now automatically wired to this
output directory, and the `sentry.snapshot.output` system property is
set on all Test tasks so the generated code writes to the correct path.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(snapshot): Fix compile errors in generated sidecar metadata code
- Remove SentrySnapshotHandler that used java.awt.image.BufferedImage
and javax.imageio.ImageIO which are unavailable in Android test
classpath
- Use SnapshotVerifier pointed at sentry output dir instead, which
writes images with predictable names (not content hashes)
- Fix methodName access: use preview.methodName (ComposablePreview)
instead of info.methodName (AndroidPreviewInfo doesn't have it)
- Fix declaringClass: it's a non-nullable String on ComposablePreview
- Write sidecar filenames matching SnapshotVerifier's naming pattern
(Paparazzi_Preview_Test_{screenshotId_lowercased})
- Clean sentry output dir before each test run to ensure fresh writes
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* feat(snapshot): Include full preview configuration in sidecar metadata
Add nightMode, fontScale, locale, device, apiLevel, widthDp, heightDp,
showSystemUi, showBackground, previewName, and group fields to the
sidecar JSON. Non-default values are included to keep the file compact.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(snapshot): Use HtmlReportWriter recording mode for sentry images
SnapshotVerifier is verify-only and always compares against golden
files. Replace it with HtmlReportWriter which has a recording mode
(paparazzi.test.record=true) that copies images with predictable
names to a configurable snapshot directory.
Pass snapshotRootDirectory=sentryOutputDir to HtmlReportWriter so
recorded images go to build/sentry-snapshots/images/ with names
matching the sidecar JSONs (Paparazzi_Preview_Test_{screenshotId}).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(snapshot): Make sentry snapshot output directory variant-aware
Use build/sentry-snapshots/{variant}/images/ instead of a shared
directory so that different build variants don't overwrite each other.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore: Apply spotless formatting to remaining files
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(snapshot): Use Paparazzi's default snapshot dir for sidecar metadata
Instead of configuring a custom snapshotRootDirectory on HtmlReportWriter
and passing it via a sentry.snapshot.output system property, reuse the
paparazzi.snapshot.dir that Paparazzi's plugin already sets. Sidecar JSON
files are now written alongside golden images in the same directory.
Also simplifies sidecar JSON generation using a linkedMapOf and removes
dead code.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(snapshot): Remove hardcoded snapshotsPath from upload task
Let users pass the path via --snapshots-path instead of hardcoding
the now-removed build/sentry-snapshots directory.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore: Apply spotless formatting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* release: 6.4.0-alpha.3
* fix(snapshot): Use short name for sidecar display_name
Strip the fully qualified class prefix from the screenshotId so
display_name shows e.g. "BookmarksScreenAppStorePreview.NIGHT_PIXEL_5"
instead of the full package path.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore: Apply spotless formatting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(snapshot): Remove forced record mode from SentrySnapshotPlugin
Stop unconditionally setting paparazzi.test.record=true on the variant
test task, which forced all Paparazzi tests in the module into record
mode and silently overwrote golden files for existing user tests.
Users should run recordPaparazzi<Variant> which sets this property
correctly via Paparazzi's own plugin.
Also adds unit tests for GenerateSnapshotTestsTask.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(snapshot): Preserve original case in sidecar filenames
The sidecar JSON and PNG filenames were being lowercased, causing a
mismatch with the original screenshotId casing. Remove the
`.lowercase(Locale.US)` call so filenames keep their original case.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore: Apply spotless formatting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* release: 6.4.0-alpha.4
* fix(snapshot): Lowercase sidecar filenames to match Paparazzi images
Paparazzi's `Snapshot.toFileName()` applies `.lowercase(Locale.US)` to
the snapshot name when generating image filenames. The sidecar JSON
filenames must match, so re-add the lowercase call that was removed in
e460156.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(snapshot): Use symbolic constants for night mode detection
Replace hardcoded hex literals (0x30, 0x20) with UI_MODE_NIGHT_MASK
and UI_MODE_NIGHT_YES constants from PreviewConstants for consistency
with the rest of the generated test code.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore: Apply spotless formatting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: runningcode <332597+runningcode@users.noreply.github.com>1 parent 83d86bf commit a51e5be
8 files changed
Lines changed: 224 additions & 18 deletions
File tree
- plugin-build
- src
- main/kotlin/io/sentry/android/gradle
- snapshot
- metadata
- test/kotlin/io/sentry/android/gradle/snapshot
- sentry-kotlin-compiler-plugin
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
4 | 13 | | |
5 | 14 | | |
6 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
469 | 469 | | |
470 | 470 | | |
471 | 471 | | |
472 | | - | |
| 472 | + | |
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
476 | | - | |
| 476 | + | |
477 | 477 | | |
478 | 478 | | |
479 | 479 | | |
| |||
Lines changed: 43 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
| |||
219 | 221 | | |
220 | 222 | | |
221 | 223 | | |
| 224 | + | |
222 | 225 | | |
223 | 226 | | |
224 | 227 | | |
| |||
328 | 331 | | |
329 | 332 | | |
330 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
331 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
332 | 375 | | |
333 | 376 | | |
334 | 377 | | |
| |||
Lines changed: 14 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
44 | 44 | | |
45 | | - | |
46 | 45 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
Lines changed: 151 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
0 commit comments