Skip to content

refactor: default reporter, Comparison::Images, driver registry get SnapDiff homes (ADR-008 steps 4+5) - #227

Merged
pftg merged 4 commits into
masterfrom
refactor/adr8-reporter-struct-registry
Aug 22, 2026
Merged

refactor: default reporter, Comparison::Images, driver registry get SnapDiff homes (ADR-008 steps 4+5)#227
pftg merged 4 commits into
masterfrom
refactor/adr8-reporter-struct-registry

Conversation

@pftg

@pftg pftg commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

ADR-008 steps 4 and 5 in one PR: both center on lib/snap_diff/comparison.rb, which now contains zero old-namespace references.

Step 4 — SnapDiff::Reporters::Default

  • git mv lib/capybara/screenshot/diff/reporters/default.rb lib/snap_diff/reporters/default.rb (mv-then-rewrap commit pair, history preserved), rewrapped as SnapDiff::Reporters::Default.
  • comparison.rb requires and constructs the canonical name — this was the last old-namespace CLASS dependency in the core.
  • Capybara::Screenshot::Diff::Reporters::Default joins the legacy_shims mapping: lazy, warn-once, same-object, like its peers. Old file path stays requirable as a forwarder.

Step 5a — SnapDiff::Comparison::Images

The images-holder struct Capybara::Screenshot::Diff::Comparison (blocked from a SnapDiff home because SnapDiff::Comparison is the comparator class) is now nested inside the comparator as SnapDiff::Comparison::Images. Old constant joins the legacy_shims mapping (lazy, warn-once).

Step 5b — driver registry

  • SnapDiff::Drivers.loaded is the canonical driver-class cache (ex LOADED_DRIVERS, no longer defined by comparison.rb). The old constant is an EAGER same-object alias (assigned in legacy_shims): user code registers custom drivers by mutating the hash in place (LOADED_DRIVERS[:foo] = ...), so a lazy warn-once shim would either copy (silently dropping registrations) or warn on a supported surface.
  • SnapDiff::Drivers.available is the canonical reader; the value stays on the eager Capybara::Screenshot::Diff::AVAILABLE_DRIVERS constant (detection moment in config_legacy.rb unchanged, and image_compare_test pins that constant as the stub_const point for the no-drivers error path — a canonical-side cached copy would break that stub).
  • Utils.find_driver_class_for now reads both registries through the canonical accessors.

Test edits (canonical-name migrations only, per the #221 policy)

No expectations changed anywhere — these tests construct/assert the same objects under their canonical spellings (the suite's raise-on-deprecation guard would otherwise trip on the lazy shims):

  • test/support/driver_contract_tests.rb — 4 struct constructions → SnapDiff::Comparison::Images (the test: migrate suite to SnapDiff canonical names #221-documented edit).
  • test/unit/image_preprocessor_test.rb, test/unit/annotation_service_test.rb, test/unit/reporters/default_test.rb — bare Comparison.new struct constructions resolved lexically through the old nesting; same migration.
  • test/unit/reporters/default_test.rb, test/unit/image_compare_test.rbReporters::Default references → SnapDiff::Reporters::Default.
  • test/unit/namespace_forwarding_test.rb — MAPPING gains the two new lazy pairs (29 → 31, count test updated; forwarding + warn-once tests auto-generate from MAPPING), plus two new registry guards: same-object identity for .loaded/.available vs the old constants, and a write-via-old-name / read-via-canonical mutation probe.

Evidence

Baseline at 4288edb: rake test:unit 518 runs / 0 failures. After: 524 runs / 0 failures (+6: 2×2 MAPPING-generated for the new shim pairs, 2 registry guards). Full rake test: 557 runs, 0 failures, 6 skips (skips are the usual driver/browser-dependent ones). standardrb: clean.

Mutation checks (each applied, observed red, reverted):

  1. Mis-point the struct shim (Comparison:SnapDiff::ComparisonResult) → NamespaceForwardingTest...Comparison_forwards_to_SnapDiff::Comparison::Images fails on assert_same.
  2. Break registry aliasing (LOADED_DRIVERS = SnapDiff::Drivers.loaded.dup) → both registry guards fail (same-object + mutation probe).
  3. Break the reporter constant in comparison.rb (Reporters::Defalt) → 5 failures + 136 errors across the suite (ImageCompareTest, driver tests, ScreenshotAssertionTest, snap_diff_test, ...) — every path that reaches #reporter/#processed.

🤖 Generated with Claude Code

Summary by Sourcery

Complete ADR-008 namespace migration for the default reporter, comparison images, and driver registries while maintaining backward compatibility.

Enhancements:

  • Move the default reporter and image-holder comparison struct to canonical SnapDiff namespaces while preserving legacy constant forwarding.
  • Add canonical driver registry accessors with identity-preserving compatibility aliases for existing driver discovery and registration APIs.

Documentation:

  • Update architecture documentation to reference the canonical reporter location.

Tests:

  • Update namespace forwarding and unit tests to cover the new compatibility shims and driver registry aliasing.

pftg added 4 commits August 23, 2026 00:55
Pure git mv so the rename survives with history; the rewrap to
SnapDiff::Reporters::Default and the old-path forwarder land in the
next commit.
…008 step 4)

The last old-namespace CLASS dependency in the core: comparison.rb now
requires and constructs SnapDiff::Reporters::Default. The old constant
Capybara::Screenshot::Diff::Reporters::Default joins the legacy_shims
mapping (lazy, warn-once, same-object -- pinned by the MAPPING-driven
forwarding and deprecation tests, now 30 pairs). The old file path stays
requirable as a forwarder.

Test edits are canonical-name migrations only (per the #221 policy --
the raise-on-deprecation guard would trip on the old name otherwise):
default_test.rb and image_compare_test.rb reference
SnapDiff::Reporters::Default; no expectations changed.
…ADR-008 step 5a)

Resolves the Comparison name collision: the images-holder struct that
lived at Capybara::Screenshot::Diff::Comparison (blocked from a SnapDiff
home because SnapDiff::Comparison is the comparator class) is now nested
inside the comparator as SnapDiff::Comparison::Images. The old constant
joins the legacy_shims mapping (lazy, warn-once, same-object -- 31 pairs
now). comparison.rb constructs Images directly; no old-namespace class
reference remains in the compare path.

Test edits are canonical-name migrations only (per the #221 policy;
the raise-on-deprecation guard would otherwise trip): the struct
constructions in driver_contract_tests, image_preprocessor_test,
annotation_service_test and default_test now spell the canonical name.
No expectations changed.
SnapDiff::Drivers.loaded is now the canonical driver-class cache (ex
Capybara::Screenshot::Diff::LOADED_DRIVERS, which comparison.rb no
longer defines); the old constant stays as an EAGER same-object alias
in legacy_shims because user code registers custom drivers by mutating
the hash in place -- a lazy copy would silently drop registrations, and
warning on a supported surface would be noise.

SnapDiff::Drivers.available is the canonical reader for the detected
drivers list; the value itself stays on the eager
Capybara::Screenshot::Diff::AVAILABLE_DRIVERS constant (config_legacy
detection moment unchanged, and image_compare_test pins that constant
as the stub point for the no-drivers error path). Utils'
find_driver_class_for now reads both registries through the canonical
accessors, removing the last old-namespace reads from the core compare
path. Guard tests pin same-object identity and legacy-write ->
canonical-read visibility.

@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.

Sorry @pftg, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@pftg, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 41bf3704-2d40-4848-b096-749631414425

📥 Commits

Reviewing files that changed from the base of the PR and between 4288edb and 67d5b40.

📒 Files selected for processing (14)
  • docs/architecture.md
  • lib/capybara/screenshot/diff/image_compare.rb
  • lib/capybara/screenshot/diff/reporters/default.rb
  • lib/snap_diff/comparison.rb
  • lib/snap_diff/drivers.rb
  • lib/snap_diff/legacy_shims.rb
  • lib/snap_diff/reporters/default.rb
  • lib/snap_diff/utils.rb
  • test/support/driver_contract_tests.rb
  • test/unit/annotation_service_test.rb
  • test/unit/image_compare_test.rb
  • test/unit/image_preprocessor_test.rb
  • test/unit/namespace_forwarding_test.rb
  • test/unit/reporters/default_test.rb

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.

@sourcery-ai

sourcery-ai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR finishes ADR-008 steps 4 and 5 by moving the default reporter and comparison images struct into the SnapDiff namespace, and by introducing canonical driver registry accessors while keeping legacy Capybara::Screenshot::Diff constants working via shims and eager aliases. Comparison.rb no longer depends on legacy namespaces; tests are updated to use canonical names and new shims/aliasing are covered by namespace forwarding and driver registry tests.

Sequence diagram for canonical comparison and driver lookup

sequenceDiagram
  participant Caller
  participant Comparison as SnapDiff::Comparison
  participant Utils as SnapDiff::Utils
  participant Drivers as SnapDiff::Drivers
  participant Driver
  participant Reporter as SnapDiff::Reporters::Default

  Caller->>Comparison: load_comparison(base_path, new_path, options)
  Comparison->>Utils: find_driver_class_for(driver)
  Utils->>Drivers: available()
  Utils->>Drivers: loaded[driver]
  Drivers-->>Utils: driver class
  Utils-->>Comparison: driver class
  Comparison->>Driver: load_images(base_path, new_path)
  Driver-->>Comparison: base_img, new_img
  Comparison->>Comparison: Images.new(...)
  Caller->>Comparison: reporter()
  Comparison->>Reporter: new(current_difference)
Loading

File-Level Changes

Change Details Files
Default reporter implementation moved from the Capybara::Screenshot::Diff namespace into SnapDiff::Reporters::Default with a legacy forwarder.
  • Extracted the Default reporter class into lib/snap_diff/reporters/default.rb under SnapDiff::Reporters::Default with identical behavior
  • Replaced direct use of Capybara::Screenshot::Diff::Reporters::Default in SnapDiff::Comparison with the canonical Reporters::Default constant
  • Converted lib/capybara/screenshot/diff/reporters/default.rb into a thin forwarder that requires the new reporter implementation and relies on legacy_shims for const resolution
  • Extended legacy_shims to lazily map Capybara::Screenshot::Diff::Reporters::Default to SnapDiff::Reporters::Default with warn-once behavior
  • Updated docs/architecture.md and tests to reference lib/snap_diff/reporters/default.rb and SnapDiff::Reporters::Default
lib/snap_diff/reporters/default.rb
lib/capybara/screenshot/diff/reporters/default.rb
lib/snap_diff/comparison.rb
lib/snap_diff/legacy_shims.rb
docs/architecture.md
test/unit/image_compare_test.rb
test/unit/reporters/default_test.rb
test/unit/namespace_forwarding_test.rb
The internal comparison images-holder struct now lives at SnapDiff::Comparison::Images instead of Capybara::Screenshot::Diff::Comparison, with legacy mapping maintained.
  • Introduced SnapDiff::Comparison::Images as the struct holding new/base images, options, driver, and paths, preserving the skip_area accessor
  • Refactored SnapDiff::Comparison helpers to construct and consume Images instances instead of the legacy Capybara::Screenshot::Diff::Comparison struct
  • Updated YARD-style documentation comments in comparison.rb to reference Comparison::Images for parameters and return types
  • Added a lazy legacy_shims mapping from Capybara::Screenshot::Diff::Comparison to SnapDiff::Comparison::Images
  • Migrated tests that construct comparison structs to use SnapDiff::Comparison::Images as per the canonical-name policy
lib/snap_diff/comparison.rb
lib/snap_diff/legacy_shims.rb
test/support/driver_contract_tests.rb
test/unit/annotation_service_test.rb
test/unit/image_preprocessor_test.rb
test/unit/reporters/default_test.rb
test/unit/namespace_forwarding_test.rb
Driver registry responsibilities were moved into SnapDiff::Drivers with canonical loaded/available accessors, while keeping LOADED_DRIVERS and AVAILABLE_DRIVERS working via eager same-object aliasing.
  • Added SnapDiff::Drivers.loaded as the canonical mutable driver-class cache, backed by an internal @loaded hash
  • Added SnapDiff::Drivers.available as the canonical reader that returns Capybara::Screenshot::Diff::AVAILABLE_DRIVERS without copying
  • Assigned Capybara::Screenshot::Diff::LOADED_DRIVERS eagerly to SnapDiff::Drivers.loaded in legacy_shims to preserve same-object semantics for user driver registration
  • Documented LOADED_DRIVERS and AVAILABLE_DRIVERS behavior and constraints in legacy_shims header comments
  • Updated SnapDiff::Utils.find_driver_class_for to use Drivers.available and Drivers.loaded for auto-selection, caching, and error messages
  • Extended namespace_forwarding tests to assert same-object identity between canonical and legacy registry access points and visibility of mutations across names
lib/snap_diff/drivers.rb
lib/snap_diff/utils.rb
lib/snap_diff/legacy_shims.rb
test/unit/namespace_forwarding_test.rb
lib/capybara/screenshot/diff/image_compare.rb

Possibly linked issues

  • #ADR-004: PR implements ADR-004 Phase 3 namespace migration for reporters, comparison images, and driver registries while preserving compatibility.

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

@pftg
pftg merged commit 2ed7073 into master Aug 22, 2026
6 checks passed
@pftg
pftg deleted the refactor/adr8-reporter-struct-registry branch August 22, 2026 23:06
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