-
Notifications
You must be signed in to change notification settings - Fork 35
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
request: Add diff tolerance #90
Comments
Hi there, Thanks for opening an issue! While we can definitely work on a feature to allow users to define a margin of error on golden test comparisons, I think that would go against our idea of how we use these tests. In my own opinion, allowing any pixel difference above absolute 0% will impact the integrity of the test by more than 0% and may become a slippery slope. Then again, if enough people want it, that might warrant us working on this. My initial advice to your issue would be, have you tried regenerating all the golden files locally using Flutter 3.7.0 and committing that to source control? That should solve your issue. If it doesn't we have another problem on our hands, but I don't think allowing more than a 0% diff would be the answer to it, but more a mitigation of a problem that shouldn't be there in the first place. I might be wrong though. Let me know what you think! 😄 |
The widgets in golden tests are a bit more advanced canvas and RenderObject painting, so probably for most people everything is working fine: Since this package promises to solve the issue of local vs CI goldens, then indeed that's a real problem for this package. But I wasn't sure if this is issue in Alchemist or in framework. That's why I didn't opened a bug report, although now when I think about it - that's the real case we need to address here. |
@itsJoKr I think I have similar issues after upgrading, for me it seems rendering images is a bit spotty, where it seems that some pixels aren't rendered the same. While I agree that as a temporary fix a tolerance should be nice; it fixes the effect not the cause. |
@Bassiuz Exactly. For me, it's just like 1 or 2 pixels on the whole image (resulting in 0.00% diff). |
What seems to be a problem for us is that the CI runs on M1, while all our local laptops x86_64. Possibly rendering images changed for one of the architectures in Flutter 3.7. |
In my case it's the opposite: M1 local laptop and Ubuntu x64 on GitHub Actions. But that also sounded to me like a possible reason. |
@jeroen-meijer Do you know if this is something that is caused in the latest Alchemist update, or is related to Flutter itself? |
Thanks for all the additional info everybody :) As far as I'm aware, we didn't push any breaking updates, so this is something we'd need to explore further. Whether it's a discrepancy between M1 vs x86 renders, or it has to do with Flutter 3.7.0 (or both), we'll have to see. I'll discuss with the team but IMO an Alchemist update that allows for a pixel difference might not be a bad idea. I'll let you all know A.S.A.P.! |
hotfix for flutter issues, related to issue #90
Hi there, We discussed this internally. @marcossevilla mentioned the issue might have to do with the new Impeller rendering engine. See this issue for more details: flutter/flutter#119234 We've started working on a temporary Using the temporary version nowWe have yet to finish the tests, update the docs and upload a version to pub.dev, but if you want to try it out in the meantime, change the dev_dependencies:
alchemist:
git:
url: https://github.com/Betterment/alchemist
ref: d57c359ceadeae7ebde51639bcf9fbf37bb5f100 After doing so. you will find a Try it out and let me know how it works for you. |
@jeroen-meijer The diff change works, thanks for the fast update. About that Impeller issue, currently on stable Impeller is not turned on by default, you need to pass |
Thanks for the feedback and the additional info about Impeller. This might take a while, so feel free to use the |
Thanks for the quick workaround. Hopefully, we'll soon know the real cause of this issue! |
just FYI, the problem is mentioned in this issue on flutter's github: It looks like apple's sillicon macs are rendering goldens differently to all other platforms, hence the problem |
hotfix for flutter issues, related to issue #90
I'm getting an error on the newest flutter SDK version, when using the tolerance dev branch on CI:
|
sorry to +1 but.. @jeroen-meijer any update here, we have been using the branch for a while but want to get back onto 3.13 :( I think at this point I would sacrifice my first born for this feature to get merged in. much appreciated~ |
hotfix for flutter issues, related to issue #90
@hampsterx In the meantime, I just rebased that branch onto main so it should be able to work with 3.13. |
I tested with Flutter 3.13.4 and alchemist main branch, I still see the issue on my CI :
Despite running the following command the issue persist :'(
|
On main i cannot see tolerance feature, specially on this file https://github.com/Betterment/alchemist/blob/main/lib/src/alchemist_config.dart |
@EArminjon that's because you should check on branch dev/feat/tolerance |
Perfect , CI fixed :) ! AlchemistConfig get alchemistConfig {
final bool isRunningInCi = Platform.environment.containsKey('MY_CI_VARIABLE');
return AlchemistConfig(
platformGoldensConfig: PlatformGoldensConfig(
enabled: !isRunningInCi,
),
ciGoldensConfig: CiGoldensConfig(
enabled: isRunningInCi,
tolerance: 0.1,
),
);
} LGTM feature until a future fix from Flutter ! |
With the latest commit on that branch and running the tests with ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following _Exception was thrown running a test:
Exception: Failed to set AlchemistFileComparator as the goldenFileComparator.
Since this test has a tolerance value above 0.0, Alchemist must set a custom
comparator to allow for matching goldens with a tolerance value.
However, the current goldenFileComparator is not a LocalFileComparator or
AlchemistFileComparator. Instead, it is a _TestOptimizationAwareGoldenFileComparator.
Alchemist can only set a custom comparator if the current comparator is a
LocalFileComparator or AlchemistFileComparator. User-provided comparators
are currently not supported. Can someone support me? |
Are there any changes? It became necessary for me... |
Any news? |
I experienced the same issue as above. Using the
|
If you don't want to use a forked version of Alchemist and add tolerance; what worked for me is forcing all our Silicon based macs to use the Intel based Flutter version. This is the script I use to download a custom flutter version and putting it in FVM.
You could then run |
@btrautmann any idea when this would land? We have been using the tolerance branch for quite some time already. |
@jeroen-meijer did you have any thoughts about merging tolerance to |
FIY: I have fixed the branche in my fork (and using that one for now) https://github.com/vanlooverenkoen/alchemist/tree/dev/feat/tolerance |
@btrautmann Looking back at this now, I feel that, if people want it, we should allow it. However, I think we should discuss what a For example:
I haven't had time to check @vanlooverenkoen's branch yet, but I wanted to throw these questions out there as food for thought. Anyone in this thread, feel free to chime in how you'd like to use this feature, so we can implement it in a way that works for everyone (especially considering the many changes we've done to Alchemist over the last few months including changes to the config and the addition of the |
My personal preference (and how I believe it's implemented on the aforementioned branch) is that the percentage itself applies on a per-test basis but is configured/set for the entire suite, i.e each test can be "off" by up to the globally configured percentage without failing. This feels the most expected to me. I would probably push back on a per-test tolerance because that actually feels like a pretty big foot gun/maintenance nightmare. To me, the primary use case for this tolerance should be minor platform differences (like the one in this PR which is a 0.64% diff) or quirks in the Flutter framework, neither of which I would expect to be particularly meaningful at the per-test level. If we allowed for a per-test configuration, consumers would be scattering these values all over their test suites. While not "technically" an issue, it just feels like a bit of a headache. Happy to be disagreed with though 😅 |
Got it. Agreed, that makes sense! I don't see how configuring it for an individual test adds that much value, and it might incentivize people to tune the tolerance for each test in such a way that they can get away with a huge diff.
Nit-pick but interesting to think about: Do we want to throw a Also, it looks like we can use @vanlooverenkoen's branch as a foundation for this feature, correct? If so, I'm happy to co-author it if needed, or at least review. |
I actually like this idea. Another idea for the wishlist (not sure if possible), it'd be sweet if we could somehow track the overall test suite status and warn/throw if all tests passed and were below the configured tolerance. This would mean that you could effectively lower your tolerance closer to zero without impacting test success. Note: this would both require a hook for test suite completion/result and us being able to identify only alchemist driven tests. The latter may be easy via tags, but I'm not aware of anything providing notification of test suite completion. RE: the branch, I actually think you and @Kirpal authored the original code which I imagine @vanlooverenkoen |
lmao I'm an idiot, you're right. Sweet 👌🏻 I'll submit a PR somewhere next week at the latest (keeping @vanlooverenkoen's changes in mind, if any).
Great, let's implement it and see what the community thinks.
You mean a system that will basically say "hey, you've allowed your tests to tolerate a 10% diff, but only a 5% diff was detected, so consider lowering your tolerance"? I don't know if such a feature holds a lot of value (since I believe most users who set the tolerance to anything other than However, jumping off of that idea, we could consider creating something like an |
Yeah, my thinking was more the use case of: You bump tolerance to tolerate a particular test/Widget. Later, this Widget is removed but your tolerance stays the same. If left that way, you have extra "buffer" between your suite's actual diff and the tolerated diff but you don't need that buffer. I could see teams wanting to keep that buffer as slim/minimal as possible, and this would allow them to do that. This is similar to linting systems that allow baselining; often they'll have warnings baked in that warn you if you've baselined a lint violation that no longer exists/no longer violates a particular lint rule.
That could be a good compromise/v1. If users then said "would love to have this fail the build when we're not hitting the tolerance" we could always add that in within the same bits of code that produce the report 🤔 |
Is there an existing feature request for this?
Description
Since for the golden tests, you can add a comparator and make some tolerance: flutter/flutter#77014
This option should also be available for Alchemist, ideally in AlchemistConfig.
Reasoning
I wanted to do this as a workaround because our golden test are failing with 0.00% diff (there can be like 1 pixel of difference) since Flutter 3.7.0.
I don't know what's the reason for this failure, I'm not sure it's related to Alchemist so I didn't want to open a bug here.
I don't see how else I can fix this since on my local machine all tests work fine.
Additional context and comments
No response
The text was updated successfully, but these errors were encountered: