Skip to content

fix: clean up reporter diff artifacts on Snap#delete!#173

Merged
pftg merged 2 commits into
masterfrom
emdash/fix-adr-handling-tmp-8rr
Apr 12, 2026
Merged

fix: clean up reporter diff artifacts on Snap#delete!#173
pftg merged 2 commits into
masterfrom
emdash/fix-adr-handling-tmp-8rr

Conversation

@pftg

@pftg pftg commented Apr 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Snap#delete! now removes .diff.png, .base.diff.png, and .heatmap.diff.png artifacts created by Reporters::Default — previously these were orphaned on every test run
  • Reporters::Default#clean_tmp_files now also removes .heatmap.diff.png (was missing)
  • Reduces tmp/ bloat from ~30 leaked files per test run (accumulating indefinitely) to 0

Context

Each unit test run left reporter diff artifacts behind because:

  1. Snap#delete! only cleaned .png and .base.png but not the 3 reporter-generated diff files
  2. Reporters::Default#clean_tmp_files cleaned 2 of 3 artifact types (missed heatmap)
  3. Test names include Time.now.nsec, so old artifacts never matched for cleanup

Test plan

  • Added test: SnapManagerTest#cleanup! removes diff artifacts created by reporters
  • Added test: DefaultTest#clean_tmp_files removes heatmap diff along with other diff artifacts
  • Verified: tmp/ stays at 2-3 files across multiple runs (was 31→56→80+)
  • Verified: DEBUG / persist_comparisons? escape hatch still works
  • Full test suite passes (181 tests, 587 assertions)

🤖 Generated with Claude Code

Summary by Sourcery

Ensure snapshot deletion and reporter cleanup remove all generated diff artifacts to prevent tmp directory bloat.

Bug Fixes:

  • Remove reporter-generated diff artifacts when deleting snaps to avoid leaving orphaned files in tmp.
  • Include heatmap diff images in the default reporter temporary file cleanup so all diff variants are removed.

Tests:

  • Add coverage to verify SnapManager.cleanup! removes reporter diff artifacts for snaps.
  • Add test to confirm Reporters::Default#clean_tmp_files deletes heatmap diff images alongside other diff artifacts.

…nap#delete!

Snap#delete! only removed .png and .base.png but left .diff.png,
.base.diff.png, and .heatmap.diff.png orphaned. Also Reporters::Default
#clean_tmp_files missed heatmap cleanup. Each test run leaked ~30 files
into tmp/ that accumulated indefinitely across runs.

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

sourcery-ai Bot commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Extends snapshot and reporter cleanup logic so that all diff-related artifacts (including heatmap diffs) are removed when snapshots are deleted or temporary files are cleaned, and adds tests to lock in this behavior and prevent tmp/ bloat.

Sequence diagram for Snap delete! diff artifact cleanup

sequenceDiagram
  participant TestRunner
  participant SnapManager
  participant Snap
  participant FileSystem

  TestRunner->>SnapManager: delete_snap(full_name)
  SnapManager->>Snap: delete!()
  Snap->>FileSystem: delete(path) if exist
  Snap->>FileSystem: delete(base_path) if exist
  Snap->>Snap: cleanup_diff_artifacts!()
  Snap->>FileSystem: delete(path_with_diff_ext) if exist
  Snap->>FileSystem: delete(path_with_heatmap_diff_ext) if exist
  Snap->>FileSystem: delete(base_path_with_diff_ext) if exist
  Snap->>Snap: cleanup_attempts!()
  Snap->>FileSystem: delete(attempt_paths[]) if exist
Loading

Class diagram for updated Snap and Default reporter cleanup behavior

classDiagram
  class CapybaraScreenshotDiff_Snap {
    +initialize(full_name, format, manager)
    +delete!()
    +cleanup_attempts!()
    +find_attempts_paths()
    -cleanup_diff_artifacts!()
    path
    base_path
    manager
  }

  class Capybara_Screenshot_Diff_Reporters_Default {
    +generate()
    +clean_tmp_files()
    annotated_base_image_path
    annotated_image_path
    heatmap_diff_path
  }

  CapybaraScreenshotDiff_Snap --> Capybara_Screenshot_Diff_Reporters_Default : generates_diff_artifacts_for
Loading

Flow diagram for reporter tmp file cleanup including heatmap diff

flowchart TD
  A[start clean_tmp_files] --> B{annotated_base_image_path.exist?}
  B -->|yes| C[annotated_base_image_path.unlink]
  B -->|no| D[next]
  C --> D
  D --> E{annotated_image_path.exist?}
  E -->|yes| F[annotated_image_path.unlink]
  E -->|no| G[next]
  F --> G
  G --> H{heatmap_diff_path.exist?}
  H -->|yes| I[heatmap_diff_path.unlink]
  H -->|no| J[end]
  I --> J[end clean_tmp_files]
Loading

File-Level Changes

Change Details Files
Ensure Snap#delete! removes all reporter-generated diff artifacts along with the main and base snapshot files.
  • Invoke a new diff-artifact cleanup routine from delete! after removing the primary and base snapshot files.
  • Implement a private cleanup_diff_artifacts! helper that deletes diff, base diff, and heatmap diff files derived from the main and base paths.
  • Keep attempt cleanup logic unchanged but executed after diff artifact cleanup.
lib/capybara_screenshot_diff/snap.rb
Update Default reporter temp-file cleanup to also remove heatmap diff artifacts.
  • Extend clean_tmp_files to unlink the heatmap diff file if it exists, alongside annotated and base annotated images.
lib/capybara/screenshot/diff/reporters/default.rb
Add tests to verify that SnapManager cleanup and Default reporter temp cleanup remove all diff and heatmap diff artifacts.
  • Add a SnapManagerTest that simulates reporter diff artifacts and asserts cleanup! removes diff, base diff, and heatmap diff files.
  • Add a Reporters::DefaultTest that generates diff artifacts via VIPS, calls clean_tmp_files, and asserts all diff-related files are removed.
test/unit/snap_manager_test.rb
test/unit/reporters/default_test.rb

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

@coderabbitai

coderabbitai Bot commented Apr 12, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@pftg has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 20 minutes and 57 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 20 minutes and 57 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6e5b45d4-ee10-4c82-b41c-66e35d8e63e3

📥 Commits

Reviewing files that changed from the base of the PR and between c1a53c3 and e9bdad1.

📒 Files selected for processing (4)
  • lib/capybara/screenshot/diff/reporters/default.rb
  • lib/capybara_screenshot_diff/snap.rb
  • test/unit/reporters/default_test.rb
  • test/unit/snap_manager_test.rb
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch emdash/fix-adr-handling-tmp-8rr

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The diff artifact filename patterns are now duplicated between Reporters::Default and Snap#cleanup_diff_artifacts!; consider centralizing the naming logic (e.g., via a shared helper or constants) so future changes to artifact naming don’t silently drift out of sync.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The diff artifact filename patterns are now duplicated between `Reporters::Default` and `Snap#cleanup_diff_artifacts!`; consider centralizing the naming logic (e.g., via a shared helper or constants) so future changes to artifact naming don’t silently drift out of sync.

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.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pftg pftg merged commit 2a7ca5b into master Apr 12, 2026
7 checks passed
@pftg pftg deleted the emdash/fix-adr-handling-tmp-8rr branch April 12, 2026 14:36
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.

1 participant