Skip to content

fix: one predicate decides "are we on CI" - #310

Merged
pftg merged 1 commit into
snap-diff:masterfrom
oboxodo:fix/one-ci-predicate
Oct 17, 2026
Merged

pftg merged 1 commit into
snap-diff:masterfrom
oboxodo:fix/one-ci-predicate

Conversation

@oboxodo

@oboxodo oboxodo commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What changes

  • SnapDiff::Config.ci? (!ENV["CI"].to_s.empty?) replaces the three raw ENV["CI"] reads in config.rb, screenshot_matcher.rb and reporters/html.rb. The HTML reporter used !!ENV["CI"], so CI="" embedded every image as a data URI while the record-mode default treated the same value as "not CI".
  • The ACCEPT_SCREENSHOTS snippet in README, docs/configuration.md and docs/ci-integration.md becomes SnapDiff.config.record = :all unless ENV["ACCEPT_SCREENSHOTS"].to_s.empty?. The previous form (ENV[...] ? :all : :once) set an explicit :once on every normal run, and an explicit mode outranks the :none-under-CI default, so a CI run with that config no longer failed on missing baselines.

Why merge

One predicate, one meaning of "on CI", in code and in the documented config. Both items are one-liners with a focused test.

Drawbacks

  • A project that relied on CI="" to get embedded images changes behaviour (relative paths instead). Set CI=1 or pass embed_images: true explicitly.

Evidence

  • bin/rake test:unit: master 812 runs; this branch 813, 0 failures. Full suite in the CI image: 856 runs, 0 failures.
  • Probe: CI="", HTML.new default → embed_images was true, now false. Default record mode under CI=1 with the new snippet and no variable set → :none (was :once with the old snippet).

Summary by Sourcery

Use a single consistent CI predicate and correct the documented screenshot acceptance configuration.

Bug Fixes:

  • Ensure empty or unset CI indicators are consistently treated as not running on CI across recording, reporting, and sample report behavior.
  • Fix the documented screenshot-acceptance configuration so CI retains its missing-baseline checks unless acceptance is explicitly enabled.

Enhancements:

  • Centralize CI detection behind a shared configuration predicate.
  • Add unit coverage for CI detection across unset, empty, and populated environment values.

Documentation:

  • Update screenshot-acceptance examples and changelog documentation to preserve default CI behavior.

Tests:

  • Add focused tests covering the shared CI predicate.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Centralizes CI detection in SnapDiff::Config.ci? and fixes the screenshot acceptance examples.

  • Screenshot checks and reports now treat empty CI values as off.
  • The screenshot acceptance example sets bulk recording only when asked.

No actionable issues found. The previous review commit is not an ancestor of the current head, so this review used the full PR diff. No previous review threads were supplied.

Reviews (2) · Last reviewed commit: "fix: one predicate decides "are we on CI..." · Reviewed by Greptile

@sourcery-ai

sourcery-ai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

The PR makes CI detection consistent by introducing and adopting SnapDiff::Config.ci?, so empty CI is treated as not CI everywhere, and updates the documented ACCEPT_SCREENSHOTS opt-in to avoid overriding CI’s missing-baseline protection on ordinary runs.

Flow diagram for unified CI detection

flowchart TD
    CI[CI environment variable] --> P[SnapDiff::Config.ci?]
    P --> R[Config fail_if_new]
    P --> M[ScreenshotMatcher record safeguards]
    P --> H[HTML reporter embed_images]
    E[CI unset or empty] --> P
    N[CI non-empty] --> P
Loading

File-Level Changes

Change Details Files
Centralize CI detection behind a single predicate and use it consistently across configuration, screenshot matching, and HTML reporting.
  • Add SnapDiff::Config.ci?, treating unset or empty CI as not CI.
  • Replace direct ENV["CI"] checks in fail-if-new behavior, bulk-record protection, and default HTML image embedding.
  • Add unit coverage for unset, empty, and non-empty CI values.
lib/snap_diff/config.rb
lib/snap_diff/screenshot_matcher.rb
lib/snap_diff/reporters/html.rb
test/unit/snap_diff_config_test.rb
Correct the documented screenshot-acceptance configuration so it only overrides record mode when explicitly requested.
  • Change the README and configuration documentation snippet to assign :all only when ACCEPT_SCREENSHOTS is non-empty.
  • Preserve the CI default of :none when the opt-in variable is absent, preventing missing baselines from being accepted silently.
README.md
docs/configuration.md
Document the behavioral fixes and their CI implications in the changelog.
  • Record consistent handling of empty CI values across reporting and record-mode behavior.
  • Explain why the updated acceptance snippet preserves CI missing-baseline failures.
CHANGELOG.md

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 Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

Next included review available in 26 minutes.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9a591219-ddf7-48d2-b7be-5f53c153eb1c
📥 Commits

Reviewing files that changed from the base of the PR and between eb89fc5 and 7e01feb.

📒 Files selected for processing: 8
  • CHANGELOG.md
  • README.md
  • docs/configuration.md
  • lib/snap_diff/config.rb
  • lib/snap_diff/reporters/html.rb
  • lib/snap_diff/screenshot_matcher.rb
  • scripts/generate_sample_report.rb
  • test/unit/snap_diff_config_test.rb
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="lib/snap_diff/config.rb" line_range="107" />
<code_context>
+    # Are we on CI? Read live, and an empty CI is not CI: `CI: ""` is how a
+    # job opts out (docs/ci-integration.md), so every reader must agree.
+    def self.ci?
+      !ENV["CI"].to_s.empty?
+    end
+
</code_context>
<issue_to_address>
**Sample reports embed opted-out images**

When `CI` is set to an empty string and the sample-report generator runs, `scripts/generate_sample_report.rb` uses `!!ENV["CI"]` instead of the shared predicate, so its HTML reporter embeds every image and produces a data-URI report.

Use `SnapDiff::Config.ci?` when selecting image embedding in the sample-report generator.

Also at `lib/snap_diff/reporters/html.rb:223`.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: lib/snap_diff/config.rb:107


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread lib/snap_diff/config.rb
…g it

Three readers tested ENV["CI"] and two of them disagreed with the third.
The record-mode default and the `:all` refusal treated an empty value as
"not CI" (`.to_s.empty?`), which is what the documented update-baselines
job relies on when it sets `CI: ""` to opt out. The HTML reporter's
auto-registration used `!!ENV["CI"]`, so that same job still got a
report with every image inlined as a data URI.

`SnapDiff::Config.ci?` is now the single reader -- unset or empty is not
CI -- and the three call sites use it. Config is the require-graph leaf
the other two already load, so no new dependency edge.

Same theme, in the docs: the README and docs/configuration.md snippet
for re-recording was `record = ENV["ACCEPT_SCREENSHOTS"] ? :all : :once`.
On every ordinary run that sets an explicit `:once`, and an explicit
mode outranks the `:none`-under-CI default (Config#record reads
`@record || ...`), so a CI that copied the snippet stopped failing on a
screenshot with no committed baseline. The snippet now assigns `:all`
only when the variable is non-empty -- the same "empty is not set" rule
`Config.ci?` applies -- and leaves the default alone otherwise.

Not changed: what CI switches on (the `:none` default, image embedding,
the `:all` refusal), only that they all read the same answer.
@oboxodo
oboxodo force-pushed the fix/one-ci-predicate branch from d678c3e to 7e01feb Compare October 17, 2026 14:20

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

Sourcery assessment

Approved.

@pftg
pftg merged commit 34066d6 into snap-diff:master Oct 17, 2026
11 checks passed
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.

2 participants