Add rules engine types and merchant rule AST helpers - #100389
Add rules engine types and merchant rule AST helpers#100389Krishna2323 wants to merge 25 commits into
Conversation
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
…ategory tax rules Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
…gers Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
|
@codex review |
Review finding
No code changes were made, so no commit or follow-up PR was created. Checks
|
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
|
@luacmartins @JS00001 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] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 76a721a004
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const rule: ImportedMerchantRule = { | ||
| filters: { | ||
| left: 'merchant', | ||
| operator: merchantIsValue ? CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO : CONST.SEARCH.SYNTAX_OPERATORS.CONTAINS, | ||
| operator: formValues.matchType ?? CONST.SEARCH.SYNTAX_OPERATORS.CONTAINS, | ||
| right: merchantToMatch, |
There was a problem hiding this comment.
Convert imported rows to rules-engine payloads
For every valid CSV row this still builds the legacy flat CodingRule shape, but the migrated list/editor only recognize rules-engine records with CreateTransaction triggers and Set actions in the rules_ collection. Thus imports either fail at the legacy endpoint or create rules that this UI cannot display or edit; construct rules-engine bodies (or switch the import endpoint) before reporting the import as successful.
Useful? React with 👍 / 👎.
|
Switching the review to @JmillsExpensify since this is his project. |
|
🤖 Code review of What it does: moves merchant rules off The core design — 🔴 P1 — an unsupported rule is still editable by URL, and saving destroys it
Reach
if (isEditing && existingRule && !isEditableMerchantRule(existingRule) && !isClosing) {
return <NotFoundPage />;
}Test plan §8 covers only the in-app tap path — please add the direct-URL case, and a unit test asserting the route is blocked. 🟠 P2 — tax defaults now show stale values, or vanish
🟡 P3 —
|
|
🤖 Regression hunt on Six regressions, ranked. Two are silent data loss. All line references verified against the branch. The common root cause for #2–#4: merchant rules used to arrive with the policy on 1. 🔴 Revamp table: an unsupported rule opens on a plain click, and saving destroys itThe read-only gate isn't wired up. So with This corrects my earlier review, which said the path needed a deeplink. It needs one click. Bulk select-all is correctly blocked ( Fix: guard the editor itself ( 2. 🔴 Duplicate workspace and Copy settings silently drop merchant rulesThe count doesn't just label the row — it decides whether the row exists. Both flows launch from the workspaces-list three-dot menu, which never mounts any of the three fetching pages. So with an unpopulated collection the count is Scoping caveat: 3. 🟠 Home "Set up rules" checklist flips back to incompleteSame root cause. 4. 🟠 CSV import writes to a location nothing reads any moreThe producing half is unchanged from The PR body predicts a backend rejection, which is one outcome. The other is worse: a legacy-shaped success merges into Two knock-ons either way, since 5. 🟠 The rule lookup lost its policy and kind scoping
Combined with the missing guard from #1, a stale or hand-edited 6. 🟡 A rule with both trigger kinds is deleted when approvals are turned off
Paths I checked and found genuinely safeWorth stating, because these were the scariest surfaces:
Still open — needs a backend answer
Runtime checkBlocked again, for environment reasons rather than anything about this PR. A stale element ref during Control-plan setup landed a click on a help-site link, which navigated the session off the app and killed it before any merchant rule existed. Nothing above is runtime-verified — it is all static analysis, though every line reference was confirmed against the branch. view run · no recording available |
|
@Krishna2323 conflicts |
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
…etRules Signed-off-by: krishna2323 <belivethatkg@gmail.com>
|
This PR adds a new |
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Removing that, sorry for overlooking it. |
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
|
All code-level findings from both reviews are addressed, plus the earlier Codex one on the condition text.
@JS00001, two things for you, one blocker and one that checked out fine. Blocker:
So the rule exists server-side, but nothing ever hydrates the We're calling it with no parameters, as the spec in the issue describes. Does it need a Checked out fine: |
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
I'll look into this |
|
Looks like we weren't returning the response. I have a fix for that. We're also running into one more issue where the number indexed keys ( |
|
More conflicts |
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Conflicts resolved. LMK when this is fixed. |
|
PR open to fix ^ |
Explanation of Change
Fixed Issues
$ #100300
PROPOSAL:
Tests
Setup
Control workspace with Categories, Tags, Taxes, and Rules enabled. Have a second Control workspace ready for §5, §9, and §10. Test with
RULES_REVAMPon, then repeat §1–§3 with it off. Both use the same collection now.1. Create a merchant rule
Starbucks, Match type = Contains, Category = any category. Save.If merchant contains "Starbucks"/Update category to "…".2. Edit a merchant rule
3. Delete a merchant rule
4. All default fields round-trip
Create a rule with merchant rename, category, tag, tax, description, vendor, reimbursable, and billable.
Refresh and reopen. Verify all values are preserved.
false.Clear the description with spaces only. Verify it saves as empty.
5. Multi-workspace scoping⚠️
6. Fetch triggers⚠️
GetRulesdoes not fire onOpenApp.7. Offline and errors
SetRulefailure → verify red error, Rules row red dot, and clean removal after dismissing.8. Unsupported rules stay read-only
Using a hand-made rule with a nested
andtree or multiple merchant comparisons:9. CSV import
10. Duplicate workspace / Copy settings
11. Disabling approvals⚠️
12. Approval workflows regression
Keep the existing five checks, plus:
6. Edit an approval workflow with merchant rules present → verify no merchant rule changes.
7. Remove an approver → verify reconciliation works and merchant rules remain untouched.
13. Category tax defaults
policy.rules.expenseRules.14. Indicators and side effects
Notes
ImportMerchantRulesSpreadsheetshape. Backend failure here is expected until that is resolved.Offline tests
SetRulefailure → verify red error, Rules row red dot, and clean removal after dismissing.QA Steps
Same as tests
Verify that no errors appear in the JS console
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))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.ScrollViewcomponent to make it scrollable when more elements are added to the page.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_hybrid.mp4
Android: mWeb Chrome
android_mWeb.mp4
iOS: Native
ios_hybrid.mp4
iOS: mWeb Safari
ios_mWeb.mp4
MacOS: Chrome / Safari
web_chrome.mp4