Skip to content

refactor: delete dead code and stale migration narrative (3.0 readiness) - #233

Merged
pftg merged 1 commit into
masterfrom
refactor/v3ready-deletion-sweep
Aug 23, 2026
Merged

refactor: delete dead code and stale migration narrative (3.0 readiness)#233
pftg merged 1 commit into
masterfrom
refactor/v3ready-deletion-sweep

Conversation

@pftg

@pftg pftg commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Deletion sweep ahead of 3.0. Every removal below is backed by a search that
found no caller; nothing was deleted on the strength of a prior report alone.

Baseline rake test:unit 532/0522/0; rake test 565/0/6
555/0/6. standardrb clean. No version/CHANGELOG changes.

Search tooling note: serena's Ruby LSP would not start in this worktree
(LanguageServerTerminatedException on initialize), so call-site proof is
grepai hybrid search + exhaustive literal grep over the whole repo (all file
types, not just .rb), plus a check that send/public_send is never used
for these names (config.rb:194's public_send is the config-attr generator
and takes only Config attribute names).

A. Dead code

Removed Evidence
ScreenshotAssertion.assert_image_not_changed (lib/snap_diff/screenshot_assertion.rb) Repo-wide grep: 11 hits, all in test/unit/dsl_test.rb + the definition. Only "caller" was a private test helper.
ScreenshotNamer#full_name_with_path Repo-wide grep: 14 hits, all in screenshot_namer_test.rb + the definition. Zero lib callers.
ScreenshotNamer#current_group_directory Repo-wide grep: 6 hits — 4 in screenshot_namer_test.rb, 1 probe in diff_test.rb, the definition.
ScreenshotNamer#screenshot_area + @screenshot_area + the constructor arg Went dead with the two above (they were its only readers); it duplicated Config#screenshot_area. ScreenshotNamer.new had exactly one arg-passing call site, in the deleted test setup.
Reporters::Default#save_annotation_for, #annotate_difference, #annotate_skip_areas, #save Grep for each name: only the definition and the AnnotationService implementation it forwards to. Real callers use AnnotationService directly. Class and the compare.reporter seam kept.
Deprecation.warn's category: kwarg Grep category:: 13 hits, all :constant — 1 in legacy_shims.rb, 12 in the deprecation test. Word inlined into message_for.
VipsDriver.difference_area Grep: only vips_driver_test.rb and the definition. Checked the flagged risk: docs/snapdiff.md enumerates the custom-driver contract as instance methods (same_pixels?, find_difference_region, crop, …) plus the VIPS optional extras (filter_image_with_median, merge, highlight_mask, difference_level) — difference_area is a class method and appears in none of them. difference_area_size_by (the part actually used at vips_driver.rb:64) stays.

Nothing was skipped as too risky in group A.

Tests removed, and why each was not a coverage loss

−10 tests, itemised:

  • dsl_test.rb −2: #assert_image_not_changed cleans up base image when images are identical / keeps base image when images differ. These are
    line-for-line duplicates of screenshot_assertion_test.rb's
    #archive_baseline! moves the base image over the actual image and is idempotent / #archive_baseline! keeps the baseline when the comparison differs.
  • dsl_test.rb ±0: the two #assert_image_not_changed error-message tests
    were kept, not deleted. They are the only pin on the user-facing
    multi-line error string that #validate produces, and nothing else covers
    it — screenshot_assertion_test.rb only asserts raise/no-raise. The private
    helper now builds the assertion directly instead of routing through the
    deleted class method. Deleting them would have been deleting coverage, not
    dead code.
  • screenshot_namer_test.rb −7: 6 #full_name_with_path tests and 1
    #current_group_directory test that pinned the deleted methods, plus
    #group= adds group to screenshot directory path and #section= sets section for directory path which asserted through
    current_group_directory and duplicate #directory_parts contains group/section when set. Two tests named #full_name_with_path … only ever
    called #full_name; those were renamed and kept.
  • vips_driver_test.rb −1: VipsDriver.difference_area calculates correct area of difference.

diff_test.rb's screenshot_dir helper was repointed to
File.join(Capybara::Screenshot.screenshot_area, *directory_parts) so its 4
live assertions on section/group directory layout survive the deletion.

B. Stale narrative

  • 20 boilerplate # Forwarder (ADR-004 v2 step 6): X now resolves lazily via snap_diff/legacy_shims' const_missing… headers over 2-line requires →
    one line each. Where a header carried a live constraint (drivers.rb's
    same-object guarantee, region.rb's eager top-level alias,
    reporters/default.rb's eager-and-silent rationale, image_compare.rb's
    "must still provide everything the pre-move file did") the constraint was
    kept and only the step numbering dropped.
  • lib/snap_diff.rb: the ~16-line acyclicity proof arguing against "the old
    autoload-based wiring this replaced" → one sentence naming the live rule
    (this lean entry must never load the umbrella; snap_diff_test.rb's "bare
    require never loads the umbrella" guard enforces it
    ). The capybara/dsl
    and forwarder-path constraints were kept verbatim.
  • lib/snap_diff/dsl.rb: the same argument restated → the live constraint
    only (must not require the umbrella, it would cycle back).
  • capybara_screenshot_diff.rb, legacy_shims.rb: dropped "ADR-008 step 2",
    "ADR-004 v2 step 6", "(v2 step 4)" and the "unlike before this file's units
    moved" aside; kept the eager-vs-lazy alias rules and every
    defined?/const_defined? exception, which are live.
  • capture/viewport.rb: dropped "when v3 adds scroll preservation … designs
    its own parameters here" — a promise, not documentation.
  • screenshoter.rb: dropped the stale TODO: Adds tests when this case is true / ODOT (resize_if_needed is tested now). The retina code itself is
    untouched — it is live behaviour for Mac + Selenium + retina users.
  • snap_manager.rb: dropped # TODO: rename to delete!. Call: this is not
    worth a 3.0 rename — cleanup! does more than delete (it also prunes
    attempt files and clears the tracked set), so delete! would be the less
    accurate name. Nothing to carry forward.

C. Structural

C.1 — AssertionRegistry#verify. Removed the duplicated
active? && fail_on_difference guard (verify_screenshots! applies it and
returns nil) and moved failed_assertions.first inside the raising branch:

def verify(screenshots = assertions)
  result = ScreenshotAssertion.verify_screenshots!(screenshots)
  return unless result

  raise SnapDiff::ExpectationNotMet.new(result.join("\n\n"), failed_assertions.first.caller)
end

The flagged risk — that eagerly forcing every comparison through different?
is load-bearing for the reporter flow — was checked, not assumed. A throwaway
probe test printed, for three scenarios, which comparisons got forced
(compare.processed?), whether archive_baseline! had moved the base image,
and the raised error's backtrace and message. Run before the edit and again
after:

before: all-pass  processed=[true, true] base_exists=[false, false]
after:  all-pass  processed=[true, true] base_exists=[false, false]

before: mixed     processed=[true, true] base_exists=[false, true] backtrace_head="probe.rb:1" names_in_msg=[["p4"]]
after:  mixed     processed=[true, true] base_exists=[false, true] backtrace_head="probe.rb:1" names_in_msg=[["p4"]]

before: inactive  processed=false
after:  inactive  processed=false

Identical. It holds because Comparison#processed memoises via
difference and @error_message ||= reporter.generate, so different? does
its file-touching work exactly once regardless of who calls it first; both
orderings still force every comparison. The probe was deleted after use.

C.2 — SnapDiff::DSL. Inlined the two genuinely empty private hops,
build_screenshot_assertion and screenshot_namer. The 4-layer spine is
otherwise untouched. Note the skip_stack_frames arithmetic: removing the
private hop removes a real frame from the stack that
ScreenshotMatcher#create_screenshot_assertion walks with caller(n), so the
argument goes +1 at the call site rather than the +2 a naive inline would
produce. dsl_test.rb's our_screenshot stack-frame tests pass.

Skipped

  • lib/snap_diff/config.rb — B asked for the "since step 7b" / "inverted
    from the original v2 consolidation" chronology at lines 5, 30, 122 and 188,
    but config.rb is owned by a parallel lane and on the do-not-touch list. Left
    as-is; the four comments are still there for whoever owns that file.
  • drivers.rb, utils.rb, config_legacy.rb, legacy_tree_is_alias_only_test.rb
    — parallel-lane files, not touched. No deletion in this sweep needed them.
  • require_relative "screenshot_namer" in dsl.rb is now arguably
    unnecessary (DSL reaches the namer through SnapDiff.session), but
    screenshot_assertion.rb requires it anyway and pruning require lines is a
    different risk class. Left alone.

🤖 Generated with Claude Code

Summary by Sourcery

Prepare the codebase for 3.0 by removing verified dead code, simplifying affected flows, and eliminating stale migration narrative while preserving live compatibility behavior.

Enhancements:

  • Remove unused screenshot assertion, naming, reporter, and VIPS driver APIs while preserving active comparison and reporting behavior.
  • Simplify screenshot DSL assertion construction and registry verification without changing stack attribution or comparison processing.
  • Replace obsolete migration and future-work commentary with concise documentation of the remaining namespace and loading constraints.

Tests:

  • Remove tests that only covered deleted APIs and retain or redirect coverage for live screenshot naming, error reporting, and directory layout behavior.

Chores:

  • Simplify deprecation warnings by removing the unused category argument and inline the constant category in generated messages.

Summary by CodeRabbit

  • Documentation

    • Clarified legacy compatibility and forwarding behavior.
    • Simplified internal migration and implementation notes.
  • Refactor

    • Streamlined screenshot naming and assertion flows.
    • Removed obsolete image annotation and difference-area APIs.
    • Simplified deprecation warning handling.
  • Tests

    • Updated coverage for revised screenshot naming, assertions, and deprecation behavior.
    • Removed tests for retired APIs and obsolete path handling.

Dead code (no caller in lib, test or docs):
- ScreenshotAssertion.assert_image_not_changed
- ScreenshotNamer#full_name_with_path / #current_group_directory, and the
  @screenshot_area duplication of Config#screenshot_area they were the only
  users of
- three pure pass-throughs on Reporters::Default (save_annotation_for,
  annotate_difference, annotate_skip_areas) plus #save
- VipsDriver.difference_area
- Deprecation.warn's category: kwarg (one value in the tree)

Structural:
- AssertionRegistry#verify drops the guard verify_screenshots! already
  applies and stops computing failed_assertions.first outside the branch
  that reads it
- DSL inlines two empty private hops (build_screenshot_assertion,
  screenshot_namer)

Narrative: collapsed the 20 boilerplate ADR-step forwarder headers under
lib/capybara* to one line each and stripped migration chronology from
snap_diff.rb, dsl.rb, capybara_screenshot_diff.rb, legacy_shims.rb,
image_compare.rb, capture/viewport.rb, screenshoter.rb and snap_manager.rb,
keeping the live constraints.

rake test:unit 532 -> 522, rake test 565 -> 555, both 0 failures.

@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

@sourcery-ai

sourcery-ai Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Refactors snap_diff and Capybara integration for 3.0 readiness by deleting unused screenshot APIs and tests, simplifying deprecation/legacy forwarding, and tightening the DSL/assertion/driver flows without changing externally visible behavior.

Sequence diagram for simplified screenshot assertion verification

sequenceDiagram
    participant Registry as AssertionRegistry
    participant Assertion as ScreenshotAssertion
    participant Comparison as Comparison
    participant Error as ExpectationNotMet

    Registry->>Assertion: verify_screenshots!(screenshots)
    Assertion->>Comparison: different?
    Comparison-->>Assertion: result
    Assertion-->>Registry: nil or errors
    alt errors returned
        Registry->>Registry: failed_assertions.first
        Registry->>Error: new(message, caller)
        Error-->>Registry: raise
    end
Loading

Sequence diagram for inlined DSL screenshot assertion construction

sequenceDiagram
    actor User
    participant DSL as SnapDiff::DSL
    participant Session as SnapDiff.session
    participant Namer as ScreenshotNamer
    participant Matcher as ScreenshotMatcher
    participant Assertion as ScreenshotAssertion

    User->>DSL: assert_matches_screenshot(name, options)
    DSL->>Session: screenshot_namer
    Session-->>DSL: Namer
    DSL->>Namer: full_name(name)
    Namer-->>DSL: full_name
    DSL->>Matcher: new(full_name, options)
    DSL->>Matcher: build_screenshot_assertion(skip_stack_frames)
    Matcher-->>DSL: Assertion or nil
    DSL->>Assertion: validate!
Loading

File-Level Changes

Change Details Files
Remove dead screenshot assertion/namer/driver APIs and their dedicated tests while preserving behavior via existing paths.
  • Delete ScreenshotAssertion.assert_image_not_changed class method and rewire tests to construct assertions directly via the instance API.
  • Drop ScreenshotNamer constructor argument, screenshot_area accessor, and path helpers, and update tests/helpers to use directory_parts plus Capybara::Screenshot.screenshot_area.
  • Remove VipsDriver.difference_area class helper and its unit test, relying on difference_area_size_by as the only class API.
lib/snap_diff/screenshot_assertion.rb
lib/snap_diff/screenshot_namer.rb
lib/snap_diff/drivers/vips_driver.rb
test/unit/dsl_test.rb
test/unit/screenshot_namer_test.rb
test/unit/drivers/vips_driver_test.rb
test/unit/diff_test.rb
Simplify SnapDiff::DSL wiring and assertion registry behavior while keeping call stacks and comparison processing semantics intact.
  • Inline build_screenshot_assertion and screenshot_namer into DSL methods, calling SnapDiff.session.screenshot_namer and ScreenshotMatcher directly.
  • Adjust skip_stack_frames arithmetic when building assertions to account for the removed private hop, keeping stack-frame-sensitive tests green.
  • Simplify AssertionRegistry#verify by removing redundant Capybara::Screenshot guards and using failed_assertions.first only in the raising branch.
lib/snap_diff/dsl.rb
lib/snap_diff/screenshot_assertion.rb
test/unit/dsl_test.rb
Tighten and homogenize legacy forwarder/deprecation narrative while preserving all functional constraints.
  • Shorten ADR-004/ADR-008 forwarder comments across capybara_screenshot_diff and capybara/screenshot/diff entries, keeping only the live rules (eager vs lazy, same-object aliases, acyclicity).
  • Clarify snap_diff.rb and snap_diff/dsl.rb comments around require-graph acyclicity and umbrella entry-point relationships without changing requires.
  • Update legacy_shims comments and calls to Deprecation.warn to match the simplified deprecation API.
lib/capybara/screenshot/diff/annotation_service.rb
lib/capybara/screenshot/diff/area_calculator.rb
lib/capybara/screenshot/diff/browser_helpers.rb
lib/capybara/screenshot/diff/difference.rb
lib/capybara/screenshot/diff/drivers.rb
lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb
lib/capybara/screenshot/diff/drivers/vips_driver.rb
lib/capybara/screenshot/diff/image_compare.rb
lib/capybara/screenshot/diff/image_preprocessor.rb
lib/capybara/screenshot/diff/region.rb
lib/capybara/screenshot/diff/reporters/default.rb
lib/capybara/screenshot/diff/screenshot_matcher.rb
lib/capybara/screenshot/diff/screenshoter.rb
lib/capybara/screenshot/diff/stable_screenshoter.rb
lib/capybara/screenshot/diff/utils.rb
lib/capybara/screenshot/diff/vcs.rb
lib/capybara_screenshot_diff.rb
lib/capybara_screenshot_diff/attempts_reporter.rb
lib/capybara_screenshot_diff/error_with_filtered_backtrace.rb
lib/capybara_screenshot_diff/reporters/html.rb
lib/capybara_screenshot_diff/screenshot_namer.rb
lib/capybara_screenshot_diff/snap.rb
lib/capybara_screenshot_diff/snap_manager.rb
lib/snap_diff.rb
lib/snap_diff/dsl.rb
lib/snap_diff/legacy_shims.rb
Simplify deprecation API to a single-category constant deprecation while preserving behavior and tests.
  • Remove Deprecation.warn category keyword argument and hard-code the message category to "constant".
  • Update all call sites (legacy_shims and tests) to use the new signature.
  • Keep thread-safety, silence-deprecations, and origin reporting behavior unchanged.
lib/snap_diff/deprecation.rb
lib/snap_diff/legacy_shims.rb
test/unit/snap_diff_deprecation_test.rb
Minor cleanup of comments and TODOs around capture, screenshoter, and snap manager behavior.
  • Trim speculative v3 capture/viewport narrative to a concise description of current behavior.
  • Remove stale TODO/ODOT comments around retina resize and SnapManager#cleanup! rename.
  • Leave functional behavior and public APIs untouched in these areas.
lib/snap_diff/capture/viewport.rb
lib/snap_diff/screenshoter.rb
lib/snap_diff/snap_manager.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 Aug 23, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6d4160ab-7a37-4c45-ada1-c076f637e0e9

📥 Commits

Reviewing files that changed from the base of the PR and between 02e281e and d5bbd44.

📒 Files selected for processing (39)
  • lib/capybara/screenshot/diff/annotation_service.rb
  • lib/capybara/screenshot/diff/area_calculator.rb
  • lib/capybara/screenshot/diff/browser_helpers.rb
  • lib/capybara/screenshot/diff/difference.rb
  • lib/capybara/screenshot/diff/drivers.rb
  • lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb
  • lib/capybara/screenshot/diff/drivers/vips_driver.rb
  • lib/capybara/screenshot/diff/image_compare.rb
  • lib/capybara/screenshot/diff/image_preprocessor.rb
  • lib/capybara/screenshot/diff/region.rb
  • lib/capybara/screenshot/diff/reporters/default.rb
  • lib/capybara/screenshot/diff/screenshot_matcher.rb
  • lib/capybara/screenshot/diff/screenshoter.rb
  • lib/capybara/screenshot/diff/stable_screenshoter.rb
  • lib/capybara/screenshot/diff/utils.rb
  • lib/capybara/screenshot/diff/vcs.rb
  • lib/capybara_screenshot_diff.rb
  • lib/capybara_screenshot_diff/attempts_reporter.rb
  • lib/capybara_screenshot_diff/error_with_filtered_backtrace.rb
  • lib/capybara_screenshot_diff/reporters/html.rb
  • lib/capybara_screenshot_diff/screenshot_namer.rb
  • lib/capybara_screenshot_diff/snap.rb
  • lib/capybara_screenshot_diff/snap_manager.rb
  • lib/snap_diff.rb
  • lib/snap_diff/capture/viewport.rb
  • lib/snap_diff/deprecation.rb
  • lib/snap_diff/drivers/vips_driver.rb
  • lib/snap_diff/dsl.rb
  • lib/snap_diff/legacy_shims.rb
  • lib/snap_diff/reporters/default.rb
  • lib/snap_diff/screenshot_assertion.rb
  • lib/snap_diff/screenshot_namer.rb
  • lib/snap_diff/screenshoter.rb
  • lib/snap_diff/snap_manager.rb
  • test/unit/diff_test.rb
  • test/unit/drivers/vips_driver_test.rb
  • test/unit/dsl_test.rb
  • test/unit/screenshot_namer_test.rb
  • test/unit/snap_diff_deprecation_test.rb

📝 Walkthrough

Walkthrough

This PR updates legacy compatibility documentation, simplifies deprecation APIs, removes obsolete forwarding methods, and streamlines screenshot assertion and naming paths. Runtime screenshot behavior remains unchanged except for the listed API removals and signature updates.

Changes

Compatibility cleanup

Layer / File(s) Summary
Compatibility documentation and cleanup
lib/capybara/screenshot/diff/*, lib/capybara_screenshot_diff*, lib/snap_diff.rb, lib/snap_diff/capture/viewport.rb, lib/snap_diff/screenshoter.rb, lib/snap_diff/snap_manager.rb
Legacy forwarder and entry-point comments now describe current SnapDiff and snap_diff/legacy_shims behavior. Obsolete migration and TODO text was removed.
Deprecation API simplification
lib/snap_diff/deprecation.rb, lib/snap_diff/legacy_shims.rb, test/unit/snap_diff_deprecation_test.rb
Deprecation calls no longer accept category: :constant. Warning behavior and related test coverage remain otherwise unchanged.
Obsolete API removal and assertion flow
lib/snap_diff/drivers/vips_driver.rb, lib/snap_diff/reporters/default.rb, lib/snap_diff/screenshot_assertion.rb, test/unit/drivers/vips_driver_test.rb, test/unit/dsl_test.rb
Removed obsolete area, annotation, and screenshot assertion forwarding APIs. Assertion registry verification now raises from the first failed assertion.
DSL and screenshot naming simplification
lib/snap_diff/dsl.rb, lib/snap_diff/screenshot_namer.rb, test/unit/diff_test.rb, test/unit/screenshot_namer_test.rb
The DSL now uses session state and ScreenshotMatcher. ScreenshotNamer no longer manages screenshot-area paths, and tests cover its remaining naming behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/v3ready-deletion-sweep

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.

@pftg
pftg merged commit 5f3fee6 into master Aug 23, 2026
5 of 6 checks passed
@pftg
pftg deleted the refactor/v3ready-deletion-sweep branch August 23, 2026 08:35
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