feat: add Diff.compare for standalone image comparison#163
Conversation
|
Warning Rate limit exceeded
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 15 minutes and 24 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Reviewer's GuideAdds a new public Diff.compare API for standalone, browser-independent image comparison and documents it, with tests covering behavior and options support. Sequence diagram for the new Diff.compare standalone image comparison APIsequenceDiagram
actor Developer
participant Diff
participant ImageCompare
Developer->>Diff: compare(base_image_path, new_image_path, options)
activate Diff
Diff->>Diff: default_options()
Diff-->>Diff: base_options
Diff->>ImageCompare: new(new_image_path, base_image_path, base_options + options)
deactivate Diff
activate ImageCompare
ImageCompare-->>Developer: image_compare_result
deactivate ImageCompare
Developer->>image_compare_result: quick_equal()
Developer->>image_compare_result: different()
Updated class diagram for Diff and ImageCompare standalone comparisonclassDiagram
class Diff {
+compare(base_image_path, new_image_path, options)
+default_options()
}
class ImageCompare {
+ImageCompare(new_image_path, base_image_path, options)
+quick_equal()
+different()
}
Diff ..> ImageCompare : creates
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
Diff.comparesignature uses(base_image_path, new_image_path)but then passes(new_image_path, base_image_path)intoImageCompare.new, which works but is easy to misread; consider either aligning the parameter order withImageCompareor renaming the parameters (baseline_path,current_path) and adding a short code comment to make the reversal explicit.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `Diff.compare` signature uses `(base_image_path, new_image_path)` but then passes `(new_image_path, base_image_path)` into `ImageCompare.new`, which works but is easy to misread; consider either aligning the parameter order with `ImageCompare` or renaming the parameters (`baseline_path`, `current_path`) and adding a short code comment to make the reversal explicit.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Browser-independent API for comparing any two images:
result = Capybara::Screenshot::Diff.compare("a.png", "b.png")
result.quick_equal? # byte-identical?
result.different? # visually different?
Supports all existing options (driver, tolerance, perceptual_threshold).
Based on real usage from corsis/pet which uses the gem for PDF regression.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
Browser-independent API for comparing any two images:
Supports all options: driver, tolerance, perceptual_threshold, color_distance_limit.
Based on real usage from corsis/pet which uses the gem for PDF visual regression.
Test plan
🤖 Generated with Claude Code
Summary by Sourcery
Add a public Diff.compare API for standalone image comparison without Capybara or a browser.
New Features:
Enhancements:
Tests: