Repository navigation
refactor: decouple AI from reporters via a Contributions registry #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Contribution points: how OPTIONAL modules (AI triage today, anything | ||
| # else tomorrow) feed the reports and the failure decision without the | ||
| # reporters or the assertion knowing those modules exist. | ||
| # | ||
| # The contract follows the two proven shapes in the ecosystem: | ||
| # Minitest's CompositeReporter (plugins append themselves to a | ||
| # core-owned list; core calls a uniform interface and never names a | ||
| # plugin) and SimpleCov's formatter pipeline (consumers receive a plain | ||
| # data payload, never a plugin's class). A contributor is any object | ||
| # responding to #annotate(name) -> {source:, text:, data:} or nil; | ||
| # reports render whatever comes back. | ||
| # | ||
| # Failure suppression is deliberately a SINGLE slot (it was | ||
| # SnapDiff::AI.gate before): two gates with different accept-lists | ||
| # would silently suppress each other's real bugs, so registration | ||
| # replaces the previous gate rather than stacking. | ||
| module SnapDiff | ||
| module Contributions | ||
| @providers = [] | ||
| @suppression = nil | ||
| @mutex = Mutex.new | ||
|
|
||
| class << self | ||
| # Register a report contributor. The provider must respond to | ||
| # #annotate(name), returning {source:, text:, data: (optional)} | ||
| # or nil. Registering the same object twice is a no-op -- identity, | ||
| # not ==: two distinct providers that happen to compare equal | ||
| # (e.g. Structs with equal fields) must BOTH contribute. | ||
| def register(provider) | ||
| @mutex.synchronize { @providers << provider unless @providers.any? { |p| p.equal?(provider) } } | ||
| end | ||
|
|
||
| # All contributions for one screenshot, in registration order. | ||
| # Empty when nothing is registered -- the no-AI default. | ||
| def annotations_for(name) | ||
| @mutex.synchronize { @providers.dup }.filter_map { |provider| provider.annotate(name) } | ||
| end | ||
|
|
||
| # The one failure gate: #suppress(name, difference) -> | ||
| # {source:, text:} (failure waived) or nil (failure stands). | ||
| # nil clears the slot (test teardown, reconfiguration). | ||
| def register_suppression(provider) | ||
| @mutex.synchronize { @suppression = provider } | ||
| end | ||
|
|
||
| # Cheap probe so callers can skip building `difference` entirely | ||
| # when no gate is registered. | ||
| def any_suppressor? | ||
| @mutex.synchronize { !@suppression.nil? } | ||
| end | ||
|
|
||
| # Ask the current suppressor to evaluate a screenshot difference. | ||
| # Return its {source:, text:} waiver, or nil when no gate waives the failure. | ||
| def suppression_for(name, difference) | ||
| @mutex.synchronize { @suppression }&.suppress(name, difference) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.