Add the overlaps section to Rule health
Closes #5175
Fork pre-flight: jaysbeekay/sure#830 (same branch, same commit).
Stack: #5525 Claims extraction → #5526 Rule health page → #5527 overlaps section → #5528 save-time warning on the rule form (stack #5529). This PR adds item 4 of the issue, Overlaps, the last part not yet in the stack. It was split from #5526 to keep that PR near the ~300-line guide.
Summary
Adds the Overlaps section to the Rule health page: active rules below another that sets the same field on transactions both match ("1 of its 2 matches is also matched by the rule above"), or whose conditions name the same or contained text (a merchant condition read as the merchant's name) with otherwise the same conditions, so uber AND amount > 100 and uber AND amount < 10 are not listed. Pairs already listed as duplicates or conflicts, and shadowed rules, are left out.
What changed
Rule::Health#overlaps, withsame_text?,texts,conditions_besides_textandmerchant_names(commit "Add the overlaps section to Rule health" restores what #5526's branch moved out).same_text?once folded every condition's text, so= Uberand= uberwere listed as the same text although=matches case and the two rules match disjoint transactions. Text is now folded only when one side runs as ILIKE (like,starts_with,ends_with), the same rulecondition_valueuses.rules/_health_report.html.erboverlaps section and itsrules.health.overlaps.*strings. The shared line pluralises on the shared count ("1 of its 2 matches is…", "2 of its 3 matches are…").
Size: 115 non-test lines added.
Deliberately left out
- Scoping
merchant_namesto the family's merchants: declined. The ids come from the family's own rule conditions, the name is only compared as text and never rendered, andfamily.merchantswould drop the provider merchants a merchant condition legitimately names (TransactionMerchant#optionslistsavailable_merchants_for). Scoping throughavailable_merchantsadds a pluck of every transaction's merchant id per report for no exposure. - The shared count reads matches before any rule runs, like the rest of the report; it is advisory, and #5526 holds back the shadowed and match-nothing verdicts where a rule above changes what a rule reads.
Blast radius: who else hits this line, and what do they pass?
same_text?andtextsare read byoverlapshere and byRule::Health#similar_toin #5528, which passes the form's unsaved rule; both get the same case rule.condition_value(duplicates, conflicts) is unchanged here.
Tests
test/models/rule/health_test.rb: the 8 overlap tests moved back from #5526's branch, plus 1 new; rules_controller_test.rb: the report test asserts the overlaps section again, plus 1 new test for the shared line's wording.
| Test | Kind |
|---|---|
| shared transactions on the same field: overlap, 1 of 2 | positive |
| shared transactions, different fields: no overlap | negative |
| "contains uber" vs "= UBER EATS": overlap with 0 shared | positive |
= "Uber" vs = "uber": not the same text (new; failed before the fix: overlap listed with same_text=true) | negative |
| contained text with contradicting amount conditions: no overlap | negative |
| contained text inside an OR group: still the same text | positive |
| merchant condition read by name: overlap; merchant renamed: none | delta |
| contained text, different fields: no overlap | negative |
| same conditions, same value, plus another action: overlap | positive |
| controller: report renders the conflicts, shadowed and overlaps sections | controller |
| controller: shared line reads "1 of its 2 matches is" and "2 of its 3 matches are" (failed before: "1 of its 2 matches are") | wording |
Mutations (container copy only)
| Mutation | Caught by |
|---|---|
| fold text for every operator | = "Uber" vs = "uber" |
| never fold text | merchant condition read by name |
| overlaps ignore the shared field, merchant compared by id, skip every same-conditions pair | run when this code was first written, unchanged since |
Validation
- Full
bin/rails testat 2d521e66d: 18187 runs, 112408 assertions, 0 failures, 8 errors, 9 skips. All 8 errors are environmental:ReleaseNotesWorkflowTest,Errno::ENOENT: node. - Wording fix: the new test failed before it on
1 of its 2 matches is; with theone:form changed back to "are" it fails again. test/system/rules_test.rb: 13 runs, 1 failure (keeps a rule with long text inside a phone-width screen), which fails the same way onmain(9e419e7be) in the same container.bin/rubocopanderb_linton the changed files: no offenses.bin/brakeman: 0 warnings.- Checked against upstream
AGENTS.md(blob 1a5dbebd): no deviations.
Screenshots
Before (#5526's head): Duplicates and Shadowed only. After: the Overlaps section, light, dark and mobile.
| Before | After | |
|---|---|---|
| Light | ![]() | ![]() |
| Dark | ![]() | ![]() |
| Mobile | ![]() | ![]() |
Summary by cubic
Adds the Overlaps section to the Rule health page, completing item 4 of #5175. The page now lists active rules below another that set the same field on transactions both match, or whose conditions name the same or contained text, alongside the existing duplicates, conflicts, shadowed, and match-nothing sections. Pairs already listed as duplicates or conflicts are left out.
- Text comparison is case-sensitive for
=conditions, so= Uberand= uberno longer count as the same text; text is folded only when one side runs as ILIKE (like,starts_with,ends_with). Twostarts_withrules overlap only when one prefix starts with the other, and twoends_withrules likewise for suffixes. - Only required conditions (top-level and in AND groups) are compared, so text alternatives inside OR groups don't keep rules apart; a rule whose required name conditions can't all hold at once — two different exact names, or prefixes or suffixes neither of which extends the other — is not listed. An exact
=text must also pass the other side's contains, starts with, or ends with check. Merchant conditions compare the merchant's id, and rules that require different merchants never overlap. - Shadowed rules are left out entirely, both as the rule below and as the other rule of an overlap.
- The shared line pluralises on the shared match count ("1 of its 2 matches is…" vs "2 of its 3 matches are…").
Summary by CodeRabbit
- New Features
- The rule health report now highlights overlapping active rules that may match the same transactions and affect the same fields.
- Overlap details show affected fields, shared-match counts when available, and whether rules use the same or related text conditions, such as matching or contained text.
- Shadowed or failed rules, and rules already reported as duplicates or conflicts, are excluded from overlap results.





