test: carry the snapshot fixes onto main ahead of the CI migration - #48
Merged
Conversation
The image snapshots in test-Plot-snapshots.R were recorded with the full
Suggests set installed, and they are not portable to a run without it --
not because the rendering differs, but because the *names* do.
Several tests build a `rasts` list and then double its length inside
`if (requireNamespace("raster", quietly = TRUE))`. Snapshot file names come
from `fn()` (helper-testInit.R), which pulls from a running `counter` over
those lists. Drop `raster` and every list shortens, so each name after the
first raster block lines up against a different plot. "internal functions
in Plot" additionally computes `val <- (testNum - 1) %% (length(rasts) / 2) + 1`,
hard-coding the doubling, so without raster it renders plots 1 and 2 twice
and never renders 3 or 4.
This is exactly the `_R_CHECK_DEPENDS_ONLY_` leg that PredictiveEcology/actions'
shared R-CMD-check matrix runs: 11 failures there, all in this file, all of
them a reference image compared against the wrong plot.
Maintaining a second set of reference images for that configuration would be
a lot of pixels for no extra signal, so skip the image comparisons when
raster is absent. The nosuggests leg keeps its real purpose -- the package
loads and its non-image tests pass without Suggests.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011kpoQV6nNqcknk16R3RzBB
(cherry picked from commit 57600bb)
`test_that("rePlot doesn't work")` took two snapshots under one name: it
called `announce_snapshot_file()` + `expect_snapshot_file()` twice with the
same `fil`, `unlink()`ing the file in between. testthat rejects a duplicate
snapshot name outright, so the second call errored and aborted the test:
Error ('test-Plot-snapshots.R:612:5'): rePlot doesn't work
Snapshot file names must be unique. "rePlot_doesn't_work1Linux.png" has
already been used.
This is a plain ERROR on every Linux and Windows leg (macOS is unaffected --
`oses` is c("Win", "Linux"), so no snapshot runs there), and it predates the
CI migration: the same failure is in the development-branch run from
2026-08-29, run 33278110145.
The second snapshot now gets a name derived from the first rather than a
second `fn()` call, because `fn()` bumps the shared `counter` and that would
renumber every snapshot after this one. `unlink(fil)` goes with it -- it only
existed to clear the path for reuse.
Two new reference images follow in the next commit, recorded from CI.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011kpoQV6nNqcknk16R3RzBB
(cherry picked from commit b9a1ce6)
All three are taken from this branch's own CI run 33897686977, not rendered locally -- expect_snapshot_file() compares PNG bytes exactly and those bytes depend on the runner's cairo and fontconfig. rePlot_doesn't_work0Win-rePlot.png (windows-latest, release) rePlot_doesn't_work1Linux-rePlot.png (ubuntu-latest, release) Plot_listsggplotVnewer2Linux.png (ubuntu-latest, release) The two rePlot images are byte-identical to their non-rePlot counterparts already in the repo -- which is exactly the assertion the original code was reaching for with "same file for snapshot b/c basename is same as previous": rePlot() reproduces the plot pixel for pixel. It just could not express that through a snapshot name testthat had already seen. Plot_listsggplotVnewer2Linux.png closes a pre-existing gap unrelated to this branch: only the ...2Win.png variant had ever been committed, so test-Plot-snapshots.R:703 reported "Adding new file snapshot" on every Linux leg, including in the development run from 2026-08-29. As a side check, the Linux and Windows artifacts from that run reproduce the already-committed rePlot_doesn't_work1Linux.png and rePlot_doesn't_work0Win.png byte for byte, so those legs are stable and the new files are recorded against the same rendering. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011kpoQV6nNqcknk16R3RzBB (cherry picked from commit 2724b9d)
Issue_20;_arr_working0Win.png 4 px changed Issue_32_Plot_factors_lower_case_id0Win.png 1 px changed Issue_32_Plot_factors_lower_case_id2Win.png 1 px changed Issue_32_Plot_factors_lower_case_id4Win.png 1 px changed Seven pixels out of 1,920,000, max channel delta 58/255, and in every case the changed pixels sit inside a text glyph -- a glyph of the plot title `maps$forestAge` for Issue 20, the legend label `A` for the three Issue 32 images. No mark, axis, colour ramp or raster cell moved. This is the windows-latest runner's font rasteriser rounding an antialiased edge differently than it did when the references were recorded. Taken from run 33899141206, which produced byte-identical renders on all four Windows legs (release, devel, oldrel-1, oldrel-2), so one accepted set clears all four. The same bytes also came back from runs 33779375229 and 33897686977, i.e. the new rendering is stable, not a flake. expect_snapshot_file() compares PNG bytes exactly, so a one-pixel change in a font rasteriser is indistinguishable from a real regression. A custom `compare =` with a small per-pixel budget would keep the signal and drop this class of failure; not attempted here. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011kpoQV6nNqcknk16R3RzBB (cherry picked from commit cb4637e)
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.
Cherry-picks (with
-x) the four test commits already merged intodevelopmentvia #45, #46 and #47.4f9ebd157600bb(#46)skip_if_not_installed("raster")in the 9 snapshot-takingtest_that()blocks0d86dffb9a1ce6(#45)ab7d1262724b9d(#45)9d365b2cb4637e(#47)Why this needs to happen before, not after, #44
mainanddevelopmentdiffer intests/testthat/test-Plot-snapshots.Rby exactly one thing —res =→resolution =(3b84c9c, development only).maincarries all four of the same snapshot bugs, and has since long before the CI work started.They have simply never been visible: the current
R-CMD-check.yamlonmaintriggers on[master, development], and this repo has nomasterbranch, so R-CMD-check has never once run againstmain. #44 changes the triggers to[main, development]. The moment it lands,maingets its first R-CMD-check in the repo's history and it reproduces:FAIL 11on the newnosuggestslegLanding this first means
main's first-ever CI run is green.Verification
Two things are checked, and one cannot be:
tests/testthat/_snaps/on this branch is byte-identical todevelopment's (git diffempty).test-Plot-snapshots.Rdiffers fromdevelopment's only by the pre-existingres =/resolution =split and two blank lines — no cherry-pick drift.main's current workflow does not trigger on PRs intomain, so onlypkgdownruns here. The same four commits are green ondevelopment— run 33921573171, all 9 legs plus coverage.Suggested order
main. It should go fromFAIL 5/FAIL 2/FAIL 11to green across the whole new matrix — that is the real verification.Not included
3b84c9c("fix partial argument match warning",res =→resolution =) is stilldevelopment-only. It is unrelated to CI — R only warns on a partial argument match underwarnPartialMatchArgs, which neither the tests nor R CMD check enable — so it is left for the next release merge rather than folded in here.🤖 Generated with Claude Code
https://claude.ai/code/session_011kpoQV6nNqcknk16R3RzBB