Repository navigation
[Payment due @aimane-chnaif] [No QA] Fix flaky EditMerchantRulePage guard test - #104828
Conversation
Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
|
@MelvinBot which PR caused this? |
|
Add rules engine types and merchant rule AST helpers ( That PR added both the flaky test and the hook that sends the leaking
Neither the test file nor the hook has changed on Evidence
|
|
@MelvinBot pull main |
…rchantRuleGuardTest Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
|
Merged the latest Only |
Codecov Report✅ All modified and coverable lines are covered by tests. |
|
@MelvinBot mark this PR ready for review |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safaritest.mov |
|
I marked this PR ready for review. The |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
🎯 @aimane-chnaif, thanks for reviewing and testing this PR! 🎉 A payment issue will be created for your review once this PR is deployed to production. If payment is not needed (e.g., regression PR review fix etc), react with 👎 to this comment to prevent the payment issue from being created. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 93276740d3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| }); | ||
|
|
||
| afterEach(async () => { | ||
| readSpy.mockRestore(); |
There was a problem hiding this comment.
Keep the API spy active while clearing Onyx
In the tests that seed either RAM_ONLY_IS_LOADING_RULES or RAM_ONLY_HAS_RULES_DATA_BEEN_FETCHED, the editor is still mounted when this scoped afterEach runs because React Native Testing Library's auto-cleanup is registered in an outer hook. Restoring the spy before Onyx.clear() therefore lets useRulesPrefetch observe those flags reverting to empty and call the real API.read; its asynchronous response can then update Onyx during the following test, preserving the cross-test leak this change is intended to eliminate. Clear or unmount while the spy is still installed, and restore it afterward.
Useful? React with 👍 / 👎.
|
@MelvinBot add |
|
This PR fixes the flake we saw, but it doesn't fully close the leak. One real What is fixed: Every test now stubs What can still leak: Nothing fails today, because the next test does not depend on that flag. But a future test placed after those two could flake the same way. Suggested fix: Restore the spy after the clear: afterEach(async () => {
await act(async () => {
await Onyx.clear();
});
readSpy.mockRestore();
});Why the editor is still mounted
I checked this by reading the code. I did not run the suite. Reply |
|
@MelvinBot address #104828 (comment), #104828 (comment) |
|
I added Investigate workflow job failing on main: test / test (job 8) to the Fixed Issues section: |
Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
|
@shubham1206agra @roryabraham One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
I applied the
I couldn't run Jest locally, so CI will confirm the test passes. |
|
🚀 Deployed to staging by https://github.com/roryabraham in version: 9.5.21-0 🚀
|
|
🚀 Deployed to staging by https://github.com/roryabraham in version: 9.5.23-0 🚀
|
|
🚀 Deployed to production by https://github.com/jasperhuangg in version: 9.5.23-3 🚀
Bundle Size Analysis (Sentry): |
|
🤖 Payment issue created: #105186 |
Explanation of Change
tests/ui/EditMerchantRulePageGuardTest.tsx› "fetches the rules collection when it is reached without one loaded" fails intermittently onmainwithNumber of calls: 0forGetRules(for example, test / test (job 8)). The runs merged immediately before and after it pass.Why it flakes:
API.read. The other tests (which seed a rule) mount the editor, anduseRulesPrefetchsends a realGetRules. The default Jest fetch mock answers it withjsonCode: 200, so itssuccessDatasetsRAM_ONLY_HAS_RULES_DATA_BEEN_FETCHED: true.waitForWritesand the network middleware chain, so its response can land after the next test has already cleared Onyx. When it lands during the fetch test, the hook sees the collection as already fetched and never sendsGetRules.GetRulesonly goes out after the fetch flags load from Onyx and the effect runs.The fix:
API.readinbeforeEach(and restore it inafterEach) for every test in the file, so no realGetRulesresponse can leak into a later test.GetRulesassertion inwaitFor.This is a test-only change. App code is unchanged.
Fixed Issues
$ #104806
PROPOSAL:
Tests
// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review"
// Please describe what tests you performed that validates your changed worked.
Offline tests
QA Steps
// TODO: The human co-author must fill out the QA tests you ran before marking this PR as "ready for review".
// Please describe what QA needs to do to validate your changes and what areas do they need to test for regressions.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari